source: trunk/debbuild@ 22

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

/trunk

Move POD to bottom

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