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-09 21:27:14 +0000 (Thu, 09 Aug 2007) $
|
---|
9 | # SVN revision $Rev: 128 $
|
---|
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 |
|
---|
28 | use strict;
|
---|
29 | use warnings;
|
---|
30 | use Fcntl; # for sysopen flags
|
---|
31 | use Cwd 'abs_path'; # for finding where files really are
|
---|
32 | use 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 |
|
---|
42 | sub 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
|
---|
55 | my $finalmessages = ''; # A place to stuff messages that I want printed at the *very* end of any processing.
|
---|
56 | my $specfile;
|
---|
57 | my $tarball;
|
---|
58 | my $srcpkg;
|
---|
59 | my $cmdbuildroot;
|
---|
60 | my $tarballdir = '%{name}-%{version}'; # We do this in case of a spec file not using %setup...
|
---|
61 | my %specglobals; # For %define's in specfile, among other things.
|
---|
62 |
|
---|
63 | $specglobals{'_vendor'} = 'debbuild';
|
---|
64 |
|
---|
65 | # Initialized globals
|
---|
66 | my $verbosity = 0;
|
---|
67 | my $NoAutoReq = 0;
|
---|
68 | my %cmdopts = (type => '',
|
---|
69 | stage => 'a',
|
---|
70 | short => 'n'
|
---|
71 | );
|
---|
72 | my $topdir = "/usr/src/debian";
|
---|
73 | my $buildroot = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
|
---|
74 |
|
---|
75 | # "Constants"
|
---|
76 | my %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
|
---|
86 | my %optflags = ( 'i386' => '-O2 -g -march=i386 -mcpu=i686',
|
---|
87 | 'amd64' => '-O2 -g'
|
---|
88 | );
|
---|
89 | my $hostarch; # we set this later...
|
---|
90 | my $scriptletbase =
|
---|
91 | q(#!/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 | );
|
---|
108 | foreach (`dpkg-architecture`) {
|
---|
109 | s/=(.+)/="$1"/;
|
---|
110 | $scriptletbase .= " $_";
|
---|
111 | ($hostarch) = (/^DEB_HOST_ARCH="(.+)"$/) if /DEB_HOST_ARCH=/;
|
---|
112 | }
|
---|
113 | $scriptletbase .=
|
---|
114 | q(
|
---|
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
|
---|
123 | my %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
|
---|
151 | my %pkgdata;
|
---|
152 | my @pkglist = ('main'); #sigh
|
---|
153 | # Files listing. Embedding this in %pkgdata would be, um, messy.
|
---|
154 | my %filelist;
|
---|
155 | my %doclist;
|
---|
156 | my $buildreq = '';
|
---|
157 |
|
---|
158 | # Scriptlets
|
---|
159 | my $prepscript = '';
|
---|
160 | my $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?
|
---|
163 | my $installscript = '[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT'."\n";
|
---|
164 | my $cleanscript = '';
|
---|
165 |
|
---|
166 | die "Not enough arguments\n" if #$argv == 0;
|
---|
167 |
|
---|
168 | # Snag some environment data
|
---|
169 | my $tmpdir;
|
---|
170 | if (defined $ENV{TMP} && $ENV{TMP} =~ /^(\/var)?\/tmp$/) {
|
---|
171 | $tmpdir = $ENV{TMP};
|
---|
172 | } else {
|
---|
173 | $tmpdir = "/var/tmp";
|
---|
174 | }
|
---|
175 |
|
---|
176 | ##main
|
---|
177 |
|
---|
178 | load_userconfig();
|
---|
179 | parse_cmd();
|
---|
180 |
|
---|
181 | if ($cmdopts{install}) {
|
---|
182 | install_sdeb();
|
---|
183 | exit 0;
|
---|
184 | }
|
---|
185 |
|
---|
186 | # output stage of --showpkgs
|
---|
187 | if ($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
|
---|
208 | if ($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 |
|
---|
228 | if ($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 |
|
---|
236 | if ($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
|
---|
257 | if ($cmdopts{stage} eq 's') {
|
---|
258 | srcpackage();
|
---|
259 | exit 0;
|
---|
260 | }
|
---|
261 |
|
---|
262 | # Hokay. Need to:
|
---|
263 | # -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
|
---|
264 | if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
265 | prep();
|
---|
266 | }
|
---|
267 | # -> build if -.c OR (-.[ilabs] AND !--short-circuit)
|
---|
268 | if ($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')) {
|
---|
273 | if ($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
|
---|
281 | if ($cmdopts{stage} eq 'a') {
|
---|
282 | binpackage();
|
---|
283 | srcpackage();
|
---|
284 | clean();
|
---|
285 | }
|
---|
286 | # -> binpkg if -.b
|
---|
287 | if ($cmdopts{stage} eq 'b') {
|
---|
288 | binpackage();
|
---|
289 | clean();
|
---|
290 | }
|
---|
291 |
|
---|
292 | # Spit out any closing remarks
|
---|
293 | print $finalmessages;
|
---|
294 |
|
---|
295 | # Just in case.
|
---|
296 | exit 0;
|
---|
297 |
|
---|
298 |
|
---|
299 | ## load_userconfig()
|
---|
300 | # Loads user configuration (if any)
|
---|
301 | # Currently only handles .debmacros
|
---|
302 | # Needs to handle "other files"
|
---|
303 | sub 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
|
---|
326 | sub 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.
|
---|
461 | sub 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 |
|
---|
483 | LINE: 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 | if (my ($dname,$dvalue) = (/^(Summary|Group|Version|Requires|Provides|BuildArch(?:itecture)?):\s+(.+)$/i)) {
|
---|
664 | $dname =~ tr/[A-Z]/[a-z]/;
|
---|
665 | if ($dname =~ /^BuildArch/i) {
|
---|
666 | $dvalue =~ s/^noarch/all/ig;
|
---|
667 | $buildarch = $dvalue; # Emulate rpm's behaviour to a degree
|
---|
668 | $dname = 'arch';
|
---|
669 | }
|
---|
670 | $pkgdata{$subname}{$dname} = expandmacros($dvalue, 'gp');
|
---|
671 | }
|
---|
672 | } # package
|
---|
673 |
|
---|
674 | if ($stage eq 'prep') {
|
---|
675 | # Actual handling for %prep section. May have %setup macro; may
|
---|
676 | # include %patch tags, may be just a bare shell script.
|
---|
677 | if (/^\%setup/) {
|
---|
678 | # Parse out the %setup macro. Note that we aren't supporting
|
---|
679 | # many of RPM's %setup features.
|
---|
680 | $prepscript .= "cd $topdir/BUILD\n";
|
---|
681 | if ( /\s+-n\s+([^\s]+)\s+/ ) {
|
---|
682 | $tarballdir = $1;
|
---|
683 | }
|
---|
684 | $tarballdir = expandmacros($tarballdir,'gp');
|
---|
685 | $prepscript .= "rm -rf $tarballdir\n";
|
---|
686 | if (/\s+-c\s+/) {
|
---|
687 | $prepscript .= "mkdir $tarballdir\ncd $tarballdir\n";
|
---|
688 | }
|
---|
689 | $prepscript .= "tar -".
|
---|
690 | ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
|
---|
691 | ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
|
---|
692 | ( /\s+-q\s+/ ? '' : 'vv' )."xf ".
|
---|
693 | "$topdir/SOURCES/$pkgdata{main}{source}\n".
|
---|
694 | qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
|
---|
695 | "cd $topdir/BUILD/$tarballdir\n".
|
---|
696 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
|
---|
697 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
|
---|
698 | qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
|
---|
699 | } elsif ( my ($patchnum,$patchopts) = (/^\%patch([^\s]+)(\s+.+)?$/) ) {
|
---|
700 | chomp $patchnum;
|
---|
701 | $prepscript .= qq(echo "Patch #$patchnum ($pkgdata{main}{"patch$patchnum"}):"\n).
|
---|
702 | "patch ";
|
---|
703 | # If there are options passed, use'em.
|
---|
704 | # Otherwise, catch a bare %patch and ASS-U-ME it's '-p0'-able.
|
---|
705 | # Will break on options that don't provide -pnn, but what the hell.
|
---|
706 | $prepscript .= $patchopts if $patchopts;
|
---|
707 | $prepscript .= "-p0" if !$patchopts;
|
---|
708 | $prepscript .= " -s <$topdir/SOURCES/".$pkgdata{main}{"patch$patchnum"}."\n";
|
---|
709 | } else {
|
---|
710 | $prepscript .= expandmacros($_,'gp');
|
---|
711 | }
|
---|
712 | next LINE;
|
---|
713 | } # prep
|
---|
714 |
|
---|
715 | if ($stage eq 'build') {
|
---|
716 | # %build. This is pretty much just a shell script. There
|
---|
717 | # aren't many local macros to deal with.
|
---|
718 | if (/^\%configure/) {
|
---|
719 | $buildscript .= expandmacros($_,'cgbp');
|
---|
720 | } elsif (/^\%\{__make\}/) {
|
---|
721 | $buildscript .= expandmacros($_,'mgbp');
|
---|
722 | } else {
|
---|
723 | $buildscript .= expandmacros($_,'gp');
|
---|
724 | }
|
---|
725 | next LINE;
|
---|
726 | } # build
|
---|
727 |
|
---|
728 | if ($stage eq 'install') {
|
---|
729 | if (/^\%makeinstall/) {
|
---|
730 | $installscript .= expandmacros($_,'igbp');
|
---|
731 | } else {
|
---|
732 | $installscript .= expandmacros($_,'gp');
|
---|
733 | }
|
---|
734 | next LINE;
|
---|
735 | } # install
|
---|
736 |
|
---|
737 | if ($stage eq 'clean') {
|
---|
738 | $cleanscript .= expandmacros($_,'gp');
|
---|
739 | next LINE;
|
---|
740 | } # clean
|
---|
741 |
|
---|
742 | if ($stage eq 'prepost') {
|
---|
743 | $pkgdata{$subname}{$scriptlet} .= expandmacros($_,'gp');
|
---|
744 | next LINE;
|
---|
745 | } # prepost
|
---|
746 |
|
---|
747 | if ($stage eq 'files') {
|
---|
748 | # need to deal with these someday
|
---|
749 | next LINE if /^\%dir/;
|
---|
750 | next LINE if /^\%defattr/;
|
---|
751 | next LINE if /^\%verify/;
|
---|
752 | # dunno what to do with this; not sure if there's space in Debian's package structure for it.
|
---|
753 | next LINE if /^\%ghost/;
|
---|
754 | # Debian dpkg doesn't speak "%docdir". Meh.
|
---|
755 | next LINE if /^\%docdir/;
|
---|
756 | # my $singleton = 0; # don't recall what this was for
|
---|
757 |
|
---|
758 | # create and initialize flags
|
---|
759 | my ($perms, $owner, $group, $conf, $filesline);
|
---|
760 | $perms = $owner = $group = $conf = '-';
|
---|
761 |
|
---|
762 | $filesline = $_;
|
---|
763 |
|
---|
764 | # strip and flag %attr constructs
|
---|
765 | if ($filesline =~ /\%attr\b/) {
|
---|
766 | # Extract %attr...
|
---|
767 | my ($args) = (/(\%attr\s*\(\s*[\d-]+\s*,\s*["a-zA-Z0-9-]+\s*,\s*["a-zA-Z0-9-]+\s*\))/);
|
---|
768 | $args =~ s/\s+//g;
|
---|
769 | $args =~ s/"//g; # don't think quotes are ever necessary, but they're *allowed*
|
---|
770 | # ... and parse it ...
|
---|
771 | ($perms,$owner,$group) = ($args =~ /\(([\d-]+),([a-zA-Z0-9-]+),([a-zA-Z0-9-]+)/);
|
---|
772 | # ... and wipe it when we're done.
|
---|
773 | $filesline =~ s/\%attr\s*\(\s*[\d-]+\s*,\s*["a-zA-Z0-9-]+\s*,\s*["a-zA-Z0-9-]+\s*\)//;
|
---|
774 | }
|
---|
775 |
|
---|
776 | # Conffiles. Note that Debian and RH have similar, but not
|
---|
777 | # *quite* identical ideas of what constitutes a conffile. Nrgh.
|
---|
778 | # Note that dpkg will always ask if you want to replace the file - noreplace
|
---|
779 | # is more or less permanently enabled.
|
---|
780 | ##fixme
|
---|
781 | # also need to handle missingok (file that doesn't exist, but should be removed on uninstall)
|
---|
782 | # hmm. not sure if such is **POSSIBLE** with Debian... maybe an addition to %post?
|
---|
783 | if ($filesline =~ /\%config\b(?:\s*\(\s*noreplace\s*\)\s*)?/) {
|
---|
784 | $pkgdata{$subname}{conffiles} = 1; # Flag it for later
|
---|
785 | $conf = 'y';
|
---|
786 | $filesline =~ s/\%config\b(?:\s*\(\s*noreplace\s*\)\s*)?//;
|
---|
787 | }
|
---|
788 |
|
---|
789 | # %doc needs extra processing, because it can be a space-separated list, and may
|
---|
790 | # include both full and partial pathnames. The partial pathnames must be fiddled
|
---|
791 | # into place in the %install script, because Debian doesn't really have the concept
|
---|
792 | # of "documentation file" that rpm does. (Debian "documentation files" are files
|
---|
793 | # in /usr/share/doc/<packagename>.)
|
---|
794 | ##fixme: unhandled case: %doc %defattr. Eeep.
|
---|
795 | # don't really know what to do with %defattr, generally. :(
|
---|
796 | if ($filesline =~ /\%doc\b/) {
|
---|
797 | $filesline =~ s/\s*\%doc\s+//;
|
---|
798 |
|
---|
799 | # this could probably go elsewhere.
|
---|
800 | my $pkgname = $pkgdata{$subname}{name};
|
---|
801 | $pkgname =~ tr/_/-/;
|
---|
802 |
|
---|
803 | # have to extract the partial pathnames that %doc installs automagically
|
---|
804 | foreach (split /\s+/, $filesline) {
|
---|
805 | if (! (/^\%/ or m|^/|) ) {
|
---|
806 | $doclist{$subname} .= " $_";
|
---|
807 | my ($element) = m|([^/\s]+/?)$|;
|
---|
808 | $filesline =~ s|$_|\%{_docdir}/$pkgname/$element|;
|
---|
809 | }
|
---|
810 | }
|
---|
811 | } # $filesline =~ /\%doc\b/
|
---|
812 |
|
---|
813 | $filesline =~ s/^\s*//; # Just In Case. For, uh, neatness.
|
---|
814 |
|
---|
815 | # due to Debian's total lack of real permissions-processing in its actual package
|
---|
816 | # handling component (dpkg-deb), this can't really be done "properly". We'll have
|
---|
817 | # to add chown/chmod commands to the postinst instead. Feh.
|
---|
818 | $pkgdata{$subname}{'post'} .= "chown $owner $filesline\n" if $owner ne '-';
|
---|
819 | $pkgdata{$subname}{'post'} .= "chgrp $group $filesline\n" if $group ne '-';
|
---|
820 | $pkgdata{$subname}{'post'} .= "chmod $perms $filesline\n" if $perms ne '-';
|
---|
821 |
|
---|
822 | ##fixme
|
---|
823 | # need hackery to assure only one filespec per %config. NB: "*" is one filespec. <g>
|
---|
824 | push @{$pkgdata{$subname}{conflist}}, $filesline if $conf ne '-';
|
---|
825 |
|
---|
826 | # now that we've got the specials out of the way, we can add things to the appropriate list of files.
|
---|
827 | # ... and finally everything else
|
---|
828 | $filelist{$subname} .= " $filesline";
|
---|
829 |
|
---|
830 | next LINE;
|
---|
831 | } # files
|
---|
832 |
|
---|
833 | if ($stage eq 'changelog') {
|
---|
834 | # this is one of the few places we do NOT generally want to replace macros...
|
---|
835 | $pkgdata{main}{changelog} .= $_;
|
---|
836 | }
|
---|
837 |
|
---|
838 | if ($stage eq 'preamble') {
|
---|
839 | if (/^summary:\s+(.+)/i) {
|
---|
840 | $pkgdata{main}{summary} = $1;
|
---|
841 | } elsif (/^name:\s+(.+)/i) {
|
---|
842 | $pkgdata{main}{name} = expandmacros($1,'g');
|
---|
843 | } elsif (/^epoch:\s+(.+)/i) {
|
---|
844 | $pkgdata{main}{epoch} = expandmacros($1,'g');
|
---|
845 | } elsif (/^version:\s+(.+)/i) {
|
---|
846 | $pkgdata{main}{version} = expandmacros($1,'g');
|
---|
847 | } elsif (/^release:\s+(.+)/i) {
|
---|
848 | $pkgdata{main}{release} = expandmacros($1,'g');
|
---|
849 | } elsif (/^group:\s+(.+)/i) {
|
---|
850 | $pkgdata{main}{group} = $1;
|
---|
851 | } elsif (/^copyright:\s+(.+)/i) {
|
---|
852 | $pkgdata{main}{copyright} = $1;
|
---|
853 | } elsif (/^url:\s+(.+)/i) {
|
---|
854 | $pkgdata{main}{url} = $1;
|
---|
855 | } elsif (/^packager:\s+(.+)/i) {
|
---|
856 | $pkgdata{main}{packager} = $1;
|
---|
857 | } elsif (/^buildroot:\s+(.+)/i) {
|
---|
858 | $buildroot = $1;
|
---|
859 | } elsif (/^source0?:\s+(.+)/i) {
|
---|
860 | $pkgdata{main}{source} = $1;
|
---|
861 | die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
|
---|
862 | } elsif (/^source([0-9]+):\s+(.+)/i) {
|
---|
863 | $pkgdata{sources}{$1} = $2;
|
---|
864 | } elsif (/^patch([^:]+):\s+(.+)$/i) {
|
---|
865 | my $patchname = "patch$1";
|
---|
866 | $pkgdata{main}{$patchname} = $2;
|
---|
867 | if ($pkgdata{main}{$patchname} =~ /\//) {
|
---|
868 | # URL-style patch. Rare but not unheard-of.
|
---|
869 | my @patchbits = split '/', $pkgdata{main}{$patchname};
|
---|
870 | $pkgdata{main}{$patchname} = $patchbits[$#patchbits];
|
---|
871 | }
|
---|
872 | chomp $pkgdata{main}{$patchname};
|
---|
873 | } elsif (/^buildarch(?:itecture)?:\s+(.+)/i) {
|
---|
874 | $pkgdata{main}{arch} = $1;
|
---|
875 | $pkgdata{main}{arch} =~ s/^noarch$/all/;
|
---|
876 | $buildarch = $pkgdata{main}{arch};
|
---|
877 | } elsif (/^buildreq(?:uires)?:\s+(.+)/i) {
|
---|
878 | $buildreq .= ", $1";
|
---|
879 | } elsif (/^requires:\s+(.+)/i) {
|
---|
880 | $pkgdata{main}{requires} .= ", ".expandmacros("$1", 'gp');
|
---|
881 | } elsif (/^provides:\s+(.+)/i) {
|
---|
882 | $pkgdata{main}{provides} .= ", $1";
|
---|
883 | } elsif (/^conflicts:\s+(.+)/i) {
|
---|
884 | $pkgdata{main}{conflicts} .= ", $1";
|
---|
885 | } elsif (/^autoreq(?:prov)?:\s+(.+)/i) {
|
---|
886 | # we don't handle auto-provides (yet)
|
---|
887 | $NoAutoReq = 1 if $1 =~ /(?:no|0)/i;
|
---|
888 | }
|
---|
889 | next LINE;
|
---|
890 | } # preamble
|
---|
891 |
|
---|
892 | } # while <SPEC>
|
---|
893 |
|
---|
894 | # Parse and replace some more macros. More will be replaced even later.
|
---|
895 |
|
---|
896 | # Expand macros as necessary.
|
---|
897 | $scriptletbase = expandmacros($scriptletbase,'gp');
|
---|
898 |
|
---|
899 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
900 |
|
---|
901 | $buildroot = $cmdbuildroot if $cmdbuildroot;
|
---|
902 | $buildroot = expandmacros($buildroot,'gp');
|
---|
903 |
|
---|
904 | close SPECFILE;
|
---|
905 | } # end parse_spec()
|
---|
906 |
|
---|
907 |
|
---|
908 | ## prep()
|
---|
909 | # Writes and executes the %prep script (mostly) built while reading the spec file.
|
---|
910 | sub prep {
|
---|
911 | # Replace some things here just to make sure.
|
---|
912 | $prepscript = expandmacros($prepscript,'gp');
|
---|
913 |
|
---|
914 | # create script filename
|
---|
915 | my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
|
---|
916 | sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
917 | or die $!;
|
---|
918 | print PREPSCRIPT $scriptletbase;
|
---|
919 | print PREPSCRIPT $prepscript;
|
---|
920 | close PREPSCRIPT;
|
---|
921 |
|
---|
922 | # execute
|
---|
923 | print "Calling \%prep script $prepscriptfile...\n";
|
---|
924 | system("/bin/sh -e $prepscriptfile") == 0
|
---|
925 | or die "Can't exec: $!\n";
|
---|
926 |
|
---|
927 | # and clean up
|
---|
928 | unlink $prepscriptfile;
|
---|
929 | } # end prep()
|
---|
930 |
|
---|
931 |
|
---|
932 | ## build()
|
---|
933 | # Writes and executes the %build script (mostly) built while reading the spec file.
|
---|
934 | sub build {
|
---|
935 | # Expand the macros
|
---|
936 | $buildscript = expandmacros($buildscript,'cgbp');
|
---|
937 |
|
---|
938 | # create script filename
|
---|
939 | my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
|
---|
940 | sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
941 | or die $!;
|
---|
942 | print BUILDSCRIPT $scriptletbase;
|
---|
943 | print BUILDSCRIPT $buildscript;
|
---|
944 | close BUILDSCRIPT;
|
---|
945 |
|
---|
946 | # execute
|
---|
947 | print "Calling \%build script $buildscriptfile...\n";
|
---|
948 | system("/bin/sh -e $buildscriptfile") == 0
|
---|
949 | or die "Can't exec: $!\n";
|
---|
950 |
|
---|
951 | # and clean up
|
---|
952 | unlink $buildscriptfile;
|
---|
953 | } # end build()
|
---|
954 |
|
---|
955 |
|
---|
956 | ## install()
|
---|
957 | # Writes and executes the %install script (mostly) built while reading the spec file.
|
---|
958 | sub install {
|
---|
959 |
|
---|
960 | # munge %doc entries into place
|
---|
961 | # rpm handles this with a separate executed %doc script, we're not going to bother.
|
---|
962 | foreach my $docpkg (keys %doclist) {
|
---|
963 | my $pkgname = $pkgdata{$docpkg}{name};
|
---|
964 | $pkgname =~ s/_/-/g;
|
---|
965 |
|
---|
966 | $installscript .= "DOCDIR=\$RPM_BUILD_ROOT\%{_docdir}/$pkgname\nexport DOCDIR\n";
|
---|
967 | $installscript .= "mkdir -p \$DOCDIR\n";
|
---|
968 | $doclist{$docpkg} =~ s/^\s*//;
|
---|
969 | foreach (split(' ',$doclist{$docpkg})) {
|
---|
970 | $installscript .= "cp -pr $_ \$DOCDIR/\n";
|
---|
971 | }
|
---|
972 | }
|
---|
973 |
|
---|
974 | # Expand the macros
|
---|
975 | $installscript = expandmacros($installscript,'igbp');
|
---|
976 |
|
---|
977 | # create script filename
|
---|
978 | my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
|
---|
979 | sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
980 | or die $!;
|
---|
981 | print INSTSCRIPT $scriptletbase;
|
---|
982 | print INSTSCRIPT $installscript;
|
---|
983 | close INSTSCRIPT;
|
---|
984 |
|
---|
985 | # execute
|
---|
986 | print "Calling \%install script $installscriptfile...\n";
|
---|
987 | system("/bin/sh -e $installscriptfile") == 0
|
---|
988 | or die "Can't exec: $!\n";
|
---|
989 |
|
---|
990 | # and clean up
|
---|
991 | unlink $installscriptfile;
|
---|
992 | } # end install()
|
---|
993 |
|
---|
994 |
|
---|
995 | ## binpackage()
|
---|
996 | # Creates the binary .deb package from the installed tree in $buildroot.
|
---|
997 | # Writes and executes a shell script to do so.
|
---|
998 | # Creates miscellaneous files required by dpkg-deb to actually build the package file.
|
---|
999 | # Should handle simple subpackages
|
---|
1000 | sub binpackage {
|
---|
1001 |
|
---|
1002 | foreach my $pkg (@pkglist) {
|
---|
1003 |
|
---|
1004 | $pkgdata{$pkg}{arch} = $hostarch if !$pkgdata{$pkg}{arch}; # Just In Case.
|
---|
1005 |
|
---|
1006 | # Make sure we have somewhere to write the .deb file
|
---|
1007 | if (!-e "$topdir/DEBS/$pkgdata{$pkg}{arch}") {
|
---|
1008 | mkdir "$topdir/DEBS/$pkgdata{$pkg}{arch}";
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | # Skip building a package if it doesn't actually have any files. NB: This
|
---|
1012 | # differs slightly from rpm's behaviour where a package *will* be built -
|
---|
1013 | # even without any files - if %files is specified anywhere. I can think
|
---|
1014 | # of odd corner cases where that *may* be desireable.
|
---|
1015 | next if (!$filelist{$pkg} or $filelist{$pkg} =~ /^\s*$/);
|
---|
1016 |
|
---|
1017 | # Gotta do this first, otherwise we don't have a place to move files from %files
|
---|
1018 | mkdir "$buildroot/$pkg";
|
---|
1019 |
|
---|
1020 | # Eliminate any lingering % macros
|
---|
1021 | $filelist{$pkg} = expandmacros $filelist{$pkg}, 'g';
|
---|
1022 |
|
---|
1023 | my @pkgfilelist = split ' ', $filelist{$pkg};
|
---|
1024 | foreach my $pkgfile (@pkgfilelist) {
|
---|
1025 | $pkgfile = expandmacros($pkgfile, 'gp');
|
---|
1026 |
|
---|
1027 | # Feh. Manpages don't **NEED** to be gzipped, but rpmbuild does, and so shall we.
|
---|
1028 | if ($pkgfile =~ m|/usr/share/man/man|) {
|
---|
1029 | # need to check to see if manpage is gzipped
|
---|
1030 | if (-e "$buildroot$pkgfile") {
|
---|
1031 | if ($pkgfile !~ m|\.gz$|) {
|
---|
1032 | qx { gzip $buildroot$pkgfile };
|
---|
1033 | $pkgfile .= ".gz";
|
---|
1034 | }
|
---|
1035 | } else {
|
---|
1036 | if ($pkgfile !~ m|\.gz$|) {
|
---|
1037 | $pkgfile .= ".gz";
|
---|
1038 | } else {
|
---|
1039 | $pkgfile =~ s/\.gz$//;
|
---|
1040 | qx { gzip $buildroot$pkgfile };
|
---|
1041 | $pkgfile .= ".gz";
|
---|
1042 | }
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | my ($fpath,$fname) = ($pkgfile =~ m|(.+?/?)?([^/]+/?)$|); # We don't need $fname now, but we might.
|
---|
1047 | qx { mkdir -p $buildroot/$pkg$fpath }
|
---|
1048 | if $fpath && $fpath ne '';
|
---|
1049 | qx { mv $buildroot$pkgfile $buildroot/$pkg$fpath };
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | # Get the "Depends" (Requires) a la RPM. Ish. We strip the leading
|
---|
1053 | # comma and space here (if needed) in case there were "Requires" specified
|
---|
1054 | # in the spec file - those would precede these.
|
---|
1055 | $pkgdata{$pkg}{requires} .= getreqs("$buildroot/$pkg") if ! $NoAutoReq;
|
---|
1056 |
|
---|
1057 | # magic needed to properly version dependencies...
|
---|
1058 | # only provided deps will really be included
|
---|
1059 | $pkgdata{$pkg}{requires} =~ s/^, //; # Still have to do this here.
|
---|
1060 | $pkgdata{$pkg}{requires} =~ s/\s+//g;
|
---|
1061 | my @deps = split /,/, $pkgdata{$pkg}{requires};
|
---|
1062 | my $tmp = '';
|
---|
1063 | foreach my $dep (@deps) {
|
---|
1064 | # Hack up the perl(Class::SubClass) deps into something dpkg can understand.
|
---|
1065 | # May or may not be versioned.
|
---|
1066 | # We do this first so the version rewriter can do its magic next.
|
---|
1067 | if (my ($mod,$ver) = ($dep =~ /^perl\(([A-Za-z0-9\:\-]+)\)([><=]+.+)?/) ) {
|
---|
1068 | $mod =~ s/^perl\(//;
|
---|
1069 | $mod =~ s/\)$//;
|
---|
1070 | $mod =~ s/::/-/g;
|
---|
1071 | $mod =~ tr/A-Z/a-z/;
|
---|
1072 | $mod = "lib$mod-perl";
|
---|
1073 | $mod .= $ver if $ver;
|
---|
1074 | $dep = $mod;
|
---|
1075 | }
|
---|
1076 | if (my ($name,$rel,$value) = ($dep =~ /^([a-zA-Z0-9._-]+)([><=]+)([a-zA-Z0-9._-]+)$/)) {
|
---|
1077 | $tmp .= ", $name ($rel $value)";
|
---|
1078 | } else {
|
---|
1079 | $tmp .= ", $dep";
|
---|
1080 | }
|
---|
1081 | }
|
---|
1082 | ($pkgdata{$pkg}{requires} = $tmp) =~ s/^, //;
|
---|
1083 |
|
---|
1084 | # Do this here since we're doing {depends}...
|
---|
1085 | if (defined($pkgdata{$pkg}{provides})) {
|
---|
1086 | $pkgdata{$pkg}{provides} =~ s/^, //;
|
---|
1087 | $pkgdata{$pkg}{provides} = expandmacros($pkgdata{$pkg}{provides},'gp');
|
---|
1088 | }
|
---|
1089 | if (defined($pkgdata{$pkg}{conflicts})) {
|
---|
1090 | $pkgdata{$pkg}{conflicts} =~ s/^, //;
|
---|
1091 | $pkgdata{$pkg}{conflicts} = expandmacros($pkgdata{$pkg}{conflicts},'gp');
|
---|
1092 | }
|
---|
1093 |
|
---|
1094 | # Gotta do this next, otherwise the control file has nowhere to go. >:(
|
---|
1095 | mkdir "$buildroot/$pkg/DEBIAN";
|
---|
1096 |
|
---|
1097 | # Hack the filename for the package into a Debian-tool-compatible format. GRRRRRR!!!!!
|
---|
1098 | # Have I mentioned I hate Debian Policy?
|
---|
1099 | $pkgdata{$pkg}{name} =~ tr/_/-/;
|
---|
1100 |
|
---|
1101 | # create script filename
|
---|
1102 | my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
|
---|
1103 | sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
1104 | or die $!;
|
---|
1105 | print DEBSCRIPT $scriptletbase;
|
---|
1106 | print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot/$pkg $topdir/DEBS/$pkgdata{$pkg}{arch}/".
|
---|
1107 | "$pkgdata{$pkg}{name}_".
|
---|
1108 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
1109 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb\n";
|
---|
1110 | # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
|
---|
1111 | close DEBSCRIPT;
|
---|
1112 |
|
---|
1113 | my $control = "Package: $pkgdata{$pkg}{name}\n".
|
---|
1114 | "Version: ".
|
---|
1115 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
1116 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}\n".
|
---|
1117 | "Section: $pkgdata{$pkg}{group}\n".
|
---|
1118 | "Priority: optional\n".
|
---|
1119 | "Architecture: $pkgdata{$pkg}{arch}\n".
|
---|
1120 | "Maintainer: $pkgdata{main}{packager}\n".
|
---|
1121 | ( $pkgdata{$pkg}{requires} ne '' ? "Depends: $pkgdata{$pkg}{requires}\n" : '' ).
|
---|
1122 | ( defined($pkgdata{$pkg}{provides}) ? "Provides: $pkgdata{$pkg}{provides}\n" : '' ).
|
---|
1123 | ( defined($pkgdata{$pkg}{conflicts}) ? "Conflicts: $pkgdata{$pkg}{conflicts}\n" : '' ).
|
---|
1124 | "Description: $pkgdata{$pkg}{summary}\n";
|
---|
1125 | $control .= "$pkgdata{$pkg}{desc}\n";
|
---|
1126 |
|
---|
1127 | open CONTROL, ">$buildroot/$pkg/DEBIAN/control";
|
---|
1128 | print CONTROL $control;
|
---|
1129 | close CONTROL;
|
---|
1130 |
|
---|
1131 | # Iff there are conffiles (as specified in the %files list(s), add'em
|
---|
1132 | # in so dpkg-deb can tag them.
|
---|
1133 | if ($pkgdata{$pkg}{conffiles}) {
|
---|
1134 | open CONFLIST, ">$buildroot/$pkg/DEBIAN/conffiles";
|
---|
1135 | foreach my $conffile (@{$pkgdata{$pkg}{conflist}}) {
|
---|
1136 | $conffile = expandmacros($conffile, 'g');
|
---|
1137 | my @tmp = glob "$buildroot/$pkg/$conffile";
|
---|
1138 | foreach (@tmp) {
|
---|
1139 | s|$buildroot/$pkg/||g; # nrgl. gotta be a better way to do this...
|
---|
1140 | s/\s+/\n/g; # Not gonna support spaces in filenames. Ewww.
|
---|
1141 | print CONFLIST "$_\n";
|
---|
1142 | }
|
---|
1143 | }
|
---|
1144 | close CONFLIST;
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | # found the point of scripts on subpackages.
|
---|
1148 | if ($pkgdata{$pkg}{'pre'}) {
|
---|
1149 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'pre'},'gp');
|
---|
1150 | open PREINST, ">$buildroot/$pkg/DEBIAN/preinst";
|
---|
1151 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
1152 | print PREINST $pkgdata{$pkg}{'pre'};
|
---|
1153 | close PREINST;
|
---|
1154 | `chmod 0755 $buildroot/$pkg/DEBIAN/preinst`;
|
---|
1155 | }
|
---|
1156 | if ($pkgdata{$pkg}{'post'}) {
|
---|
1157 | $pkgdata{$pkg}{'post'} = expandmacros($pkgdata{$pkg}{'post'},'gp');
|
---|
1158 | open PREINST, ">$buildroot/$pkg/DEBIAN/postinst";
|
---|
1159 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
1160 | print PREINST $pkgdata{$pkg}{'post'};
|
---|
1161 | close PREINST;
|
---|
1162 | `chmod 0755 $buildroot/$pkg/DEBIAN/postinst`;
|
---|
1163 | }
|
---|
1164 | if ($pkgdata{$pkg}{'preun'}) {
|
---|
1165 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'preun'},'gp');
|
---|
1166 | open PREINST, ">$buildroot/$pkg/DEBIAN/prerm";
|
---|
1167 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
1168 | print PREINST $pkgdata{$pkg}{'preun'};
|
---|
1169 | close PREINST;
|
---|
1170 | `chmod 0755 $buildroot/$pkg/DEBIAN/prerm`;
|
---|
1171 | }
|
---|
1172 | if ($pkgdata{$pkg}{'postun'}) {
|
---|
1173 | $pkgdata{$pkg}{'postun'} = expandmacros($pkgdata{$pkg}{'postun'},'gp');
|
---|
1174 | open PREINST, ">$buildroot/$pkg/DEBIAN/postrm";
|
---|
1175 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
1176 | print PREINST $pkgdata{$pkg}{'postun'};
|
---|
1177 | close PREINST;
|
---|
1178 | `chmod 0755 $buildroot/$pkg/DEBIAN/postrm`;
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | # execute
|
---|
1182 | print "Calling package creation script $debscriptfile for $pkgdata{$pkg}{name}...\n";
|
---|
1183 | system("/bin/sh -e $debscriptfile") == 0
|
---|
1184 | or die "Can't exec: $!\n";
|
---|
1185 |
|
---|
1186 | $finalmessages .= "Wrote binary package ".
|
---|
1187 | "$pkgdata{$pkg}{name}_".
|
---|
1188 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
1189 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb".
|
---|
1190 | " in $topdir/DEBS/$pkgdata{$pkg}{arch}\n";
|
---|
1191 | # and clean up
|
---|
1192 | unlink $debscriptfile;
|
---|
1193 |
|
---|
1194 | } # subpackage loop
|
---|
1195 |
|
---|
1196 | } # end binpackage()
|
---|
1197 |
|
---|
1198 |
|
---|
1199 | ## srcpackage()
|
---|
1200 | # Builds a .src.deb source package. Note that Debian's idea of
|
---|
1201 | # a "source package" is seriously flawed IMO, because you can't
|
---|
1202 | # easily copy it as-is.
|
---|
1203 | # Not quite identical to RPM, but Good Enough (TM).
|
---|
1204 | sub srcpackage {
|
---|
1205 | # In case we were called with -bs.
|
---|
1206 | $pkgdata{main}{name} =~ tr/_/-/;
|
---|
1207 | my $pkgsrcname = "$pkgdata{main}{name}-".
|
---|
1208 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
1209 | "$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb";
|
---|
1210 |
|
---|
1211 | my $paxcmd;
|
---|
1212 |
|
---|
1213 | # We'll definitely need this later, and *may* need it sooner.
|
---|
1214 | (my $barespec = $specfile) =~ s|.+/([^/]+)$|$1|;
|
---|
1215 |
|
---|
1216 | # Copy the specfile to the build tree, but only if it's not there already.
|
---|
1217 | ##buglet: need to deal with silly case where silly user has put the spec
|
---|
1218 | # file in a subdir of %{_topdir}/SPECS. Ewww. Silly user!
|
---|
1219 | if (abs_path($specfile) !~ /^$topdir\/SPECS/) {
|
---|
1220 | $paxcmd .= "cp $specfile %{_topdir}/SPECS/; \n"
|
---|
1221 | }
|
---|
1222 |
|
---|
1223 | # use pax -w [file] [file] ... >outfile.sdeb
|
---|
1224 | $paxcmd = "cd $topdir; pax -w ";
|
---|
1225 |
|
---|
1226 | # tweak source entry into usable form. Need it locally somewhere along the line.
|
---|
1227 | (my $pkgsrc = $pkgdata{main}{source}) =~ s|.+/([^/]+)$|$1|;
|
---|
1228 | $paxcmd .= "SOURCES/$pkgsrc ";
|
---|
1229 |
|
---|
1230 | # create file list: Source[nn], Patch[nn]
|
---|
1231 | foreach my $specbit (keys %{$pkgdata{main}} ) {
|
---|
1232 | next if $specbit eq 'source';
|
---|
1233 | $paxcmd .= "SOURCES/$pkgdata{main}{$specbit} " if $specbit =~ /^patch/;
|
---|
1234 | ##buglet: need to deal with case where patches are listed as URLs?
|
---|
1235 | # or other extended pathnames? Silly !@$%^&!%%!%!! user!
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
1239 | $paxcmd .= "SOURCES/$pkgdata{sources}{$source} ";
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | # add the spec file, source package destination, and cd back where we came from.
|
---|
1243 | $paxcmd .= "SPECS/$barespec > $topdir/SDEBS/$pkgsrcname; cd -";
|
---|
1244 |
|
---|
1245 | # In case of %-macros...
|
---|
1246 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
1247 |
|
---|
1248 | system "$paxcmd";
|
---|
1249 | $finalmessages .= "Wrote source package $pkgsrcname in $topdir/SDEBS.\n";
|
---|
1250 | } # end srcpackage()
|
---|
1251 |
|
---|
1252 |
|
---|
1253 | ## clean()
|
---|
1254 | # Writes and executes the %clean script (mostly) built while reading the spec file.
|
---|
1255 | sub clean {
|
---|
1256 | # Replace some things here just to make sure.
|
---|
1257 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
1258 |
|
---|
1259 | # create script filename
|
---|
1260 | my $cleanscriptfile = "$tmpdir/deb-tmp.clean.".int(rand(99998)+1);
|
---|
1261 | sysopen(CLEANSCRIPT, $cleanscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
1262 | or die $!;
|
---|
1263 | print CLEANSCRIPT $scriptletbase;
|
---|
1264 | print CLEANSCRIPT $cleanscript;
|
---|
1265 | close CLEANSCRIPT;
|
---|
1266 |
|
---|
1267 | # execute
|
---|
1268 | print "Calling \%clean script $cleanscriptfile...\n";
|
---|
1269 | system("/bin/sh -e $cleanscriptfile") == 0
|
---|
1270 | or die "Can't exec: $!\n";
|
---|
1271 |
|
---|
1272 | # and clean up
|
---|
1273 | unlink $cleanscriptfile;
|
---|
1274 | } # end clean()
|
---|
1275 |
|
---|
1276 |
|
---|
1277 | ## checkbuildreq()
|
---|
1278 | # Checks the build requirements (if any)
|
---|
1279 | # Spits out a rude warning and returns a true-false error if any
|
---|
1280 | # requirements are not met.
|
---|
1281 | sub checkbuildreq {
|
---|
1282 | return 1 if $buildreq eq ''; # No use doing extra work.
|
---|
1283 |
|
---|
1284 | if ( ! -e "/usr/bin/dpkg-query" ) {
|
---|
1285 | print "**WARNING** dpkg-query not found. Can't check build-deps.\n".
|
---|
1286 | " Required for sucessful build:\n".$buildreq."\n".
|
---|
1287 | " Continuing anyway.\n";
|
---|
1288 | return 1;
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 | my $reqflag = 1; # unset iff a buildreq is missing
|
---|
1292 |
|
---|
1293 | $buildreq =~ s/^, //; # Strip the leading comma and space
|
---|
1294 | my @reqlist = split /,\s+/, $buildreq;
|
---|
1295 |
|
---|
1296 | foreach my $req (@reqlist) {
|
---|
1297 | my ($pkg,$rel,$ver);
|
---|
1298 |
|
---|
1299 | # We have two classes of requirements - versioned and unversioned.
|
---|
1300 | if ($req =~ /[><=]/) {
|
---|
1301 | # Pick up the details of versioned buildreqs
|
---|
1302 | ($pkg,$rel,$ver) = ($req =~ /([a-z0-9._-]+)\s+([><=]+)\s+([a-z0-9._-]+)/);
|
---|
1303 | } else {
|
---|
1304 | # And the unversioned ones.
|
---|
1305 | $pkg = $req;
|
---|
1306 | $rel = '>=';
|
---|
1307 | $ver = 0;
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | my @pkglist = qx { dpkg-query --showformat '\${status}\t\${version}\n' -W $pkg };
|
---|
1311 | # need to check if no lines returned - means a bad buildreq
|
---|
1312 | my ($reqstat,undef,undef,$reqver) = split /\s+/, $pkglist[0];
|
---|
1313 | if ($reqstat !~ /install/) {
|
---|
1314 | print " * Missing build-dependency $pkg!\n";
|
---|
1315 | $reqflag = 0;
|
---|
1316 | } else {
|
---|
1317 | # gotta be a better way to do this... :/
|
---|
1318 | if ($rel eq '>=' && !($reqver ge $ver)) {
|
---|
1319 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
1320 | $reqflag = 0;
|
---|
1321 | }
|
---|
1322 | if ($rel eq '>' && !($reqver gt $ver)) {
|
---|
1323 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
1324 | $reqflag = 0;
|
---|
1325 | }
|
---|
1326 | if ($rel eq '<=' && !($reqver le $ver)) {
|
---|
1327 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
1328 | $reqflag = 0;
|
---|
1329 | }
|
---|
1330 | if ($rel eq '<' && !($reqver lt $ver)) {
|
---|
1331 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
1332 | $reqflag = 0;
|
---|
1333 | }
|
---|
1334 | if ($rel eq '=' && !($reqver eq $ver)) {
|
---|
1335 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
1336 | $reqflag = 0;
|
---|
1337 | }
|
---|
1338 | } # end not installed/installed check
|
---|
1339 | } # end req loop
|
---|
1340 |
|
---|
1341 | return $reqflag;
|
---|
1342 | } # end checkbuildreq()
|
---|
1343 |
|
---|
1344 |
|
---|
1345 | ## getreqs()
|
---|
1346 | # Find out which libraries/packages are required for any
|
---|
1347 | # executables and libs in a given file tree.
|
---|
1348 | # (Debian doesn't have soname-level deps; just package-level)
|
---|
1349 | # Returns an empty string if the tree contains no binaries.
|
---|
1350 | # Doesn't work well on shell scripts. but those *should* be
|
---|
1351 | # fine anyway. (Yeah, right...)
|
---|
1352 | sub getreqs() {
|
---|
1353 | my $pkgtree = $_[0];
|
---|
1354 |
|
---|
1355 | print "Checking library requirements...\n";
|
---|
1356 | my @binlist = qx { find $pkgtree -type f -perm 755 };
|
---|
1357 |
|
---|
1358 | if (scalar(@binlist) == 0) {
|
---|
1359 | return '';
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | my @reqlist;
|
---|
1363 | foreach (@binlist) {
|
---|
1364 | push @reqlist, qx { ldd $_ };
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | # Get the list of libs provided by this package. Still doesn't
|
---|
1368 | # handle the case where the lib gets stuffed into a subpackage. :/
|
---|
1369 | my @intprovlist = qx { find $pkgtree -type f -name "*.so*" };
|
---|
1370 | my $provlist = '';
|
---|
1371 | foreach (@intprovlist) {
|
---|
1372 | s/$pkgtree//;
|
---|
1373 | $provlist .= "$_";
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | my %reqs;
|
---|
1377 | my $reqlibs = '';
|
---|
1378 |
|
---|
1379 | foreach (@reqlist) {
|
---|
1380 | next if /^$pkgtree/;
|
---|
1381 | next if /not a dynamic executable/;
|
---|
1382 | next if m|/lib/ld-linux.so|; # Hack! Hack! PTHBTT! (libc suxx0rz)
|
---|
1383 | next if /linux-gate.so/; # Kernel hackery for teh W1n!!1!1eleventy-one!1 (Don't ask. Feh.)
|
---|
1384 |
|
---|
1385 | my ($req) = (/^\s+([a-z0-9._-]+)/); # dig out the actual library (so)name
|
---|
1386 |
|
---|
1387 | # Ignore libs provided by this package. Note that we don't match
|
---|
1388 | # on word-boundary at the *end* of the lib we're looking for, as the
|
---|
1389 | # looked-for lib may not have the full soname version. (ie, it may
|
---|
1390 | # "just" point to one of the symlinks that get created somewhere.)
|
---|
1391 | next if $provlist =~ /\b$req/;
|
---|
1392 |
|
---|
1393 | $reqlibs .= " $req";
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | if ($reqlibs ne '') {
|
---|
1397 | foreach (qx { dpkg -S $reqlibs }) {
|
---|
1398 | my ($libpkg,undef) = split /:\s+/;
|
---|
1399 | $reqs{$libpkg} = 1;
|
---|
1400 | }
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | my $deplist = '';
|
---|
1404 | foreach (keys %reqs) {
|
---|
1405 | $deplist .= ", $_";
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | # For now, we're done. We're not going to meddle with versions yet.
|
---|
1409 | # Among other things, it's messier than handling "simple" yes/no "do
|
---|
1410 | # we have this lib?" deps. >:(
|
---|
1411 |
|
---|
1412 | return $deplist;
|
---|
1413 | } # end getreqs()
|
---|
1414 |
|
---|
1415 |
|
---|
1416 | ## install_sdeb()
|
---|
1417 | # Extracts .sdeb contents to %_topdir as appropriate
|
---|
1418 | sub install_sdeb {
|
---|
1419 | $srcpkg = abs_path($srcpkg);
|
---|
1420 |
|
---|
1421 | my $paxcmd = "cd $topdir; pax -r <$srcpkg; cd -";
|
---|
1422 |
|
---|
1423 | # In case of %-macros...
|
---|
1424 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
1425 |
|
---|
1426 | system "$paxcmd";
|
---|
1427 | print "Extracted source package $srcpkg to $topdir.\n";
|
---|
1428 | } # end install_sdeb()
|
---|
1429 |
|
---|
1430 |
|
---|
1431 | ## expandmacros()
|
---|
1432 | # Expands all %{blah} macros in the passed string
|
---|
1433 | # Split up a bit with some sections so we don't spend time trying to
|
---|
1434 | # expand macros that are only used in a few specific places.
|
---|
1435 | sub expandmacros {
|
---|
1436 | my $macrostring = shift;
|
---|
1437 | my $section = shift;
|
---|
1438 |
|
---|
1439 | # To allow the FHS-ish %configure and %makeinstall to work The Right Way.
|
---|
1440 | # (Without clobbering the global $buildroot.)
|
---|
1441 | my $prefix = '';
|
---|
1442 |
|
---|
1443 | if ($section =~ /c/) {
|
---|
1444 | # %configure macro
|
---|
1445 | # Don't know what it's for, don't have a useful default replacement
|
---|
1446 | # --program-prefix=%{_program_prefix} \
|
---|
1447 | $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
|
---|
1448 | --build=$DEB_BUILD_GNU_TYPE \
|
---|
1449 | --prefix=%{_prefix} \
|
---|
1450 | --exec-prefix=%{_exec_prefix} \
|
---|
1451 | --bindir=%{_bindir} \
|
---|
1452 | --sbindir=%{_sbindir} \
|
---|
1453 | --sysconfdir=%{_sysconfdir} \
|
---|
1454 | --datadir=%{_datadir} \
|
---|
1455 | --includedir=%{_includedir} \
|
---|
1456 | --libdir=%{_libdir} \
|
---|
1457 | --libexecdir=%{_libexecdir} \
|
---|
1458 | --localstatedir=%{_localstatedir} \
|
---|
1459 | --sharedstatedir=%{_sharedstatedir} \
|
---|
1460 | --mandir=%{_mandir} \
|
---|
1461 | --infodir=%{_infodir} ';
|
---|
1462 | } # done %configure
|
---|
1463 |
|
---|
1464 | if ($section =~ /m/) {
|
---|
1465 | $macrostring =~ s'%{__make}'make ';
|
---|
1466 | } # done make
|
---|
1467 |
|
---|
1468 | if ($section =~ /i/) {
|
---|
1469 | # This is where we need to mangle $prefix.
|
---|
1470 | $macrostring =~ s'%makeinstall'make %{fhs} install';
|
---|
1471 | $prefix = $buildroot;
|
---|
1472 | } # done %install and/or %makeinstall
|
---|
1473 |
|
---|
1474 | # Build data
|
---|
1475 | # Note that these are processed in reverse order to get the substitution order right
|
---|
1476 | if ($section =~ /b/) {
|
---|
1477 | # $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
|
---|
1478 | # build=$DEB_BUILD_GNU_TYPE \
|
---|
1479 | $macrostring =~ s'%{fhs}'prefix=%{_prefix} \
|
---|
1480 | exec-prefix=%{_exec_prefix} \
|
---|
1481 | bindir=%{_bindir} \
|
---|
1482 | sbindir=%{_sbindir} \
|
---|
1483 | sysconfdir=%{_sysconfdir} \
|
---|
1484 | datadir=%{_datadir} \
|
---|
1485 | includedir=%{_includedir} \
|
---|
1486 | libdir=%{_libdir} \
|
---|
1487 | libexecdir=%{_libexecdir} \
|
---|
1488 | localstatedir=%{_localstatedir} \
|
---|
1489 | sharedstatedir=%{_sharedstatedir} \
|
---|
1490 | mandir=%{_mandir} \
|
---|
1491 | infodir=%{_infodir} \
|
---|
1492 | ';
|
---|
1493 |
|
---|
1494 | # Note that the above regex terminates with the extra space
|
---|
1495 | # "Just In Case" of user additions, which will then get neatly
|
---|
1496 | # tagged on the end where they take precedence (supposedly)
|
---|
1497 | # over the "default" ones.
|
---|
1498 |
|
---|
1499 | # Now we cascade the macros introduced above. >_<
|
---|
1500 | # Wot ot to go theah:
|
---|
1501 | $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
|
---|
1502 | $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
|
---|
1503 | $macrostring =~ s|%{_oldincludedir}|/usr/include|g; #/usr/include
|
---|
1504 | $macrostring =~ s|%{_includedir}|%{_prefix}/include|g; #/usr/include
|
---|
1505 | $macrostring =~ s|%{_libdir}|%{_exec_prefix}/%{_lib}|g; #/usr/lib
|
---|
1506 | $macrostring =~ s|%{_lib}|lib|g; #?
|
---|
1507 | $macrostring =~ s|%{_localstatedir}|/var|g; #/var
|
---|
1508 | $macrostring =~ s|%{_sharedstatedir}|%{_prefix}/com|g; #/usr/com WTF?
|
---|
1509 | $macrostring =~ s|%{_sysconfdir}|/etc|g; #/etc
|
---|
1510 | $macrostring =~ s|%{_datadir}|%{_prefix}/share|g; #/usr/share
|
---|
1511 | $macrostring =~ s|%{_libexecdir}|%{_exec_prefix}/libexec|g; #/usr/libexec
|
---|
1512 | $macrostring =~ s|%{_sbindir}|%{_exec_prefix}/sbin|g; #/usr/sbin
|
---|
1513 | $macrostring =~ s|%{_bindir}|%{_exec_prefix}/bin|g; #/usr/bin
|
---|
1514 | $macrostring =~ s|%{_exec_prefix}|%{_prefix}|g; #/usr
|
---|
1515 | $macrostring =~ s|%{_prefix}|/usr|g; #/usr
|
---|
1516 | } # done with config section
|
---|
1517 |
|
---|
1518 | # Package data
|
---|
1519 | if ($section =~ /p/) {
|
---|
1520 | $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
|
---|
1521 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
1522 | $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
|
---|
1523 | }
|
---|
1524 | $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
|
---|
1525 | $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
|
---|
1526 | $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
|
---|
1527 | }
|
---|
1528 |
|
---|
1529 | # Globals, and not-so-globals
|
---|
1530 | if ($section =~ /g/) {
|
---|
1531 |
|
---|
1532 | $macrostring =~ s|%{_builddir}|%{_topdir}/BUILD|g;
|
---|
1533 | $macrostring =~ s|%{_topdir}|$topdir|g;
|
---|
1534 | $macrostring =~ s|%{_tmppath}|$tmpdir|g;
|
---|
1535 | $macrostring =~ s'%{_docdir}'%{_datadir}/doc'g;
|
---|
1536 |
|
---|
1537 | # Standard FHS locations. More or less.
|
---|
1538 | $macrostring =~ s'%{_bindir}'/usr/bin'g;
|
---|
1539 | $macrostring =~ s'%{_sbindir}'/usr/sbin'g;
|
---|
1540 | $macrostring =~ s'%{_mandir}'%{_datadir}/man'g;
|
---|
1541 | $macrostring =~ s'%{_includedir}'/usr/include'g;
|
---|
1542 | $macrostring =~ s'%{_libdir}'/usr/lib'g;
|
---|
1543 | $macrostring =~ s'%{_sysconfdir}'/etc'g;
|
---|
1544 | $macrostring =~ s'%{_localstatedir}'/var'g;
|
---|
1545 |
|
---|
1546 | # FHS-ish locations that aren't quite actually FHS-specified.
|
---|
1547 | $macrostring =~ s'%{_datadir}'/usr/share'g;
|
---|
1548 |
|
---|
1549 | # special %define's. Handle the general case where we eval anything.
|
---|
1550 | # Even more general: %(...) is a spec-parse-time shell code wrapper.
|
---|
1551 | # Prime example:
|
---|
1552 | #%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
|
---|
1553 | if ($macrostring =~ /\%\((.+)\)/) {
|
---|
1554 | my $shellstr = $1;
|
---|
1555 | # Oy vey this gets silly for the perl bits. Executing a shell to
|
---|
1556 | # call Perl to get the vendorlib/sitelib/whatever "core" globals.
|
---|
1557 | # This can do more, but... eww.
|
---|
1558 | $shellstr = qx { /bin/sh -c '$shellstr' }; # Yay! ' characters apparently get properly exscapededed.
|
---|
1559 | $macrostring =~ s/\%\(.+\)/$shellstr/;
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | # support for **some** %if constructs. Note that this breaks somewhat if
|
---|
1563 | # there's no value specified... but so does rpm.
|
---|
1564 | my $tmpcount = 0;
|
---|
1565 | while ($macrostring =~ /\%\{(!\?|\?!|\?)([a-z0-9_.-]+)(?:\:([a-z0-9_.-]+))?\}/g) { #Whew....
|
---|
1566 | my $qex = $1;
|
---|
1567 | my $macro = $2;
|
---|
1568 | my $value = $3;
|
---|
1569 |
|
---|
1570 | my $neg = '1' if $qex =~ /\!/;
|
---|
1571 | if ($specglobals{$macro}) {
|
---|
1572 | $value = '' if $neg;
|
---|
1573 | } else {
|
---|
1574 | $value = '' if !$neg;
|
---|
1575 | }
|
---|
1576 | $macrostring =~ s/\%\{!?\?\!?[a-z0-9_.-]+(?:\:[a-z0-9_.-]+)?\}/$value/;
|
---|
1577 |
|
---|
1578 | # not certain about this, but I don't want to run away. It *can* happen if planned carefully. :/
|
---|
1579 | $tmpcount++;
|
---|
1580 | die "excessive recursive macro replacement; dying.\n" if $tmpcount > 6;
|
---|
1581 |
|
---|
1582 | } # while()
|
---|
1583 |
|
---|
1584 | # Misc expansions
|
---|
1585 | $macrostring =~ s|%{_arch}|$hostarch|g;
|
---|
1586 | $macrostring =~ s|%{optflags}|$optflags{$hostarch}|g;
|
---|
1587 | $macrostring =~ s|%{_vendor}|$specglobals{'_vendor'}|g;
|
---|
1588 |
|
---|
1589 | # should probably stick a "no runaway" flag in here... Just In Case...
|
---|
1590 | # %define's
|
---|
1591 | while (my ($key) = ($macrostring =~ /%{([a-z0-9]+)}/i) ) {
|
---|
1592 | # hrm. This needs thinking.
|
---|
1593 | #die "A horrible death! \%{$key}, '$macrostring'\n" if !$specglobals{$key};
|
---|
1594 | $macrostring =~ s|%{$key}|$specglobals{$key}|g;
|
---|
1595 | # wanna limit this to "... if $specglobals{$key}", but need more magic
|
---|
1596 | }
|
---|
1597 |
|
---|
1598 | # system programs. RPM uses a global config file for these; we'll just
|
---|
1599 | # ASS-U-ME and make life a little simpler.
|
---|
1600 | if ($macrostring =~ /\%\{\_\_([a-z0-9_-]+)\}/) {
|
---|
1601 | $macrostring =~ s|%{__([a-z0-9_-]+)}|$1|g;
|
---|
1602 | }
|
---|
1603 |
|
---|
1604 | # Perl @INC/...lib locations, and other related bits.
|
---|
1605 | $macrostring =~ s|%{perl_archlib}|$Config{installarchlib}|g;
|
---|
1606 | $macrostring =~ s|%{perl_sitelib}|$Config{installsitelib}|g;
|
---|
1607 | $macrostring =~ s|%{perl_sitearch}|$Config{installsitearch}|g;
|
---|
1608 | $macrostring =~ s|%{perl_vendorlib}|$Config{installvendorlib}|g;
|
---|
1609 | $macrostring =~ s|%{perl_vendorarch}|$Config{installvendorarch}|g;
|
---|
1610 |
|
---|
1611 | } # done with globals section
|
---|
1612 |
|
---|
1613 | return $macrostring;
|
---|
1614 | } # end expandmacros()
|
---|
1615 |
|
---|
1616 |
|
---|
1617 |
|
---|
1618 | __END__
|
---|
1619 |
|
---|
1620 |
|
---|
1621 |
|
---|
1622 | =head1 NAME
|
---|
1623 |
|
---|
1624 | debbuild - Build Debian-compatible packages from RPM spec files
|
---|
1625 |
|
---|
1626 | =head1 SYNOPSIS
|
---|
1627 |
|
---|
1628 | debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
|
---|
1629 |
|
---|
1630 | debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2}
|
---|
1631 |
|
---|
1632 | debbuild --rebuild file.{src.rpm|sdeb}
|
---|
1633 |
|
---|
1634 | debbuild --showpkgs
|
---|
1635 |
|
---|
1636 | =head1 DESCRIPTION
|
---|
1637 |
|
---|
1638 | This script attempts to build Debian-friendly semi-native packages from RPM spec files,
|
---|
1639 | RPM-friendly tarballs, and RPM source packages (.src.rpm files). It accepts I<most> of the
|
---|
1640 | options rpmbuild does, and should be able to interpret most spec files usefully. Perl
|
---|
1641 | modules should be handled via CPAN+dh-make-perl instead; Debian's conventions for such
|
---|
1642 | things do not lend themselves to automated conversion.
|
---|
1643 |
|
---|
1644 | As far as possible, the command-line options are identical to those from rpmbuild, although
|
---|
1645 | several rpmbuild options are not supported:
|
---|
1646 |
|
---|
1647 | --recompile
|
---|
1648 | --showrc
|
---|
1649 | --buildroot
|
---|
1650 | --clean
|
---|
1651 | --nobuild
|
---|
1652 | --rmsource
|
---|
1653 | --rmspec
|
---|
1654 | --sign
|
---|
1655 | --target
|
---|
1656 |
|
---|
1657 | Some of these could probably be trivially added. Feel free to send me a patch. ;)
|
---|
1658 |
|
---|
1659 | Complex spec files will most likely not work well, if at all. Rewrite them from scratch -
|
---|
1660 | you'll have to make heavy modifications anyway.
|
---|
1661 |
|
---|
1662 | If you see something you don't like, mail me. Send a patch if you feel inspired. I don't
|
---|
1663 | promise I'll do anything other than say "Yup, that's broken" or "Got your message".
|
---|
1664 |
|
---|
1665 | =head1 ASSUMPTIONS
|
---|
1666 |
|
---|
1667 | As with rpmbuild, debbuild makes some assumptions about your system.
|
---|
1668 |
|
---|
1669 | =over 4
|
---|
1670 |
|
---|
1671 | =item *
|
---|
1672 |
|
---|
1673 | Either you have rights to do as you please under /usr/src/debian, or you have created a file
|
---|
1674 | ~/.debmacros containing a suitable %_topdir definition.
|
---|
1675 |
|
---|
1676 | Both rpmbuild and debbuild require the directories %_topdir/{BUILD,SOURCES,SPECS}. However,
|
---|
1677 | where rpmbuild requires the %_topdir/{RPMS,SRPMS} directories, debbuild
|
---|
1678 | requires %_topdir/{DEBS,SDEBS} instead. Create them in advance;
|
---|
1679 | some subdirectories are created automatically as needed, but most are not.
|
---|
1680 |
|
---|
1681 | =item *
|
---|
1682 |
|
---|
1683 | /var/tmp must allow script execution - rpmbuild and debbuild both rely on creating and
|
---|
1684 | executing shell scripts for much of their functionality. By default, debbuild also creates
|
---|
1685 | install trees under /var/tmp - however this is (almost) entirely under the control of the
|
---|
1686 | package's .spec file.
|
---|
1687 |
|
---|
1688 | =item *
|
---|
1689 |
|
---|
1690 | If you wish to --rebuild a .src.rpm, your %_topdir for both debbuild and rpmbuild must either
|
---|
1691 | match, or be suitably symlinked one direction or another so that both programs are effectively
|
---|
1692 | working in the same tree. (Or you could just manually wrestle files around your system.)
|
---|
1693 |
|
---|
1694 | You could symlink ~/.rpmmacros to ~/.debmacros (or vice versa) and save yourself some hassle
|
---|
1695 | if you need to rebuild .src.rpm packages on a regular basis. Currently debbuild only uses the
|
---|
1696 | %_topdir macro definition, although there are many more things that rpmbuild can use from
|
---|
1697 | ~/.rpmmacros.
|
---|
1698 |
|
---|
1699 | =back
|
---|
1700 |
|
---|
1701 | =head1 ERRATA
|
---|
1702 |
|
---|
1703 | debbuild deliberately does a few things differently from rpm.
|
---|
1704 |
|
---|
1705 | =head2 BuildArch or BuildArchitecture
|
---|
1706 |
|
---|
1707 | rpm takes the last BuildArch entry it finds in the .spec file, whatever it is, and runs with
|
---|
1708 | that for all packages. Debian's repository system is fairly heavily designed around the
|
---|
1709 | assumption that a single source package may generate small binary (executable) packages
|
---|
1710 | for each arch, and large binary arch-all packages containing shared data.
|
---|
1711 |
|
---|
1712 | debbuild allows this by using the architecture specified by (in order of preference):
|
---|
1713 |
|
---|
1714 | =over 4
|
---|
1715 |
|
---|
1716 | =item * Host architecture
|
---|
1717 |
|
---|
1718 | =item * BuildArch specified in .spec file preamble
|
---|
1719 |
|
---|
1720 | =item * "Last specified" BuildArch for packages with several subpackages
|
---|
1721 |
|
---|
1722 | =item * BuildArch specified in the %package section for that subpackage
|
---|
1723 |
|
---|
1724 | =back
|
---|
1725 |
|
---|
1726 | =head2 Finding out what packages should be built (--showpkgs)
|
---|
1727 |
|
---|
1728 | rpmbuild does not include any convenient method I know of to list the packages a spec file
|
---|
1729 | will produce. Since I needed this ability for another tool, I added it.
|
---|
1730 |
|
---|
1731 | It requires the .spec file for the package, and produces a list of full package filenames
|
---|
1732 | (without path data) that would be generated by one of --rebuild, -ta, -tb, -ba, or -bb.
|
---|
1733 | This includes the .sdeb source package.
|
---|
1734 |
|
---|
1735 | =head1 AUTHOR
|
---|
1736 |
|
---|
1737 | debbuild was written by Kris Deugau <kdeugau@deepnet.cx>. A version that approximates
|
---|
1738 | current is available at http://www.deepnet.cx/debbuild/.
|
---|
1739 |
|
---|
1740 | =head1 BUGS
|
---|
1741 |
|
---|
1742 | Funky Things Happen if you forget a command-line option or two. I've been too lazy to bother
|
---|
1743 | fixing this.
|
---|
1744 |
|
---|
1745 | Many macro expansions are unsupported or incompletely supported.
|
---|
1746 |
|
---|
1747 | The generated scriptlets don't quite match those from rpmbuild exactly. There are extra
|
---|
1748 | environment variables and preprocessing that I haven't needed (yet).
|
---|
1749 |
|
---|
1750 | Dcumentation, such as it is, will likely remain perpetually out of date.
|
---|
1751 |
|
---|
1752 | %_topdir and the five "working" directories under %_topdir could arguably be created by
|
---|
1753 | debbuild. However, rpmbuild doesn't create these directories either.
|
---|
1754 |
|
---|
1755 | =head1 SEE ALSO
|
---|
1756 |
|
---|
1757 | rpm(8), rpmbuild(8), and pretty much any document describing how to write a .spec file.
|
---|
1758 |
|
---|
1759 | =cut
|
---|