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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
#!/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<-B>] [B<-X>I<PATTERN>] [-- [tar options]]
[files and/or directories to extract]
=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.).
C<dh_illumos_gate> extracts given files or directories, if any.
Otherwise it extracts entire F<illumos-gate/usr/>.
In any case B<-X> option can be used to exclude some files or directories,
and top directory F<illumos-gate> is always stripped..
If files interested to C<dh_illumos_gate> are unpacked they will be configured.
See L</DETAILS>.
After executing C<dh_illumos_gate> one can use commands like this to configure or build
components of illumos gate:
ksh93 usr/bldenv.sh usr/env.sh -c "cd usr/src/lib/libzfs && make --sun install"
L<dh_illumos_make(1)> provides more convenient way to do this.
=head1 OPTIONS
=over 4
=item B<-B> B<--build>
Extract files known to be required for building illumos components.
These are F<usr/src/tools/scripts/bldenv.sh>, F<usr/src/Makefile*>,
F<usr/src/common/mapfiles/*>. If any file under F<usr/src/lib> is
requested, F<usr/src/lib/Makefile*> are extracted too. Same for
F<usr/src/cmd>. This option is provided only for convenience.
You are free to extract these files explicitly.
=item B<-X>I<PATTERN> B<--exclude=>I<PATTERN>
Do not extract files or directories matching I<PATTERN>.
This option can be used multiple times. I<PATTERN> is passed
as is to L<tar(1)> via I<--exclude=PATTERN>.
=back
=head1 EXAMPLES
=over 4
=item Unpack and configure the whole illumos source tree (F<usr/>)
dh_illumos_gate
=item Unpack and configure whole illumos source tree, but F<usr/src/uts/>
dh_illumos_gate -X usr/src/uts
=item Unpack and configure whole illumos source tree, but F<usr/src/uts/>;
then add F<usr/src/uts/common/sys/>
dh_illumos_gate -X usr/src/uts
dh_illumos_gate usr/src/uts/common/sys
=item Unpack all Makefiles under F<usr/src/>
dh_illumos_gate usr/src/Makefile\*
=item Unpack all header files under F<usr/src/uts>
dh_illumos_gate -- --wildcards-match-slash usr/src/uts/*.h
=back
=head1 FILES
=over 4
=item /usr/src/illumos-gate/illumos-gate-$(VER).tar.xz
This file contains complete and unmodified illumos sources.
It is provided by package I<illumos-source-$(VER)>.
Version C<$(VER)> is determined from F<debian/changelog>:
(\d+\.\d+).* => \1, e. g.:
2.10+3 => VER = 2.10
=back
=head1 DETAILS
Here are things which this helper does after unpacking illumos sources.
=over 4
=cut
init(options => {
"build|B" => \$dh{BUILD},
});
my %options = (file => 'debian/changelog');
my $changelog = changelog_parse(%options);
my $version = $changelog->{'Version'};
my $VER;
if ($version =~ /^(\d+\.\d+).*$/) {
$VER = $1;
} else {
error("Could not determine illumos source version from changelog. "
."It should be like 2.10+1, but it is '$version'");
}
my $tarball = "/usr/src/illumos-gate/illumos-gate-$VER.tar.xz";
if (! -f $tarball) {
error("$tarball does not exist. You might not have package illumos-source-$VER "
."installed or have a typo in debian/changelog");
}
my @tar_X = ();
if (defined($dh{'EXCLUDE'}) && $dh{'EXCLUDE'}) {
foreach my $x (@{$dh{'EXCLUDE'}}) {
push @tar_X, '--exclude';
push @tar_X, $x;
}
}
my @to_extract = ();
if (@ARGV) {
if ($dh{'BUILD'}) {
push @to_extract, (
'usr/src/Makefile*',
'usr/src/common/mapfiles',
'usr/src/tools/scripts/bldenv.sh',
);
if (grep {m|.*usr/src/lib/.*|} @ARGV) {
push @to_extract, 'usr/src/lib/Makefile*'
}
if (grep {m|.*usr/src/cmd/.*|} @ARGV) {
push @to_extract, 'usr/src/cmd/Makefile*'
}
}
push @to_extract, map {m,(?:illumos-gate/)?(.*),; $1} @ARGV;
} else {
push @to_extract, 'usr';
}
my @to_extract_real = ();
foreach my $p (@to_extract) {
if ($p =~ /^-/) {
push @to_extract_real, $p; #XXX: tar option
} else {
push @to_extract_real, 'illumos-gate/' . $p; #XXX: path
}
}
doit('tar', '-x', '-f', $tarball, @tar_X, '--wildcards', '--strip-components=1', @to_extract_real);
=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<diff -dub usr/src/Makefile.master.orig usr/src/Makefile.master>
to see all changes.
=cut
=item Changes to F<usr/src/Makefile.master> (if extracted):
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>.
Append C<i386_XARCH> with C<-m32> since native host compiler can produce 64-bit
code by default.
Explicitly undefine some CPP macros related to amd64 for building 32-bit
objects, e. i. options like C<-U__amd64> are appended to C<i386_XARCH>
and C<i386_AS_XARCH>.
C<i386_AS_XARCH> flags are appended to C<COMPILE.s> command.
Delete (set to empty) variable C<MAPFILE.LEX>, cause we are not
using shared lex library (F<libl.so.1>), but static Flex
library (libl.a).
In variables C<OFFSETS_CREATE> and C<OFFSETS_CREATE64> replace
variables C<$(CTFSTABS)> and C<$(CTFCONVERT)> with explicit
F<ctfstabs> and F<ctfconvert>, because those variables are
empty when building without CTF, but creating offsets
really requires CTF data. This is used when compiling libc and
illumos kernel.
=cut
my $multiarch = `dpkg-architecture -qDEB_HOST_MULTIARCH`;
chomp $multiarch;
my $bits = `dpkg-architecture -qDEB_HOST_ARCH_BITS`;
chomp $bits;
# In illumos source 32-bit binaries are default
my ($libdir32, $libdir64, $usrlibdir32, $usrlibdir64);
if ($bits == 64) {
$libdir32 = "lib32";
$usrlibdir32 = "usr/$libdir32";
$libdir64 = "lib/$multiarch";
$usrlibdir64 = "usr/$libdir64";
} else {
$libdir32 = "lib/$multiarch";
$usrlibdir32 = "usr/$libdir32";
$libdir64 = "lib64";
$usrlibdir64 = "usr/$libdir64";
}
my $Makefile_master = 'usr/src/Makefile.master';
my $Makefile_master_orig = $Makefile_master . '.orig';
if (-f $Makefile_master) {
if (! -e $Makefile_master_orig) {
doit('cp', '-f', $Makefile_master, $Makefile_master_orig);
}
# Be careful with modern CPP:
my $i386_undef = '-Uamd64 -U__amd64 -U__amd64__ -U__x86_64__ -U__x86_64 -U_LP64';
doit('sed', '-r', '-i', '
/^INS\.(file|dir)/ s, -s,,;
/^INS\.file/ s, -f, -t,;
/^i386_XARCH\s*=/s,$, -m32 ' . $i386_undef . ',;
/^i386_AS_XARCH\s*=/s,$, ' . $i386_undef . ',;
/^COMPILE\.s/s,$, $($(MACH)_AS_XARCH),;
/^MAPFILE.LEX/d;
/^OFFSETS_CREATE/ s,\$\(CTFSTABS\),ctfstabs,;
/^OFFSETS_CREATE/ s,\$\(CTFCONVERT\),ctfconvert,;
', $Makefile_master
);
}
=item Changes to F<usr/src/lib/Makefile.lib> (if extracted):
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 = '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=\$(ROOT)/$libdir32,;
s,^(ROOTFS_LIBDIR64)\\s*=.*,\\1=\$(ROOT)/$libdir64,;
s,^(ROOTLIBDIR)\\s*=.*,\\1=\$(ROOT)/$usrlibdir32,;
s,^(ROOTLIBDIR64)\\s*=.*,\\1=\$(ROOT)/$usrlibdir64,;
", $Makefile_lib
);
}
=item Changes to F<usr/src/cmd/Makefile.cmd> (if extracted):
Remove trailing spaces in the line C<TEXT_DOMAIN= SUNW_OST_OSCMD >
Maybe we should patch GNU make to do it for us in SunOS mode.
Remove linker flag for setting ELF interpreter (-Wl,-I/lib/ld.so.1)
=cut
my $Makefile_cmd = 'usr/src/cmd/Makefile.cmd';
my $Makefile_cmd_orig = $Makefile_cmd . '.orig';
if (-f $Makefile_cmd) {
if (! -e $Makefile_cmd_orig) {
doit('cp', '-f', $Makefile_cmd, $Makefile_cmd_orig);
}
doit('sed', '-r', '-i', '
/^TEXT_DOMAIN/ s,\s+$,,g;
', $Makefile_cmd
);
doit('sed', '-r', '-i', '
/LDFLAGS\s*\+=\s*-Wl,-I\/lib\/ld\.so\.1/d;
', $Makefile_cmd
);
}
=item Create F<usr/env.sh> (if F<usr> exists and F<usr/env.sh> does not)
Set C<CODEMGR_WS> to the current directry.
Set C<VERSION> from F<./debian/changelog>.
For example it can be C<2.10-3>.
Set C<LD_ALTEXEC>=F</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 linting libraries by replacing C<LINT> with ":".
So it will do nothing. Successfully. Also define C<LINTLIB> to empty
string to prevent installation of lint libraries (which do not exist).
Disable modifying comment section of ELFs by replacing C<MCS> with ":".
Disable stripping by replacing C<STRIP> with ":".
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<LEX> to be C</usr/bin/flex -l>.
Export all C<DEB_*> variables (using C<dpkg-architecture -s>)
to make them available from makefiles.
=cut
if ( -d 'usr' && ! -f 'usr/env.sh') {
my $cwd = getcwd();
my $env = 'usr/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'\n";
print ENV "export ROOT='$cwd/debian/tmp'\n";
print ENV "export SRC='$cwd/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 CW_GCC=gcc\n";
print ENV "export SAVEARGS=\n";
print ENV "export LEX='/usr/bin/flex -l'\n";
print ENV "export STRIP=':'\n";
print ENV "export MCS=':'\n";
print ENV "export DEB_LIBDIR_32='/$libdir32'\n";
print ENV "export DEB_USRLIBDIR_32='/$usrlibdir32'\n";
print ENV "export DEB_LIBDIR_64='/$libdir64'\n";
print ENV "export DEB_USRLIBDIR_64='/$usrlibdir64'\n";
print ENV "export LDLIBS32=\"-YP,\$ROOT/\$DEB_LIBDIR_32:\$ROOT/\$DEB_USRLIBDIR_32\"\n";
print ENV "export LDLIBS64=\"-YP,\$ROOT/\$DEB_LIBDIR_64:\$ROOT/\$DEB_USRLIBDIR_64\"\n";
print ENV 'export LDLIBS_NATIVE="', ($bits == 64) ? '$LDLIBS64' : '$LDLIBS32', "\"\n";
print ENV `dpkg-architecture -s`;
close(ENV);
} else {
error("Failed to write `$env': $!");
}
}
=item Create F<usr/bldenv.sh> (if not exists and F<usr/src/tools/scripts/bldenv.sh> extracted)
Copy F<usr/src/tools/scripts/bldenv.sh>
to F<usr/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 = 'usr/src/tools/scripts/bldenv.sh';
if (-f $bldenv_sh && ! -f 'usr/bldenv.sh') {
doit('cp', '-f', $bldenv_sh, 'usr/bldenv.sh');
doit('sed', '-r', '-i', '
s,export +(CTF.+)="(.+)",export \1="${\1:-\2}",;
s,^PATH=".+",PATH="${PATH}:/opt/onbld/bin:/opt/onbld/bin/${MACH}:.",;
', 'usr/bldenv.sh'
);
}
=back
=head1 NOTES
To clean package (via C<./debian/rules clean>) you should just remove F<usr/> directory:
rm -rf usr
C<dh_illumos_gate --build> will fail if extracting files which should be extracted
due to option C<--build>. This is a L<tar(1)> issue (tar: ...: Not found in archive).
For example, this will fail:
dh_illumos_gate --build usr/src/cmd usr/src/lib/Makefile.lib
Workaround:
dh_illumos_gate --build usr/src/cmd
dh_illumos_gate usr/src/lib/Makefile.lib
=head1 SEE ALSO
L<debhelper(7)>, L<dh_illumos_make(1)>.
=head1 AUTHOR
Igor Pashev <pashev.igor@gmail.com>
=cut
|