[93] | 1 | #!/usr/bin/perl -w
|
---|
[2] | 2 | # debbuild script
|
---|
[86] | 3 | # Shamelessly steals interface from rpm's "rpmbuild" to create
|
---|
[2] | 4 | # Debian packages. Please note that such packages are highly
|
---|
| 5 | # unlikely to conform to "Debian Policy".
|
---|
| 6 | ###
|
---|
| 7 | # SVN revision info
|
---|
| 8 | # $Date: 2012-10-16 20:53:33 +0000 (Tue, 16 Oct 2012) $
|
---|
| 9 | # SVN revision $Rev: 174 $
|
---|
| 10 | # Last update by $Author: kdeugau $
|
---|
| 11 | ###
|
---|
[163] | 12 | # Copyright (C) 2005-2012 Kris Deugau <kdeugau@deepnet.cx>
|
---|
[56] | 13 | #
|
---|
| 14 | # This program is free software; you can redistribute it and/or modify
|
---|
| 15 | # it under the terms of the GNU General Public License as published by
|
---|
| 16 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 17 | # (at your option) any later version.
|
---|
| 18 | #
|
---|
| 19 | # This program is distributed in the hope that it will be useful,
|
---|
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 22 | # GNU General Public License for more details.
|
---|
| 23 | #
|
---|
| 24 | # You should have received a copy of the GNU General Public License
|
---|
| 25 | # along with this program; if not, write to the Free Software
|
---|
| 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
[2] | 27 |
|
---|
[5] | 28 | use strict;
|
---|
[6] | 29 | use warnings;
|
---|
[7] | 30 | use Fcntl; # for sysopen flags
|
---|
[36] | 31 | use Cwd 'abs_path'; # for finding where files really are
|
---|
[113] | 32 | use Config;
|
---|
[5] | 33 |
|
---|
[163] | 34 | my $version = "0.9"; #VERSION#
|
---|
| 35 |
|
---|
[10] | 36 | # regex debugger
|
---|
| 37 | #use re "debug";
|
---|
| 38 |
|
---|
[163] | 39 | # Behavioural compatibility FTW! Yes, rpmbuild does this too.
|
---|
[130] | 40 | die "No .spec file to work with! Exiting.\n" if scalar(@ARGV) == 0;
|
---|
| 41 |
|
---|
[3] | 42 | # Program flow:
|
---|
| 43 | # -> Parse/execute "system" config/macros (if any - should be rare)
|
---|
| 44 | # -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
|
---|
| 45 | # -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
|
---|
| 46 |
|
---|
[30] | 47 | sub expandmacros;
|
---|
| 48 |
|
---|
[2] | 49 | # User's prefs for dirs, environment, etc,etc,etc.
|
---|
| 50 | # config file ~/.debmacros
|
---|
| 51 | # Default ordered search paths for config/macros:
|
---|
| 52 | # /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
|
---|
| 53 | # /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
|
---|
| 54 | # **NOTE: May be possible to (ab)use bits of debhelper
|
---|
| 55 |
|
---|
| 56 | # Build tree
|
---|
| 57 | # default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
|
---|
| 58 |
|
---|
[3] | 59 | # Globals
|
---|
[77] | 60 | my $finalmessages = ''; # A place to stuff messages that I want printed at the *very* end of any processing.
|
---|
[3] | 61 | my $specfile;
|
---|
| 62 | my $tarball;
|
---|
| 63 | my $srcpkg;
|
---|
[7] | 64 | my $cmdbuildroot;
|
---|
[95] | 65 | my $tarballdir = '%{name}-%{version}'; # We do this in case of a spec file not using %setup...
|
---|
[23] | 66 | my %specglobals; # For %define's in specfile, among other things.
|
---|
[6] | 67 |
|
---|
[98] | 68 | $specglobals{'_vendor'} = 'debbuild';
|
---|
[148] | 69 | $specglobals{'vendor'} = 'debbuild';
|
---|
[98] | 70 |
|
---|
[6] | 71 | # Initialized globals
|
---|
[3] | 72 | my $verbosity = 0;
|
---|
[112] | 73 | my $NoAutoReq = 0;
|
---|
[4] | 74 | my %cmdopts = (type => '',
|
---|
| 75 | stage => 'a',
|
---|
| 76 | short => 'n'
|
---|
| 77 | );
|
---|
[6] | 78 | my $topdir = "/usr/src/debian";
|
---|
[136] | 79 | #my $specglobals{buildroot} = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
|
---|
[170] | 80 | $specglobals{buildroot} = '%{_topdir}/BUILDROOT/%{name}-%{version}-%{release}';
|
---|
[6] | 81 |
|
---|
| 82 | # "Constants"
|
---|
[4] | 83 | my %targets = ('p' => 'Prep',
|
---|
| 84 | 'c' => 'Compile',
|
---|
| 85 | 'i' => 'Install',
|
---|
| 86 | 'l' => 'Verify %files',
|
---|
| 87 | 'a' => 'Build binary and source',
|
---|
| 88 | 'b' => 'Build binary',
|
---|
| 89 | 's' => 'Build source'
|
---|
| 90 | );
|
---|
[87] | 91 | # Ah, the joys of multiple architectures. :( Feh.
|
---|
| 92 | # As copied from rpm
|
---|
| 93 | my %optflags = ( 'i386' => '-O2 -g -march=i386 -mcpu=i686',
|
---|
| 94 | 'amd64' => '-O2 -g'
|
---|
| 95 | );
|
---|
| 96 | my $hostarch; # we set this later...
|
---|
[6] | 97 | my $scriptletbase =
|
---|
[169] | 98 | q(#!/bin/bash
|
---|
[3] | 99 |
|
---|
[6] | 100 | RPM_SOURCE_DIR="%{_topdir}/SOURCES"
|
---|
| 101 | RPM_BUILD_DIR="%{_topdir}/BUILD"
|
---|
[87] | 102 | RPM_OPT_FLAGS="%{optflags}"
|
---|
| 103 | RPM_ARCH="%{_arch}"
|
---|
[6] | 104 | RPM_OS="linux"
|
---|
| 105 | export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
|
---|
| 106 | RPM_DOC_DIR="/usr/share/doc"
|
---|
| 107 | export RPM_DOC_DIR
|
---|
| 108 | RPM_PACKAGE_NAME="%{name}"
|
---|
| 109 | RPM_PACKAGE_VERSION="%{version}"
|
---|
| 110 | RPM_PACKAGE_RELEASE="%{release}"
|
---|
| 111 | export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
|
---|
| 112 | RPM_BUILD_ROOT="%{buildroot}"
|
---|
| 113 | export RPM_BUILD_ROOT
|
---|
[10] | 114 | );
|
---|
| 115 | foreach (`dpkg-architecture`) {
|
---|
| 116 | s/=(.+)/="$1"/;
|
---|
| 117 | $scriptletbase .= " $_";
|
---|
[90] | 118 | ($hostarch) = (/^DEB_HOST_ARCH="(.+)"$/) if /DEB_HOST_ARCH=/;
|
---|
[10] | 119 | }
|
---|
| 120 | $scriptletbase .=
|
---|
| 121 | q(
|
---|
[6] | 122 | set -x
|
---|
| 123 | umask 022
|
---|
| 124 | cd %{_topdir}/BUILD
|
---|
| 125 | );
|
---|
| 126 |
|
---|
[102] | 127 | # Hackery to try to bring some semblance of sanity to packages built for more
|
---|
| 128 | # than one Debian version at the same time. Whee.
|
---|
[163] | 129 | # /etc/debian-version and/or version of base-files package
|
---|
[102] | 130 | my %distmap = (
|
---|
| 131 | "3.1.9ubuntu7.1" => "dapper",
|
---|
| 132 | "4ubuntu2" => "feisty",
|
---|
| 133 | "3.0" => "woody",
|
---|
| 134 | "3.1" => "sarge",
|
---|
| 135 | "4" => "etch",
|
---|
[151] | 136 | "5" => "lenny",
|
---|
[162] | 137 | "6.0" => "squeeze",
|
---|
| 138 | "7.0" => "wheezy", #maybe?
|
---|
[151] | 139 | "99" => "sid");
|
---|
[102] | 140 | # Enh. There doesn't seem to be any better way to do this... :(
|
---|
| 141 | {
|
---|
[151] | 142 | # could theoretically also do something with this... it's about as stable as "dpkg-query ..." below... :(
|
---|
| 143 | # my $releasever = qx { cat /etc/debian_version };
|
---|
| 144 | # chomp $releasever;
|
---|
| 145 | my $basever;
|
---|
[102] | 146 |
|
---|
[151] | 147 | if ( ! -e '/usr/bin/dpkg-query' ) {
|
---|
| 148 | # call it woody, since sarge and newer have dpkg-query, and we don't much care about obsolete^n releases
|
---|
| 149 | $basever = "3.0";
|
---|
| 150 | } else {
|
---|
| 151 |
|
---|
[162] | 152 | # *eyeroll* there *really* has to be a better way to go about this. You
|
---|
| 153 | # can't sanely build packages for multiple distro targets if you can't
|
---|
| 154 | # programmatically figure out which one you're building on.
|
---|
| 155 |
|
---|
| 156 | # note that we care only about major release numbers; tracking minor or point
|
---|
| 157 | # releases would be... exponentially more painful.
|
---|
| 158 |
|
---|
[151] | 159 | # for the lazy copy-paster: dpkg-query --showformat '${version}\n' -W base-files
|
---|
| 160 | # avoid shellisms
|
---|
| 161 | if (open BASEGETTER, "-|", "dpkg-query", "--showformat", '${version}', "-W", "base-files") {
|
---|
| 162 | $basever = <BASEGETTER>;
|
---|
| 163 | close BASEGETTER;
|
---|
| 164 |
|
---|
[162] | 165 | ($basever) = ($basever =~ /^(\d(?:\.\d)?)/);
|
---|
[151] | 166 | }
|
---|
| 167 |
|
---|
| 168 | } # got dpkg-query?
|
---|
| 169 |
|
---|
[102] | 170 | $specglobals{"debdist"} = $distmap{$basever};
|
---|
[151] | 171 | $specglobals{"debver"} = $basever; # this may have trouble with Ubuntu versions?
|
---|
[102] | 172 |
|
---|
[151] | 173 | } # done trying to set debian dist/version
|
---|
| 174 |
|
---|
[5] | 175 | # Package data
|
---|
| 176 | # This is the form of $pkgdata{pkgname}{meta}
|
---|
| 177 | # meta includes Summary, Name, Version, Release, Group, Copyright,
|
---|
[138] | 178 | # Source, URL, Packager, BuildRoot, Description, BuildRequires,
|
---|
[38] | 179 | # Requires, Provides
|
---|
[6] | 180 | # 10/31/2005 Maybe this should be flatter? -kgd
|
---|
[171] | 181 | my %pkgdata = (main => {source => ''});
|
---|
[27] | 182 | my @pkglist = ('main'); #sigh
|
---|
[23] | 183 | # Files listing. Embedding this in %pkgdata would be, um, messy.
|
---|
| 184 | my %filelist;
|
---|
[110] | 185 | my %doclist;
|
---|
[40] | 186 | my $buildreq = '';
|
---|
[5] | 187 |
|
---|
[6] | 188 | # Scriptlets
|
---|
[48] | 189 | my $prepscript = '';
|
---|
| 190 | my $buildscript = '';
|
---|
[23] | 191 | # %install doesn't need the full treatment from %clean; just an empty place to install to.
|
---|
| 192 | # NB - rpm doesn't do this; is it really necessary?
|
---|
| 193 | my $installscript = '[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT'."\n";
|
---|
[48] | 194 | my $cleanscript = '';
|
---|
[6] | 195 |
|
---|
[13] | 196 | # Snag some environment data
|
---|
| 197 | my $tmpdir;
|
---|
| 198 | if (defined $ENV{TMP} && $ENV{TMP} =~ /^(\/var)?\/tmp$/) {
|
---|
| 199 | $tmpdir = $ENV{TMP};
|
---|
| 200 | } else {
|
---|
| 201 | $tmpdir = "/var/tmp";
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[7] | 204 | ##main
|
---|
| 205 |
|
---|
[4] | 206 | load_userconfig();
|
---|
[3] | 207 | parse_cmd();
|
---|
| 208 |
|
---|
[50] | 209 | if ($cmdopts{install}) {
|
---|
| 210 | install_sdeb();
|
---|
| 211 | exit 0;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[81] | 214 | # output stage of --showpkgs
|
---|
[71] | 215 | if ($cmdopts{type} eq 'd') {
|
---|
| 216 | parse_spec();
|
---|
| 217 | foreach my $pkg (@pkglist) {
|
---|
| 218 | $pkgdata{$pkg}{name} =~ tr/_/-/;
|
---|
| 219 |
|
---|
[111] | 220 | my $pkgfullname = "$pkgdata{$pkg}{name}_".
|
---|
| 221 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 222 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb";
|
---|
[71] | 223 |
|
---|
[76] | 224 | print "$pkgfullname\n" if $filelist{$pkg};
|
---|
[79] | 225 |
|
---|
[71] | 226 | }
|
---|
[80] | 227 | # Source package
|
---|
[111] | 228 | print "$pkgdata{main}{name}-".
|
---|
| 229 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 230 | "$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb\n";
|
---|
[71] | 231 | exit 0;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[50] | 234 | # Stick --rebuild handling in here - basically install_sdeb()
|
---|
| 235 | # followed by tweaking options to run with -ba
|
---|
[54] | 236 | if ($cmdopts{type} eq 's') {
|
---|
[55] | 237 | if ($srcpkg =~ /\.src\.rpm$/) {
|
---|
[58] | 238 | my @srclist = qx { rpm -qlp $srcpkg };
|
---|
[55] | 239 | foreach (@srclist) {
|
---|
[54] | 240 | chomp;
|
---|
[55] | 241 | $specfile = "$topdir/SPECS/$_" if /\.spec$/;
|
---|
[54] | 242 | }
|
---|
[55] | 243 | qx { rpm -i $srcpkg };
|
---|
| 244 | } else {
|
---|
| 245 | install_sdeb();
|
---|
| 246 | my @srclist = qx { pax < $srcpkg };
|
---|
| 247 | foreach (@srclist) {
|
---|
| 248 | chomp;
|
---|
| 249 | $specfile = "$topdir/$_" if /SPECS/;
|
---|
| 250 | }
|
---|
[54] | 251 | }
|
---|
[55] | 252 | $cmdopts{type} = 'b';
|
---|
| 253 | $cmdopts{stage} = 'a';
|
---|
[54] | 254 | }
|
---|
[50] | 255 |
|
---|
[7] | 256 | if ($cmdopts{type} eq 'b') {
|
---|
| 257 | # Need to read the spec file to find the tarball. Note that
|
---|
| 258 | # this also generates most of the shell script required.
|
---|
| 259 | parse_spec();
|
---|
[38] | 260 | die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
|
---|
| 261 | if !checkbuildreq();
|
---|
[7] | 262 | }
|
---|
| 263 |
|
---|
[65] | 264 | if ($cmdopts{type} eq 't') {
|
---|
| 265 | # Need to unpack the tarball to find the spec file. Sort of the inverse of -b above.
|
---|
| 266 | # zcat $tarball |tar -t |grep .spec
|
---|
| 267 | # collect some info about the tarball
|
---|
[99] | 268 | $specfile = "$topdir/BUILD/". qx { zcat $tarball |tar -t |grep -e '[\.]spec\$' };
|
---|
[65] | 269 | chomp $specfile;
|
---|
[174] | 270 | my ($fileonly, $dirname) = ($tarball =~ /(([a-zA-Z0-9._-]+)\.tar\.(?:gz|bz2|xz))$/);
|
---|
[65] | 271 |
|
---|
| 272 | $tarball = abs_path($tarball);
|
---|
[174] | 273 | ##fixme: use macro expansions for the executables
|
---|
| 274 | my $unpackcmd = "cd $topdir/BUILD; ".
|
---|
| 275 | ( $tarball =~ /\.tar\.gz$/ ? "/bin/gzip" : "" ).
|
---|
| 276 | ( $tarball =~ /\.tar\.bz2$/ ? "/bin/bzip2" : "" ).
|
---|
| 277 | ( $tarball =~ /\.tar\.(?:gz|Z)$/ ? "/usr/bin/xz" : "" ).
|
---|
| 278 | " -dc $tarball |/bin/tar -xf -";
|
---|
| 279 |
|
---|
[65] | 280 | system "$unpackcmd";
|
---|
| 281 | system "cp $tarball $topdir/SOURCES/$fileonly";
|
---|
| 282 | system "cp $specfile $topdir/SPECS/";
|
---|
| 283 | parse_spec();
|
---|
| 284 | die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
|
---|
| 285 | if !checkbuildreq();
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[35] | 288 | # -> srcpkg if -.s
|
---|
| 289 | if ($cmdopts{stage} eq 's') {
|
---|
| 290 | srcpackage();
|
---|
[170] | 291 | print $finalmessages;
|
---|
[35] | 292 | exit 0;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
[4] | 295 | # Hokay. Need to:
|
---|
[14] | 296 | # -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
|
---|
[7] | 297 | if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 298 | prep();
|
---|
| 299 | }
|
---|
[14] | 300 | # -> build if -.c OR (-.[ilabs] AND !--short-circuit)
|
---|
[7] | 301 | if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 302 | build();
|
---|
| 303 | }
|
---|
[14] | 304 | # -> install if -.[ilabs]
|
---|
[28] | 305 | #if ($cmdopts{stage} eq 'i' || ($cmdopts{stage} =~ /[labs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 306 | if ($cmdopts{stage} =~ /[ilabs]/) {
|
---|
[7] | 307 | install();
|
---|
[30] | 308 | #foreach my $pkg (@pkglist) {
|
---|
| 309 | # print "files in $pkg:\n ".$filelist{$pkg}."\n";
|
---|
| 310 | #}
|
---|
| 311 |
|
---|
[7] | 312 | }
|
---|
[14] | 313 | # -> binpkg and srcpkg if -.a
|
---|
[7] | 314 | if ($cmdopts{stage} eq 'a') {
|
---|
[4] | 315 | binpackage();
|
---|
[7] | 316 | srcpackage();
|
---|
[97] | 317 | clean();
|
---|
[4] | 318 | }
|
---|
[14] | 319 | # -> binpkg if -.b
|
---|
[7] | 320 | if ($cmdopts{stage} eq 'b') {
|
---|
| 321 | binpackage();
|
---|
[97] | 322 | clean();
|
---|
[7] | 323 | }
|
---|
[4] | 324 |
|
---|
[77] | 325 | # Spit out any closing remarks
|
---|
| 326 | print $finalmessages;
|
---|
| 327 |
|
---|
[4] | 328 | # Just in case.
|
---|
| 329 | exit 0;
|
---|
| 330 |
|
---|
| 331 |
|
---|
| 332 | ## load_userconfig()
|
---|
| 333 | # Loads user configuration (if any)
|
---|
| 334 | # Currently only handles .debmacros
|
---|
| 335 | # Needs to handle "other files"
|
---|
| 336 | sub load_userconfig {
|
---|
[96] | 337 | my $homedir = (getpwuid($<))[7];
|
---|
[4] | 338 | if (-e "$homedir/.debmacros") {
|
---|
| 339 | open USERMACROS,"<$homedir/.debmacros";
|
---|
| 340 | while (<USERMACROS>) {
|
---|
[7] | 341 | # And we also only handle a few macros at the moment.
|
---|
[4] | 342 | if (/^\%_topdir/) {
|
---|
[5] | 343 | my (undef,$tmp) = split /\s+/, $_;
|
---|
| 344 | $topdir = $tmp;
|
---|
[4] | 345 | }
|
---|
[96] | 346 | next if /^\%_/;
|
---|
| 347 | # Allow arbitrary definitions. Note that we're only doing simple defs here for now.
|
---|
| 348 | if (/^\%([a-z0-9]+)\s+(.+)$/) {
|
---|
| 349 | $specglobals{$1} = $2;
|
---|
| 350 | }
|
---|
[4] | 351 | }
|
---|
| 352 | }
|
---|
| 353 | } # end load_userconfig()
|
---|
| 354 |
|
---|
| 355 |
|
---|
[3] | 356 | ## parse_cmd()
|
---|
[4] | 357 | # Parses command line into global hash %cmdopts, other globals
|
---|
[3] | 358 | # Options based on rpmbuild's options
|
---|
| 359 | sub parse_cmd {
|
---|
| 360 | # Don't feel like coding my own option parser...
|
---|
| 361 | #use Getopt::Long;
|
---|
| 362 | # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
|
---|
| 363 | #use Getopt::Popt qw(:all);
|
---|
[4] | 364 | # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
|
---|
[3] | 365 |
|
---|
[163] | 366 | # ... also note, single-character options are mostly not flags, so they can't be
|
---|
| 367 | # sanely combined the way most other programs' single-character flag options can.
|
---|
| 368 |
|
---|
[3] | 369 | # Stuff it.
|
---|
[4] | 370 | my $prevopt = '';
|
---|
[3] | 371 | foreach (@ARGV) {
|
---|
| 372 | chomp;
|
---|
[7] | 373 |
|
---|
[3] | 374 | # Is it an option?
|
---|
| 375 | if (/^-/) {
|
---|
[7] | 376 |
|
---|
[3] | 377 | # Is it a long option?
|
---|
| 378 | if (/^--/) {
|
---|
[4] | 379 | if (/^--short-circuit/) {
|
---|
| 380 | $cmdopts{short} = 'y';
|
---|
[5] | 381 | } elsif (/^--rebuild/) {
|
---|
| 382 | $cmdopts{type} = 's';
|
---|
[71] | 383 | } elsif (/^--showpkgs/) {
|
---|
| 384 | $cmdopts{type} = 'd'; # d for 'diagnostic' or 'debug' or 'dump'
|
---|
[163] | 385 | } elsif (/^--help/) {
|
---|
| 386 | print "debbuild v$version".q{
|
---|
| 387 | Copyright 2005-2012 Kris Deugau <kdeugau@deepnet.cx>
|
---|
| 388 |
|
---|
| 389 | Build .deb packages from RPM-style .spec files
|
---|
| 390 | debbuild supports most package-building options rpmbuild does.
|
---|
| 391 |
|
---|
| 392 | Build options with [ <specfile> | <tarball> | <source package> ]:
|
---|
| 393 | -bp build through %prep (unpack sources and apply patches) from <specfile>
|
---|
| 394 | -bc build through %build (%prep, then compile) from <specfile>
|
---|
| 395 | -bi build through %install (%prep, %build, then install) from <specfile>
|
---|
| 396 | -bl verify %files section from <specfile>
|
---|
| 397 | -ba build source and binary packages from <specfile>
|
---|
| 398 | -bb build binary package only from <specfile>
|
---|
| 399 | -bs build source package only from <specfile>
|
---|
| 400 | -tp build through %prep (unpack sources and apply patches) from <tarball>
|
---|
| 401 | -tc build through %build (%prep, then compile) from <tarball>
|
---|
| 402 | -ti build through %install (%prep, %build, then install) from <tarball>
|
---|
| 403 | -ta build source and binary packages from <tarball>
|
---|
| 404 | -tb build binary package only from <tarball>
|
---|
| 405 | -ts build source package only from <tarball>
|
---|
| 406 | --rebuild build binary package from <source package>
|
---|
| 407 | --buildroot=DIRECTORY override build root
|
---|
| 408 | --short-circuit skip straight to specified stage (only for c,i)
|
---|
| 409 |
|
---|
| 410 | Common options:
|
---|
| 411 | -D, --define='MACRO EXPR' define MACRO with value EXPR
|
---|
| 412 |
|
---|
| 413 | debbuild-specific options:
|
---|
| 414 | -i Unpack a .sdeb in the %_topdir tree
|
---|
| 415 | --showpkgs Show package names that would be built. Only works with .spec files.
|
---|
| 416 |
|
---|
| 417 | };
|
---|
| 418 | exit;
|
---|
| 419 |
|
---|
[94] | 420 | } elsif (/^--define/) {
|
---|
| 421 | # nothing to do? Can't see anything needed, we handle the actual definition later.
|
---|
[122] | 422 | ##fixme
|
---|
| 423 | # add --self-package here
|
---|
| 424 | # deps build-essential pax fakeroot
|
---|
[4] | 425 | } else {
|
---|
[93] | 426 | print "Long option $_ not handled\n";
|
---|
[4] | 427 | }
|
---|
[3] | 428 | } else {
|
---|
[14] | 429 | # Not a long option
|
---|
[5] | 430 | if (/^-[bt]/) {
|
---|
| 431 | if ($cmdopts{stage} eq 's') {
|
---|
| 432 | # Mutually exclusive options.
|
---|
| 433 | die "Can't use $_ with --rebuild\n";
|
---|
| 434 | } else {
|
---|
[14] | 435 | # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
|
---|
[5] | 436 | ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
|
---|
| 437 | ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
|
---|
| 438 | }
|
---|
[4] | 439 | } elsif (/^-v/) {
|
---|
| 440 | # bump verbosity. Not sure what I'll actually do here...
|
---|
[50] | 441 | } elsif (/^-i/) {
|
---|
| 442 | $cmdopts{install} = 1;
|
---|
| 443 | $prevopt = '-i';
|
---|
[163] | 444 | } elsif (/^-D/) {
|
---|
| 445 | # --define. nothing to do on this round; actual work is done next time.
|
---|
[4] | 446 | } else {
|
---|
| 447 | die "Bad option $_\n";
|
---|
| 448 | }
|
---|
[3] | 449 | }
|
---|
[14] | 450 |
|
---|
| 451 | } else { # Not an option argument
|
---|
| 452 |
|
---|
[5] | 453 | # --buildroot is the only option that takes an argument
|
---|
| 454 | # Therefore, any *other* bare arguments are the spec file,
|
---|
| 455 | # tarball, or source package we're operating on - depending
|
---|
| 456 | # on which one we meet.
|
---|
| 457 | if ($prevopt eq '--buildroot') {
|
---|
[7] | 458 | $cmdbuildroot = $_;
|
---|
[163] | 459 | } elsif ($prevopt eq '--define' || $prevopt eq '-D') {
|
---|
[118] | 460 | my ($macro,$value) = (/([a-z0-9_.-]+)(?:\s+(.+))?/i);
|
---|
[127] | 461 | if ($value ne '') {
|
---|
[94] | 462 | $specglobals{$macro} = $value;
|
---|
| 463 | } else {
|
---|
| 464 | warn "WARNING: missing value for macro $macro in --define! Ignoring.\n";
|
---|
| 465 | }
|
---|
[50] | 466 | } elsif ($prevopt eq '-i') {
|
---|
| 467 | $srcpkg = $_;
|
---|
[5] | 468 | } else {
|
---|
| 469 | if ($cmdopts{type} eq 's') {
|
---|
| 470 | # Source package
|
---|
[50] | 471 | if (!/(sdeb|\.src\.rpm)$/) {
|
---|
[5] | 472 | die "Can't --rebuild with $_\n";
|
---|
| 473 | }
|
---|
[50] | 474 | $srcpkg = $_;
|
---|
[71] | 475 | } elsif ($cmdopts{type} eq 'b' || $cmdopts{type} eq 'd') {
|
---|
[65] | 476 | # Spec file
|
---|
[5] | 477 | $specfile = $_;
|
---|
| 478 | } else {
|
---|
[65] | 479 | # Tarball build. Need to extract tarball to find spec file. Whee.
|
---|
| 480 | $tarball = $_;
|
---|
[5] | 481 | }
|
---|
| 482 | }
|
---|
[3] | 483 | }
|
---|
[7] | 484 | $prevopt = $_;
|
---|
| 485 | } # foreach @ARGV
|
---|
[4] | 486 |
|
---|
| 487 | # Some cross-checks. rpmbuild limits --short-circuit to just
|
---|
| 488 | # the "compile" and "install" targets - with good reason IMO.
|
---|
[14] | 489 | # Note that --short-circuit with -.p is not really an error, just redundant.
|
---|
[4] | 490 | # NB - this is NOT fatal, just ignored!
|
---|
[10] | 491 | if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
|
---|
[4] | 492 | warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
|
---|
[28] | 493 | $cmdopts{short} = 'n';
|
---|
[4] | 494 | }
|
---|
[14] | 495 |
|
---|
[3] | 496 | # Valid options, with example arguments (if any):
|
---|
| 497 | # Build from .spec file; mutually exclusive:
|
---|
| 498 | # -bp
|
---|
| 499 | # -bc
|
---|
| 500 | # -bi
|
---|
| 501 | # -bl
|
---|
| 502 | # -ba
|
---|
| 503 | # -bb
|
---|
| 504 | # -bs
|
---|
| 505 | # Build from tarball; mutually exclusive:
|
---|
| 506 | # -tp
|
---|
| 507 | # -tc
|
---|
| 508 | # -ti
|
---|
| 509 | # -ta
|
---|
| 510 | # -tb
|
---|
| 511 | # -ts
|
---|
| 512 | # Build from .src.(deb|rpm)
|
---|
| 513 | # --rebuild
|
---|
| 514 | # --recompile
|
---|
| 515 |
|
---|
| 516 | # General options
|
---|
| 517 | # --buildroot=DIRECTORY
|
---|
| 518 | # --clean
|
---|
| 519 | # --nobuild
|
---|
| 520 | # --nodeps
|
---|
| 521 | # --nodirtokens
|
---|
| 522 | # --rmsource
|
---|
| 523 | # --rmspec
|
---|
| 524 | # --short-circuit
|
---|
| 525 | # --target=CPU-VENDOR-OS
|
---|
| 526 |
|
---|
| 527 | #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
|
---|
| 528 |
|
---|
| 529 | } # end parse_cmd()
|
---|
| 530 |
|
---|
[4] | 531 |
|
---|
[5] | 532 | ## parse_spec()
|
---|
[14] | 533 | # Parse the .spec file.
|
---|
[5] | 534 | sub parse_spec {
|
---|
[130] | 535 | die "No .spec file specified! Exiting.\n" if !$specfile;
|
---|
[65] | 536 | open SPECFILE,"<$specfile" or die "specfile ($specfile) barfed: $!";
|
---|
[5] | 537 |
|
---|
[95] | 538 | my $iflevel = 0;
|
---|
[87] | 539 | my $buildarch = $hostarch;
|
---|
[88] | 540 | $pkgdata{main}{arch} = $hostarch;
|
---|
[87] | 541 |
|
---|
[103] | 542 | my $stage = 'preamble';
|
---|
| 543 | my $subname = 'main';
|
---|
| 544 | my $scriptlet;
|
---|
[14] | 545 |
|
---|
[103] | 546 | # Basic algorithm:
|
---|
| 547 | # For each line
|
---|
| 548 | # if it's a member of an %if construct, branch and see which segment of the
|
---|
| 549 | # spec file we need to parse and which one gets discarded, then
|
---|
| 550 | # short-circuit back to the top of the loop.
|
---|
| 551 | # if it's a %section, bump the stage. Preparse addons to the %section line
|
---|
| 552 | # (eg subpackage) and stuff them in suitable loop-global variables, then
|
---|
| 553 | # short-circuit back to the top of the loop.
|
---|
| 554 | # Otherwise, parse the line according to which section we're supposedly
|
---|
| 555 | # parsing right now
|
---|
[14] | 556 |
|
---|
[103] | 557 | LINE: while (<SPECFILE>) {
|
---|
[109] | 558 | next if /^#/ && $stage eq 'preamble'; # Ignore comments...
|
---|
| 559 | next if /^\s*$/ && $stage eq 'preamble'; # ... and blank lines.
|
---|
[23] | 560 |
|
---|
[119] | 561 | # no sense in continuing if we find something we don't grok
|
---|
| 562 | # Yes, this is really horribly fugly. But it's a cheap crosscheck against invalid
|
---|
| 563 | # %-tags which also make rpmbuild barf. In theory.
|
---|
| 564 | # notes: some of these are not *entirely* case-sensitive (%ifxxx), but most are.
|
---|
| 565 | # Extracted from the Maximum RPM online doc via:
|
---|
| 566 | # grep -h %[a-z] *|perl -e 'while (<>) { /\%([a-z0-9]+)\b/; print "$1|\n"; }'|sort -u
|
---|
| 567 | if (/^%[a-z]/ &&
|
---|
[120] | 568 | $_ !~ /^%(?:attr|build|changelog|check|clean|config|configure|defattr|define|description|
|
---|
[119] | 569 | dir|doc|docdir|else|endif|files|ghost|if|ifarch|ifn|ifnarch|ifnos|ifnxxx|fos|ifxxx|
|
---|
[133] | 570 | install|makeinstall|package|patch\d+|post|postun|pre|prep|preun|readme|setup|
|
---|
[119] | 571 | triggerin|triggerpostun|triggerun|verify|verifyscript)\b/x
|
---|
| 572 | ) {
|
---|
| 573 | my ($badtag) = (/^%([a-z]+)/i);
|
---|
| 574 | die "Unknown tag \%$badtag at line $. of $specfile\n";
|
---|
| 575 | }
|
---|
| 576 |
|
---|
[103] | 577 | # preprocess %define's
|
---|
| 578 | if (my ($key, $def) = (/^\%define\s+([^\s]+)\s+(.+)$/) ) {
|
---|
| 579 | $specglobals{$key} = expandmacros($def,'g');
|
---|
| 580 | }
|
---|
[98] | 581 |
|
---|
[103] | 582 | if (/^\%if/) {
|
---|
| 583 | s/^\%if//;
|
---|
| 584 | chomp;
|
---|
| 585 | my $expr = expandmacros($_, 'g');
|
---|
| 586 | $iflevel++;
|
---|
[98] | 587 |
|
---|
[103] | 588 | if ($expr !~ /^\s*\d+\s*$/) {
|
---|
| 589 | # gots a logic statement we want to turn into a 1 or a 0. most likely by eval'ing it.
|
---|
[98] | 590 |
|
---|
[103] | 591 | $expr =~ s/\s+//g;
|
---|
[98] | 592 |
|
---|
[104] | 593 | # For Great w00tness! New and Improved multilayered logic handling.
|
---|
| 594 |
|
---|
| 595 | my @bits = split /\b/, $expr;
|
---|
| 596 | $expr = '';
|
---|
| 597 | foreach my $bit (@bits) {
|
---|
| 598 | next if $bit eq '"';
|
---|
| 599 | $bit =~ s/"//g;
|
---|
| 600 | $expr .= qq("$bit") if $bit =~ /^\w+$/;
|
---|
| 601 | $expr .= $bit if $bit !~ /^\w+$/;
|
---|
| 602 | }
|
---|
| 603 |
|
---|
[103] | 604 | # Done in this order so we don't cascade incorrectly. Yes, those spaces ARE correct in the replacements!
|
---|
[104] | 605 | $expr =~ s/==/ eq /g;
|
---|
| 606 | $expr =~ s/!=/ ne /g;
|
---|
| 607 | $expr =~ s/<=>/ cmp /g;
|
---|
| 608 | $expr =~ s/<=/ le /g;
|
---|
| 609 | $expr =~ s/>=/ ge /g;
|
---|
| 610 | $expr =~ s/</ lt /g;
|
---|
| 611 | $expr =~ s/>/ gt /g;
|
---|
[98] | 612 |
|
---|
[103] | 613 | # Turn it into something that eval's to a number. Maybe not needed? O_o
|
---|
| 614 | #$expr = "( $expr ? 1 : 0 )";
|
---|
[98] | 615 |
|
---|
[103] | 616 | $expr = eval $expr;
|
---|
[95] | 617 | }
|
---|
[103] | 618 |
|
---|
| 619 | next LINE if $expr != 0; # This appears to be the only case we call false.
|
---|
| 620 | while (<SPECFILE>) {
|
---|
| 621 | if (/^\%endif/) {
|
---|
| 622 | $iflevel--;
|
---|
| 623 | next LINE;
|
---|
| 624 | } elsif (/^\%else/) {
|
---|
| 625 | next LINE;
|
---|
| 626 | }
|
---|
[95] | 627 | }
|
---|
[103] | 628 | }
|
---|
| 629 | if (/^\%else/) {
|
---|
| 630 | while (<SPECFILE>) {
|
---|
| 631 | if (/^\%endif/) {
|
---|
| 632 | $iflevel--;
|
---|
| 633 | next LINE;
|
---|
| 634 | }
|
---|
[95] | 635 | }
|
---|
[103] | 636 | }
|
---|
| 637 | if (/^\%endif/) {
|
---|
| 638 | $iflevel--;
|
---|
| 639 | next LINE;
|
---|
| 640 | } # %if/%else/%endif
|
---|
[95] | 641 |
|
---|
[126] | 642 | if (/^\%{echo:(.+)}/) {
|
---|
| 643 | my $output = expandmacros($1, 'gp');
|
---|
[136] | 644 | print "$output";
|
---|
[126] | 645 | }
|
---|
| 646 |
|
---|
[105] | 647 | # now we pick out the sections and set "state" to parse that section. Fugly but I can't see a better way. >:(
|
---|
| 648 |
|
---|
[103] | 649 | if (/^\%description(?:\s+(?:-n\s+)?(.+))?/) {
|
---|
[105] | 650 | $stage = 'desc';
|
---|
[103] | 651 | $subname = "main";
|
---|
| 652 | if ($1) { # Magic to add entries to the right package
|
---|
[153] | 653 | my $tmp = expandmacros("$1", 'gp');
|
---|
[103] | 654 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
[18] | 655 | }
|
---|
[105] | 656 | next LINE;
|
---|
[103] | 657 | } # %description
|
---|
| 658 |
|
---|
| 659 | if (/^\%package\s+(?:-n\s+)?(.+)/) {
|
---|
| 660 | $stage = 'package';
|
---|
| 661 | if ($1) { # Magic to add entries to the right package
|
---|
[153] | 662 | my $tmp = expandmacros("$1", 'gp');
|
---|
[103] | 663 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
| 664 | }
|
---|
| 665 | push @pkglist, $subname;
|
---|
| 666 | $pkgdata{$subname}{name} = $subname;
|
---|
| 667 | $pkgdata{$subname}{version} = $pkgdata{main}{version};
|
---|
[87] | 668 | # Build "same arch as previous package found" by default. Where rpm just picks the
|
---|
| 669 | # *very* last one, we want to allow arch<native>+arch-all
|
---|
| 670 | # (eg, Apache is i386, but apache-manual is all)
|
---|
[103] | 671 | $pkgdata{$subname}{arch} = $buildarch; # Since it's likely subpackages will NOT have a BuildArch line...
|
---|
| 672 | next LINE;
|
---|
| 673 | } # %package
|
---|
| 674 |
|
---|
| 675 | if (/^\%prep/) {
|
---|
| 676 | $stage = 'prep';
|
---|
| 677 | # Replace some core macros
|
---|
| 678 | $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
|
---|
| 679 | next LINE;
|
---|
| 680 | } # %prep
|
---|
| 681 |
|
---|
| 682 | if (/^\%build/) {
|
---|
| 683 | $stage = 'build';
|
---|
| 684 | $buildscript .= "cd $tarballdir\n";
|
---|
| 685 | next LINE;
|
---|
| 686 | } # %build
|
---|
| 687 |
|
---|
| 688 | if (/^\%install/) {
|
---|
| 689 | $stage = 'install';
|
---|
| 690 | $installscript .= "cd $tarballdir\n";
|
---|
| 691 | next LINE;
|
---|
| 692 | } # %install
|
---|
| 693 |
|
---|
| 694 | if (/^\%clean/) {
|
---|
| 695 | $stage = 'clean';
|
---|
| 696 | $cleanscript .= "cd $tarballdir\n";
|
---|
| 697 | next LINE;
|
---|
| 698 | } # %clean
|
---|
| 699 |
|
---|
| 700 | if (/^\%(pre|post|preun|postun)\b(?:\s+(?:-n\s+)?(.+))?/i) {
|
---|
| 701 | $stage = 'prepost';
|
---|
| 702 | $scriptlet = lc $1;
|
---|
| 703 | $subname = 'main';
|
---|
| 704 | if ($2) { # Magic to add entries to the right package
|
---|
| 705 | my $tmp = expandmacros("$2", 'g');
|
---|
| 706 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
[27] | 707 | }
|
---|
[103] | 708 | next LINE;
|
---|
| 709 | } # %pre/%post/%preun/%postun
|
---|
[8] | 710 |
|
---|
[103] | 711 | if (/^\%files(?:\s+(?:-n\s+)?(.+))?/) {
|
---|
| 712 | $stage = 'files';
|
---|
| 713 | $subname = 'main';
|
---|
| 714 | if ($1) { # Magic to add entries to the right list of files
|
---|
[153] | 715 | my $tmp = expandmacros("$1", 'gp');
|
---|
[103] | 716 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
| 717 | }
|
---|
| 718 | next LINE;
|
---|
| 719 | } # %files
|
---|
[6] | 720 |
|
---|
[103] | 721 | if (/^\%changelog/) {
|
---|
| 722 | $stage = 'changelog';
|
---|
| 723 | $pkgdata{main}{changelog} = '';
|
---|
| 724 | next LINE;
|
---|
| 725 | }
|
---|
[6] | 726 |
|
---|
[103] | 727 | # now we handle individual lines from the various sections
|
---|
[6] | 728 |
|
---|
[105] | 729 | if ($stage eq 'desc') {
|
---|
[170] | 730 | next LINE if /^\s*#/;
|
---|
[105] | 731 | $pkgdata{$subname}{desc} .= " $_";
|
---|
| 732 | } # description
|
---|
| 733 |
|
---|
[103] | 734 | if ($stage eq 'package') {
|
---|
| 735 | # gotta expand %defines here. Whee.
|
---|
[129] | 736 | # Note that we look for the Debian-specific Recommends, Suggests, and Replaces,
|
---|
| 737 | # although they will have to be wrapped in '%if %{_vendor} == "debbuild"' for
|
---|
| 738 | # an rpmbuild-compatible .spec file
|
---|
| 739 | # NB: NOT going to support Pre-Depends, since it's a "Don't Use" (mis)feature, and
|
---|
| 740 | # RPM's support for a similar tag (PreReq) has been recently dropped.
|
---|
[145] | 741 | if (my ($dname,$dvalue) = (/^(Recommends|Suggests|Enhances|Replaces|Summary|Group|Version|Requires|Conflicts|Provides|BuildArch(?:itecture)?):\s+(.+)$/i)) {
|
---|
[103] | 742 | $dname =~ tr/[A-Z]/[a-z]/;
|
---|
| 743 | if ($dname =~ /^BuildArch/i) {
|
---|
| 744 | $dvalue =~ s/^noarch/all/ig;
|
---|
| 745 | $buildarch = $dvalue; # Emulate rpm's behaviour to a degree
|
---|
| 746 | $dname = 'arch';
|
---|
| 747 | }
|
---|
[172] | 748 | if ($dname =~ /recommends|suggests|enhances|replaces|requires|conflicts|provides/) {
|
---|
| 749 | $pkgdata{$subname}{$dname} .= ", ".expandmacros($dvalue, 'gp');
|
---|
| 750 | } else {
|
---|
| 751 | $pkgdata{$subname}{$dname} = expandmacros($dvalue, 'gp');
|
---|
| 752 | }
|
---|
[103] | 753 | }
|
---|
| 754 | } # package
|
---|
| 755 |
|
---|
| 756 | if ($stage eq 'prep') {
|
---|
| 757 | # Actual handling for %prep section. May have %setup macro; may
|
---|
| 758 | # include %patch tags, may be just a bare shell script.
|
---|
| 759 | if (/^\%setup/) {
|
---|
| 760 | # Parse out the %setup macro. Note that we aren't supporting
|
---|
| 761 | # many of RPM's %setup features.
|
---|
| 762 | $prepscript .= "cd $topdir/BUILD\n";
|
---|
| 763 | if ( /\s+-n\s+([^\s]+)\s+/ ) {
|
---|
| 764 | $tarballdir = $1;
|
---|
| 765 | }
|
---|
| 766 | $tarballdir = expandmacros($tarballdir,'gp');
|
---|
| 767 | $prepscript .= "rm -rf $tarballdir\n";
|
---|
| 768 | if (/\s+-c\s+/) {
|
---|
| 769 | $prepscript .= "mkdir $tarballdir\ncd $tarballdir\n";
|
---|
| 770 | }
|
---|
[174] | 771 | $prepscript .=
|
---|
| 772 | ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "/bin/gzip" : "" ).
|
---|
| 773 | ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "/bin/bzip2" : "" ).
|
---|
| 774 | ( $pkgdata{main}{source} =~ /\.tar\.xz$/ ? "/usr/bin/xz" : "" ).
|
---|
| 775 | " -dc $topdir/SOURCES/$pkgdata{main}{source} | /bin/tar -".
|
---|
| 776 | ( /\s+-q\s+/ ? '' : 'vv' )."xf -\n".
|
---|
[6] | 777 | qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
|
---|
[69] | 778 | "cd $topdir/BUILD/$tarballdir\n".
|
---|
[6] | 779 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
|
---|
| 780 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
|
---|
| 781 | qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
|
---|
[103] | 782 | } elsif ( my ($patchnum,$patchopts) = (/^\%patch([^\s]+)(\s+.+)?$/) ) {
|
---|
| 783 | chomp $patchnum;
|
---|
[155] | 784 | $prepscript .= qq(echo "Patch #$patchnum ($pkgdata{main}{"patch$patchnum"}):"\n);
|
---|
| 785 | # If there are options passed, use'em.
|
---|
| 786 | # Otherwise, catch a bare %patch and ASS-U-ME it's '-p0'-able.
|
---|
| 787 | # Will break on options that don't provide -pnn, but what the hell.
|
---|
| 788 | # Need to decompress .bz2 and .gz patches on the fly. Not sure why one
|
---|
| 789 | # would ever have such things, but there they are... and rpmbuild supports 'em
|
---|
| 790 | # patch originally suggested by Lucian Cristian for .bz2
|
---|
[174] | 791 | # reworked and expanded to support .Z/.gz/.xz as well
|
---|
| 792 | if ( $pkgdata{main}{"patch$patchnum"} =~ /\.(?:Z|gz|bz2|xz)$/ ) {
|
---|
[155] | 793 | my $decompressor;
|
---|
[174] | 794 | $decompressor = 'gzip' if $pkgdata{main}{"patch$patchnum"} =~ /\.(?:Z|gz)$/;
|
---|
[155] | 795 | $decompressor = 'bzip2' if $pkgdata{main}{"patch$patchnum"} =~ /\.bz2$/;
|
---|
[174] | 796 | $decompressor = 'xz' if $pkgdata{main}{"patch$patchnum"} =~ /\.xz$/;
|
---|
[155] | 797 | $prepscript .= qq(/bin/$decompressor -d < $topdir/SOURCES/$pkgdata{main}{"patch$patchnum"} | patch );
|
---|
| 798 | $prepscript .= $patchopts if $patchopts;
|
---|
| 799 | $prepscript .= "-p0" if !$patchopts;
|
---|
| 800 | $prepscript .= qq( -s\nSTATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n);
|
---|
| 801 | } else {
|
---|
| 802 | $prepscript .= "patch ";
|
---|
| 803 | $prepscript .= $patchopts if $patchopts;
|
---|
| 804 | $prepscript .= "-p0" if !$patchopts;
|
---|
| 805 | $prepscript .= " -s <$topdir/SOURCES/".$pkgdata{main}{"patch$patchnum"}."\n";
|
---|
| 806 | }
|
---|
[103] | 807 | } else {
|
---|
[107] | 808 | $prepscript .= expandmacros($_,'gp');
|
---|
[6] | 809 | }
|
---|
[103] | 810 | next LINE;
|
---|
| 811 | } # prep
|
---|
| 812 |
|
---|
| 813 | if ($stage eq 'build') {
|
---|
| 814 | # %build. This is pretty much just a shell script. There
|
---|
| 815 | # aren't many local macros to deal with.
|
---|
| 816 | if (/^\%configure/) {
|
---|
| 817 | $buildscript .= expandmacros($_,'cgbp');
|
---|
| 818 | } elsif (/^\%\{__make\}/) {
|
---|
| 819 | $buildscript .= expandmacros($_,'mgbp');
|
---|
| 820 | } else {
|
---|
[108] | 821 | $buildscript .= expandmacros($_,'gp');
|
---|
[5] | 822 | }
|
---|
[103] | 823 | next LINE;
|
---|
| 824 | } # build
|
---|
[29] | 825 |
|
---|
[103] | 826 | if ($stage eq 'install') {
|
---|
| 827 | if (/^\%makeinstall/) {
|
---|
| 828 | $installscript .= expandmacros($_,'igbp');
|
---|
| 829 | } else {
|
---|
[107] | 830 | $installscript .= expandmacros($_,'gp');
|
---|
[6] | 831 | }
|
---|
[103] | 832 | next LINE;
|
---|
| 833 | } # install
|
---|
[29] | 834 |
|
---|
[103] | 835 | if ($stage eq 'clean') {
|
---|
[107] | 836 | $cleanscript .= expandmacros($_,'gp');
|
---|
[103] | 837 | next LINE;
|
---|
| 838 | } # clean
|
---|
[37] | 839 |
|
---|
[103] | 840 | if ($stage eq 'prepost') {
|
---|
[107] | 841 | $pkgdata{$subname}{$scriptlet} .= expandmacros($_,'gp');
|
---|
[103] | 842 | next LINE;
|
---|
| 843 | } # prepost
|
---|
[37] | 844 |
|
---|
[103] | 845 | if ($stage eq 'files') {
|
---|
[121] | 846 | # need to deal with these someday
|
---|
[103] | 847 | next LINE if /^\%dir/;
|
---|
| 848 | next LINE if /^\%defattr/;
|
---|
[121] | 849 | next LINE if /^\%verify/;
|
---|
| 850 | # dunno what to do with this; not sure if there's space in Debian's package structure for it.
|
---|
| 851 | next LINE if /^\%ghost/;
|
---|
[103] | 852 | # Debian dpkg doesn't speak "%docdir". Meh.
|
---|
| 853 | next LINE if /^\%docdir/;
|
---|
[121] | 854 | # my $singleton = 0; # don't recall what this was for
|
---|
[169] | 855 | next LINE if /^\s*#/;
|
---|
| 856 | next LINE if /^\s*$/;
|
---|
[121] | 857 |
|
---|
| 858 | # create and initialize flags
|
---|
| 859 | my ($perms, $owner, $group, $conf, $filesline);
|
---|
| 860 | $perms = $owner = $group = $conf = '-';
|
---|
| 861 |
|
---|
| 862 | $filesline = $_;
|
---|
| 863 |
|
---|
| 864 | # strip and flag %attr constructs
|
---|
| 865 | if ($filesline =~ /\%attr\b/) {
|
---|
| 866 | # Extract %attr...
|
---|
| 867 | my ($args) = (/(\%attr\s*\(\s*[\d-]+\s*,\s*["a-zA-Z0-9-]+\s*,\s*["a-zA-Z0-9-]+\s*\))/);
|
---|
| 868 | $args =~ s/\s+//g;
|
---|
| 869 | $args =~ s/"//g; # don't think quotes are ever necessary, but they're *allowed*
|
---|
| 870 | # ... and parse it ...
|
---|
| 871 | ($perms,$owner,$group) = ($args =~ /\(([\d-]+),([a-zA-Z0-9-]+),([a-zA-Z0-9-]+)/);
|
---|
| 872 | # ... and wipe it when we're done.
|
---|
| 873 | $filesline =~ s/\%attr\s*\(\s*[\d-]+\s*,\s*["a-zA-Z0-9-]+\s*,\s*["a-zA-Z0-9-]+\s*\)//;
|
---|
| 874 | }
|
---|
| 875 |
|
---|
| 876 | # Conffiles. Note that Debian and RH have similar, but not
|
---|
| 877 | # *quite* identical ideas of what constitutes a conffile. Nrgh.
|
---|
| 878 | # Note that dpkg will always ask if you want to replace the file - noreplace
|
---|
| 879 | # is more or less permanently enabled.
|
---|
[76] | 880 | ##fixme
|
---|
[121] | 881 | # also need to handle missingok (file that doesn't exist, but should be removed on uninstall)
|
---|
| 882 | # hmm. not sure if such is **POSSIBLE** with Debian... maybe an addition to %post?
|
---|
| 883 | if ($filesline =~ /\%config\b(?:\s*\(\s*noreplace\s*\)\s*)?/) {
|
---|
| 884 | $pkgdata{$subname}{conffiles} = 1; # Flag it for later
|
---|
| 885 | $conf = 'y';
|
---|
| 886 | $filesline =~ s/\%config\b(?:\s*\(\s*noreplace\s*\)\s*)?//;
|
---|
[18] | 887 | }
|
---|
[121] | 888 |
|
---|
[110] | 889 | # %doc needs extra processing, because it can be a space-separated list, and may
|
---|
| 890 | # include both full and partial pathnames. The partial pathnames must be fiddled
|
---|
| 891 | # into place in the %install script, because Debian doesn't really have the concept
|
---|
| 892 | # of "documentation file" that rpm does. (Debian "documentation files" are files
|
---|
| 893 | # in /usr/share/doc/<packagename>.)
|
---|
[121] | 894 | ##fixme: unhandled case: %doc %defattr. Eeep.
|
---|
| 895 | # don't really know what to do with %defattr, generally. :(
|
---|
| 896 | if ($filesline =~ /\%doc\b/) {
|
---|
| 897 | $filesline =~ s/\s*\%doc\s+//;
|
---|
[110] | 898 |
|
---|
[121] | 899 | # this could probably go elsewhere.
|
---|
| 900 | my $pkgname = $pkgdata{$subname}{name};
|
---|
| 901 | $pkgname =~ tr/_/-/;
|
---|
| 902 |
|
---|
| 903 | # have to extract the partial pathnames that %doc installs automagically
|
---|
| 904 | foreach (split /\s+/, $filesline) {
|
---|
| 905 | if (! (/^\%/ or m|^/|) ) {
|
---|
[110] | 906 | $doclist{$subname} .= " $_";
|
---|
[121] | 907 | my ($element) = m|([^/\s]+/?)$|;
|
---|
| 908 | $filesline =~ s|$_|\%{_docdir}/$pkgname/$element|;
|
---|
[110] | 909 | }
|
---|
[121] | 910 | }
|
---|
| 911 | } # $filesline =~ /\%doc\b/
|
---|
| 912 |
|
---|
| 913 | $filesline =~ s/^\s*//; # Just In Case. For, uh, neatness.
|
---|
| 914 |
|
---|
| 915 | # due to Debian's total lack of real permissions-processing in its actual package
|
---|
| 916 | # handling component (dpkg-deb), this can't really be done "properly". We'll have
|
---|
| 917 | # to add chown/chmod commands to the postinst instead. Feh.
|
---|
| 918 | $pkgdata{$subname}{'post'} .= "chown $owner $filesline\n" if $owner ne '-';
|
---|
| 919 | $pkgdata{$subname}{'post'} .= "chgrp $group $filesline\n" if $group ne '-';
|
---|
| 920 | $pkgdata{$subname}{'post'} .= "chmod $perms $filesline\n" if $perms ne '-';
|
---|
| 921 |
|
---|
[115] | 922 | ##fixme
|
---|
[121] | 923 | # need hackery to assure only one filespec per %config. NB: "*" is one filespec. <g>
|
---|
| 924 | push @{$pkgdata{$subname}{conflist}}, $filesline if $conf ne '-';
|
---|
| 925 |
|
---|
| 926 | # now that we've got the specials out of the way, we can add things to the appropriate list of files.
|
---|
[103] | 927 | # ... and finally everything else
|
---|
[121] | 928 | $filelist{$subname} .= " $filesline";
|
---|
| 929 |
|
---|
[103] | 930 | next LINE;
|
---|
| 931 | } # files
|
---|
[14] | 932 |
|
---|
[103] | 933 | if ($stage eq 'changelog') {
|
---|
[107] | 934 | # this is one of the few places we do NOT generally want to replace macros...
|
---|
[103] | 935 | $pkgdata{main}{changelog} .= $_;
|
---|
| 936 | }
|
---|
[14] | 937 |
|
---|
[103] | 938 | if ($stage eq 'preamble') {
|
---|
[135] | 939 | if (/^summary:\s*(.+)/i) {
|
---|
[103] | 940 | $pkgdata{main}{summary} = $1;
|
---|
[135] | 941 | } elsif (/^name:\s*(.+)/i) {
|
---|
[103] | 942 | $pkgdata{main}{name} = expandmacros($1,'g');
|
---|
[135] | 943 | } elsif (/^epoch:\s*(.+)/i) {
|
---|
[111] | 944 | $pkgdata{main}{epoch} = expandmacros($1,'g');
|
---|
[135] | 945 | } elsif (/^version:\s*(.+)/i) {
|
---|
[103] | 946 | $pkgdata{main}{version} = expandmacros($1,'g');
|
---|
[135] | 947 | } elsif (/^release:\s*(.+)/i) {
|
---|
[103] | 948 | $pkgdata{main}{release} = expandmacros($1,'g');
|
---|
[135] | 949 | } elsif (/^group:\s*(.+)/i) {
|
---|
[103] | 950 | $pkgdata{main}{group} = $1;
|
---|
[135] | 951 | } elsif (/^copyright:\s*(.+)/i) {
|
---|
[103] | 952 | $pkgdata{main}{copyright} = $1;
|
---|
[135] | 953 | } elsif (/^url:\s*(.+)/i) {
|
---|
[103] | 954 | $pkgdata{main}{url} = $1;
|
---|
[135] | 955 | } elsif (/^packager:\s*(.+)/i) {
|
---|
[103] | 956 | $pkgdata{main}{packager} = $1;
|
---|
[135] | 957 | } elsif (/^buildroot:\s*(.+)/i) {
|
---|
[136] | 958 | $specglobals{buildroot} = $1;
|
---|
[135] | 959 | } elsif (/^source0?:\s*(.+)/i) {
|
---|
[103] | 960 | $pkgdata{main}{source} = $1;
|
---|
[171] | 961 | # Do this here since we don't use any URL forms elsewhere (maybe some other time)
|
---|
| 962 | $pkgdata{main}{source} =~ s|^.+/([^/]+)$|$1|;
|
---|
[174] | 963 | # .tar, .tar.gz, .tar.bz2, .tgz, .xz
|
---|
| 964 | die "Unknown tarball format $1\n" if $1 !~ /\.(?:tar(?:\.(?:gz|bz2|xz))?|tgz)$/;
|
---|
[171] | 965 | } elsif (my ($srcnum, $src) = (/^source([0-9]+):\s*(.+)/i)) {
|
---|
| 966 | $pkgdata{sources}{$srcnum} = $src;
|
---|
| 967 | # Do this here since we don't use any URL forms elsewhere (maybe some other time)
|
---|
| 968 | $pkgdata{sources}{$srcnum} =~ s|^.+/([^/]+)$|$1|;
|
---|
[135] | 969 | } elsif (/^patch([^:]+):\s*(.+)$/i) {
|
---|
[103] | 970 | my $patchname = "patch$1";
|
---|
| 971 | $pkgdata{main}{$patchname} = $2;
|
---|
| 972 | if ($pkgdata{main}{$patchname} =~ /\//) {
|
---|
| 973 | # URL-style patch. Rare but not unheard-of.
|
---|
| 974 | my @patchbits = split '/', $pkgdata{main}{$patchname};
|
---|
| 975 | $pkgdata{main}{$patchname} = $patchbits[$#patchbits];
|
---|
| 976 | }
|
---|
| 977 | chomp $pkgdata{main}{$patchname};
|
---|
[135] | 978 | } elsif (/^buildarch(?:itecture)?:\s*(.+)/i) {
|
---|
[103] | 979 | $pkgdata{main}{arch} = $1;
|
---|
| 980 | $pkgdata{main}{arch} =~ s/^noarch$/all/;
|
---|
| 981 | $buildarch = $pkgdata{main}{arch};
|
---|
[138] | 982 | } elsif (/^buildrequires:\s*(.+)/i) {
|
---|
[103] | 983 | $buildreq .= ", $1";
|
---|
[135] | 984 | } elsif (/^requires:\s*(.+)/i) {
|
---|
[103] | 985 | $pkgdata{main}{requires} .= ", ".expandmacros("$1", 'gp');
|
---|
[135] | 986 | } elsif (/^provides:\s*(.+)/i) {
|
---|
[103] | 987 | $pkgdata{main}{provides} .= ", $1";
|
---|
[135] | 988 | } elsif (/^conflicts:\s*(.+)/i) {
|
---|
[103] | 989 | $pkgdata{main}{conflicts} .= ", $1";
|
---|
[135] | 990 | } elsif (/^recommends:\s*(.+)/i) {
|
---|
[129] | 991 | $pkgdata{main}{recommends} .= ", $1";
|
---|
| 992 | warn "Warning: Debian-specific 'Recommends:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[135] | 993 | } elsif (/^suggests:\s*(.+)/i) {
|
---|
[129] | 994 | $pkgdata{main}{suggests} .= ", $1";
|
---|
| 995 | warn "Warning: Debian-specific 'Suggests:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[145] | 996 | } elsif (/^enhances:\s*(.+)/i) {
|
---|
| 997 | $pkgdata{main}{enhances} .= ", $1";
|
---|
[169] | 998 | warn "Warning: Debian-specific 'Enhances:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[135] | 999 | } elsif (/^replaces:\s*(.+)/i) {
|
---|
[129] | 1000 | $pkgdata{main}{replaces} .= ", $1";
|
---|
| 1001 | warn "Warning: Debian-specific 'Replaces:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[135] | 1002 | } elsif (/^autoreq(?:prov)?:\s*(.+)/i) {
|
---|
[112] | 1003 | # we don't handle auto-provides (yet)
|
---|
| 1004 | $NoAutoReq = 1 if $1 =~ /(?:no|0)/i;
|
---|
[5] | 1005 | }
|
---|
[103] | 1006 | next LINE;
|
---|
| 1007 | } # preamble
|
---|
[5] | 1008 |
|
---|
[103] | 1009 | } # while <SPEC>
|
---|
[7] | 1010 |
|
---|
[14] | 1011 | # Parse and replace some more macros. More will be replaced even later.
|
---|
| 1012 |
|
---|
[10] | 1013 | # Expand macros as necessary.
|
---|
[12] | 1014 | $scriptletbase = expandmacros($scriptletbase,'gp');
|
---|
[7] | 1015 |
|
---|
[103] | 1016 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
| 1017 |
|
---|
[136] | 1018 | $specglobals{buildroot} = $cmdbuildroot if $cmdbuildroot;
|
---|
| 1019 | $specglobals{buildroot} = expandmacros($specglobals{buildroot},'gp');
|
---|
[7] | 1020 |
|
---|
[16] | 1021 | close SPECFILE;
|
---|
[5] | 1022 | } # end parse_spec()
|
---|
| 1023 |
|
---|
| 1024 |
|
---|
[7] | 1025 | ## prep()
|
---|
[14] | 1026 | # Writes and executes the %prep script (mostly) built while reading the spec file.
|
---|
[7] | 1027 | sub prep {
|
---|
[10] | 1028 | # Replace some things here just to make sure.
|
---|
[12] | 1029 | $prepscript = expandmacros($prepscript,'gp');
|
---|
[10] | 1030 |
|
---|
| 1031 | # create script filename
|
---|
[13] | 1032 | my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
|
---|
[10] | 1033 | sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 1034 | or die "Can't open/create prep script file $prepscriptfile: $!\n";
|
---|
[10] | 1035 | print PREPSCRIPT $scriptletbase;
|
---|
| 1036 | print PREPSCRIPT $prepscript;
|
---|
| 1037 | close PREPSCRIPT;
|
---|
[7] | 1038 |
|
---|
[10] | 1039 | # execute
|
---|
| 1040 | print "Calling \%prep script $prepscriptfile...\n";
|
---|
| 1041 | system("/bin/sh -e $prepscriptfile") == 0
|
---|
[14] | 1042 | or die "Can't exec: $!\n";
|
---|
[7] | 1043 |
|
---|
[10] | 1044 | # and clean up
|
---|
| 1045 | unlink $prepscriptfile;
|
---|
[7] | 1046 | } # end prep()
|
---|
| 1047 |
|
---|
| 1048 |
|
---|
[5] | 1049 | ## build()
|
---|
[14] | 1050 | # Writes and executes the %build script (mostly) built while reading the spec file.
|
---|
[5] | 1051 | sub build {
|
---|
[12] | 1052 | # Expand the macros
|
---|
| 1053 | $buildscript = expandmacros($buildscript,'cgbp');
|
---|
| 1054 |
|
---|
[7] | 1055 | # create script filename
|
---|
[13] | 1056 | my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
|
---|
[7] | 1057 | sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 1058 | or die "Can't open/create build script file $buildscriptfile: $!\n";
|
---|
[7] | 1059 | print BUILDSCRIPT $scriptletbase;
|
---|
| 1060 | print BUILDSCRIPT $buildscript;
|
---|
| 1061 | close BUILDSCRIPT;
|
---|
| 1062 |
|
---|
| 1063 | # execute
|
---|
| 1064 | print "Calling \%build script $buildscriptfile...\n";
|
---|
| 1065 | system("/bin/sh -e $buildscriptfile") == 0
|
---|
[14] | 1066 | or die "Can't exec: $!\n";
|
---|
[7] | 1067 |
|
---|
| 1068 | # and clean up
|
---|
| 1069 | unlink $buildscriptfile;
|
---|
[5] | 1070 | } # end build()
|
---|
| 1071 |
|
---|
| 1072 |
|
---|
[7] | 1073 | ## install()
|
---|
[14] | 1074 | # Writes and executes the %install script (mostly) built while reading the spec file.
|
---|
[7] | 1075 | sub install {
|
---|
[110] | 1076 |
|
---|
| 1077 | # munge %doc entries into place
|
---|
| 1078 | # rpm handles this with a separate executed %doc script, we're not going to bother.
|
---|
| 1079 | foreach my $docpkg (keys %doclist) {
|
---|
| 1080 | my $pkgname = $pkgdata{$docpkg}{name};
|
---|
| 1081 | $pkgname =~ s/_/-/g;
|
---|
| 1082 |
|
---|
| 1083 | $installscript .= "DOCDIR=\$RPM_BUILD_ROOT\%{_docdir}/$pkgname\nexport DOCDIR\n";
|
---|
| 1084 | $installscript .= "mkdir -p \$DOCDIR\n";
|
---|
| 1085 | $doclist{$docpkg} =~ s/^\s*//;
|
---|
| 1086 | foreach (split(' ',$doclist{$docpkg})) {
|
---|
| 1087 | $installscript .= "cp -pr $_ \$DOCDIR/\n";
|
---|
| 1088 | }
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
[12] | 1091 | # Expand the macros
|
---|
| 1092 | $installscript = expandmacros($installscript,'igbp');
|
---|
| 1093 |
|
---|
[7] | 1094 | # create script filename
|
---|
[13] | 1095 | my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
|
---|
[7] | 1096 | sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 1097 | or die "Can't open/create install script file $installscriptfile: $!\n";
|
---|
[7] | 1098 | print INSTSCRIPT $scriptletbase;
|
---|
| 1099 | print INSTSCRIPT $installscript;
|
---|
| 1100 | close INSTSCRIPT;
|
---|
| 1101 |
|
---|
| 1102 | # execute
|
---|
| 1103 | print "Calling \%install script $installscriptfile...\n";
|
---|
| 1104 | system("/bin/sh -e $installscriptfile") == 0
|
---|
[14] | 1105 | or die "Can't exec: $!\n";
|
---|
[7] | 1106 |
|
---|
| 1107 | # and clean up
|
---|
| 1108 | unlink $installscriptfile;
|
---|
[132] | 1109 |
|
---|
| 1110 | # final bit: compress manpages if present
|
---|
| 1111 | # done here cuz I don't grok shell well
|
---|
| 1112 | # should probably error-check all kinds of things. <g>
|
---|
[136] | 1113 | if (opendir MANROOT, "$specglobals{buildroot}/usr/share/man") {
|
---|
[132] | 1114 | my @mansects = readdir MANROOT;
|
---|
| 1115 | closedir MANROOT;
|
---|
| 1116 | foreach my $mandir (@mansects) {
|
---|
| 1117 | next if $mandir !~ /^man/;
|
---|
[136] | 1118 | opendir MANPAGES, "$specglobals{buildroot}/usr/share/man/$mandir";
|
---|
[132] | 1119 | my @pagelist = readdir MANPAGES;
|
---|
| 1120 | closedir MANPAGES; # Slightly safer to to this; no accidental recursion. O_o
|
---|
| 1121 | foreach my $manpage (@pagelist) {
|
---|
[136] | 1122 | $manpage = "$specglobals{buildroot}/usr/share/man/$mandir/$manpage";
|
---|
[132] | 1123 | if ( -f $manpage) {
|
---|
| 1124 | if ($manpage =~ /^(.+)\.(?:Z|gz|bz2)\n?$/) {
|
---|
| 1125 | my $newpage = $1;
|
---|
| 1126 | `gunzip $manpage` if $manpage =~ /\.(?:Z|gz)$/;
|
---|
| 1127 | `bunzip2 $manpage` if $manpage =~ /\.bz2$/;
|
---|
| 1128 | $manpage = $newpage;
|
---|
| 1129 | }
|
---|
| 1130 | `gzip -9 -n $manpage`;
|
---|
| 1131 | } elsif ( -l $manpage) {
|
---|
| 1132 | my $linkdest = readlink $manpage;
|
---|
| 1133 | $linkdest =~ s/\.(?:Z|gz|bz2)//;
|
---|
| 1134 | unlink $manpage;
|
---|
| 1135 | $manpage =~ s/\.(?:Z|gz|bz2)//;
|
---|
| 1136 | symlink "$linkdest.gz", "$manpage.gz" or print "DEBUG: wibble: symlinking manpage failed: $!\n";
|
---|
| 1137 | }
|
---|
| 1138 | }
|
---|
| 1139 | }
|
---|
| 1140 | } # if opendir MANROOT
|
---|
[7] | 1141 | } # end install()
|
---|
| 1142 |
|
---|
| 1143 |
|
---|
[8] | 1144 | ## binpackage()
|
---|
[136] | 1145 | # Creates the binary .deb package from the installed tree in $specglobals{buildroot}.
|
---|
[14] | 1146 | # Writes and executes a shell script to do so.
|
---|
| 1147 | # Creates miscellaneous files required by dpkg-deb to actually build the package file.
|
---|
[27] | 1148 | # Should handle simple subpackages
|
---|
[8] | 1149 | sub binpackage {
|
---|
[14] | 1150 |
|
---|
[27] | 1151 | foreach my $pkg (@pkglist) {
|
---|
[8] | 1152 |
|
---|
[87] | 1153 | $pkgdata{$pkg}{arch} = $hostarch if !$pkgdata{$pkg}{arch}; # Just In Case.
|
---|
| 1154 |
|
---|
| 1155 | # Make sure we have somewhere to write the .deb file
|
---|
| 1156 | if (!-e "$topdir/DEBS/$pkgdata{$pkg}{arch}") {
|
---|
| 1157 | mkdir "$topdir/DEBS/$pkgdata{$pkg}{arch}";
|
---|
| 1158 | }
|
---|
| 1159 |
|
---|
[73] | 1160 | # Skip building a package if it doesn't actually have any files. NB: This
|
---|
| 1161 | # differs slightly from rpm's behaviour where a package *will* be built -
|
---|
| 1162 | # even without any files - if %files is specified anywhere. I can think
|
---|
| 1163 | # of odd corner cases where that *may* be desireable.
|
---|
[74] | 1164 | next if (!$filelist{$pkg} or $filelist{$pkg} =~ /^\s*$/);
|
---|
[73] | 1165 |
|
---|
[27] | 1166 | # Gotta do this first, otherwise we don't have a place to move files from %files
|
---|
[136] | 1167 | mkdir "$specglobals{buildroot}/$pkg";
|
---|
[28] | 1168 |
|
---|
[30] | 1169 | # Eliminate any lingering % macros
|
---|
| 1170 | $filelist{$pkg} = expandmacros $filelist{$pkg}, 'g';
|
---|
| 1171 |
|
---|
[27] | 1172 | my @pkgfilelist = split ' ', $filelist{$pkg};
|
---|
| 1173 | foreach my $pkgfile (@pkgfilelist) {
|
---|
[37] | 1174 | $pkgfile = expandmacros($pkgfile, 'gp');
|
---|
[117] | 1175 |
|
---|
| 1176 | # Feh. Manpages don't **NEED** to be gzipped, but rpmbuild does, and so shall we.
|
---|
[153] | 1177 | # ... and your little info page too!
|
---|
| 1178 | if ($pkgfile =~ m{/usr/share/(?:man/man|info)}) {
|
---|
[117] | 1179 | # need to check to see if manpage is gzipped
|
---|
[136] | 1180 | if (-e "$specglobals{buildroot}$pkgfile") {
|
---|
[153] | 1181 | # if we've just been pointed to a manpage section with "many" pages,
|
---|
| 1182 | # we need to gzip them all.
|
---|
| 1183 | # fortunately, we do NOT need to explicitly track each file for the
|
---|
| 1184 | # purpose of stuffing them in the package... the original %files
|
---|
| 1185 | # entry will do just fine.
|
---|
| 1186 | if ( -d "$specglobals{buildroot}$pkgfile") {
|
---|
| 1187 | foreach my $globfile (glob("$specglobals{buildroot}$pkgfile/*")) {
|
---|
| 1188 | gzip $globfile if $globfile !~ m|\.gz$|;
|
---|
| 1189 | }
|
---|
| 1190 | } else {
|
---|
| 1191 | if ($pkgfile !~ m|\.gz$|) {
|
---|
| 1192 | qx { gzip $specglobals{buildroot}$pkgfile };
|
---|
| 1193 | $pkgfile .= ".gz";
|
---|
| 1194 | }
|
---|
[117] | 1195 | }
|
---|
| 1196 | } else {
|
---|
| 1197 | if ($pkgfile !~ m|\.gz$|) {
|
---|
| 1198 | $pkgfile .= ".gz";
|
---|
| 1199 | } else {
|
---|
| 1200 | $pkgfile =~ s/\.gz$//;
|
---|
[136] | 1201 | qx { gzip $specglobals{buildroot}$pkgfile };
|
---|
[117] | 1202 | $pkgfile .= ".gz";
|
---|
| 1203 | }
|
---|
| 1204 | }
|
---|
| 1205 | }
|
---|
| 1206 |
|
---|
[124] | 1207 | my ($fpath,$fname) = ($pkgfile =~ m|(.+?/?)?([^/]+/?)$|); # We don't need $fname now, but we might.
|
---|
[136] | 1208 | qx { mkdir -p $specglobals{buildroot}/$pkg$fpath }
|
---|
[44] | 1209 | if $fpath && $fpath ne '';
|
---|
[136] | 1210 | qx { mv $specglobals{buildroot}$pkgfile $specglobals{buildroot}/$pkg$fpath };
|
---|
[27] | 1211 | }
|
---|
[28] | 1212 |
|
---|
[38] | 1213 | # Get the "Depends" (Requires) a la RPM. Ish. We strip the leading
|
---|
| 1214 | # comma and space here (if needed) in case there were "Requires" specified
|
---|
| 1215 | # in the spec file - those would precede these.
|
---|
[136] | 1216 | $pkgdata{$pkg}{requires} .= getreqs("$specglobals{buildroot}/$pkg") if ! $NoAutoReq;
|
---|
[38] | 1217 |
|
---|
[64] | 1218 | # magic needed to properly version dependencies...
|
---|
| 1219 | # only provided deps will really be included
|
---|
[65] | 1220 | $pkgdata{$pkg}{requires} =~ s/^, //; # Still have to do this here.
|
---|
[64] | 1221 | $pkgdata{$pkg}{requires} =~ s/\s+//g;
|
---|
| 1222 | my @deps = split /,/, $pkgdata{$pkg}{requires};
|
---|
| 1223 | my $tmp = '';
|
---|
| 1224 | foreach my $dep (@deps) {
|
---|
[68] | 1225 | # Hack up the perl(Class::SubClass) deps into something dpkg can understand.
|
---|
| 1226 | # May or may not be versioned.
|
---|
| 1227 | # We do this first so the version rewriter can do its magic next.
|
---|
| 1228 | if (my ($mod,$ver) = ($dep =~ /^perl\(([A-Za-z0-9\:\-]+)\)([><=]+.+)?/) ) {
|
---|
| 1229 | $mod =~ s/^perl\(//;
|
---|
| 1230 | $mod =~ s/\)$//;
|
---|
| 1231 | $mod =~ s/::/-/g;
|
---|
| 1232 | $mod =~ tr/A-Z/a-z/;
|
---|
| 1233 | $mod = "lib$mod-perl";
|
---|
| 1234 | $mod .= $ver if $ver;
|
---|
| 1235 | $dep = $mod;
|
---|
| 1236 | }
|
---|
[64] | 1237 | if (my ($name,$rel,$value) = ($dep =~ /^([a-zA-Z0-9._-]+)([><=]+)([a-zA-Z0-9._-]+)$/)) {
|
---|
| 1238 | $tmp .= ", $name ($rel $value)";
|
---|
| 1239 | } else {
|
---|
| 1240 | $tmp .= ", $dep";
|
---|
| 1241 | }
|
---|
| 1242 | }
|
---|
| 1243 | ($pkgdata{$pkg}{requires} = $tmp) =~ s/^, //;
|
---|
| 1244 |
|
---|
[38] | 1245 | # Do this here since we're doing {depends}...
|
---|
[41] | 1246 | if (defined($pkgdata{$pkg}{provides})) {
|
---|
| 1247 | $pkgdata{$pkg}{provides} =~ s/^, //;
|
---|
| 1248 | $pkgdata{$pkg}{provides} = expandmacros($pkgdata{$pkg}{provides},'gp');
|
---|
| 1249 | }
|
---|
[51] | 1250 | if (defined($pkgdata{$pkg}{conflicts})) {
|
---|
| 1251 | $pkgdata{$pkg}{conflicts} =~ s/^, //;
|
---|
| 1252 | $pkgdata{$pkg}{conflicts} = expandmacros($pkgdata{$pkg}{conflicts},'gp');
|
---|
| 1253 | }
|
---|
[38] | 1254 |
|
---|
[129] | 1255 | # These are Debian-specific!
|
---|
| 1256 | if (defined($pkgdata{$pkg}{recommends})) {
|
---|
| 1257 | $pkgdata{$pkg}{recommends} =~ s/^, //;
|
---|
| 1258 | $pkgdata{$pkg}{recommends} = expandmacros($pkgdata{$pkg}{recommends},'gp');
|
---|
| 1259 | }
|
---|
| 1260 | if (defined($pkgdata{$pkg}{suggests})) {
|
---|
| 1261 | $pkgdata{$pkg}{suggests} =~ s/^, //;
|
---|
| 1262 | $pkgdata{$pkg}{suggests} = expandmacros($pkgdata{$pkg}{suggests},'gp');
|
---|
| 1263 | }
|
---|
[145] | 1264 | if (defined($pkgdata{$pkg}{enhances})) {
|
---|
| 1265 | $pkgdata{$pkg}{enhances} =~ s/^, //;
|
---|
| 1266 | $pkgdata{$pkg}{enhances} = expandmacros($pkgdata{$pkg}{enhances},'gp');
|
---|
| 1267 | }
|
---|
[129] | 1268 | if (defined($pkgdata{$pkg}{replaces})) {
|
---|
| 1269 | $pkgdata{$pkg}{replaces} =~ s/^, //;
|
---|
| 1270 | $pkgdata{$pkg}{replaces} = expandmacros($pkgdata{$pkg}{replaces},'gp');
|
---|
| 1271 | }
|
---|
| 1272 |
|
---|
[27] | 1273 | # Gotta do this next, otherwise the control file has nowhere to go. >:(
|
---|
[136] | 1274 | mkdir "$specglobals{buildroot}/$pkg/DEBIAN";
|
---|
[27] | 1275 |
|
---|
[33] | 1276 | # Hack the filename for the package into a Debian-tool-compatible format. GRRRRRR!!!!!
|
---|
| 1277 | # Have I mentioned I hate Debian Policy?
|
---|
| 1278 | $pkgdata{$pkg}{name} =~ tr/_/-/;
|
---|
| 1279 |
|
---|
[27] | 1280 | # create script filename
|
---|
| 1281 | my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
|
---|
| 1282 | sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 1283 | or die "Can't open/create package-creation script file $debscriptfile: $!\n";
|
---|
[27] | 1284 | print DEBSCRIPT $scriptletbase;
|
---|
[166] | 1285 | print DEBSCRIPT "fakeroot -- dpkg-deb -b $specglobals{buildroot}/$pkg $topdir/DEBS/$pkgdata{$pkg}{arch}/".
|
---|
[111] | 1286 | "$pkgdata{$pkg}{name}_".
|
---|
| 1287 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1288 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb\n";
|
---|
[27] | 1289 | # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
|
---|
| 1290 | close DEBSCRIPT;
|
---|
[8] | 1291 |
|
---|
[27] | 1292 | my $control = "Package: $pkgdata{$pkg}{name}\n".
|
---|
[111] | 1293 | "Version: ".
|
---|
| 1294 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1295 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}\n".
|
---|
[27] | 1296 | "Section: $pkgdata{$pkg}{group}\n".
|
---|
[8] | 1297 | "Priority: optional\n".
|
---|
[87] | 1298 | "Architecture: $pkgdata{$pkg}{arch}\n".
|
---|
[8] | 1299 | "Maintainer: $pkgdata{main}{packager}\n".
|
---|
[47] | 1300 | ( $pkgdata{$pkg}{requires} ne '' ? "Depends: $pkgdata{$pkg}{requires}\n" : '' ).
|
---|
[39] | 1301 | ( defined($pkgdata{$pkg}{provides}) ? "Provides: $pkgdata{$pkg}{provides}\n" : '' ).
|
---|
[51] | 1302 | ( defined($pkgdata{$pkg}{conflicts}) ? "Conflicts: $pkgdata{$pkg}{conflicts}\n" : '' ).
|
---|
[129] | 1303 | ( defined($pkgdata{$pkg}{recommends}) ? "Recommends: $pkgdata{$pkg}{recommends}\n" : '' ).
|
---|
| 1304 | ( defined($pkgdata{$pkg}{suggests}) ? "Suggests: $pkgdata{$pkg}{suggests}\n" : '' ).
|
---|
[145] | 1305 | ( defined($pkgdata{$pkg}{enhances}) ? "Enhances: $pkgdata{$pkg}{enhances}\n" : '' ).
|
---|
[129] | 1306 | ( defined($pkgdata{$pkg}{replaces}) ? "Replaces: $pkgdata{$pkg}{replaces}\n" : '' ).
|
---|
[27] | 1307 | "Description: $pkgdata{$pkg}{summary}\n";
|
---|
[161] | 1308 | # Munge things so that Debian tools don't choke on errant blank lines
|
---|
| 1309 | $pkgdata{$pkg}{desc} =~ s/\s+$//g; # Trim trailing blanks
|
---|
| 1310 | $pkgdata{$pkg}{desc} =~ s/^ $/ ./mg; # Replace lines consisting of " \n" with " .\n"
|
---|
[27] | 1311 | $control .= "$pkgdata{$pkg}{desc}\n";
|
---|
[8] | 1312 |
|
---|
[136] | 1313 | open CONTROL, ">$specglobals{buildroot}/$pkg/DEBIAN/control";
|
---|
[27] | 1314 | print CONTROL $control;
|
---|
| 1315 | close CONTROL;
|
---|
[8] | 1316 |
|
---|
[37] | 1317 | # Iff there are conffiles (as specified in the %files list(s), add'em
|
---|
| 1318 | # in so dpkg-deb can tag them.
|
---|
| 1319 | if ($pkgdata{$pkg}{conffiles}) {
|
---|
[136] | 1320 | open CONFLIST, ">$specglobals{buildroot}/$pkg/DEBIAN/conffiles";
|
---|
[37] | 1321 | foreach my $conffile (@{$pkgdata{$pkg}{conflist}}) {
|
---|
[125] | 1322 | $conffile = expandmacros($conffile, 'g');
|
---|
[136] | 1323 | my @tmp = glob "$specglobals{buildroot}/$pkg/$conffile";
|
---|
[106] | 1324 | foreach (@tmp) {
|
---|
[136] | 1325 | s|$specglobals{buildroot}/$pkg/||g; # nrgl. gotta be a better way to do this...
|
---|
[106] | 1326 | s/\s+/\n/g; # Not gonna support spaces in filenames. Ewww.
|
---|
| 1327 | print CONFLIST "$_\n";
|
---|
| 1328 | }
|
---|
[37] | 1329 | }
|
---|
| 1330 | close CONFLIST;
|
---|
| 1331 | }
|
---|
| 1332 |
|
---|
[75] | 1333 | # found the point of scripts on subpackages.
|
---|
| 1334 | if ($pkgdata{$pkg}{'pre'}) {
|
---|
| 1335 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'pre'},'gp');
|
---|
[136] | 1336 | open PREINST, ">$specglobals{buildroot}/$pkg/DEBIAN/preinst";
|
---|
[75] | 1337 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1338 | print PREINST $pkgdata{$pkg}{'pre'};
|
---|
| 1339 | close PREINST;
|
---|
[136] | 1340 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/preinst";
|
---|
[27] | 1341 | }
|
---|
[75] | 1342 | if ($pkgdata{$pkg}{'post'}) {
|
---|
| 1343 | $pkgdata{$pkg}{'post'} = expandmacros($pkgdata{$pkg}{'post'},'gp');
|
---|
[136] | 1344 | open POSTINST, ">$specglobals{buildroot}/$pkg/DEBIAN/postinst";
|
---|
[131] | 1345 | print POSTINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1346 | print POSTINST $pkgdata{$pkg}{'post'};
|
---|
| 1347 | close POSTINST;
|
---|
[136] | 1348 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/postinst";
|
---|
[75] | 1349 | }
|
---|
| 1350 | if ($pkgdata{$pkg}{'preun'}) {
|
---|
| 1351 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'preun'},'gp');
|
---|
[136] | 1352 | open PREUNINST, ">$specglobals{buildroot}/$pkg/DEBIAN/prerm";
|
---|
[131] | 1353 | print PREUNINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1354 | print PREUNINST $pkgdata{$pkg}{'preun'};
|
---|
| 1355 | close PREUNINST;
|
---|
[136] | 1356 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/prerm";
|
---|
[75] | 1357 | }
|
---|
| 1358 | if ($pkgdata{$pkg}{'postun'}) {
|
---|
| 1359 | $pkgdata{$pkg}{'postun'} = expandmacros($pkgdata{$pkg}{'postun'},'gp');
|
---|
[136] | 1360 | open POSTUNINST, ">$specglobals{buildroot}/$pkg/DEBIAN/postrm";
|
---|
[131] | 1361 | print POSTUNINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1362 | print POSTUNINST $pkgdata{$pkg}{'postun'};
|
---|
| 1363 | close POSTUNINST;
|
---|
[136] | 1364 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/postrm";
|
---|
[75] | 1365 | }
|
---|
[16] | 1366 |
|
---|
[27] | 1367 | # execute
|
---|
| 1368 | print "Calling package creation script $debscriptfile for $pkgdata{$pkg}{name}...\n";
|
---|
| 1369 | system("/bin/sh -e $debscriptfile") == 0
|
---|
[14] | 1370 | or die "Can't exec: $!\n";
|
---|
[8] | 1371 |
|
---|
[77] | 1372 | $finalmessages .= "Wrote binary package ".
|
---|
[111] | 1373 | "$pkgdata{$pkg}{name}_".
|
---|
| 1374 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1375 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb".
|
---|
[87] | 1376 | " in $topdir/DEBS/$pkgdata{$pkg}{arch}\n";
|
---|
[27] | 1377 | # and clean up
|
---|
| 1378 | unlink $debscriptfile;
|
---|
| 1379 |
|
---|
| 1380 | } # subpackage loop
|
---|
| 1381 |
|
---|
[8] | 1382 | } # end binpackage()
|
---|
| 1383 |
|
---|
| 1384 |
|
---|
[35] | 1385 | ## srcpackage()
|
---|
| 1386 | # Builds a .src.deb source package. Note that Debian's idea of
|
---|
| 1387 | # a "source package" is seriously flawed IMO, because you can't
|
---|
| 1388 | # easily copy it as-is.
|
---|
[36] | 1389 | # Not quite identical to RPM, but Good Enough (TM).
|
---|
[35] | 1390 | sub srcpackage {
|
---|
[54] | 1391 | # In case we were called with -bs.
|
---|
| 1392 | $pkgdata{main}{name} =~ tr/_/-/;
|
---|
[111] | 1393 | my $pkgsrcname = "$pkgdata{main}{name}-".
|
---|
| 1394 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1395 | "$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb";
|
---|
[36] | 1396 |
|
---|
| 1397 | my $paxcmd;
|
---|
| 1398 |
|
---|
| 1399 | # We'll definitely need this later, and *may* need it sooner.
|
---|
| 1400 | (my $barespec = $specfile) =~ s|.+/([^/]+)$|$1|;
|
---|
| 1401 |
|
---|
| 1402 | # Copy the specfile to the build tree, but only if it's not there already.
|
---|
| 1403 | ##buglet: need to deal with silly case where silly user has put the spec
|
---|
| 1404 | # file in a subdir of %{_topdir}/SPECS. Ewww. Silly user!
|
---|
| 1405 | if (abs_path($specfile) !~ /^$topdir\/SPECS/) {
|
---|
| 1406 | $paxcmd .= "cp $specfile %{_topdir}/SPECS/; \n"
|
---|
| 1407 | }
|
---|
| 1408 |
|
---|
[35] | 1409 | # use pax -w [file] [file] ... >outfile.sdeb
|
---|
[36] | 1410 | $paxcmd = "cd $topdir; pax -w ";
|
---|
[10] | 1411 |
|
---|
[171] | 1412 | # some packages may not have a "main" source.
|
---|
| 1413 | $paxcmd .= "SOURCES/$pkgdata{main}{source} " if $pkgdata{main}{source};
|
---|
[10] | 1414 |
|
---|
[35] | 1415 | # create file list: Source[nn], Patch[nn]
|
---|
| 1416 | foreach my $specbit (keys %{$pkgdata{main}} ) {
|
---|
| 1417 | next if $specbit eq 'source';
|
---|
[53] | 1418 | $paxcmd .= "SOURCES/$pkgdata{main}{$specbit} " if $specbit =~ /^patch/;
|
---|
[36] | 1419 | ##buglet: need to deal with case where patches are listed as URLs?
|
---|
| 1420 | # or other extended pathnames? Silly !@$%^&!%%!%!! user!
|
---|
[35] | 1421 | }
|
---|
| 1422 |
|
---|
[53] | 1423 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
| 1424 | $paxcmd .= "SOURCES/$pkgdata{sources}{$source} ";
|
---|
| 1425 | }
|
---|
| 1426 |
|
---|
[36] | 1427 | # add the spec file, source package destination, and cd back where we came from.
|
---|
| 1428 | $paxcmd .= "SPECS/$barespec > $topdir/SDEBS/$pkgsrcname; cd -";
|
---|
[35] | 1429 |
|
---|
[36] | 1430 | # In case of %-macros...
|
---|
[35] | 1431 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
| 1432 |
|
---|
[36] | 1433 | system "$paxcmd";
|
---|
[77] | 1434 | $finalmessages .= "Wrote source package $pkgsrcname in $topdir/SDEBS.\n";
|
---|
[97] | 1435 | } # end srcpackage()
|
---|
[35] | 1436 |
|
---|
| 1437 |
|
---|
[97] | 1438 | ## clean()
|
---|
| 1439 | # Writes and executes the %clean script (mostly) built while reading the spec file.
|
---|
| 1440 | sub clean {
|
---|
| 1441 | # Replace some things here just to make sure.
|
---|
| 1442 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
| 1443 |
|
---|
| 1444 | # create script filename
|
---|
| 1445 | my $cleanscriptfile = "$tmpdir/deb-tmp.clean.".int(rand(99998)+1);
|
---|
| 1446 | sysopen(CLEANSCRIPT, $cleanscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
| 1447 | or die $!;
|
---|
| 1448 | print CLEANSCRIPT $scriptletbase;
|
---|
| 1449 | print CLEANSCRIPT $cleanscript;
|
---|
| 1450 | close CLEANSCRIPT;
|
---|
| 1451 |
|
---|
| 1452 | # execute
|
---|
| 1453 | print "Calling \%clean script $cleanscriptfile...\n";
|
---|
| 1454 | system("/bin/sh -e $cleanscriptfile") == 0
|
---|
| 1455 | or die "Can't exec: $!\n";
|
---|
| 1456 |
|
---|
| 1457 | # and clean up
|
---|
| 1458 | unlink $cleanscriptfile;
|
---|
| 1459 | } # end clean()
|
---|
| 1460 |
|
---|
| 1461 |
|
---|
[38] | 1462 | ## checkbuildreq()
|
---|
| 1463 | # Checks the build requirements (if any)
|
---|
| 1464 | # Spits out a rude warning and returns a true-false error if any
|
---|
| 1465 | # requirements are not met.
|
---|
| 1466 | sub checkbuildreq {
|
---|
[40] | 1467 | return 1 if $buildreq eq ''; # No use doing extra work.
|
---|
[38] | 1468 |
|
---|
[52] | 1469 | if ( ! -e "/usr/bin/dpkg-query" ) {
|
---|
| 1470 | print "**WARNING** dpkg-query not found. Can't check build-deps.\n".
|
---|
| 1471 | " Required for sucessful build:\n".$buildreq."\n".
|
---|
| 1472 | " Continuing anyway.\n";
|
---|
| 1473 | return 1;
|
---|
| 1474 | }
|
---|
| 1475 |
|
---|
[38] | 1476 | my $reqflag = 1; # unset iff a buildreq is missing
|
---|
| 1477 |
|
---|
| 1478 | $buildreq =~ s/^, //; # Strip the leading comma and space
|
---|
| 1479 | my @reqlist = split /,\s+/, $buildreq;
|
---|
| 1480 |
|
---|
| 1481 | foreach my $req (@reqlist) {
|
---|
[169] | 1482 | # from rpmbuild error message
|
---|
| 1483 | # Dependency tokens must begin with alpha-numeric, '_' or '/'
|
---|
| 1484 | ##fixme: check for suitable whitespace around $rel
|
---|
[38] | 1485 | my ($pkg,$rel,$ver);
|
---|
| 1486 |
|
---|
| 1487 | # We have two classes of requirements - versioned and unversioned.
|
---|
| 1488 | if ($req =~ /[><=]/) {
|
---|
| 1489 | # Pick up the details of versioned buildreqs
|
---|
| 1490 | ($pkg,$rel,$ver) = ($req =~ /([a-z0-9._-]+)\s+([><=]+)\s+([a-z0-9._-]+)/);
|
---|
| 1491 | } else {
|
---|
| 1492 | # And the unversioned ones.
|
---|
| 1493 | $pkg = $req;
|
---|
| 1494 | $rel = '>=';
|
---|
| 1495 | $ver = 0;
|
---|
| 1496 | }
|
---|
| 1497 |
|
---|
| 1498 | my @pkglist = qx { dpkg-query --showformat '\${status}\t\${version}\n' -W $pkg };
|
---|
[154] | 1499 | if (!$pkglist[0]) {
|
---|
[38] | 1500 | print " * Missing build-dependency $pkg!\n";
|
---|
| 1501 | $reqflag = 0;
|
---|
| 1502 | } else {
|
---|
[169] | 1503 | # real package, installed
|
---|
| 1504 | #kdeugau:~$ dpkg-query --showformat '${status}\t${version}\n' -W libc-client2007e-dev 2>&1
|
---|
| 1505 | #install ok installed 8:2007f~dfsg-1
|
---|
| 1506 | # virtual package, provided by ???
|
---|
| 1507 | #kdeugau:~$ dpkg-query --showformat '${status}\t${version}\n' -W libc-client-dev 2>&1
|
---|
| 1508 | #unknown ok not-installed
|
---|
| 1509 | # real package or virtual package not installed or provided
|
---|
| 1510 | #kdeugau:~$ dpkg-query --showformat '${status}\t${version}\n' -W libdb4.8-dbg 2>&1
|
---|
| 1511 | #dpkg-query: no packages found matching libdb4.8-dbg
|
---|
| 1512 |
|
---|
[154] | 1513 | my ($reqstat,undef,undef,$reqver) = split /\s+/, $pkglist[0];
|
---|
[169] | 1514 | if ($reqstat =~ /^unknown/) {
|
---|
| 1515 | # this seems to be a virtual package.
|
---|
| 1516 | print " * Warning: $pkg is probably installed but seems to be a virtual package.\n";
|
---|
| 1517 | } elsif ($reqstat =~ /^install/) {
|
---|
[154] | 1518 | my ($resp) = qx { dpkg --compare-versions $reqver '$rel' $ver && echo "ok" };
|
---|
| 1519 | if ($resp !~ /^ok/) {
|
---|
| 1520 | $reqflag = 0;
|
---|
| 1521 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n"
|
---|
| 1522 | }
|
---|
[169] | 1523 | } else {
|
---|
| 1524 | # whatever state it's in, it's not completely installed, therefore it's missing.
|
---|
| 1525 | print " * Missing build-dependency $pkg!\n";
|
---|
| 1526 | $reqflag = 0;
|
---|
[154] | 1527 | } # end not installed/installed check
|
---|
| 1528 | }
|
---|
[38] | 1529 | } # end req loop
|
---|
| 1530 |
|
---|
| 1531 | return $reqflag;
|
---|
| 1532 | } # end checkbuildreq()
|
---|
| 1533 |
|
---|
| 1534 |
|
---|
| 1535 | ## getreqs()
|
---|
| 1536 | # Find out which libraries/packages are required for any
|
---|
| 1537 | # executables and libs in a given file tree.
|
---|
| 1538 | # (Debian doesn't have soname-level deps; just package-level)
|
---|
[41] | 1539 | # Returns an empty string if the tree contains no binaries.
|
---|
| 1540 | # Doesn't work well on shell scripts. but those *should* be
|
---|
| 1541 | # fine anyway. (Yeah, right...)
|
---|
[38] | 1542 | sub getreqs() {
|
---|
| 1543 | my $pkgtree = $_[0];
|
---|
| 1544 |
|
---|
[39] | 1545 | print "Checking library requirements...\n";
|
---|
[43] | 1546 | my @binlist = qx { find $pkgtree -type f -perm 755 };
|
---|
[38] | 1547 |
|
---|
[41] | 1548 | if (scalar(@binlist) == 0) {
|
---|
| 1549 | return '';
|
---|
| 1550 | }
|
---|
| 1551 |
|
---|
| 1552 | my @reqlist;
|
---|
| 1553 | foreach (@binlist) {
|
---|
[166] | 1554 | push @reqlist, qx { LANG=C ldd $_ };
|
---|
[41] | 1555 | }
|
---|
| 1556 |
|
---|
| 1557 | # Get the list of libs provided by this package. Still doesn't
|
---|
| 1558 | # handle the case where the lib gets stuffed into a subpackage. :/
|
---|
| 1559 | my @intprovlist = qx { find $pkgtree -type f -name "*.so*" };
|
---|
| 1560 | my $provlist = '';
|
---|
| 1561 | foreach (@intprovlist) {
|
---|
| 1562 | s/$pkgtree//;
|
---|
| 1563 | $provlist .= "$_";
|
---|
| 1564 | }
|
---|
| 1565 |
|
---|
[38] | 1566 | my %reqs;
|
---|
[43] | 1567 | my $reqlibs = '';
|
---|
[38] | 1568 |
|
---|
| 1569 | foreach (@reqlist) {
|
---|
| 1570 | next if /^$pkgtree/;
|
---|
[42] | 1571 | next if /not a dynamic executable/;
|
---|
[139] | 1572 | next if m|/lib(?:64)?/ld-linux|; # Hack! Hack! PTHBTT! (libc suxx0rz)
|
---|
[100] | 1573 | next if /linux-gate.so/; # Kernel hackery for teh W1n!!1!1eleventy-one!1 (Don't ask. Feh.)
|
---|
[151] | 1574 | next if /linux-vdso.so/; # More kernel hackery. Whee!
|
---|
[38] | 1575 |
|
---|
[169] | 1576 | my ($req) = (m|=\>\s+([a-zA-Z0-9._/+-]+)|); # dig out the actual library (so)name.
|
---|
[147] | 1577 | # And feh, we need the *path*, since I've discovered a new edge case where
|
---|
| 1578 | # the same libnnn.1.2.3 *file*name is found across *several* lib dirs. >:(
|
---|
[41] | 1579 |
|
---|
| 1580 | # Ignore libs provided by this package. Note that we don't match
|
---|
| 1581 | # on word-boundary at the *end* of the lib we're looking for, as the
|
---|
| 1582 | # looked-for lib may not have the full soname version. (ie, it may
|
---|
| 1583 | # "just" point to one of the symlinks that get created somewhere.)
|
---|
| 1584 | next if $provlist =~ /\b$req/;
|
---|
| 1585 |
|
---|
[38] | 1586 | $reqlibs .= " $req";
|
---|
| 1587 | }
|
---|
| 1588 |
|
---|
[43] | 1589 | if ($reqlibs ne '') {
|
---|
| 1590 | foreach (qx { dpkg -S $reqlibs }) {
|
---|
[167] | 1591 | my ($libpkg,undef) = split /:/;
|
---|
[43] | 1592 | $reqs{$libpkg} = 1;
|
---|
| 1593 | }
|
---|
[38] | 1594 | }
|
---|
| 1595 |
|
---|
[43] | 1596 | my $deplist = '';
|
---|
[38] | 1597 | foreach (keys %reqs) {
|
---|
| 1598 | $deplist .= ", $_";
|
---|
| 1599 | }
|
---|
| 1600 |
|
---|
| 1601 | # For now, we're done. We're not going to meddle with versions yet.
|
---|
| 1602 | # Among other things, it's messier than handling "simple" yes/no "do
|
---|
| 1603 | # we have this lib?" deps. >:(
|
---|
| 1604 |
|
---|
| 1605 | return $deplist;
|
---|
| 1606 | } # end getreqs()
|
---|
| 1607 |
|
---|
| 1608 |
|
---|
[50] | 1609 | ## install_sdeb()
|
---|
| 1610 | # Extracts .sdeb contents to %_topdir as appropriate
|
---|
| 1611 | sub install_sdeb {
|
---|
[92] | 1612 | $srcpkg = abs_path($srcpkg);
|
---|
| 1613 |
|
---|
[50] | 1614 | my $paxcmd = "cd $topdir; pax -r <$srcpkg; cd -";
|
---|
| 1615 |
|
---|
| 1616 | # In case of %-macros...
|
---|
| 1617 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
| 1618 |
|
---|
| 1619 | system "$paxcmd";
|
---|
| 1620 | print "Extracted source package $srcpkg to $topdir.\n";
|
---|
| 1621 | } # end install_sdeb()
|
---|
| 1622 |
|
---|
| 1623 |
|
---|
[10] | 1624 | ## expandmacros()
|
---|
| 1625 | # Expands all %{blah} macros in the passed string
|
---|
[14] | 1626 | # Split up a bit with some sections so we don't spend time trying to
|
---|
| 1627 | # expand macros that are only used in a few specific places.
|
---|
[10] | 1628 | sub expandmacros {
|
---|
| 1629 | my $macrostring = shift;
|
---|
[14] | 1630 | my $section = shift;
|
---|
[10] | 1631 |
|
---|
[25] | 1632 | # To allow the FHS-ish %configure and %makeinstall to work The Right Way.
|
---|
[136] | 1633 | # (Without clobbering the global $specglobals{buildroot}.)
|
---|
[12] | 1634 | my $prefix = '';
|
---|
| 1635 |
|
---|
[11] | 1636 | if ($section =~ /c/) {
|
---|
[12] | 1637 | # %configure macro
|
---|
[17] | 1638 | # Don't know what it's for, don't have a useful default replacement
|
---|
| 1639 | # --program-prefix=%{_program_prefix} \
|
---|
| 1640 | $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
|
---|
| 1641 | --build=$DEB_BUILD_GNU_TYPE \
|
---|
| 1642 | --prefix=%{_prefix} \
|
---|
| 1643 | --exec-prefix=%{_exec_prefix} \
|
---|
| 1644 | --bindir=%{_bindir} \
|
---|
| 1645 | --sbindir=%{_sbindir} \
|
---|
| 1646 | --sysconfdir=%{_sysconfdir} \
|
---|
| 1647 | --datadir=%{_datadir} \
|
---|
| 1648 | --includedir=%{_includedir} \
|
---|
| 1649 | --libdir=%{_libdir} \
|
---|
| 1650 | --libexecdir=%{_libexecdir} \
|
---|
| 1651 | --localstatedir=%{_localstatedir} \
|
---|
| 1652 | --sharedstatedir=%{_sharedstatedir} \
|
---|
| 1653 | --mandir=%{_mandir} \
|
---|
| 1654 | --infodir=%{_infodir} ';
|
---|
[12] | 1655 | } # done %configure
|
---|
| 1656 |
|
---|
| 1657 | if ($section =~ /m/) {
|
---|
| 1658 | $macrostring =~ s'%{__make}'make ';
|
---|
[25] | 1659 | } # done make
|
---|
[12] | 1660 |
|
---|
[136] | 1661 | # %makeinstall expands with recursive macros in rpm. whee.
|
---|
[12] | 1662 | if ($section =~ /i/) {
|
---|
| 1663 | # This is where we need to mangle $prefix.
|
---|
[136] | 1664 | $macrostring =~ s'%makeinstall'make \
|
---|
| 1665 | prefix=%{?buildroot:%{buildroot}}%{_prefix} \
|
---|
| 1666 | exec_prefix=%{?buildroot:%{buildroot}}%{_exec_prefix} \
|
---|
| 1667 | bindir=%{?buildroot:%{buildroot}}%{_bindir} \
|
---|
| 1668 | sbindir=%{?buildroot:%{buildroot}}%{_sbindir} \
|
---|
| 1669 | sysconfdir=%{?buildroot:%{buildroot}}%{_sysconfdir} \
|
---|
| 1670 | datadir=%{?buildroot:%{buildroot}}%{_datadir} \
|
---|
| 1671 | includedir=%{?buildroot:%{buildroot}}%{_includedir} \
|
---|
| 1672 | libdir=%{?buildroot:%{buildroot}}%{_libdir} \
|
---|
| 1673 | libexecdir=%{?buildroot:%{buildroot}}%{_libexecdir} \
|
---|
| 1674 | localstatedir=%{?buildroot:%{buildroot}}%{_localstatedir} \
|
---|
| 1675 | sharedstatedir=%{?buildroot:%{buildroot}}%{_sharedstatedir} \
|
---|
| 1676 | mandir=%{?buildroot:%{buildroot}}%{_mandir} \
|
---|
| 1677 | infodir=%{?buildroot:%{buildroot}}%{_infodir} \
|
---|
| 1678 | install ';
|
---|
| 1679 | $prefix = $specglobals{buildroot};
|
---|
[12] | 1680 | } # done %install and/or %makeinstall
|
---|
| 1681 |
|
---|
| 1682 | # Build data
|
---|
| 1683 | # Note that these are processed in reverse order to get the substitution order right
|
---|
| 1684 | if ($section =~ /b/) {
|
---|
[24] | 1685 | # $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
|
---|
| 1686 | # build=$DEB_BUILD_GNU_TYPE \
|
---|
| 1687 | $macrostring =~ s'%{fhs}'prefix=%{_prefix} \
|
---|
[17] | 1688 | exec-prefix=%{_exec_prefix} \
|
---|
| 1689 | bindir=%{_bindir} \
|
---|
| 1690 | sbindir=%{_sbindir} \
|
---|
| 1691 | sysconfdir=%{_sysconfdir} \
|
---|
| 1692 | datadir=%{_datadir} \
|
---|
| 1693 | includedir=%{_includedir} \
|
---|
| 1694 | libdir=%{_libdir} \
|
---|
| 1695 | libexecdir=%{_libexecdir} \
|
---|
| 1696 | localstatedir=%{_localstatedir} \
|
---|
| 1697 | sharedstatedir=%{_sharedstatedir} \
|
---|
| 1698 | mandir=%{_mandir} \
|
---|
| 1699 | infodir=%{_infodir} \
|
---|
| 1700 | ';
|
---|
[10] | 1701 |
|
---|
| 1702 | # Note that the above regex terminates with the extra space
|
---|
[12] | 1703 | # "Just In Case" of user additions, which will then get neatly
|
---|
| 1704 | # tagged on the end where they take precedence (supposedly)
|
---|
| 1705 | # over the "default" ones.
|
---|
[10] | 1706 |
|
---|
[14] | 1707 | # Now we cascade the macros introduced above. >_<
|
---|
| 1708 | # Wot ot to go theah:
|
---|
| 1709 | $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
|
---|
| 1710 | $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
|
---|
[25] | 1711 | $macrostring =~ s|%{_oldincludedir}|/usr/include|g; #/usr/include
|
---|
[84] | 1712 | $macrostring =~ s|%{_includedir}|%{_prefix}/include|g; #/usr/include
|
---|
[25] | 1713 | $macrostring =~ s|%{_libdir}|%{_exec_prefix}/%{_lib}|g; #/usr/lib
|
---|
[14] | 1714 | $macrostring =~ s|%{_lib}|lib|g; #?
|
---|
[25] | 1715 | $macrostring =~ s|%{_localstatedir}|/var|g; #/var
|
---|
| 1716 | $macrostring =~ s|%{_sharedstatedir}|%{_prefix}/com|g; #/usr/com WTF?
|
---|
| 1717 | $macrostring =~ s|%{_sysconfdir}|/etc|g; #/etc
|
---|
| 1718 | $macrostring =~ s|%{_datadir}|%{_prefix}/share|g; #/usr/share
|
---|
| 1719 | $macrostring =~ s|%{_libexecdir}|%{_exec_prefix}/libexec|g; #/usr/libexec
|
---|
| 1720 | $macrostring =~ s|%{_sbindir}|%{_exec_prefix}/sbin|g; #/usr/sbin
|
---|
| 1721 | $macrostring =~ s|%{_bindir}|%{_exec_prefix}/bin|g; #/usr/bin
|
---|
| 1722 | $macrostring =~ s|%{_exec_prefix}|%{_prefix}|g; #/usr
|
---|
[14] | 1723 | $macrostring =~ s|%{_prefix}|/usr|g; #/usr
|
---|
[10] | 1724 | } # done with config section
|
---|
| 1725 |
|
---|
[12] | 1726 | # Package data
|
---|
| 1727 | if ($section =~ /p/) {
|
---|
[136] | 1728 | $macrostring =~ s/\%\{buildroot\}/$specglobals{buildroot}/gi;
|
---|
[149] | 1729 | $macrostring =~ s/\%\{source0?}/$topdir\/SOURCES\/$pkgdata{main}{source}/gi;
|
---|
[15] | 1730 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
| 1731 | $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
|
---|
| 1732 | }
|
---|
| 1733 | $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
|
---|
| 1734 | $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
|
---|
| 1735 | $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
|
---|
[12] | 1736 | }
|
---|
| 1737 |
|
---|
| 1738 | # Globals, and not-so-globals
|
---|
| 1739 | if ($section =~ /g/) {
|
---|
[60] | 1740 |
|
---|
[29] | 1741 | $macrostring =~ s|%{_builddir}|%{_topdir}/BUILD|g;
|
---|
[169] | 1742 | $macrostring =~ s|%{buildsubdir}|$tarballdir|g;
|
---|
[29] | 1743 | $macrostring =~ s|%{_topdir}|$topdir|g;
|
---|
[13] | 1744 | $macrostring =~ s|%{_tmppath}|$tmpdir|g;
|
---|
[84] | 1745 | $macrostring =~ s'%{_docdir}'%{_datadir}/doc'g;
|
---|
[23] | 1746 |
|
---|
[31] | 1747 | # Standard FHS locations. More or less.
|
---|
[30] | 1748 | $macrostring =~ s'%{_bindir}'/usr/bin'g;
|
---|
[31] | 1749 | $macrostring =~ s'%{_sbindir}'/usr/sbin'g;
|
---|
[84] | 1750 | $macrostring =~ s'%{_mandir}'%{_datadir}/man'g;
|
---|
[153] | 1751 | $macrostring =~ s'%{_infodir}'%{_datadir}/info'g;
|
---|
[30] | 1752 | $macrostring =~ s'%{_includedir}'/usr/include'g;
|
---|
[31] | 1753 | $macrostring =~ s'%{_libdir}'/usr/lib'g;
|
---|
| 1754 | $macrostring =~ s'%{_sysconfdir}'/etc'g;
|
---|
| 1755 | $macrostring =~ s'%{_localstatedir}'/var'g;
|
---|
[30] | 1756 |
|
---|
[84] | 1757 | # FHS-ish locations that aren't quite actually FHS-specified.
|
---|
| 1758 | $macrostring =~ s'%{_datadir}'/usr/share'g;
|
---|
| 1759 |
|
---|
[96] | 1760 | # special %define's. Handle the general case where we eval anything.
|
---|
| 1761 | # Even more general: %(...) is a spec-parse-time shell code wrapper.
|
---|
| 1762 | # Prime example:
|
---|
| 1763 | #%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
|
---|
| 1764 | if ($macrostring =~ /\%\((.+)\)/) {
|
---|
| 1765 | my $shellstr = $1;
|
---|
| 1766 | # Oy vey this gets silly for the perl bits. Executing a shell to
|
---|
| 1767 | # call Perl to get the vendorlib/sitelib/whatever "core" globals.
|
---|
| 1768 | # This can do more, but... eww.
|
---|
| 1769 | $shellstr = qx { /bin/sh -c '$shellstr' }; # Yay! ' characters apparently get properly exscapededed.
|
---|
| 1770 | $macrostring =~ s/\%\(.+\)/$shellstr/;
|
---|
| 1771 | }
|
---|
| 1772 |
|
---|
[95] | 1773 | # support for **some** %if constructs. Note that this breaks somewhat if
|
---|
| 1774 | # there's no value specified... but so does rpm.
|
---|
[136] | 1775 |
|
---|
| 1776 | my $tmpcount = 0; # runaway shutdown. Not really sure how else to avoid getting stuck.
|
---|
| 1777 | while ($macrostring =~ m/\%\{([?!]+)([a-z0-9_.-]+)(?:\:([a-z0-9_.\/\-\\]+)?)?\}/g) { #Whew....
|
---|
[116] | 1778 | my $qex = $1;
|
---|
| 1779 | my $macro = $2;
|
---|
[136] | 1780 | my $value = (defined($3) ? $3 : '');
|
---|
[114] | 1781 |
|
---|
| 1782 | my $neg = '1' if $qex =~ /\!/;
|
---|
[95] | 1783 | if ($specglobals{$macro}) {
|
---|
| 1784 | $value = '' if $neg;
|
---|
| 1785 | } else {
|
---|
| 1786 | $value = '' if !$neg;
|
---|
| 1787 | }
|
---|
[136] | 1788 | $macrostring =~ s/\%\{[?!]+[a-z0-9_.-]+(?:\:([a-z0-9_.\/\-\\]+)?)?\}/$value/;
|
---|
[95] | 1789 |
|
---|
[114] | 1790 | # not certain about this, but I don't want to run away. It *can* happen if planned carefully. :/
|
---|
| 1791 | $tmpcount++;
|
---|
[136] | 1792 | # %makeinstall has 13 occurrences. D'Oh!
|
---|
| 1793 | die "excessive recursive macro replacement; dying.\n" if $tmpcount > 14;
|
---|
[114] | 1794 |
|
---|
| 1795 | } # while()
|
---|
| 1796 |
|
---|
[123] | 1797 | # Misc expansions
|
---|
| 1798 | $macrostring =~ s|%{_arch}|$hostarch|g;
|
---|
| 1799 | $macrostring =~ s|%{optflags}|$optflags{$hostarch}|g;
|
---|
[125] | 1800 | $macrostring =~ s|%{_vendor}|$specglobals{'_vendor'}|g;
|
---|
[123] | 1801 |
|
---|
[159] | 1802 | # system programs. RPM uses a global config file for these; we'll just
|
---|
| 1803 | # ASS-U-ME and make life a little simpler.
|
---|
| 1804 | if ($macrostring =~ /\%\{\_\_([a-z0-9_-]+)\}/) {
|
---|
| 1805 | $macrostring =~ s|%{__([a-z0-9_-]+)}|$1|g;
|
---|
| 1806 | }
|
---|
| 1807 |
|
---|
[116] | 1808 | # should probably stick a "no runaway" flag in here... Just In Case...
|
---|
| 1809 | # %define's
|
---|
[158] | 1810 | # note to self: find out valid chars for %define name/label so we can parse them
|
---|
| 1811 | while (my ($key) = ($macrostring =~ /%{([a-z0-9_]+)}/i) ) {
|
---|
[123] | 1812 | # hrm. This needs thinking.
|
---|
| 1813 | #die "A horrible death! \%{$key}, '$macrostring'\n" if !$specglobals{$key};
|
---|
[116] | 1814 | $macrostring =~ s|%{$key}|$specglobals{$key}|g;
|
---|
| 1815 | # wanna limit this to "... if $specglobals{$key}", but need more magic
|
---|
| 1816 | }
|
---|
| 1817 |
|
---|
[113] | 1818 | # Perl @INC/...lib locations, and other related bits.
|
---|
| 1819 | $macrostring =~ s|%{perl_archlib}|$Config{installarchlib}|g;
|
---|
| 1820 | $macrostring =~ s|%{perl_sitelib}|$Config{installsitelib}|g;
|
---|
| 1821 | $macrostring =~ s|%{perl_sitearch}|$Config{installsitearch}|g;
|
---|
| 1822 | $macrostring =~ s|%{perl_vendorlib}|$Config{installvendorlib}|g;
|
---|
| 1823 | $macrostring =~ s|%{perl_vendorarch}|$Config{installvendorarch}|g;
|
---|
| 1824 |
|
---|
[10] | 1825 | } # done with globals section
|
---|
| 1826 |
|
---|
| 1827 | return $macrostring;
|
---|
| 1828 | } # end expandmacros()
|
---|
[22] | 1829 |
|
---|
| 1830 |
|
---|
| 1831 |
|
---|
[38] | 1832 | __END__
|
---|
| 1833 |
|
---|
| 1834 |
|
---|
| 1835 |
|
---|
[22] | 1836 | =head1 NAME
|
---|
| 1837 |
|
---|
[140] | 1838 | debbuild - Build Debian-compatible .deb packages from RPM .spec files
|
---|
[22] | 1839 |
|
---|
| 1840 | =head1 SYNOPSIS
|
---|
| 1841 |
|
---|
| 1842 | debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
|
---|
| 1843 |
|
---|
[174] | 1844 | debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2|xz}
|
---|
[22] | 1845 |
|
---|
[55] | 1846 | debbuild --rebuild file.{src.rpm|sdeb}
|
---|
[22] | 1847 |
|
---|
[89] | 1848 | debbuild --showpkgs
|
---|
| 1849 |
|
---|
[22] | 1850 | =head1 DESCRIPTION
|
---|
| 1851 |
|
---|
[140] | 1852 | debbuild attempts to build Debian-friendly semi-native packages from RPM spec files,
|
---|
[55] | 1853 | RPM-friendly tarballs, and RPM source packages (.src.rpm files). It accepts I<most> of the
|
---|
| 1854 | options rpmbuild does, and should be able to interpret most spec files usefully. Perl
|
---|
[140] | 1855 | modules should be handled via CPAN+dh-make-perl instead as it's simpler than even tweaking
|
---|
| 1856 | a .spec template.
|
---|
[22] | 1857 |
|
---|
[55] | 1858 | As far as possible, the command-line options are identical to those from rpmbuild, although
|
---|
[57] | 1859 | several rpmbuild options are not supported:
|
---|
[22] | 1860 |
|
---|
[57] | 1861 | --recompile
|
---|
| 1862 | --showrc
|
---|
| 1863 | --buildroot
|
---|
| 1864 | --clean
|
---|
| 1865 | --nobuild
|
---|
| 1866 | --rmsource
|
---|
| 1867 | --rmspec
|
---|
| 1868 | --sign
|
---|
| 1869 | --target
|
---|
| 1870 |
|
---|
| 1871 | Some of these could probably be trivially added. Feel free to send me a patch. ;)
|
---|
| 1872 |
|
---|
| 1873 | Complex spec files will most likely not work well, if at all. Rewrite them from scratch -
|
---|
| 1874 | you'll have to make heavy modifications anyway.
|
---|
| 1875 |
|
---|
| 1876 | If you see something you don't like, mail me. Send a patch if you feel inspired. I don't
|
---|
| 1877 | promise I'll do anything other than say "Yup, that's broken" or "Got your message".
|
---|
| 1878 |
|
---|
[55] | 1879 | =head1 ASSUMPTIONS
|
---|
| 1880 |
|
---|
| 1881 | As with rpmbuild, debbuild makes some assumptions about your system.
|
---|
| 1882 |
|
---|
| 1883 | =over 4
|
---|
| 1884 |
|
---|
| 1885 | =item *
|
---|
| 1886 |
|
---|
| 1887 | Either you have rights to do as you please under /usr/src/debian, or you have created a file
|
---|
| 1888 | ~/.debmacros containing a suitable %_topdir definition.
|
---|
| 1889 |
|
---|
[57] | 1890 | Both rpmbuild and debbuild require the directories %_topdir/{BUILD,SOURCES,SPECS}. However,
|
---|
| 1891 | where rpmbuild requires the %_topdir/{RPMS,SRPMS} directories, debbuild
|
---|
| 1892 | requires %_topdir/{DEBS,SDEBS} instead. Create them in advance;
|
---|
[55] | 1893 | some subdirectories are created automatically as needed, but most are not.
|
---|
| 1894 |
|
---|
| 1895 | =item *
|
---|
| 1896 |
|
---|
| 1897 | /var/tmp must allow script execution - rpmbuild and debbuild both rely on creating and
|
---|
| 1898 | executing shell scripts for much of their functionality. By default, debbuild also creates
|
---|
| 1899 | install trees under /var/tmp - however this is (almost) entirely under the control of the
|
---|
| 1900 | package's .spec file.
|
---|
| 1901 |
|
---|
| 1902 | =item *
|
---|
| 1903 |
|
---|
| 1904 | If you wish to --rebuild a .src.rpm, your %_topdir for both debbuild and rpmbuild must either
|
---|
| 1905 | match, or be suitably symlinked one direction or another so that both programs are effectively
|
---|
| 1906 | working in the same tree. (Or you could just manually wrestle files around your system.)
|
---|
| 1907 |
|
---|
| 1908 | You could symlink ~/.rpmmacros to ~/.debmacros (or vice versa) and save yourself some hassle
|
---|
| 1909 | if you need to rebuild .src.rpm packages on a regular basis. Currently debbuild only uses the
|
---|
| 1910 | %_topdir macro definition, although there are many more things that rpmbuild can use from
|
---|
| 1911 | ~/.rpmmacros.
|
---|
| 1912 |
|
---|
| 1913 | =back
|
---|
| 1914 |
|
---|
[89] | 1915 | =head1 ERRATA
|
---|
| 1916 |
|
---|
| 1917 | debbuild deliberately does a few things differently from rpm.
|
---|
| 1918 |
|
---|
| 1919 | =head2 BuildArch or BuildArchitecture
|
---|
| 1920 |
|
---|
| 1921 | rpm takes the last BuildArch entry it finds in the .spec file, whatever it is, and runs with
|
---|
| 1922 | that for all packages. Debian's repository system is fairly heavily designed around the
|
---|
| 1923 | assumption that a single source package may generate small binary (executable) packages
|
---|
| 1924 | for each arch, and large binary arch-all packages containing shared data.
|
---|
| 1925 |
|
---|
| 1926 | debbuild allows this by using the architecture specified by (in order of preference):
|
---|
| 1927 |
|
---|
| 1928 | =over 4
|
---|
| 1929 |
|
---|
| 1930 | =item * Host architecture
|
---|
| 1931 |
|
---|
| 1932 | =item * BuildArch specified in .spec file preamble
|
---|
| 1933 |
|
---|
| 1934 | =item * "Last specified" BuildArch for packages with several subpackages
|
---|
| 1935 |
|
---|
| 1936 | =item * BuildArch specified in the %package section for that subpackage
|
---|
| 1937 |
|
---|
| 1938 | =back
|
---|
| 1939 |
|
---|
| 1940 | =head2 Finding out what packages should be built (--showpkgs)
|
---|
| 1941 |
|
---|
| 1942 | rpmbuild does not include any convenient method I know of to list the packages a spec file
|
---|
| 1943 | will produce. Since I needed this ability for another tool, I added it.
|
---|
| 1944 |
|
---|
| 1945 | It requires the .spec file for the package, and produces a list of full package filenames
|
---|
| 1946 | (without path data) that would be generated by one of --rebuild, -ta, -tb, -ba, or -bb.
|
---|
| 1947 | This includes the .sdeb source package.
|
---|
| 1948 |
|
---|
[57] | 1949 | =head1 AUTHOR
|
---|
[55] | 1950 |
|
---|
[57] | 1951 | debbuild was written by Kris Deugau <kdeugau@deepnet.cx>. A version that approximates
|
---|
| 1952 | current is available at http://www.deepnet.cx/debbuild/.
|
---|
[55] | 1953 |
|
---|
| 1954 | =head1 BUGS
|
---|
| 1955 |
|
---|
[57] | 1956 | Funky Things Happen if you forget a command-line option or two. I've been too lazy to bother
|
---|
| 1957 | fixing this.
|
---|
[55] | 1958 |
|
---|
[57] | 1959 | Many macro expansions are unsupported or incompletely supported.
|
---|
| 1960 |
|
---|
| 1961 | The generated scriptlets don't quite match those from rpmbuild exactly. There are extra
|
---|
| 1962 | environment variables and preprocessing that I haven't needed (yet).
|
---|
| 1963 |
|
---|
| 1964 | Dcumentation, such as it is, will likely remain perpetually out of date.
|
---|
| 1965 |
|
---|
| 1966 | %_topdir and the five "working" directories under %_topdir could arguably be created by
|
---|
| 1967 | debbuild. However, rpmbuild doesn't create these directories either.
|
---|
| 1968 |
|
---|
| 1969 | =head1 SEE ALSO
|
---|
| 1970 |
|
---|
| 1971 | rpm(8), rpmbuild(8), and pretty much any document describing how to write a .spec file.
|
---|
| 1972 |
|
---|
[22] | 1973 | =cut
|
---|