source: trunk/debbuild@ 20

Last change on this file since 20 was 20, checked in by kdeugau, 19 years ago

/trunk

Tweak readability on processing to determine options for tar

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 22.0 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: 2005-11-14 21:34:04 +0000 (Mon, 14 Nov 2005) $
9# SVN revision $Rev: 20 $
10# Last update by $Author: kdeugau $
11###
12
13=head1 NAME
14
15debbuild - Build Debian-compatible packages from RPM spec files
16
17=head1 SYNOPSIS
18
19 debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
20
21 debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2}
22
23 debbuild --rebuild file.src.{rpm|deb}
24
25=head1 DESCRIPTION
26
27This script attempts to build Debian-friendly semi-native packages
28from RPM spec files, RPM-friendly tarballs, and RPM source packages
29(.src.rpm). It accepts I<most> of the options rpmbuild does, and
30should be able to interpret most spec files usefully. Perl modules
31should be handled via CPAN+dh-make-perl instead; Debian's conventions
32for such things do not lend themselves to automated conversion.
33
34As far as possible, the command-line options are identical to those
35from rpmbuild, although several rpmbuild options are not supported.
36
37=cut
38
39use strict;
40use warnings;
41use Fcntl; # for sysopen flags
42
43# regex debugger
44#use re "debug";
45
46# Program flow:
47# -> Parse/execute "system" config/macros (if any - should be rare)
48# -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
49# -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
50
51# User's prefs for dirs, environment, etc,etc,etc.
52# config file ~/.debmacros
53# Default ordered search paths for config/macros:
54# /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
55# /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
56# **NOTE: May be possible to (ab)use bits of debhelper
57
58# Build tree
59# default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
60
61# Globals
62my $specfile;
63my $tarball;
64my $srcpkg;
65my $cmdbuildroot;
66my $tarballdir; # This should really be initialized, but the coding makes it, um, ugly.
67
68# Initialized globals
69my $verbosity = 0;
70my %cmdopts = (type => '',
71 stage => 'a',
72 short => 'n'
73 );
74my $topdir = "/usr/src/debian";
75my $buildroot = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
76
77# "Constants"
78my %targets = ('p' => 'Prep',
79 'c' => 'Compile',
80 'i' => 'Install',
81 'l' => 'Verify %files',
82 'a' => 'Build binary and source',
83 'b' => 'Build binary',
84 's' => 'Build source'
85 );
86my $scriptletbase =
87q(#!/bin/sh
88
89 RPM_SOURCE_DIR="%{_topdir}/SOURCES"
90 RPM_BUILD_DIR="%{_topdir}/BUILD"
91 RPM_OPT_FLAGS="-O2 -g -march=i386 -mcpu=i686"
92 RPM_ARCH="i386"
93 RPM_OS="linux"
94 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
95 RPM_DOC_DIR="/usr/share/doc"
96 export RPM_DOC_DIR
97 RPM_PACKAGE_NAME="%{name}"
98 RPM_PACKAGE_VERSION="%{version}"
99 RPM_PACKAGE_RELEASE="%{release}"
100 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
101 RPM_BUILD_ROOT="%{buildroot}"
102 export RPM_BUILD_ROOT
103);
104foreach (`dpkg-architecture`) {
105 s/=(.+)/="$1"/;
106 $scriptletbase .= " $_";
107}
108$scriptletbase .=
109q(
110 set -x
111 umask 022
112 cd %{_topdir}/BUILD
113);
114
115# Package data
116# This is the form of $pkgdata{pkgname}{meta}
117# meta includes Summary, Name, Version, Release, Group, Copyright,
118# Source, URL, Packager, BuildRoot, Description
119# 10/31/2005 Maybe this should be flatter? -kgd
120my %pkgdata;
121
122# Scriptlets
123my $prepscript;
124my $buildscript;
125my $installscript;
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{type} eq 'b') {
149 # Need to read the spec file to find the tarball. Note that
150 # this also generates most of the shell script required.
151 parse_spec();
152}
153
154# Hokay. Need to:
155# -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
156if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
157 prep();
158}
159# -> build if -.c OR (-.[ilabs] AND !--short-circuit)
160if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
161 build();
162}
163# -> install if -.[ilabs]
164if ($cmdopts{stage} =~ /[ilabs]/) {
165 install();
166}
167# -> binpkg and srcpkg if -.a
168if ($cmdopts{stage} eq 'a') {
169 binpackage();
170 srcpackage();
171}
172# -> binpkg if -.b
173if ($cmdopts{stage} eq 'b') {
174 binpackage();
175}
176# -> srcpkg if -.s
177if ($cmdopts{stage} eq 's') {
178 srcpackage();
179}
180
181# Just in case.
182exit 0;
183
184
185## load_userconfig()
186# Loads user configuration (if any)
187# Currently only handles .debmacros
188# Needs to handle "other files"
189sub load_userconfig {
190 my (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
191 if (-e "$homedir/.debmacros") {
192 open USERMACROS,"<$homedir/.debmacros";
193 while (<USERMACROS>) {
194 # And we also only handle a few macros at the moment.
195 if (/^\%_topdir/) {
196 my (undef,$tmp) = split /\s+/, $_;
197 $topdir = $tmp;
198 }
199 }
200 }
201} # end load_userconfig()
202
203
204## parse_cmd()
205# Parses command line into global hash %cmdopts, other globals
206# Options based on rpmbuild's options
207sub parse_cmd {
208 # Don't feel like coding my own option parser...
209 #use Getopt::Long;
210 # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
211 #use Getopt::Popt qw(:all);
212 # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
213
214 # Stuff it.
215 my $prevopt = '';
216 foreach (@ARGV) {
217 chomp;
218
219 # Is it an option?
220 if (/^-/) {
221
222 # Is it a long option?
223 if (/^--/) {
224 if (/^--short-circuit/) {
225 $cmdopts{short} = 'y';
226 } elsif (/^--rebuild/) {
227 $cmdopts{type} = 's';
228 } else {
229 print "Long opt $_\n";
230 }
231 } else {
232 # Not a long option
233 if (/^-[bt]/) {
234 if ($cmdopts{stage} eq 's') {
235 # Mutually exclusive options.
236 die "Can't use $_ with --rebuild\n";
237 } else {
238 # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
239 ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
240 ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
241 }
242 } elsif (/^-v/) {
243 # bump verbosity. Not sure what I'll actually do here...
244 } else {
245 die "Bad option $_\n";
246 }
247 }
248
249 } else { # Not an option argument
250
251 # --buildroot is the only option that takes an argument
252 # Therefore, any *other* bare arguments are the spec file,
253 # tarball, or source package we're operating on - depending
254 # on which one we meet.
255 if ($prevopt eq '--buildroot') {
256 $cmdbuildroot = $_;
257 } else {
258 if ($cmdopts{type} eq 's') {
259 # Source package
260 if (!/\.src\.(deb|rpm)$/) {
261 die "Can't --rebuild with $_\n";
262 }
263 } elsif ($cmdopts{type} eq 'b') {
264 $specfile = $_;
265 # Spec file
266 } else {
267 # Tarball
268 }
269 }
270 }
271 $prevopt = $_;
272 } # foreach @ARGV
273
274 # Some cross-checks. rpmbuild limits --short-circuit to just
275 # the "compile" and "install" targets - with good reason IMO.
276 # Note that --short-circuit with -.p is not really an error, just redundant.
277 # NB - this is NOT fatal, just ignored!
278 if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
279 warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
280 $cmdopts{short} = 'n';
281 }
282
283 # Valid options, with example arguments (if any):
284# Build from .spec file; mutually exclusive:
285 # -bp
286 # -bc
287 # -bi
288 # -bl
289 # -ba
290 # -bb
291 # -bs
292# Build from tarball; mutually exclusive:
293 # -tp
294 # -tc
295 # -ti
296 # -ta
297 # -tb
298 # -ts
299# Build from .src.(deb|rpm)
300 # --rebuild
301 # --recompile
302
303# General options
304 # --buildroot=DIRECTORY
305 # --clean
306 # --nobuild
307 # --nodeps
308 # --nodirtokens
309 # --rmsource
310 # --rmspec
311 # --short-circuit
312 # --target=CPU-VENDOR-OS
313
314 #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
315
316} # end parse_cmd()
317
318
319## parse_spec()
320# Parse the .spec file.
321sub parse_spec {
322 open SPECFILE,"<$specfile";
323
324LINE: while (<SPECFILE>) {
325 next if /^#/; # Ignore comments...
326 next if /^\s+$/; # ... and blank lines.
327
328 if (/^\%/) {
329 # A macro that needs further processing.
330
331 if (/^\%description/) {
332 $pkgdata{main}{desc} .= $_;
333 while (<SPECFILE>) {
334 redo LINE if /^\%/;
335 $pkgdata{main}{desc} .= " $_";
336 }
337 }
338
339 if (/^\%prep/) {
340 # %prep section. May have %setup macro; may include %patch tags,
341 # may be just a bare shell script.
342
343 # This really should be local-ish, but we need just the filename for the source
344 $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
345
346 # Replace some core macros
347 $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
348
349PREPSCRIPT: while (<SPECFILE>) {
350 if (/^\%setup/) {
351 # Parse out the %setup macro. Note that we aren't supporting
352 # many of RPM's %setup features.
353 $prepscript .= "cd $topdir/BUILD\n";
354 if ( /\s+-n\s+([^\s]+)\s+/ ) {
355 $tarballdir = $1;
356 } else {
357 $tarballdir = "$pkgdata{main}{name}-$pkgdata{main}{version}";
358 }
359 $prepscript .= "rm -rf $tarballdir\ntar -xf".
360 ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
361 ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
362 ( /\s+-q\s+/ ? '' : 'vv' ).
363 " $topdir/SOURCES/$pkgdata{main}{source}\n".
364 qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
365 ( /\s+-n\s+([^\s]+)\s+/ ?
366 "cd $1\n" : "cd $pkgdata{main}{name}-$pkgdata{main}{version}\n" ).
367 qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
368 qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
369 qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
370 } elsif (/^\%patch([^:]+)\s+(.+)$/) {
371 $prepscript .= "patch $2 <$topdir/SOURCES/".$pkgdata{main}{"patch$1"}."\n";
372 } else {
373 last PREPSCRIPT if /^\%/;
374 $prepscript .= $_;
375 }
376 }
377 redo LINE;
378 }
379 if (/^\%build/) {
380 # %build. This is pretty much just a shell script. There
381 # *are* a few macros, but we're not going to deal with them yet.
382 $buildscript .= "cd $tarballdir\n";
383BUILDSCRIPT: while (<SPECFILE>) {
384 if (/^\%configure/) {
385 $buildscript .= expandmacros($_,'cgbp');
386 } elsif (/^\%\{(__)?make\}/) {
387 $buildscript .= expandmacros($_,'mgbp');
388 } else {
389 last BUILDSCRIPT if /^\%/;
390 $buildscript .= $_;
391 }
392 }
393 redo LINE;
394 }
395 if (/^\%install/) {
396 $installscript .= "cd $tarballdir\n";
397INSTALLSCRIPT: while (<SPECFILE>) {
398 if (/^\%makeinstall/) {
399 $installscript .= expandmacros($_,'igbp');
400 } else {
401 last INSTALLSCRIPT if /^\%/;
402 $installscript .= $_;
403 }
404 }
405 redo LINE;
406 }
407 if (/^\%clean/) {
408 while (<SPECFILE>) {
409 redo LINE if /^\%/;
410 $cleanscript .= $_;
411 }
412 $cleanscript = expandmacros($cleanscript,'gp');
413 }
414 # pre/post (un)install scripts
415 if (/^\%pre\b/) {
416 while (<SPECFILE>) {
417 redo LINE if /^\%/;
418 $preinstscript .= $_;
419 }
420 }
421 if (/^\%post\b/) {
422 while (<SPECFILE>) {
423 redo LINE if /^\%/;
424 $postinstscript .= $_;
425 }
426 }
427 if (/^\%preun\b/) {
428 while (<SPECFILE>) {
429 redo LINE if /^\%/;
430 $preuninstscript .= $_;
431 }
432 }
433 if (/^\%postun\b/) {
434 while (<SPECFILE>) {
435 redo LINE if /^\%/;
436 $postuninstscript .= $_;
437 }
438 }
439 if (/^\%files/) {
440 # Danger! Danger!
441 }
442 if (/^\%changelog/) {
443 $pkgdata{main}{changelog} = '';
444 while (<SPECFILE>) {
445 redo LINE if /^\%/;
446 $pkgdata{main}{changelog} .= $_;
447 }
448 }
449
450 } else { # Data from the spec file "header"
451
452 if (/^summary:\s+(.+)/i) {
453 $pkgdata{main}{summary} = $1;
454 } elsif (/^name:\s+(.+)/i) {
455 $pkgdata{main}{name} = $1;
456 } elsif (/^version:\s+(.+)/i) {
457 $pkgdata{main}{version} = $1;
458 } elsif (/^release:\s+(.+)/i) {
459 $pkgdata{main}{release} = $1;
460 } elsif (/^group:\s+(.+)/i) {
461 $pkgdata{main}{group} = $1;
462 } elsif (/^copyright:\s+(.+)/i) {
463 $pkgdata{main}{copyright} = $1;
464 } elsif (/^url:\s+(.+)/i) {
465 $pkgdata{main}{url} = $1;
466 } elsif (/^packager:\s+(.+)/i) {
467 $pkgdata{main}{packager} = $1;
468 } elsif (/^buildroot:\s+(.+)/i) {
469 $buildroot = $1;
470 } elsif (/^source:\s+(.+)/i) {
471 $pkgdata{main}{source} = $1;
472 die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
473 } elsif (/^source([0-9]+):\s+(.+)/i) {
474 $pkgdata{sources}{$1} = $2;
475 } elsif (/^patch([^:]+):\s+(.+)$/i) {
476 $pkgdata{main}{"patch$1"} = $2;
477 }
478#Name: suwrap
479#Version: 0.04
480#Release: 3
481#Group: Applications/System
482#Copyright: WebHart internal ONLY. :(
483#BuildArchitectures: i386
484#BuildRoot: /tmp/%{name}-%{version}
485#Url: http://virtual.webhart.net
486#Packager: Kris Deugau <kdeugau@deepnet.cx>
487#Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
488
489 }
490 }
491
492 # Parse and replace some more macros. More will be replaced even later.
493
494 # Expand macros as necessary.
495 $scriptletbase = expandmacros($scriptletbase,'gp');
496
497 $buildroot = $cmdbuildroot if $cmdbuildroot;
498 $buildroot = expandmacros($buildroot,'gp');
499
500 close SPECFILE;
501} # end parse_spec()
502
503
504## prep()
505# Writes and executes the %prep script (mostly) built while reading the spec file.
506sub prep {
507 # Replace some things here just to make sure.
508 $prepscript = expandmacros($prepscript,'gp');
509
510 # create script filename
511 my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
512 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
513 or die $!;
514 print PREPSCRIPT $scriptletbase;
515 print PREPSCRIPT $prepscript;
516 close PREPSCRIPT;
517
518 # execute
519 print "Calling \%prep script $prepscriptfile...\n";
520 system("/bin/sh -e $prepscriptfile") == 0
521 or die "Can't exec: $!\n";
522
523 # and clean up
524 unlink $prepscriptfile;
525} # end prep()
526
527
528## build()
529# Writes and executes the %build script (mostly) built while reading the spec file.
530sub build {
531 # Expand the macros
532 $buildscript = expandmacros($buildscript,'cgbp');
533
534 # create script filename
535 my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
536 sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
537 or die $!;
538 print BUILDSCRIPT $scriptletbase;
539 print BUILDSCRIPT $buildscript;
540 close BUILDSCRIPT;
541
542 # execute
543 print "Calling \%build script $buildscriptfile...\n";
544 system("/bin/sh -e $buildscriptfile") == 0
545 or die "Can't exec: $!\n";
546
547 # and clean up
548 unlink $buildscriptfile;
549} # end build()
550
551
552## install()
553# Writes and executes the %install script (mostly) built while reading the spec file.
554sub install {
555 # Expand the macros
556 $installscript = expandmacros($installscript,'igbp');
557
558 # create script filename
559 my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
560 sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
561 or die $!;
562 print INSTSCRIPT $scriptletbase;
563 print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it.
564 print INSTSCRIPT $installscript;
565 close INSTSCRIPT;
566
567 # execute
568 print "Calling \%install script $installscriptfile...\n";
569 system("/bin/sh -e $installscriptfile") == 0
570 or die "Can't exec: $!\n";
571
572 # and clean up
573 unlink $installscriptfile;
574} # end install()
575
576
577## binpackage()
578# Creates the binary .deb package from the installed tree in $buildroot.
579# Writes and executes a shell script to do so.
580# Creates miscellaneous files required by dpkg-deb to actually build the package file.
581sub binpackage {
582 # Make sure we have somewhere to write the .deb file
583 if (!-e "$topdir/DEBS/i386") {
584# "if [ -e $topdir/DEBS/i386 ]; then\n\tmkdir $topdir/DEBS/i386\nfi\n".
585 mkdir "$topdir/DEBS/i386";
586 }
587
588 # Gotta do this first, otherwise the control file has nowhere to go. >:(
589 mkdir "$buildroot/DEBIAN";
590
591 # create script filename
592 my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
593 sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
594 or die $!;
595 print DEBSCRIPT $scriptletbase;
596 print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot $topdir/DEBS/i386/".
597 "$pkgdata{main}{name}_$pkgdata{main}{version}-$pkgdata{main}{release}_i386.deb\n";
598 # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
599 close DEBSCRIPT;
600
601 my $control = "Package: $pkgdata{main}{name}\n".
602 "Version: $pkgdata{main}{version}-$pkgdata{main}{release}\n".
603 "Section: unknown\n".
604 "Priority: optional\n".
605 "Architecture: i386\n".
606 "Maintainer: $pkgdata{main}{packager}\n".
607 "Description: $pkgdata{main}{desc}\n";
608
609 open CONTROL, ">$buildroot/DEBIAN/control";
610 print CONTROL $control;
611 close CONTROL;
612
613 if ($preinstscript ne '') {
614 open PREINST, ">$buildroot/DEBIAN/preinst";
615 print PREINST "#!/bin/sh\nset -e\n\n";
616 print PREINST $preinstscript;
617 close PREINST;
618 `chmod 0755 $buildroot/DEBIAN/preinst`;
619 }
620 if ($postinstscript ne '') {
621 open POSTINST, ">$buildroot/DEBIAN/postinst";
622 print POSTINST "#!/bin/sh\nset -e\n\n";
623 print POSTINST $postinstscript;
624 close POSTINST;
625 `chmod 0755 $buildroot/DEBIAN/postinst`;
626 }
627 if ($preuninstscript ne '') {
628 open PREUNINST, ">$buildroot/DEBIAN/prerm";
629 print PREUNINST "#!/bin/sh\nset -e\n\n";
630 print PREUNINST $preuninstscript;
631 close PREUNINST;
632 `chmod 0755 $buildroot/DEBIAN/prerm`;
633 }
634 if ($postuninstscript ne '') {
635 open POSTUNINST, ">$buildroot/DEBIAN/postrm";
636 print POSTUNINST "#!/bin/sh\nset -e\n\n";
637 print POSTUNINST $postuninstscript;
638 close POSTUNINST;
639 `chmod 0755 $buildroot/DEBIAN/postrm`;
640 }
641
642print `ls -l $buildroot/DEBIAN`;
643
644#Package: httpd
645#Version: 2.0.54-7via
646#Section: unknown
647#Priority: optional
648#Architecture: i386
649#Depends: libc6 (>= 2.3.2.ds1-21), libdb4.2, libexpat1 (>= 1.95.8), libssl0.9.7, libapr0
650#Replaces: apache2
651#Installed-Size: 3076
652#Maintainer: Kris Deugau <kdeugau@vianet.ca>
653#Description: apache2 for ViaNet
654# apache2 for ViaNet. Includes per-vhost setuid patches from
655# http://home.samfundet.no/~sesse/mpm-itk/.
656
657 # execute
658 print "Calling package creation script $debscriptfile for $pkgdata{main}{name}...\n";
659 system("/bin/sh -e $debscriptfile") == 0
660 or die "Can't exec: $!\n";
661
662 # and clean up
663 unlink $debscriptfile;
664} # end binpackage()
665
666
667sub srcpackage {}
668
669
670## expandmacros()
671# Expands all %{blah} macros in the passed string
672# Split up a bit with some sections so we don't spend time trying to
673# expand macros that are only used in a few specific places.
674sub expandmacros {
675 my $macrostring = shift;
676 my $section = shift;
677
678 # To allow the FHS-ish %configure, %make, and %makeinstall to work The Right Way.
679 # (Without clobbering the global $buildroot.)
680 my $prefix = '';
681
682# %configure, %make, and %makeinstall all share quite a pile - almost. GRR.
683# I call it the FHS block, so it gets pushed forward as %{fhs}. Note that
684# %configure doesn't use this because of the -- bits.
685 if ($section =~ /c/) {
686 # %configure macro
687# Don't know what it's for, don't have a useful default replacement
688# --program-prefix=%{_program_prefix} \
689 $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
690 --build=$DEB_BUILD_GNU_TYPE \
691 --prefix=%{_prefix} \
692 --exec-prefix=%{_exec_prefix} \
693 --bindir=%{_bindir} \
694 --sbindir=%{_sbindir} \
695 --sysconfdir=%{_sysconfdir} \
696 --datadir=%{_datadir} \
697 --includedir=%{_includedir} \
698 --libdir=%{_libdir} \
699 --libexecdir=%{_libexecdir} \
700 --localstatedir=%{_localstatedir} \
701 --sharedstatedir=%{_sharedstatedir} \
702 --mandir=%{_mandir} \
703 --infodir=%{_infodir} ';
704 } # done %configure
705
706 if ($section =~ /m/) {
707 $macrostring =~ s'%make'make %{fhs}';
708 $macrostring =~ s'%{__make}'make ';
709 } # done %make
710
711 if ($section =~ /i/) {
712 # This is where we need to mangle $prefix.
713 $macrostring =~ s'%makeinstall'make %{fhs}
714 install';
715 $prefix = $buildroot;
716 } # done %install and/or %makeinstall
717
718 # Build data
719 # Note that these are processed in reverse order to get the substitution order right
720 if ($section =~ /b/) {
721 $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
722 build=$DEB_BUILD_GNU_TYPE \
723 prefix=%{_prefix} \
724 exec-prefix=%{_exec_prefix} \
725 bindir=%{_bindir} \
726 sbindir=%{_sbindir} \
727 sysconfdir=%{_sysconfdir} \
728 datadir=%{_datadir} \
729 includedir=%{_includedir} \
730 libdir=%{_libdir} \
731 libexecdir=%{_libexecdir} \
732 localstatedir=%{_localstatedir} \
733 sharedstatedir=%{_sharedstatedir} \
734 mandir=%{_mandir} \
735 infodir=%{_infodir} \
736';
737
738 # Note that the above regex terminates with the extra space
739 # "Just In Case" of user additions, which will then get neatly
740 # tagged on the end where they take precedence (supposedly)
741 # over the "default" ones.
742
743 # Now we cascade the macros introduced above. >_<
744 # Wot ot to go theah:
745 $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
746 $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
747 $macrostring =~ s|%{_oldincludedir}|$prefix/usr/include|g; #/usr/include
748 $macrostring =~ s|%{_includedir}|$prefix%{_prefix\}/include|g; #/usr/include
749 $macrostring =~ s|%{_libdir}|$prefix%{_exec_prefix}/%{_lib}|g; #/usr/lib
750 $macrostring =~ s|%{_lib}|lib|g; #?
751 $macrostring =~ s|%{_localstatedir}|$prefix/var|g; #/var
752 $macrostring =~ s|%{_sharedstatedir}|$prefix%{_prefix}/com|g; #/usr/com WTF?
753 $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g; #/etc
754 $macrostring =~ s|%{_datadir}|$prefix%{_prefix}/share|g; #/usr/share
755 $macrostring =~ s|%{_libexecdir}|$prefix%{_exec_prefix}/libexec|g; #/usr/libexec
756 $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g; #/usr/sbin
757 $macrostring =~ s|%{_bindir}|$prefix%{_exec_prefix}/bin|g; #/usr/bin
758 $macrostring =~ s|%{_exec_prefix}|$prefix%{_prefix}|g; #/usr
759 $macrostring =~ s|%{_prefix}|/usr|g; #/usr
760 } # done with config section
761
762 # Package data
763 if ($section =~ /p/) {
764 $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
765 foreach my $source (keys %{$pkgdata{sources}}) {
766 $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
767 }
768 $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
769 $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
770 $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
771 }
772
773 # Globals, and not-so-globals
774 if ($section =~ /g/) {
775 $macrostring =~ s/\%\{_topdir\}/$topdir/g;
776 $macrostring =~ s|%{_tmppath}|$tmpdir|g;
777 $macrostring =~ s'%{_docdir}'/usr/share/doc'g;
778 } # done with globals section
779
780 return $macrostring;
781} # end expandmacros()
Note: See TracBrowser for help on using the repository browser.