#!/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 [S>] [B<-X>I] =head1 DESCRIPTION C 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 and F in the root of source tree, configures build environment in F. Sources are always unpacked into F subdirectory of the current directory. After executing C 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 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. =back =head1 OPTIONS =over 4 =item B<-X>I B<--exclude=>I By default C unpack the whole archive of illumos sources. Use this options to exclude some parts. For example, if you are building illumos kernel (F), you do not need libraries or programs and use F<-XI> F<-XI>. These options passed as is to L 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 to see all changes. =cut =item Changes to F: Remove option C<-s> (strip) from install command for directories and files. This options does not make sense for directories and GNU L 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: Append C to C command, because C by default uses C compiler to create shared library. Set C, C, C and C to match Debian multiarch layout. For example C = F and C = F on I. It cannot be done in environment file F (see below), because in some cases C will be overriden by C 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 Set C to be C. Set C to be C by parsing F<./debian/chnagelog>. For example it can be C. Set C to call L instead of GNU L. Default system GCC is build to use GNU L, but L is required to build most illumos components. See L. Set proto area to be F<./debian/tmp>. Disable C libraries by replacing C with ":". So it will do nothing. Successfully. Also define C 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, so the default system compiler is used. Define C since illumos sources expect default compiler to generate 32-bit code. Define C to be C. =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 Copy F to F. Fix definition of C variables, so this script will not override them if they are already defined. These variables can be set to ":", when executing L 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 directory: rm -rf illumos-gate =head1 SEE ALSO L, L. =head1 AUTHOR Igor Pashev =cut