source: trunk/debbuild@ 64

Last change on this file since 64 was 64, checked in by kdeugau, 18 years ago

/trunk

"Correct" (hah!) format for versioned Requires

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 40.3 KB
Line 
1#!/usr/bin/perl
2# debbuild script
3# Shamlessly steals intreface 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: 2006-06-06 18:46:53 +0000 (Tue, 06 Jun 2006) $
9# SVN revision $Rev: 64 $
10# Last update by $Author: kdeugau $
11###
12# Copyright 2005,2006 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
32
33# regex debugger
34#use re "debug";
35
36# Program flow:
37# -> Parse/execute "system" config/macros (if any - should be rare)
38# -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
39# -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
40
41sub expandmacros;
42
43# User's prefs for dirs, environment, etc,etc,etc.
44# config file ~/.debmacros
45# Default ordered search paths for config/macros:
46# /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
47# /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
48# **NOTE: May be possible to (ab)use bits of debhelper
49
50# Build tree
51# default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
52
53# Globals
54my $specfile;
55my $tarball;
56my $srcpkg;
57my $cmdbuildroot;
58my $tarballdir; # This should really be initialized, but the coding makes it, um, ugly.
59my %specglobals; # For %define's in specfile, among other things.
60
61# Initialized globals
62my $verbosity = 0;
63my %cmdopts = (type => '',
64 stage => 'a',
65 short => 'n'
66 );
67my $topdir = "/usr/src/debian";
68my $buildroot = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
69
70# "Constants"
71my %targets = ('p' => 'Prep',
72 'c' => 'Compile',
73 'i' => 'Install',
74 'l' => 'Verify %files',
75 'a' => 'Build binary and source',
76 'b' => 'Build binary',
77 's' => 'Build source'
78 );
79my $scriptletbase =
80q(#!/bin/sh
81
82 RPM_SOURCE_DIR="%{_topdir}/SOURCES"
83 RPM_BUILD_DIR="%{_topdir}/BUILD"
84 RPM_OPT_FLAGS="-O2 -g -march=i386 -mcpu=i686"
85 RPM_ARCH="i386"
86 RPM_OS="linux"
87 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
88 RPM_DOC_DIR="/usr/share/doc"
89 export RPM_DOC_DIR
90 RPM_PACKAGE_NAME="%{name}"
91 RPM_PACKAGE_VERSION="%{version}"
92 RPM_PACKAGE_RELEASE="%{release}"
93 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
94 RPM_BUILD_ROOT="%{buildroot}"
95 export RPM_BUILD_ROOT
96);
97foreach (`dpkg-architecture`) {
98 s/=(.+)/="$1"/;
99 $scriptletbase .= " $_";
100}
101$scriptletbase .=
102q(
103 set -x
104 umask 022
105 cd %{_topdir}/BUILD
106);
107
108# Package data
109# This is the form of $pkgdata{pkgname}{meta}
110# meta includes Summary, Name, Version, Release, Group, Copyright,
111# Source, URL, Packager, BuildRoot, Description, BuildReq(uires),
112# Requires, Provides
113# 10/31/2005 Maybe this should be flatter? -kgd
114my %pkgdata;
115my @pkglist = ('main'); #sigh
116# Files listing. Embedding this in %pkgdata would be, um, messy.
117my %filelist;
118my $buildreq = '';
119
120# Scriptlets
121my $prepscript = '';
122my $buildscript = '';
123# %install doesn't need the full treatment from %clean; just an empty place to install to.
124# NB - rpm doesn't do this; is it really necessary?
125my $installscript = '[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT'."\n";
126my $cleanscript = '';
127# pre/post (un)install scripts. Note that these will likely barf as-is. :/
128my $preinstscript = '';
129my $postinstscript = '';
130my $preuninstscript = '';
131my $postuninstscript = '';
132
133die "Not enough arguments\n" if #$argv == 0;
134
135# Snag some environment data
136my $tmpdir;
137if (defined $ENV{TMP} && $ENV{TMP} =~ /^(\/var)?\/tmp$/) {
138 $tmpdir = $ENV{TMP};
139} else {
140 $tmpdir = "/var/tmp";
141}
142
143##main
144
145load_userconfig();
146parse_cmd();
147
148if ($cmdopts{install}) {
149 install_sdeb();
150 exit 0;
151}
152
153# Stick --rebuild handling in here - basically install_sdeb()
154# followed by tweaking options to run with -ba
155if ($cmdopts{type} eq 's') {
156 if ($srcpkg =~ /\.src\.rpm$/) {
157 my @srclist = qx { rpm -qlp $srcpkg };
158 foreach (@srclist) {
159 chomp;
160 $specfile = "$topdir/SPECS/$_" if /\.spec$/;
161 }
162 qx { rpm -i $srcpkg };
163 } else {
164 install_sdeb();
165 my @srclist = qx { pax < $srcpkg };
166 foreach (@srclist) {
167 chomp;
168 $specfile = "$topdir/$_" if /SPECS/;
169 }
170 }
171 $cmdopts{type} = 'b';
172 $cmdopts{stage} = 'a';
173}
174
175if ($cmdopts{type} eq 'b') {
176 # Need to read the spec file to find the tarball. Note that
177 # this also generates most of the shell script required.
178 parse_spec();
179 die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
180 if !checkbuildreq();
181}
182
183# -> srcpkg if -.s
184if ($cmdopts{stage} eq 's') {
185 srcpackage();
186 exit 0;
187}
188
189# Hokay. Need to:
190# -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
191if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
192 prep();
193}
194# -> build if -.c OR (-.[ilabs] AND !--short-circuit)
195if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
196 build();
197}
198# -> install if -.[ilabs]
199#if ($cmdopts{stage} eq 'i' || ($cmdopts{stage} =~ /[labs]/ && $cmdopts{short} ne 'y')) {
200if ($cmdopts{stage} =~ /[ilabs]/) {
201 install();
202#foreach my $pkg (@pkglist) {
203# print "files in $pkg:\n ".$filelist{$pkg}."\n";
204#}
205
206}
207# -> binpkg and srcpkg if -.a
208if ($cmdopts{stage} eq 'a') {
209 binpackage();
210 srcpackage();
211}
212# -> binpkg if -.b
213if ($cmdopts{stage} eq 'b') {
214 binpackage();
215}
216
217# Just in case.
218exit 0;
219
220
221## load_userconfig()
222# Loads user configuration (if any)
223# Currently only handles .debmacros
224# Needs to handle "other files"
225sub load_userconfig {
226 my (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
227 if (-e "$homedir/.debmacros") {
228 open USERMACROS,"<$homedir/.debmacros";
229 while (<USERMACROS>) {
230 # And we also only handle a few macros at the moment.
231 if (/^\%_topdir/) {
232 my (undef,$tmp) = split /\s+/, $_;
233 $topdir = $tmp;
234 }
235 }
236 }
237} # end load_userconfig()
238
239
240## parse_cmd()
241# Parses command line into global hash %cmdopts, other globals
242# Options based on rpmbuild's options
243sub parse_cmd {
244 # Don't feel like coding my own option parser...
245 #use Getopt::Long;
246 # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
247 #use Getopt::Popt qw(:all);
248 # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
249
250 # Stuff it.
251 my $prevopt = '';
252 foreach (@ARGV) {
253 chomp;
254
255 # Is it an option?
256 if (/^-/) {
257
258 # Is it a long option?
259 if (/^--/) {
260 if (/^--short-circuit/) {
261 $cmdopts{short} = 'y';
262 } elsif (/^--rebuild/) {
263 $cmdopts{type} = 's';
264 } else {
265 print "Long opt $_\n";
266 }
267 } else {
268 # Not a long option
269 if (/^-[bt]/) {
270 if ($cmdopts{stage} eq 's') {
271 # Mutually exclusive options.
272 die "Can't use $_ with --rebuild\n";
273 } else {
274 # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
275 ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
276 ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
277 }
278 } elsif (/^-v/) {
279 # bump verbosity. Not sure what I'll actually do here...
280 } elsif (/^-i/) {
281 $cmdopts{install} = 1;
282 $prevopt = '-i';
283 } else {
284 die "Bad option $_\n";
285 }
286 }
287
288 } else { # Not an option argument
289
290 # --buildroot is the only option that takes an argument
291 # Therefore, any *other* bare arguments are the spec file,
292 # tarball, or source package we're operating on - depending
293 # on which one we meet.
294 if ($prevopt eq '--buildroot') {
295 $cmdbuildroot = $_;
296 } elsif ($prevopt eq '-i') {
297 $srcpkg = $_;
298 } else {
299 if ($cmdopts{type} eq 's') {
300 # Source package
301 if (!/(sdeb|\.src\.rpm)$/) {
302 die "Can't --rebuild with $_\n";
303 }
304 $srcpkg = $_;
305 } elsif ($cmdopts{type} eq 'b') {
306 $specfile = $_;
307 # Spec file
308 } else {
309 # Tarball
310 }
311 }
312 }
313 $prevopt = $_;
314 } # foreach @ARGV
315
316 # Some cross-checks. rpmbuild limits --short-circuit to just
317 # the "compile" and "install" targets - with good reason IMO.
318 # Note that --short-circuit with -.p is not really an error, just redundant.
319 # NB - this is NOT fatal, just ignored!
320 if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
321 warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
322 $cmdopts{short} = 'n';
323 }
324
325 # Valid options, with example arguments (if any):
326# Build from .spec file; mutually exclusive:
327 # -bp
328 # -bc
329 # -bi
330 # -bl
331 # -ba
332 # -bb
333 # -bs
334# Build from tarball; mutually exclusive:
335 # -tp
336 # -tc
337 # -ti
338 # -ta
339 # -tb
340 # -ts
341# Build from .src.(deb|rpm)
342 # --rebuild
343 # --recompile
344
345# General options
346 # --buildroot=DIRECTORY
347 # --clean
348 # --nobuild
349 # --nodeps
350 # --nodirtokens
351 # --rmsource
352 # --rmspec
353 # --short-circuit
354 # --target=CPU-VENDOR-OS
355
356 #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
357
358} # end parse_cmd()
359
360
361## parse_spec()
362# Parse the .spec file.
363sub parse_spec {
364 open SPECFILE,"<$specfile";
365
366LINE: while (<SPECFILE>) {
367 next if /^#/; # Ignore comments...
368 next if /^\s+$/; # ... and blank lines.
369
370 if (/^\%/) {
371 # A macro that needs further processing.
372
373 if (my ($key, $def) = (/^\%define\s+([^\s]+)\s+(.+)$/) ) {
374 $specglobals{$key} = expandmacros($def,'g');
375 }
376
377 if (/^\%description(?:\s+(?:-n\s+)?(.+))?/) {
378 my $subname = "main";
379 if ($1) {
380 my $tmp = expandmacros("$1", 'g');
381 if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
382 }
383 while (<SPECFILE>) {
384 next if /^#/; # Messy. Should be possible to do better. :/
385 redo LINE if /^\%/;
386 $pkgdata{$subname}{desc} .= " $_";
387 }
388 }
389 if (/^\%package\s+(?:-n\s+)?(.+)/) {
390 # gotta expand %defines here. Whee.
391 my $subname = expandmacros("$1", 'g');
392 if (! /-n/) { $subname = "$pkgdata{main}{name}-$1"; }
393 push @pkglist, $subname;
394 $pkgdata{$subname}{name} = $subname;
395 $pkgdata{$subname}{version} = $pkgdata{main}{version};
396 while (<SPECFILE>) {
397 redo LINE if /^\%/;
398 if (my ($dname,$dvalue) = (/^(Summary|Group|Version|Requires|Provides):\s+(.+)$/i)) {
399 $dname =~ tr/[A-Z]/[a-z]/;
400 $pkgdata{$subname}{$dname} = expandmacros($dvalue, 'gp');
401 }
402 }
403 }
404
405 if (/^\%prep/) {
406 # %prep section. May have %setup macro; may include %patch tags,
407 # may be just a bare shell script.
408
409 # This really should be local-ish, but we need just the filename for the source
410 $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
411
412 # Replace some core macros
413 $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
414
415PREPSCRIPT: while (<SPECFILE>) {
416 if (/^\%setup/) {
417 # Parse out the %setup macro. Note that we aren't supporting
418 # many of RPM's %setup features.
419 $prepscript .= "cd $topdir/BUILD\n";
420 if ( /\s+-n\s+([^\s]+)\s+/ ) {
421 $tarballdir = $1;
422 } else {
423 $tarballdir = "$pkgdata{main}{name}-$pkgdata{main}{version}";
424 }
425 $prepscript .= "rm -rf $tarballdir\ntar -".
426 ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
427 ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
428 ( /\s+-q\s+/ ? '' : 'vv' )."xf ".
429 "$topdir/SOURCES/$pkgdata{main}{source}\n".
430 qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
431 ( /\s+-n\s+([^\s]+)\s+/ ?
432 "cd $1\n" : "cd $pkgdata{main}{name}-$pkgdata{main}{version}\n" ).
433 qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
434 qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
435 qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
436 } elsif (/^\%patch([^:]+)\s+(.+)$/) {
437 $prepscript .= "patch $2 <$topdir/SOURCES/".$pkgdata{main}{"patch$1"}."\n";
438 } else {
439 last PREPSCRIPT if /^\%/;
440 $prepscript .= $_;
441 }
442 }
443 redo LINE;
444 }
445 if (/^\%build/) {
446 # %build. This is pretty much just a shell script. There
447 # *are* a few macros, but we're not going to deal with them yet.
448 $buildscript .= "cd $tarballdir\n";
449BUILDSCRIPT: while (<SPECFILE>) {
450 if (/^\%configure/) {
451 $buildscript .= expandmacros($_,'cgbp');
452 } elsif (/^\%\{__make\}/) {
453 $buildscript .= expandmacros($_,'mgbp');
454 } else {
455 last BUILDSCRIPT if /^\%[^{]/;
456 $buildscript .= $_;
457 }
458 }
459 redo LINE;
460 }
461 if (/^\%install/) {
462 $installscript .= "cd $tarballdir\n";
463INSTALLSCRIPT: while (<SPECFILE>) {
464 if (/^\%makeinstall/) {
465 $installscript .= expandmacros($_,'igbp');
466 } else {
467 last INSTALLSCRIPT if /^\%/;
468 $installscript .= $_;
469 }
470 }
471 redo LINE;
472 }
473 if (/^\%clean/) {
474 while (<SPECFILE>) {
475 redo LINE if /^\%/;
476 $cleanscript .= $_;
477 }
478 $cleanscript = expandmacros($cleanscript,'gp');
479 }
480
481 # pre/post (un)install scripts
482 if (/^\%pre\b/) {
483 while (<SPECFILE>) {
484 redo LINE if /^\%/;
485 $preinstscript .= $_;
486 }
487 }
488 if (/^\%post\b/) {
489 while (<SPECFILE>) {
490 redo LINE if /^\%/;
491 $postinstscript .= $_;
492 }
493 }
494 if (/^\%preun\b/) {
495 while (<SPECFILE>) {
496 redo LINE if /^\%/;
497 $preuninstscript .= $_;
498 }
499 }
500 if (/^\%postun\b/) {
501 while (<SPECFILE>) {
502 redo LINE if /^\%/;
503 $postuninstscript .= $_;
504 }
505 }
506 # done %pre/%post scripts
507
508 if (/^\%files(?:\s+(?:-n\s+)?(.+))?/) {
509 my $pkgname = 'main';
510 if ($1) { # Magic to add entries to the right list of files
511 my $tmp = expandmacros("$1", 'g');
512 if (/-n/) { $pkgname = $tmp; } else { $pkgname = "$pkgdata{main}{name}-$tmp"; }
513 }
514
515 # Set this now, so it can be flipped a bit later, and used much later.
516 #$pkgdata{$pkgname}{conffiles} = 0;
517
518 while (<SPECFILE>) {
519 chomp;
520 next if /^#/;
521 # need to update this to deal (properly) with %dir, %attr, etc
522 next if /^\%dir/;
523 next if /^\%attr/;
524 next if /^\%defattr/;
525
526 # Debian dpkg doesn't speak "%docdir". Meh.
527 next if /^\%docdir/;
528
529 # Conffiles. Note that Debian and RH have similar, but not
530 # *quite* identical ideas of what constitutes a conffile. Nrgh.
531 if (/^\%config\s+(.+)$/) {
532 $pkgdata{$pkgname}{conffiles} = 1; # Flag it for later
533 my $tmp = $1; # Now we can mangleificationate it. And we probably need to. :/
534 $tmp = expandmacros($tmp, 'gp'); # Expand common macros
535 if ($tmp !~ /\s+/) {
536 # Simplest case, just a file. Whew.
537 push @{$pkgdata{$pkgname}{conflist}}, $tmp;
538 $filelist{$pkgname} .= " $tmp";
539 } else {
540 # Wot? Spaces? That means extra %-macros. Which, for the most part, can be ignored.
541 ($tmp) = ($tmp =~ /.+\s([^\s]+)/); # Strip everything before the last space
542 push @{$pkgdata{$pkgname}{conflist}}, $tmp;
543 $filelist{$pkgname} .= " $tmp";
544 }
545 next;
546 }
547
548 # and finally we can fall through %{_<FHS>}-prefixed locations...
549 if (/^\%\{_/) {
550 $filelist{$pkgname} .= " $_";
551 next;
552 }
553 # EW. Necessary to clear up %define expansions before we exit with redo.
554 $_ = expandmacros $_, 'g';
555
556 # ... unknown or "next section" % directives ...
557 redo LINE if /^\%/;
558
559 # ... and "normal" files
560 $filelist{$pkgname} .= " $_";
561 }
562 $filelist{$pkgname} = expandmacros($filelist{$pkgname}, 'gp');
563 } # done %file section
564
565 if (/^\%changelog/) {
566 $pkgdata{main}{changelog} = '';
567 while (<SPECFILE>) {
568 redo LINE if /^\%/;
569 $pkgdata{main}{changelog} .= $_;
570 }
571 }
572
573 } else { # Data from the spec file "header"
574
575 if (/^summary:\s+(.+)/i) {
576 $pkgdata{main}{summary} = $1;
577 } elsif (/^name:\s+(.+)/i) {
578 $pkgdata{main}{name} = expandmacros($1,'g');
579 } elsif (/^version:\s+(.+)/i) {
580 $pkgdata{main}{version} = expandmacros($1,'g');
581 } elsif (/^release:\s+(.+)/i) {
582 $pkgdata{main}{release} = expandmacros($1,'g');
583 } elsif (/^group:\s+(.+)/i) {
584 $pkgdata{main}{group} = $1;
585 } elsif (/^copyright:\s+(.+)/i) {
586 $pkgdata{main}{copyright} = $1;
587 } elsif (/^url:\s+(.+)/i) {
588 $pkgdata{main}{url} = $1;
589 } elsif (/^packager:\s+(.+)/i) {
590 $pkgdata{main}{packager} = $1;
591 } elsif (/^buildroot:\s+(.+)/i) {
592 $buildroot = $1;
593 } elsif (/^source0?:\s+(.+)/i) {
594 $pkgdata{main}{source} = $1;
595 die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
596 } elsif (/^source([0-9]+):\s+(.+)/i) {
597 $pkgdata{sources}{$1} = $2;
598 } elsif (/^patch([^:]+):\s+(.+)$/i) {
599 my $patchname = "patch$1";
600 $pkgdata{main}{$patchname} = $2;
601 if ($pkgdata{main}{$patchname} =~ /\//) {
602 # URL-style patch. Rare but not unheard-of.
603 my @patchbits = split '/', $pkgdata{main}{$patchname};
604 $pkgdata{main}{$patchname} = $patchbits[$#patchbits];
605 }
606 } elsif (/^buildreq(?:uires)?:\s+(.+)/i) {
607 $buildreq .= ", $1";
608 } elsif (/^requires:\s+(.+)/i) {
609 $pkgdata{main}{requires} .= ", ".expandmacros("$1", 'gp');
610 } elsif (/^provides:\s+(.+)/i) {
611 $pkgdata{main}{provides} .= ", $1";
612 } elsif (/^conflicts:\s+(.+)/i) {
613 $pkgdata{main}{conflicts} .= ", $1";
614 }
615#Name: suwrap
616#Version: 0.04
617#Release: 3
618#Group: Applications/System
619#Copyright: WebHart internal ONLY. :(
620#BuildArchitectures: i386
621#BuildRoot: /tmp/%{name}-%{version}
622#Url: http://virtual.webhart.net
623#Packager: Kris Deugau <kdeugau@deepnet.cx>
624#Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
625
626 }
627 }
628
629 # Parse and replace some more macros. More will be replaced even later.
630
631 # Expand macros as necessary.
632 $scriptletbase = expandmacros($scriptletbase,'gp');
633
634 $buildroot = $cmdbuildroot if $cmdbuildroot;
635 $buildroot = expandmacros($buildroot,'gp');
636
637 close SPECFILE;
638} # end parse_spec()
639
640
641## prep()
642# Writes and executes the %prep script (mostly) built while reading the spec file.
643sub prep {
644 # Replace some things here just to make sure.
645 $prepscript = expandmacros($prepscript,'gp');
646
647#print $prepscript; exit 0;
648
649 # create script filename
650 my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
651 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
652 or die $!;
653 print PREPSCRIPT $scriptletbase;
654 print PREPSCRIPT $prepscript;
655 close PREPSCRIPT;
656
657 # execute
658 print "Calling \%prep script $prepscriptfile...\n";
659 system("/bin/sh -e $prepscriptfile") == 0
660 or die "Can't exec: $!\n";
661
662 # and clean up
663 unlink $prepscriptfile;
664} # end prep()
665
666
667## build()
668# Writes and executes the %build script (mostly) built while reading the spec file.
669sub build {
670 # Expand the macros
671 $buildscript = expandmacros($buildscript,'cgbp');
672
673 # create script filename
674 my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
675 sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
676 or die $!;
677 print BUILDSCRIPT $scriptletbase;
678 print BUILDSCRIPT $buildscript;
679 close BUILDSCRIPT;
680
681 # execute
682 print "Calling \%build script $buildscriptfile...\n";
683 system("/bin/sh -e $buildscriptfile") == 0
684 or die "Can't exec: $!\n";
685
686 # and clean up
687 unlink $buildscriptfile;
688} # end build()
689
690
691## install()
692# Writes and executes the %install script (mostly) built while reading the spec file.
693sub install {
694 # Expand the macros
695 $installscript = expandmacros($installscript,'igbp');
696
697 # create script filename
698 my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
699 sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
700 or die $!;
701 print INSTSCRIPT $scriptletbase;
702# print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it.
703 print INSTSCRIPT $installscript;
704 close INSTSCRIPT;
705
706 # execute
707 print "Calling \%install script $installscriptfile...\n";
708 system("/bin/sh -e $installscriptfile") == 0
709 or die "Can't exec: $!\n";
710
711 # and clean up
712 unlink $installscriptfile;
713} # end install()
714
715
716## binpackage()
717# Creates the binary .deb package from the installed tree in $buildroot.
718# Writes and executes a shell script to do so.
719# Creates miscellaneous files required by dpkg-deb to actually build the package file.
720# Should handle simple subpackages
721sub binpackage {
722 # Make sure we have somewhere to write the .deb file
723 if (!-e "$topdir/DEBS/i386") {
724 mkdir "$topdir/DEBS/i386";
725 }
726
727 foreach my $pkg (@pkglist) {
728
729 # Gotta do this first, otherwise we don't have a place to move files from %files
730 mkdir "$buildroot/$pkg";
731
732 # Eliminate any lingering % macros
733 $filelist{$pkg} = expandmacros $filelist{$pkg}, 'g';
734
735 my @pkgfilelist = split ' ', $filelist{$pkg};
736 foreach my $pkgfile (@pkgfilelist) {
737 $pkgfile = expandmacros($pkgfile, 'gp');
738 my ($fpath,$fname) = ($pkgfile =~ m|(.+?/?)?([^/]+)$|); # We don't need $fname now, but we might.
739 qx { mkdir -p $buildroot/$pkg$fpath }
740 if $fpath && $fpath ne '';
741 qx { mv $buildroot$pkgfile $buildroot/$pkg$fpath };
742 }
743
744 # Get the "Depends" (Requires) a la RPM. Ish. We strip the leading
745 # comma and space here (if needed) in case there were "Requires" specified
746 # in the spec file - those would precede these.
747 $pkgdata{$pkg}{requires} .= getreqs("$buildroot/$pkg");
748
749 # magic needed to properly version dependencies...
750 # only provided deps will really be included
751 $pkgdata{$pkg}{requires} =~ s/\s+//g;
752 my @deps = split /,/, $pkgdata{$pkg}{requires};
753 my $tmp = '';
754 foreach my $dep (@deps) {
755 if (my ($name,$rel,$value) = ($dep =~ /^([a-zA-Z0-9._-]+)([><=]+)([a-zA-Z0-9._-]+)$/)) {
756 $tmp .= ", $name ($rel $value)";
757 } else {
758 $tmp .= ", $dep";
759 }
760 }
761 ($pkgdata{$pkg}{requires} = $tmp) =~ s/^, //;
762
763 # Do this here since we're doing {depends}...
764 if (defined($pkgdata{$pkg}{provides})) {
765 $pkgdata{$pkg}{provides} =~ s/^, //;
766 $pkgdata{$pkg}{provides} = expandmacros($pkgdata{$pkg}{provides},'gp');
767 }
768 if (defined($pkgdata{$pkg}{conflicts})) {
769 $pkgdata{$pkg}{conflicts} =~ s/^, //;
770 $pkgdata{$pkg}{conflicts} = expandmacros($pkgdata{$pkg}{conflicts},'gp');
771 }
772
773 # Gotta do this next, otherwise the control file has nowhere to go. >:(
774 mkdir "$buildroot/$pkg/DEBIAN";
775
776 # Hack the filename for the package into a Debian-tool-compatible format. GRRRRRR!!!!!
777 # Have I mentioned I hate Debian Policy?
778 $pkgdata{$pkg}{name} =~ tr/_/-/;
779
780 # create script filename
781 my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
782 sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
783 or die $!;
784 print DEBSCRIPT $scriptletbase;
785 print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot/$pkg $topdir/DEBS/i386/".
786 "$pkgdata{$pkg}{name}_$pkgdata{$pkg}{version}-$pkgdata{main}{release}_i386.deb\n";
787 # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
788 close DEBSCRIPT;
789
790 my $control = "Package: $pkgdata{$pkg}{name}\n".
791 "Version: $pkgdata{$pkg}{version}-$pkgdata{main}{release}\n".
792 "Section: $pkgdata{$pkg}{group}\n".
793 "Priority: optional\n".
794 "Architecture: i386\n".
795 "Maintainer: $pkgdata{main}{packager}\n".
796 ( $pkgdata{$pkg}{requires} ne '' ? "Depends: $pkgdata{$pkg}{requires}\n" : '' ).
797 ( defined($pkgdata{$pkg}{provides}) ? "Provides: $pkgdata{$pkg}{provides}\n" : '' ).
798 ( defined($pkgdata{$pkg}{conflicts}) ? "Conflicts: $pkgdata{$pkg}{conflicts}\n" : '' ).
799 "Description: $pkgdata{$pkg}{summary}\n";
800 $control .= "$pkgdata{$pkg}{desc}\n";
801
802 open CONTROL, ">$buildroot/$pkg/DEBIAN/control";
803 print CONTROL $control;
804 close CONTROL;
805
806 # Iff there are conffiles (as specified in the %files list(s), add'em
807 # in so dpkg-deb can tag them.
808 if ($pkgdata{$pkg}{conffiles}) {
809 open CONFLIST, ">$buildroot/$pkg/DEBIAN/conffiles";
810 foreach my $conffile (@{$pkgdata{$pkg}{conflist}}) {
811 print CONFLIST "$conffile\n";
812 }
813 close CONFLIST;
814 }
815
816 # Can't see much point in scripts on subpackages... although since
817 # it's *possible* I should support it at some point.
818 if ($pkg eq 'main') {
819 if ($preinstscript ne '') {
820 $preinstscript = expandmacros($preinstscript,'g');
821 open PREINST, ">$buildroot/$pkg/DEBIAN/preinst";
822 print PREINST "#!/bin/sh\nset -e\n\n";
823 print PREINST $preinstscript;
824 close PREINST;
825 `chmod 0755 $buildroot/$pkg/DEBIAN/preinst`;
826 }
827 if ($postinstscript ne '') {
828 $postinstscript = expandmacros($postinstscript,'g');
829 open POSTINST, ">$buildroot/$pkg/DEBIAN/postinst";
830 print POSTINST "#!/bin/sh\nset -e\n\n";
831 print POSTINST $postinstscript;
832 close POSTINST;
833 `chmod 0755 $buildroot/$pkg/DEBIAN/postinst`;
834 }
835 if ($preuninstscript ne '') {
836 $preuninstscript = expandmacros($preuninstscript,'g');
837 open PREUNINST, ">$buildroot/$pkg/DEBIAN/prerm";
838 print PREUNINST "#!/bin/sh\nset -e\n\n";
839 print PREUNINST $preuninstscript;
840 close PREUNINST;
841 `chmod 0755 $buildroot/$pkg/DEBIAN/prerm`;
842 }
843 if ($postuninstscript ne '') {
844 $postuninstscript = expandmacros($postuninstscript,'g');
845 open POSTUNINST, ">$buildroot/$pkg/DEBIAN/postrm";
846 print POSTUNINST "#!/bin/sh\nset -e\n\n";
847 print POSTUNINST $postuninstscript;
848 close POSTUNINST;
849 `chmod 0755 $buildroot/$pkg/DEBIAN/postrm`;
850 }
851 }
852
853 # execute
854 print "Calling package creation script $debscriptfile for $pkgdata{$pkg}{name}...\n";
855 system("/bin/sh -e $debscriptfile") == 0
856 or die "Can't exec: $!\n";
857
858 # and clean up
859 unlink $debscriptfile;
860
861 } # subpackage loop
862
863} # end binpackage()
864
865
866## srcpackage()
867# Builds a .src.deb source package. Note that Debian's idea of
868# a "source package" is seriously flawed IMO, because you can't
869# easily copy it as-is.
870# Not quite identical to RPM, but Good Enough (TM).
871sub srcpackage {
872 # In case we were called with -bs.
873 $pkgdata{main}{name} =~ tr/_/-/;
874 my $pkgsrcname = "$pkgdata{main}{name}-$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb";
875
876 my $paxcmd;
877
878 # We'll definitely need this later, and *may* need it sooner.
879 (my $barespec = $specfile) =~ s|.+/([^/]+)$|$1|;
880
881 # Copy the specfile to the build tree, but only if it's not there already.
882##buglet: need to deal with silly case where silly user has put the spec
883# file in a subdir of %{_topdir}/SPECS. Ewww. Silly user!
884 if (abs_path($specfile) !~ /^$topdir\/SPECS/) {
885 $paxcmd .= "cp $specfile %{_topdir}/SPECS/; \n"
886 }
887
888 # use pax -w [file] [file] ... >outfile.sdeb
889 $paxcmd = "cd $topdir; pax -w ";
890
891# tweak source entry into usable form. Need it locally somewhere along the line.
892 (my $pkgsrc = $pkgdata{main}{source}) =~ s|.+/([^/]+)$|$1|;
893 $paxcmd .= "SOURCES/$pkgsrc ";
894
895 # create file list: Source[nn], Patch[nn]
896 foreach my $specbit (keys %{$pkgdata{main}} ) {
897 next if $specbit eq 'source';
898 $paxcmd .= "SOURCES/$pkgdata{main}{$specbit} " if $specbit =~ /^patch/;
899##buglet: need to deal with case where patches are listed as URLs?
900# or other extended pathnames? Silly !@$%^&!%%!%!! user!
901 }
902
903 foreach my $source (keys %{$pkgdata{sources}}) {
904 $paxcmd .= "SOURCES/$pkgdata{sources}{$source} ";
905 }
906
907 # add the spec file, source package destination, and cd back where we came from.
908 $paxcmd .= "SPECS/$barespec > $topdir/SDEBS/$pkgsrcname; cd -";
909
910 # In case of %-macros...
911 $paxcmd = expandmacros($paxcmd,'gp');
912
913 system "$paxcmd";
914 print "Wrote source package $pkgsrcname in $topdir/SDEBS.\n";
915}
916
917
918## checkbuildreq()
919# Checks the build requirements (if any)
920# Spits out a rude warning and returns a true-false error if any
921# requirements are not met.
922sub checkbuildreq {
923 return 1 if $buildreq eq ''; # No use doing extra work.
924
925 if ( ! -e "/usr/bin/dpkg-query" ) {
926 print "**WARNING** dpkg-query not found. Can't check build-deps.\n".
927 " Required for sucessful build:\n".$buildreq."\n".
928 " Continuing anyway.\n";
929 return 1;
930 }
931
932 my $reqflag = 1; # unset iff a buildreq is missing
933
934 $buildreq =~ s/^, //; # Strip the leading comma and space
935 my @reqlist = split /,\s+/, $buildreq;
936
937 foreach my $req (@reqlist) {
938 my ($pkg,$rel,$ver);
939
940 # We have two classes of requirements - versioned and unversioned.
941 if ($req =~ /[><=]/) {
942 # Pick up the details of versioned buildreqs
943 ($pkg,$rel,$ver) = ($req =~ /([a-z0-9._-]+)\s+([><=]+)\s+([a-z0-9._-]+)/);
944 } else {
945 # And the unversioned ones.
946 $pkg = $req;
947 $rel = '>=';
948 $ver = 0;
949 }
950
951 my @pkglist = qx { dpkg-query --showformat '\${status}\t\${version}\n' -W $pkg };
952# need to check if no lines returned - means a bad buildreq
953 my ($reqstat,undef,undef,$reqver) = split /\s+/, $pkglist[0];
954 if ($reqstat !~ /install/) {
955 print " * Missing build-dependency $pkg!\n";
956 $reqflag = 0;
957 } else {
958# gotta be a better way to do this... :/
959 if ($rel eq '>=' && !($reqver ge $ver)) {
960 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
961 $reqflag = 0;
962 }
963 if ($rel eq '>' && !($reqver gt $ver)) {
964 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
965 $reqflag = 0;
966 }
967 if ($rel eq '<=' && !($reqver le $ver)) {
968 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
969 $reqflag = 0;
970 }
971 if ($rel eq '<' && !($reqver lt $ver)) {
972 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
973 $reqflag = 0;
974 }
975 if ($rel eq '=' && !($reqver eq $ver)) {
976 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
977 $reqflag = 0;
978 }
979 } # end not installed/installed check
980 } # end req loop
981
982 return $reqflag;
983} # end checkbuildreq()
984
985
986## getreqs()
987# Find out which libraries/packages are required for any
988# executables and libs in a given file tree.
989# (Debian doesn't have soname-level deps; just package-level)
990# Returns an empty string if the tree contains no binaries.
991# Doesn't work well on shell scripts. but those *should* be
992# fine anyway. (Yeah, right...)
993sub getreqs() {
994 my $pkgtree = $_[0];
995
996 print "Checking library requirements...\n";
997 my @binlist = qx { find $pkgtree -type f -perm 755 };
998
999 if (scalar(@binlist) == 0) {
1000 return '';
1001 }
1002
1003 my @reqlist;
1004 foreach (@binlist) {
1005 push @reqlist, qx { ldd $_ };
1006 }
1007
1008 # Get the list of libs provided by this package. Still doesn't
1009 # handle the case where the lib gets stuffed into a subpackage. :/
1010 my @intprovlist = qx { find $pkgtree -type f -name "*.so*" };
1011 my $provlist = '';
1012 foreach (@intprovlist) {
1013 s/$pkgtree//;
1014 $provlist .= "$_";
1015 }
1016
1017 my %reqs;
1018 my $reqlibs = '';
1019
1020 foreach (@reqlist) {
1021 next if /^$pkgtree/;
1022 next if /not a dynamic executable/;
1023 next if m|/lib/ld-linux.so|; # Hack! Hack! PTHBTT! (libc suxx0rz)
1024
1025 my ($req) = (/^\s+([a-z0-9._-]+)/); # dig out the actual library (so)name
1026
1027 # Ignore libs provided by this package. Note that we don't match
1028 # on word-boundary at the *end* of the lib we're looking for, as the
1029 # looked-for lib may not have the full soname version. (ie, it may
1030 # "just" point to one of the symlinks that get created somewhere.)
1031 next if $provlist =~ /\b$req/;
1032
1033 $reqlibs .= " $req";
1034 }
1035
1036 if ($reqlibs ne '') {
1037 foreach (qx { dpkg -S $reqlibs }) {
1038 my ($libpkg,undef) = split /:\s+/;
1039 $reqs{$libpkg} = 1;
1040 }
1041 }
1042
1043 my $deplist = '';
1044 foreach (keys %reqs) {
1045 $deplist .= ", $_";
1046 }
1047
1048# For now, we're done. We're not going to meddle with versions yet.
1049# Among other things, it's messier than handling "simple" yes/no "do
1050# we have this lib?" deps. >:(
1051
1052 return $deplist;
1053} # end getreqs()
1054
1055
1056## install_sdeb()
1057# Extracts .sdeb contents to %_topdir as appropriate
1058sub install_sdeb {
1059 my $paxcmd = "cd $topdir; pax -r <$srcpkg; cd -";
1060
1061 # In case of %-macros...
1062 $paxcmd = expandmacros($paxcmd,'gp');
1063
1064 system "$paxcmd";
1065 print "Extracted source package $srcpkg to $topdir.\n";
1066} # end install_sdeb()
1067
1068
1069## expandmacros()
1070# Expands all %{blah} macros in the passed string
1071# Split up a bit with some sections so we don't spend time trying to
1072# expand macros that are only used in a few specific places.
1073sub expandmacros {
1074 my $macrostring = shift;
1075 my $section = shift;
1076
1077 # To allow the FHS-ish %configure and %makeinstall to work The Right Way.
1078 # (Without clobbering the global $buildroot.)
1079 my $prefix = '';
1080
1081 if ($section =~ /c/) {
1082 # %configure macro
1083# Don't know what it's for, don't have a useful default replacement
1084# --program-prefix=%{_program_prefix} \
1085 $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
1086 --build=$DEB_BUILD_GNU_TYPE \
1087 --prefix=%{_prefix} \
1088 --exec-prefix=%{_exec_prefix} \
1089 --bindir=%{_bindir} \
1090 --sbindir=%{_sbindir} \
1091 --sysconfdir=%{_sysconfdir} \
1092 --datadir=%{_datadir} \
1093 --includedir=%{_includedir} \
1094 --libdir=%{_libdir} \
1095 --libexecdir=%{_libexecdir} \
1096 --localstatedir=%{_localstatedir} \
1097 --sharedstatedir=%{_sharedstatedir} \
1098 --mandir=%{_mandir} \
1099 --infodir=%{_infodir} ';
1100 } # done %configure
1101
1102 if ($section =~ /m/) {
1103 $macrostring =~ s'%{__make}'make ';
1104 } # done make
1105
1106 if ($section =~ /i/) {
1107 # This is where we need to mangle $prefix.
1108 $macrostring =~ s'%makeinstall'make %{fhs} install';
1109 $prefix = $buildroot;
1110 } # done %install and/or %makeinstall
1111
1112 # Build data
1113 # Note that these are processed in reverse order to get the substitution order right
1114 if ($section =~ /b/) {
1115# $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
1116# build=$DEB_BUILD_GNU_TYPE \
1117 $macrostring =~ s'%{fhs}'prefix=%{_prefix} \
1118 exec-prefix=%{_exec_prefix} \
1119 bindir=%{_bindir} \
1120 sbindir=%{_sbindir} \
1121 sysconfdir=%{_sysconfdir} \
1122 datadir=%{_datadir} \
1123 includedir=%{_includedir} \
1124 libdir=%{_libdir} \
1125 libexecdir=%{_libexecdir} \
1126 localstatedir=%{_localstatedir} \
1127 sharedstatedir=%{_sharedstatedir} \
1128 mandir=%{_mandir} \
1129 infodir=%{_infodir} \
1130';
1131
1132 # Note that the above regex terminates with the extra space
1133 # "Just In Case" of user additions, which will then get neatly
1134 # tagged on the end where they take precedence (supposedly)
1135 # over the "default" ones.
1136
1137 # Now we cascade the macros introduced above. >_<
1138 # Wot ot to go theah:
1139 $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
1140 $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
1141 $macrostring =~ s|%{_oldincludedir}|/usr/include|g; #/usr/include
1142 $macrostring =~ s|%{_includedir}|%{_prefix\}/include|g; #/usr/include
1143 $macrostring =~ s|%{_libdir}|%{_exec_prefix}/%{_lib}|g; #/usr/lib
1144 $macrostring =~ s|%{_lib}|lib|g; #?
1145 $macrostring =~ s|%{_localstatedir}|/var|g; #/var
1146 $macrostring =~ s|%{_sharedstatedir}|%{_prefix}/com|g; #/usr/com WTF?
1147 $macrostring =~ s|%{_sysconfdir}|/etc|g; #/etc
1148 $macrostring =~ s|%{_datadir}|%{_prefix}/share|g; #/usr/share
1149 $macrostring =~ s|%{_libexecdir}|%{_exec_prefix}/libexec|g; #/usr/libexec
1150 $macrostring =~ s|%{_sbindir}|%{_exec_prefix}/sbin|g; #/usr/sbin
1151 $macrostring =~ s|%{_bindir}|%{_exec_prefix}/bin|g; #/usr/bin
1152 $macrostring =~ s|%{_exec_prefix}|%{_prefix}|g; #/usr
1153 $macrostring =~ s|%{_prefix}|/usr|g; #/usr
1154 } # done with config section
1155
1156 # Package data
1157 if ($section =~ /p/) {
1158 $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
1159 foreach my $source (keys %{$pkgdata{sources}}) {
1160 $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
1161 }
1162 $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
1163 $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
1164 $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
1165 }
1166
1167 # Globals, and not-so-globals
1168 if ($section =~ /g/) {
1169
1170 # special %define's. Handle the general case where we eval anything.
1171 # Prime example:
1172 #%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
1173 if ($macrostring =~ /^\%\(eval.+\)$/) {
1174 $macrostring =~ s/^\%\(//;
1175 $macrostring =~ s/\)$//;
1176 # Oy vey this gets silly for the perl bits. Executing a shell to
1177 # call Perl to get the vendorlib/sitelib/whatever "core" globals.
1178 # This can do more, but... eww.
1179 # Next line is non-optimal - what if $macrostring contains ' characters?
1180 $macrostring = qx { /bin/sh -c '$macrostring' };
1181 }
1182
1183 $macrostring =~ s|%{_builddir}|%{_topdir}/BUILD|g;
1184 $macrostring =~ s|%{_topdir}|$topdir|g;
1185 $macrostring =~ s|%{_tmppath}|$tmpdir|g;
1186 $macrostring =~ s'%{_docdir}'/usr/share/doc'g;
1187
1188 # Standard FHS locations. More or less.
1189 $macrostring =~ s'%{_bindir}'/usr/bin'g;
1190 $macrostring =~ s'%{_sbindir}'/usr/sbin'g;
1191 $macrostring =~ s'%{_mandir}'/usr/share/man'g;
1192 $macrostring =~ s'%{_includedir}'/usr/include'g;
1193 $macrostring =~ s'%{_libdir}'/usr/lib'g;
1194 $macrostring =~ s'%{_sysconfdir}'/etc'g;
1195 $macrostring =~ s'%{_localstatedir}'/var'g;
1196
1197 # %define's
1198 foreach my $key (keys %specglobals) {
1199 $macrostring =~ s|%{$key}|$specglobals{$key}|g;
1200 }
1201
1202 # system programs. RPM uses a global config file for these; we'll just
1203 # ASS-U-ME and make life a little simpler.
1204 if ($macrostring =~ /\%\{\_\_([a-z0-9_-]+)\}/) {
1205 $macrostring =~ s|%{__([a-z0-9_-]+)}|$1|g;
1206 }
1207 } # done with globals section
1208
1209 return $macrostring;
1210} # end expandmacros()
1211
1212
1213
1214__END__
1215
1216
1217
1218=head1 NAME
1219
1220debbuild - Build Debian-compatible packages from RPM spec files
1221
1222=head1 SYNOPSIS
1223
1224 debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
1225
1226 debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2}
1227
1228 debbuild --rebuild file.{src.rpm|sdeb}
1229
1230=head1 DESCRIPTION
1231
1232This script attempts to build Debian-friendly semi-native packages from RPM spec files,
1233RPM-friendly tarballs, and RPM source packages (.src.rpm files). It accepts I<most> of the
1234options rpmbuild does, and should be able to interpret most spec files usefully. Perl
1235modules should be handled via CPAN+dh-make-perl instead; Debian's conventions for such
1236things do not lend themselves to automated conversion.
1237
1238As far as possible, the command-line options are identical to those from rpmbuild, although
1239several rpmbuild options are not supported:
1240
1241 --recompile
1242 --showrc
1243 --buildroot
1244 --clean
1245 --nobuild
1246 --rmsource
1247 --rmspec
1248 --sign
1249 --target
1250
1251Some of these could probably be trivially added. Feel free to send me a patch. ;)
1252
1253Complex spec files will most likely not work well, if at all. Rewrite them from scratch -
1254you'll have to make heavy modifications anyway.
1255
1256If you see something you don't like, mail me. Send a patch if you feel inspired. I don't
1257promise I'll do anything other than say "Yup, that's broken" or "Got your message".
1258
1259=head1 ASSUMPTIONS
1260
1261As with rpmbuild, debbuild makes some assumptions about your system.
1262
1263=over 4
1264
1265=item *
1266
1267Either you have rights to do as you please under /usr/src/debian, or you have created a file
1268~/.debmacros containing a suitable %_topdir definition.
1269
1270Both rpmbuild and debbuild require the directories %_topdir/{BUILD,SOURCES,SPECS}. However,
1271where rpmbuild requires the %_topdir/{RPMS,SRPMS} directories, debbuild
1272requires %_topdir/{DEBS,SDEBS} instead. Create them in advance;
1273some subdirectories are created automatically as needed, but most are not.
1274
1275=item *
1276
1277/var/tmp must allow script execution - rpmbuild and debbuild both rely on creating and
1278executing shell scripts for much of their functionality. By default, debbuild also creates
1279install trees under /var/tmp - however this is (almost) entirely under the control of the
1280package's .spec file.
1281
1282=item *
1283
1284If you wish to --rebuild a .src.rpm, your %_topdir for both debbuild and rpmbuild must either
1285match, or be suitably symlinked one direction or another so that both programs are effectively
1286working in the same tree. (Or you could just manually wrestle files around your system.)
1287
1288You could symlink ~/.rpmmacros to ~/.debmacros (or vice versa) and save yourself some hassle
1289if you need to rebuild .src.rpm packages on a regular basis. Currently debbuild only uses the
1290%_topdir macro definition, although there are many more things that rpmbuild can use from
1291~/.rpmmacros.
1292
1293=back
1294
1295=head1 AUTHOR
1296
1297debbuild was written by Kris Deugau <kdeugau@deepnet.cx>. A version that approximates
1298current is available at http://www.deepnet.cx/debbuild/.
1299
1300=head1 BUGS
1301
1302Funky Things Happen if you forget a command-line option or two. I've been too lazy to bother
1303fixing this.
1304
1305Many macro expansions are unsupported or incompletely supported.
1306
1307The generated scriptlets don't quite match those from rpmbuild exactly. There are extra
1308environment variables and preprocessing that I haven't needed (yet).
1309
1310Dcumentation, such as it is, will likely remain perpetually out of date.
1311
1312%_topdir and the five "working" directories under %_topdir could arguably be created by
1313debbuild. However, rpmbuild doesn't create these directories either.
1314
1315=head1 SEE ALSO
1316
1317rpm(8), rpmbuild(8), and pretty much any document describing how to write a .spec file.
1318
1319=cut
Note: See TracBrowser for help on using the repository browser.