source: trunk/debbuild@ 189

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

/trunk

Fix handling of %{vendor} vs %{_vendor} as promted by Neal Gompa

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