source: trunk/debbuild@ 26

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

/trunk

Tweak Patchnn:/%patch processing to strip URL path from patch filename

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