source: trunk/debbuild@ 119

Last change on this file since 119 was 119, checked in by kdeugau, 17 years ago

/trunk

Added chunk to the .spec parser to choke and die Just Like rpmbuild if we
encounter a %[a-z]+ tag we don't understand.

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