source: trunk/debbuild@ 14

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

/trunk

Cleanup and commenting

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