source: trunk/debbuild@ 17

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

/trunk

Tweak %configure/%make+%makeinstall "FHSification".

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 21.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-11 21:18:44 +0000 (Fri, 11 Nov 2005) $
9# SVN revision $Rev: 17 $
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 "x".( /\s+-q\s+/ ? '' : 'vv' )."f ".
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
417 } else { # Data from the spec file "header"
418
419 if (/^summary:\s+(.+)/i) {
420 $pkgdata{main}{summary} = $1;
421 } elsif (/^name:\s+(.+)/i) {
422 $pkgdata{main}{name} = $1;
423 } elsif (/^version:\s+(.+)/i) {
424 $pkgdata{main}{version} = $1;
425 } elsif (/^release:\s+(.+)/i) {
426 $pkgdata{main}{release} = $1;
427 } elsif (/^group:\s+(.+)/i) {
428 $pkgdata{main}{group} = $1;
429 } elsif (/^copyright:\s+(.+)/i) {
430 $pkgdata{main}{copyright} = $1;
431 } elsif (/^url:\s+(.+)/i) {
432 $pkgdata{main}{url} = $1;
433 } elsif (/^packager:\s+(.+)/i) {
434 $pkgdata{main}{packager} = $1;
435 } elsif (/^buildroot:\s+(.+)/i) {
436 $buildroot = $1;
437 } elsif (/^source:\s+(.+)/i) {
438 $pkgdata{main}{source} = $1;
439 die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
440 } elsif (/^source([0-9]+):\s+(.+)/i) {
441 $pkgdata{sources}{$1} = $2;
442 } elsif (/^patch([^:]+):\s+(.+)$/i) {
443 $pkgdata{main}{"patch$1"} = $2;
444 }
445#Name: suwrap
446#Version: 0.04
447#Release: 3
448#Group: Applications/System
449#Copyright: WebHart internal ONLY. :(
450#BuildArchitectures: i386
451#BuildRoot: /tmp/%{name}-%{version}
452#Url: http://virtual.webhart.net
453#Packager: Kris Deugau <kdeugau@deepnet.cx>
454#Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
455
456 }
457 }
458
459 # Parse and replace some more macros. More will be replaced even later.
460
461 # Expand macros as necessary.
462 $scriptletbase = expandmacros($scriptletbase,'gp');
463
464 $buildroot = $cmdbuildroot if $cmdbuildroot;
465 $buildroot = expandmacros($buildroot,'gp');
466
467 close SPECFILE;
468} # end parse_spec()
469
470
471## prep()
472# Writes and executes the %prep script (mostly) built while reading the spec file.
473sub prep {
474 # Replace some things here just to make sure.
475 $prepscript = expandmacros($prepscript,'gp');
476
477 # create script filename
478 my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
479 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
480 or die $!;
481 print PREPSCRIPT $scriptletbase;
482 print PREPSCRIPT $prepscript;
483 close PREPSCRIPT;
484
485 # execute
486 print "Calling \%prep script $prepscriptfile...\n";
487 system("/bin/sh -e $prepscriptfile") == 0
488 or die "Can't exec: $!\n";
489
490 # and clean up
491 unlink $prepscriptfile;
492} # end prep()
493
494
495## build()
496# Writes and executes the %build script (mostly) built while reading the spec file.
497sub build {
498 # Expand the macros
499 $buildscript = expandmacros($buildscript,'cgbp');
500
501 # create script filename
502 my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
503 sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
504 or die $!;
505 print BUILDSCRIPT $scriptletbase;
506 print BUILDSCRIPT $buildscript;
507 close BUILDSCRIPT;
508
509 # execute
510 print "Calling \%build script $buildscriptfile...\n";
511 system("/bin/sh -e $buildscriptfile") == 0
512 or die "Can't exec: $!\n";
513
514 # and clean up
515 unlink $buildscriptfile;
516} # end build()
517
518
519## install()
520# Writes and executes the %install script (mostly) built while reading the spec file.
521sub install {
522 # Expand the macros
523 $installscript = expandmacros($installscript,'igbp');
524
525 # create script filename
526 my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
527 sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
528 or die $!;
529 print INSTSCRIPT $scriptletbase;
530 print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it.
531 print INSTSCRIPT $installscript;
532 close INSTSCRIPT;
533
534 # execute
535 print "Calling \%install script $installscriptfile...\n";
536 system("/bin/sh -e $installscriptfile") == 0
537 or die "Can't exec: $!\n";
538
539 # and clean up
540 unlink $installscriptfile;
541} # end install()
542
543
544## binpackage()
545# Creates the binary .deb package from the installed tree in $buildroot.
546# Writes and executes a shell script to do so.
547# Creates miscellaneous files required by dpkg-deb to actually build the package file.
548sub binpackage {
549 # Make sure we have somewhere to write the .deb file
550 if (!-e "$topdir/DEBS/i386") {
551# "if [ -e $topdir/DEBS/i386 ]; then\n\tmkdir $topdir/DEBS/i386\nfi\n".
552 mkdir "$topdir/DEBS/i386";
553 }
554
555 # Gotta do this first, otherwise the control file has nowhere to go. >:(
556 mkdir "$buildroot/DEBIAN";
557
558 # create script filename
559 my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
560 sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
561 or die $!;
562 print DEBSCRIPT $scriptletbase;
563 print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot $topdir/DEBS/i386/".
564 "$pkgdata{main}{name}_$pkgdata{main}{version}-$pkgdata{main}{release}_i386.deb\n";
565 # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
566 close DEBSCRIPT;
567
568 my $control = "Package: $pkgdata{main}{name}\n".
569 "Version: $pkgdata{main}{version}-$pkgdata{main}{release}\n".
570 "Section: unknown\n".
571 "Priority: optional\n".
572 "Architecture: i386\n".
573 "Maintainer: $pkgdata{main}{packager}\n".
574 "Description: $pkgdata{main}{desc}\n";
575
576 open CONTROL, ">$buildroot/DEBIAN/control";
577 print CONTROL $control;
578 close CONTROL;
579
580 if ($preinstscript ne '') {
581 open PREINST, ">$buildroot/DEBIAN/preinst";
582 print PREINST "#!/bin/sh\nset -e\n\n";
583 print PREINST $preinstscript;
584 close PREINST;
585 `chmod 0755 $buildroot/DEBIAN/preinst`;
586 }
587 if ($postinstscript ne '') {
588 open POSTINST, ">$buildroot/DEBIAN/postinst";
589 print POSTINST "#!/bin/sh\nset -e\n\n";
590 print POSTINST $postinstscript;
591 close POSTINST;
592 `chmod 0755 $buildroot/DEBIAN/postinst`;
593 }
594 if ($preuninstscript ne '') {
595 open PREUNINST, ">$buildroot/DEBIAN/prerm";
596 print PREUNINST "#!/bin/sh\nset -e\n\n";
597 print PREUNINST $preuninstscript;
598 close PREUNINST;
599 `chmod 0755 $buildroot/DEBIAN/prerm`;
600 }
601 if ($postuninstscript ne '') {
602 open POSTUNINST, ">$buildroot/DEBIAN/postrm";
603 print POSTUNINST "#!/bin/sh\nset -e\n\n";
604 print POSTUNINST $postuninstscript;
605 close POSTUNINST;
606 `chmod 0755 $buildroot/DEBIAN/postrm`;
607 }
608
609print `ls -l $buildroot/DEBIAN`;
610
611#Package: httpd
612#Version: 2.0.54-7via
613#Section: unknown
614#Priority: optional
615#Architecture: i386
616#Depends: libc6 (>= 2.3.2.ds1-21), libdb4.2, libexpat1 (>= 1.95.8), libssl0.9.7, libapr0
617#Replaces: apache2
618#Installed-Size: 3076
619#Maintainer: Kris Deugau <kdeugau@vianet.ca>
620#Description: apache2 for ViaNet
621# apache2 for ViaNet. Includes per-vhost setuid patches from
622# http://home.samfundet.no/~sesse/mpm-itk/.
623
624 # execute
625 print "Calling package creation script $debscriptfile for $pkgdata{main}{name}...\n";
626 system("/bin/sh -e $debscriptfile") == 0
627 or die "Can't exec: $!\n";
628
629 # and clean up
630 unlink $debscriptfile;
631} # end binpackage()
632
633
634sub srcpackage {}
635
636
637## expandmacros()
638# Expands all %{blah} macros in the passed string
639# Split up a bit with some sections so we don't spend time trying to
640# expand macros that are only used in a few specific places.
641sub expandmacros {
642 my $macrostring = shift;
643 my $section = shift;
644
645 # To allow the FHS-ish %configure, %make, and %makeinstall to work The Right Way.
646 # (Without clobbering the global $buildroot.)
647 my $prefix = '';
648
649# %configure, %make, and %makeinstall all share quite a pile - almost. GRR.
650# I call it the FHS block, so it gets pushed forward as %{fhs}. Note that
651# %configure doesn't use this because of the -- bits.
652 if ($section =~ /c/) {
653 # %configure macro
654# Don't know what it's for, don't have a useful default replacement
655# --program-prefix=%{_program_prefix} \
656 $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
657 --build=$DEB_BUILD_GNU_TYPE \
658 --prefix=%{_prefix} \
659 --exec-prefix=%{_exec_prefix} \
660 --bindir=%{_bindir} \
661 --sbindir=%{_sbindir} \
662 --sysconfdir=%{_sysconfdir} \
663 --datadir=%{_datadir} \
664 --includedir=%{_includedir} \
665 --libdir=%{_libdir} \
666 --libexecdir=%{_libexecdir} \
667 --localstatedir=%{_localstatedir} \
668 --sharedstatedir=%{_sharedstatedir} \
669 --mandir=%{_mandir} \
670 --infodir=%{_infodir} ';
671 } # done %configure
672
673 if ($section =~ /m/) {
674 $macrostring =~ s'%make'make %{fhs}';
675 $macrostring =~ s'%{__make}'make ';
676 } # done %make
677
678 if ($section =~ /i/) {
679 # This is where we need to mangle $prefix.
680 $macrostring =~ s'%makeinstall'make %{fhs}
681 install';
682 $prefix = $buildroot;
683 } # done %install and/or %makeinstall
684
685 # Build data
686 # Note that these are processed in reverse order to get the substitution order right
687 if ($section =~ /b/) {
688 $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
689 build=$DEB_BUILD_GNU_TYPE \
690 prefix=%{_prefix} \
691 exec-prefix=%{_exec_prefix} \
692 bindir=%{_bindir} \
693 sbindir=%{_sbindir} \
694 sysconfdir=%{_sysconfdir} \
695 datadir=%{_datadir} \
696 includedir=%{_includedir} \
697 libdir=%{_libdir} \
698 libexecdir=%{_libexecdir} \
699 localstatedir=%{_localstatedir} \
700 sharedstatedir=%{_sharedstatedir} \
701 mandir=%{_mandir} \
702 infodir=%{_infodir} \
703';
704
705 # Note that the above regex terminates with the extra space
706 # "Just In Case" of user additions, which will then get neatly
707 # tagged on the end where they take precedence (supposedly)
708 # over the "default" ones.
709
710 # Now we cascade the macros introduced above. >_<
711 # Wot ot to go theah:
712 $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
713 $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
714 $macrostring =~ s|%{_oldincludedir}|$prefix/usr/include|g; #/usr/include
715 $macrostring =~ s|%{_includedir}|$prefix%{_prefix\}/include|g; #/usr/include
716 $macrostring =~ s|%{_libdir}|$prefix%{_exec_prefix}/%{_lib}|g; #/usr/lib
717 $macrostring =~ s|%{_lib}|lib|g; #?
718 $macrostring =~ s|%{_localstatedir}|$prefix/var|g; #/var
719 $macrostring =~ s|%{_sharedstatedir}|$prefix%{_prefix}/com|g; #/usr/com WTF?
720 $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g; #/etc
721 $macrostring =~ s|%{_datadir}|$prefix%{_prefix}/share|g; #/usr/share
722 $macrostring =~ s|%{_libexecdir}|$prefix%{_exec_prefix}/libexec|g; #/usr/libexec
723 $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g; #/usr/sbin
724 $macrostring =~ s|%{_bindir}|$prefix%{_exec_prefix}/bin|g; #/usr/bin
725 $macrostring =~ s|%{_exec_prefix}|$prefix%{_prefix}|g; #/usr
726 $macrostring =~ s|%{_prefix}|/usr|g; #/usr
727 } # done with config section
728
729 # Package data
730 if ($section =~ /p/) {
731 $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
732 foreach my $source (keys %{$pkgdata{sources}}) {
733 $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
734 }
735 $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
736 $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
737 $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
738 }
739
740 # Globals, and not-so-globals
741 if ($section =~ /g/) {
742 $macrostring =~ s/\%\{_topdir\}/$topdir/g;
743 $macrostring =~ s|%{_tmppath}|$tmpdir|g;
744 $macrostring =~ s'%{_docdir}'/usr/share/doc'g;
745 } # done with globals section
746
747 return $macrostring;
748} # end expandmacros()
Note: See TracBrowser for help on using the repository browser.