source: trunk/debbuild@ 129

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

/trunk

Add support for Recommends, Suggests, and Replaces. Note that these are
Debian-specific headers/tags, and MUST be wrapped with a suitable %if
construct for multiplatform builds. (%if %{_vendor} == "debbuild" is
probably the best minimum choice.)

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