source: trunk/debbuild@ 188

Last change on this file since 188 was 188, checked in by kdeugau, 9 years ago

/trunk

Fine-tune handling of %setup -c, -a, and -b to correctly handle a missed
edge case, as per a report from Andreas Scherer.

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