summaryrefslogtreecommitdiff
path: root/dh_illumos_gate
blob: 10a228a2ca5a6a23bcb45f349b5913c86a3d02ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/perl -w

=head1 NAME

dh_illumos_gate - unpack and prepare illumos sources

=cut

use strict;
use Debian::Debhelper::Dh_Lib;
use Dpkg::Changelog::Parse;
use Cwd;

=head1 SYNOPSIS

B<dh_illumos_gate> [S<I<debhelper options>>] [B<-X>I<PATTERN>]

=head1 DESCRIPTION

C<dh_illumos_gate> is responsible for unpacking illumos sources and adjusting the sources
for Debian build environment (paths to programs, command options, linker and compiler flags, etc.).

It unpacks illumos gate sources, creates F<bldenv.sh> and F<env.sh>
in the root of source tree, configures build environment in F<env.sh>.

Sources are always unpacked into F<illumos-gate> subdirectory of the current directory.

After executing C<dh_illumos_gate> one can use commands like this to configure or build
components of illumos gate:

    cd illumos-gate
    ksh93 bldenv.sh env.sh -c "cd usr/src/lib/libzfs && /usr/bin/sunmake install"

L<dh_illumos_make(1)> provides more convenient way to do this.

=head1 FILES

=over 4

=item /usr/src/illumos-gate/illumos-gate.tar.xz

This file contains recent complete and unmodified illumos sources.
It is provided by package I<illumos-source>.

=back

=head1 OPTIONS

=over 4

=item B<-X>I<PATTERN> B<--exclude=>I<PATTERN>

By default C<dh_illumos_gate> unpack the whole archive of illumos sources.
Use this options to exclude some parts. For example, if you are building
illumos kernel (F<usr/src/uts>), you do not need libraries or programs and
use F<-XI<usr/src/lib>> F<-XI<usr/src/cmd>>. These options passed
as is to L<tar(1)> via I<--exclude=PATTERN>.

=back

=head1 DETAILS

Here are things which this helper does after unpacking illumos sources.

=over 4

=cut

init(options => { 
    });

# XXX Only illumos-amd64 is supported now XXX
my $multiarch64 = `dpkg-architecture -aillumos-amd64 -qDEB_HOST_MULTIARCH`;
chomp $multiarch64;
# These vars go into makefile:
my $rootfs_libdir   = "\$(ROOT)/lib32";
my $rootfs_libdir64 = "\$(ROOT)/lib/$multiarch64";
my $rootlibdir      = "\$(ROOT)/usr/lib32";
my $rootlibdir64    = "\$(ROOT)/usr/lib/$multiarch64";
my $Makefile_master = 'illumos-gate/usr/src/Makefile.master';

my $tarball = '/usr/src/illumos-gate/illumos-gate.tar.xz';
my $changelogfile = 'debian/changelog';

my @tar_X = ();
if (defined($dh{'EXCLUDE'}) && $dh{'EXCLUDE'}) {
    foreach my $x (@{$dh{'EXCLUDE'}}) {
        push @tar_X, '--exclude';
        push @tar_X, $x;
    }
}

doit('tar', '-x', '-f', $tarball, @tar_X);

=item Saving original files

Any files from illumos sources, changed by this helper,
are saved with F<.orig> suffix, so you can investigate changes.
For example, you can use C<cd illumos-gate && diff -dub usr/src/Makefile.master.orig usr/src/Makefile.master>
to see all changes.

=cut

=item Changes to F<illumos-gate/usr/src/Makefile.master>:

Remove option C<-s> (strip) from install command for directories and files.
This options does not make sense for directories and GNU L<install(1)> is
not tolerant here. Also replace option C<-f> with C<-t>.

=cut

my $Makefile_master_orig = $Makefile_master . '.orig';
if (! -f $Makefile_master) {
    error("Could not find `$Makefile_master'. Is it accidently excluded via -X option?");
}
if (! -e $Makefile_master_orig) {
    doit('cp', '-f', $Makefile_master, $Makefile_master_orig);
}

doit('sed', '-r', '-i', '
    /^INS\.(file|dir)/ s, -s,,;
    /^INS\.file/ s, -f, -t,;
    ', $Makefile_master
);


=item Changes to F<illumos-gate/usr/src/lib/Makefile.lib>:

Append C<CFLAGS> to C<BUILD.SO> command, because C<BUILD.SO>
by default uses C compiler to create shared library.

Set C<ROOTLIBDIR>, C<ROOTLIBDIR64>, C<ROOTFS_LIBDIR> and C<ROOTLIBDIR64>
to match Debian multiarch layout. For example C<ROOTLIBDIR64> =
F</usr/lib/x86_64-illumos> and C<ROOTFS_LIBDIR> = F</lib32> on I<illumos-amd64>.
It cannot be done in environment file F<env.sh> (see below), because
in some cases C<ROOTLIBDIR> will be overriden by C<ROOTFS_LIBDIR> within makefiles.

=cut

my $Makefile_lib = 'illumos-gate/usr/src/lib/Makefile.lib';
my $Makefile_lib_orig = $Makefile_lib . '.orig';
if (-f $Makefile_lib) {
    if (! -e $Makefile_lib_orig) {
        doit('cp', '-f', $Makefile_lib, $Makefile_lib_orig);
    }
    doit('sed', '-r', '-i', '
        /^BUILD.SO/ s,\$\(CC\),$(CC) $(CFLAGS),;
        ', $Makefile_lib
    );
    doit('sed', '-r', '-i', "
        s,^(ROOTFS_LIBDIR)\\s*=.*,\\1=$rootfs_libdir,;
        s,^(ROOTFS_LIBDIR64)\\s*=.*,\\1=$rootfs_libdir64,;
        s,^(ROOTLIBDIR)\\s*=.*,\\1=$rootlibdir,;
        s,^(ROOTLIBDIR64)\\s*=.*,\\1=$rootlibdir64,;
        ", $Makefile_lib
    );
}

=item Create F<illumos-gate/env.sh>

Set C<CODEMGR_WS> to be C<current_dir/illumos-gate>.

Set C<VERSION> to be C<source_version> by parsing F<./debian/chnagelog>.
For example it can be C<uts_5.11.0-15>.

Set C<LD_ALTEXEC=/usr/bin/ld-gnu-to-sun> to call L<sunld(1)>
instead of GNU L<ld(1)>. Default system GCC is build to use GNU L<ld(1)>,
but L<sunld(1)> is required to build most illumos components.
See L<ld-gnu-to-sun(1)>.

Set proto area to be F<./debian/tmp>.

Disable C<lint> libraries by replacing C<LINT> with ":".
So it will do nothing. Successfully. Also define C<LINTLIB> to empty
string to prevent installation of lint library (which does not exist).

Enable GCC and GCC4 mode by defining C<__GNUC> and C<__GNUC4>.

Change GCC root to F</usr>, so the default system compiler is used.

Define C<i386_XARCH='-m32'> since illumos sources
expect default compiler to generate 32-bit code.

Define C<LEX> to be C</usr/bin/flex -l>.

=cut


my %options = (file => $changelogfile);
my $changelog = changelog_parse(%options);
my $version = $changelog->{'Source'} . '_' . $changelog->{'Version'};

my $cwd = getcwd();
my $env = 'illumos-gate/env.sh';
my $mach = `uname -p`; chomp $mach;
if (open (ENV, '>', $env)) {
    print ENV "# This file was generated by dh_illumos_gate(1)\n";
    print ENV "export VERSION='$version'\n";
    print ENV "export CODEMGR_WS='$cwd/illumos-gate'\n";
    print ENV "export ROOT='$cwd/debian/tmp'\n";
    print ENV "export SRC='$cwd/illumos-gate/usr/src'\n";
    print ENV "export MULTI_PROTO='no'\n";
    print ENV "export CW_NO_SHADOW=1\n";
    print ENV "export LD_ALTEXEC='/usr/bin/ld-gnu-to-sun'\n";
    print ENV "export BUILD_TOOLS='/opt'\n";
    print ENV "export MACH='$mach'\n";
    print ENV "export LINT=:\n";
    print ENV "export LINTLIB=''\n";
    print ENV "export __GNUC=''\n";
    print ENV "export __GNUC4=''\n";
    print ENV "export GCC_ROOT='/usr'\n";
    print ENV "export i386_XARCH='-m32'\n";
    print ENV "export LEX='/usr/bin/flex -l'\n";
    print ENV "export STRIP=':'\n";

    close(ENV);
} else {
    error("Failed to write `$env': $!");
}

=item Create F<illumos-gate/bldenv.sh>

Copy F<illumos-gate/usr/src/tools/scripts/bldenv.sh>
to F<illumos-gate/bldenv.sh>.

Fix definition of C<CTF*> variables, so this script will
not override them if they are already defined. These variables
can be set to ":", when executing L<dh_illumos_make(1)>
with option C<--without-ctf>.

=cut

my $bldenv_sh = 'illumos-gate/usr/src/tools/scripts/bldenv.sh';
if (! -f $bldenv_sh) {
    error("Could not find `$bldenv_sh'. Is it accidently excluded via -X option?");
}
doit('cp', '-f', $bldenv_sh, 'illumos-gate/bldenv.sh');
doit('sed', '-r', '-i', '
    s,export +(CTF.+)="(.+)",export \1="${\1:-\2}",;
    ', 'illumos-gate/bldenv.sh'
);

=back

=head1 NOTES

To clean package (via C<./debian/rules clean>) you should just remove F<illumos-gate> directory:

    rm -rf illumos-gate


=head1 SEE ALSO

L<debhelper(7)>, L<dh_illumos_make(1)>.

=head1 AUTHOR

Igor Pashev <pashev.igor@gmail.com>

=cut