source: trunk/debbuild@ 15

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

/trunk

Checkpoint
Added more-or-less support for %{sourcenn} macro expansion

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 19.1 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-08 22:16:30 +0000 (Tue, 08 Nov 2005) $
9# SVN revision $Rev: 15 $
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
102die "Not enough arguments\n" if #$argv == 0;
103
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
112##main
113
114load_userconfig();
115parse_cmd();
116
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
123# Hokay. Need to:
124# -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
125if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
126 prep();
127}
128# -> build if -.c OR (-.[ilabs] AND !--short-circuit)
129if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
130 build();
131}
132# -> install if -.[ilabs]
133if ($cmdopts{stage} =~ /[ilabs]/) {
134 install();
135}
136# -> binpkg and srcpkg if -.a
137if ($cmdopts{stage} eq 'a') {
138 binpackage();
139 srcpackage();
140}
141# -> binpkg if -.b
142if ($cmdopts{stage} eq 'b') {
143 binpackage();
144}
145# -> srcpkg if -.s
146if ($cmdopts{stage} eq 's') {
147 srcpackage();
148}
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 {
159 my (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
160 if (-e "$homedir/.debmacros") {
161 open USERMACROS,"<$homedir/.debmacros";
162 while (<USERMACROS>) {
163 # And we also only handle a few macros at the moment.
164 if (/^\%_topdir/) {
165 my (undef,$tmp) = split /\s+/, $_;
166 $topdir = $tmp;
167 }
168 }
169 }
170} # end load_userconfig()
171
172
173## parse_cmd()
174# Parses command line into global hash %cmdopts, other globals
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);
181 # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
182
183 # Stuff it.
184 my $prevopt = '';
185 foreach (@ARGV) {
186 chomp;
187
188 # Is it an option?
189 if (/^-/) {
190
191 # Is it a long option?
192 if (/^--/) {
193 if (/^--short-circuit/) {
194 $cmdopts{short} = 'y';
195 } elsif (/^--rebuild/) {
196 $cmdopts{type} = 's';
197 } else {
198 print "Long opt $_\n";
199 }
200 } else {
201 # Not a long option
202 if (/^-[bt]/) {
203 if ($cmdopts{stage} eq 's') {
204 # Mutually exclusive options.
205 die "Can't use $_ with --rebuild\n";
206 } else {
207 # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
208 ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
209 ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
210 }
211 } elsif (/^-v/) {
212 # bump verbosity. Not sure what I'll actually do here...
213 } else {
214 die "Bad option $_\n";
215 }
216 }
217
218 } else { # Not an option argument
219
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') {
225 $cmdbuildroot = $_;
226 } else {
227 if ($cmdopts{type} eq 's') {
228 # Source package
229 if (!/\.src\.(deb|rpm)$/) {
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 }
239 }
240 $prevopt = $_;
241 } # foreach @ARGV
242
243 # Some cross-checks. rpmbuild limits --short-circuit to just
244 # the "compile" and "install" targets - with good reason IMO.
245 # Note that --short-circuit with -.p is not really an error, just redundant.
246 # NB - this is NOT fatal, just ignored!
247 if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
248 warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
249 $cmdopts{short} = 'n';
250 }
251
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
287
288## parse_spec()
289# Parse the .spec file.
290sub parse_spec {
291 open SPECFILE,"<$specfile";
292
293LINE: while (<SPECFILE>) {
294 next if /^#/; # Ignore comments...
295 next if /^\s+$/; # ... and blank lines.
296
297 if (/^\%/) {
298 # A macro that needs further processing.
299
300 if (/^\%description/) {
301 $pkgdata{main}{desc} .= $_;
302 while (<SPECFILE>) {
303 redo LINE if /^\%/;
304 $pkgdata{main}{desc} .= " $_";
305 }
306
307 }
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
316 $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
317
318PREPSCRIPT: while (<SPECFILE>) {
319 if (/^\%setup/) {
320 # Parse out the %setup macro. Note that we aren't supporting
321 # many of RPM's %setup features.
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 -".
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);
339 } elsif (/^\%patch([^:]+)\s+(.+)$/) {
340 $prepscript .= "patch $2 <$topdir/SOURCES/".$pkgdata{main}{"patch$1"}."\n";
341 } else {
342 last PREPSCRIPT if /^\%/;
343 $prepscript .= $_;
344 }
345 }
346 redo LINE;
347 }
348 if (/^\%build/) {
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.
351 $buildscript .= "cd $tarballdir\n";
352BUILDSCRIPT: while (<SPECFILE>) {
353 if (/^\%configure/) {
354 $buildscript .= expandmacros($_,'cgbp');
355 } elsif (/^\%\{(__)?make\}/) {
356 $buildscript .= expandmacros($_,'mgbp');
357 } else {
358 last BUILDSCRIPT if /^\%/;
359 $buildscript .= $_;
360 }
361 }
362 redo LINE;
363 }
364 if (/^\%install/) {
365 $installscript .= "cd $tarballdir\n";
366INSTALLSCRIPT: while (<SPECFILE>) {
367 if (/^\%makeinstall/) {
368 $installscript .= expandmacros($_,'igbp');
369 } else {
370 last INSTALLSCRIPT if /^\%/;
371 $installscript .= $_;
372 }
373 }
374 redo LINE;
375 }
376 if (/^\%clean/) {
377 while (<SPECFILE>) {
378 redo LINE if /^\%/;
379 $cleanscript .= $_;
380 }
381 $cleanscript = expandmacros($cleanscript,'gp');
382 }
383 if (/^\%post/) {
384 }
385 if (/^\%preun/) {
386 }
387 if (/^\%files/) {
388 # Danger! Danger!
389 }
390
391 } else { # Data from the spec file "header"
392
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;
409 } elsif (/^buildroot:\s+(.+)/i) {
410 $buildroot = $1;
411 } elsif (/^source:\s+(.+)/i) {
412 $pkgdata{main}{source} = $1;
413 die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
414 } elsif (/^source([0-9]+):\s+(.+)/i) {
415 $pkgdata{sources}{$1} = $2;
416 } elsif (/^patch([^:]+):\s+(.+)$/i) {
417 $pkgdata{main}{"patch$1"} = $2;
418 }
419#Name: suwrap
420#Version: 0.04
421#Release: 3
422#Group: Applications/System
423#Copyright: WebHart internal ONLY. :(
424#BuildArchitectures: i386
425#BuildRoot: /tmp/%{name}-%{version}
426#Url: http://virtual.webhart.net
427#Packager: Kris Deugau <kdeugau@deepnet.cx>
428#Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
429
430 }
431 }
432
433 # Parse and replace some more macros. More will be replaced even later.
434
435 # Expand macros as necessary.
436 $scriptletbase = expandmacros($scriptletbase,'gp');
437
438 $buildroot = $cmdbuildroot if $cmdbuildroot;
439 $buildroot = expandmacros($buildroot,'gp');
440
441} # end parse_spec()
442
443
444## prep()
445# Writes and executes the %prep script (mostly) built while reading the spec file.
446sub prep {
447 # Replace some things here just to make sure.
448 $prepscript = expandmacros($prepscript,'gp');
449
450 # create script filename
451 my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
452 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
453 or die $!;
454 print PREPSCRIPT $scriptletbase;
455 print PREPSCRIPT $prepscript;
456 close PREPSCRIPT;
457
458 # execute
459 print "Calling \%prep script $prepscriptfile...\n";
460 system("/bin/sh -e $prepscriptfile") == 0
461 or die "Can't exec: $!\n";
462
463 # and clean up
464 unlink $prepscriptfile;
465} # end prep()
466
467
468## build()
469# Writes and executes the %build script (mostly) built while reading the spec file.
470sub build {
471 # Expand the macros
472 $buildscript = expandmacros($buildscript,'cgbp');
473
474 # create script filename
475 my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
476 sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
477 or die $!;
478 print BUILDSCRIPT $scriptletbase;
479 print BUILDSCRIPT $buildscript;
480 close BUILDSCRIPT;
481
482 # execute
483 print "Calling \%build script $buildscriptfile...\n";
484 system("/bin/sh -e $buildscriptfile") == 0
485 or die "Can't exec: $!\n";
486
487 # and clean up
488 unlink $buildscriptfile;
489} # end build()
490
491
492## install()
493# Writes and executes the %install script (mostly) built while reading the spec file.
494sub install {
495 # Expand the macros
496 $installscript = expandmacros($installscript,'igbp');
497
498 # create script filename
499 my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
500 sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
501 or die $!;
502 print INSTSCRIPT $scriptletbase;
503 print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it.
504 print INSTSCRIPT $installscript;
505 close INSTSCRIPT;
506
507 # execute
508 print "Calling \%install script $installscriptfile...\n";
509 system("/bin/sh -e $installscriptfile") == 0
510 or die "Can't exec: $!\n";
511
512 # and clean up
513 unlink $installscriptfile;
514} # end install()
515
516
517## binpackage()
518# Creates the binary .deb package from the installed tree in $buildroot.
519# Writes and executes a shell script to do so.
520# Creates miscellaneous files required by dpkg-deb to actually build the package file.
521sub binpackage {
522 # Make sure we have somewhere to write the .deb file
523 if (!-e "$topdir/DEBS/i386") {
524# "if [ -e $topdir/DEBS/i386 ]; then\n\tmkdir $topdir/DEBS/i386\nfi\n".
525 mkdir "$topdir/DEBS/i386";
526 }
527
528 # Gotta do this first, otherwise the control file has nowhere to go. >:(
529 mkdir "$buildroot/DEBIAN";
530
531 # create script filename
532 my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
533 sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
534 or die $!;
535 print DEBSCRIPT $scriptletbase;
536 print DEBSCRIPT "tree $buildroot\n".
537 "fakeroot dpkg-deb -b $buildroot $topdir/DEBS/i386/$pkgdata{main}{name}_$pkgdata{main}{version}-$pkgdata{main}{release}_i386.deb\n";
538 # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
539 close DEBSCRIPT;
540
541 my $control = "Package: $pkgdata{main}{name}\n".
542 "Version: $pkgdata{main}{version}-$pkgdata{main}{release}\n".
543 "Section: unknown\n".
544 "Priority: optional\n".
545 "Architecture: i386\n".
546 "Maintainer: $pkgdata{main}{packager}\n".
547 "Description: $pkgdata{main}{desc}\n";
548
549 open CONTROL, ">$buildroot/DEBIAN/control";
550 print CONTROL $control;
551 close CONTROL;
552
553#Package: httpd
554#Version: 2.0.54-7via
555#Section: unknown
556#Priority: optional
557#Architecture: i386
558#Depends: libc6 (>= 2.3.2.ds1-21), libdb4.2, libexpat1 (>= 1.95.8), libssl0.9.7, libapr0
559#Replaces: apache2
560#Installed-Size: 3076
561#Maintainer: Kris Deugau <kdeugau@vianet.ca>
562#Description: apache2 for ViaNet
563# apache2 for ViaNet. Includes per-vhost setuid patches from
564# http://home.samfundet.no/~sesse/mpm-itk/.
565
566 # execute
567 print "Creating .deb for $pkgdata{main}{name}...\n";
568 system("/bin/sh -e $debscriptfile") == 0
569 or die "Can't exec: $!\n";
570
571 # and clean up
572 unlink $debscriptfile;
573} # end binpackage()
574
575
576sub srcpackage {}
577
578
579## expandmacros()
580# Expands all %{blah} macros in the passed string
581# Split up a bit with some sections so we don't spend time trying to
582# expand macros that are only used in a few specific places.
583sub expandmacros {
584 my $macrostring = shift;
585 my $section = shift;
586
587 # To allow the FHS-ish %configure, %make, and %makeinstall to work The Right Way.
588 # (Without clobbering the global $buildroot.)
589 my $prefix = '';
590
591# %configure, %make, and %makeinstall all share quite a pile.
592# I call it the FHS block, so it gets pushed forward as %{fhs}.
593 if ($section =~ /c/) {
594 # %configure macro
595 $macrostring =~ s'%configure'./configure %{fhs}';
596 } # done %configure
597
598 if ($section =~ /m/) {
599 $macrostring =~ s'%make'make %{fhs}';
600 $macrostring =~ s'%{__make}'make ';
601 } # done %make
602
603 if ($section =~ /i/) {
604 # This is where we need to mangle $prefix.
605 $macrostring =~ s'%makeinstall'make %{fhs}
606 install';
607 $prefix = $buildroot;
608 } # done %install and/or %makeinstall
609
610 # Build data
611 # Note that these are processed in reverse order to get the substitution order right
612 if ($section =~ /b/) {
613# Don't know what it's for, don't have a useful default replacement
614# --program-prefix=%{_program_prefix} \
615 $macrostring =~ s'%{fhs}'--host=$DEB_HOST_GNU_TYPE \
616 --build=$DEB_BUILD_GNU_TYPE \
617 --prefix=%{_prefix} \
618 --exec-prefix=%{_exec_prefix} \
619 --bindir=%{_bindir} \
620 --sbindir=%{_sbindir} \
621 --sysconfdir=%{_sysconfdir} \
622 --datadir=%{_datadir} \
623 --includedir=%{_includedir} \
624 --libdir=%{_libdir} \
625 --libexecdir=%{_libexecdir} \
626 --localstatedir=%{_localstatedir} \
627 --sharedstatedir=%{_sharedstatedir} \
628 --mandir=%{_mandir} \
629 --infodir=%{_infodir} ';
630
631 # Note that the above regex terminates with the extra space
632 # "Just In Case" of user additions, which will then get neatly
633 # tagged on the end where they take precedence (supposedly)
634 # over the "default" ones.
635
636 # Now we cascade the macros introduced above. >_<
637 # Wot ot to go theah:
638 $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
639 $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
640 $macrostring =~ s|%{_oldincludedir}|$prefix/usr/include|g; #/usr/include
641 $macrostring =~ s|%{_includedir}|$prefix%{_prefix\}/include|g; #/usr/include
642 $macrostring =~ s|%{_libdir}|$prefix%{_exec_prefix}/%{_lib}|g; #/usr/lib
643 $macrostring =~ s|%{_lib}|lib|g; #?
644 $macrostring =~ s|%{_localstatedir}|$prefix/var|g; #/var
645 $macrostring =~ s|%{_sharedstatedir}|$prefix%{_prefix}/com|g; #/usr/com WTF?
646 $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g; #/etc
647 $macrostring =~ s|%{_datadir}|$prefix%{_prefix}/share|g; #/usr/share
648 $macrostring =~ s|%{_libexecdir}|$prefix%{_exec_prefix}/libexec|g; #/usr/libexec
649 $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g; #/usr/sbin
650 $macrostring =~ s|%{_bindir}|$prefix%{_exec_prefix}/bin|g; #/usr/bin
651 $macrostring =~ s|%{_exec_prefix}|$prefix%{_prefix}|g; #/usr
652 $macrostring =~ s|%{_prefix}|/usr|g; #/usr
653 } # done with config section
654
655 # Package data
656 if ($section =~ /p/) {
657 $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
658 foreach my $source (keys %{$pkgdata{sources}}) {
659 $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
660 }
661 $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
662 $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
663 $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
664 }
665
666 # Globals, and not-so-globals
667 if ($section =~ /g/) {
668 $macrostring =~ s/\%\{_topdir\}/$topdir/g;
669 $macrostring =~ s|%{_tmppath}|$tmpdir|g;
670 $macrostring =~ s'%{_docdir}'/usr/share/doc'g;
671 } # done with globals section
672
673 return $macrostring;
674} # end expandmacros()
Note: See TracBrowser for help on using the repository browser.