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
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-07 22:00:38 +0000 (Mon, 07 Nov 2005) $
9# SVN revision $Rev: 14 $
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 (/^patch([^:]+):\s+(.+)$/i) {
415 $pkgdata{main}{"patch$1"} = $2;
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 }
430
431 # Parse and replace some more macros. More will be replaced even later.
432
433 # Expand macros as necessary.
434 $scriptletbase = expandmacros($scriptletbase,'gp');
435
436 $buildroot = $cmdbuildroot if $cmdbuildroot;
437 $buildroot = expandmacros($buildroot,'gp');
438
439} # end parse_spec()
440
441
442## prep()
443# Writes and executes the %prep script (mostly) built while reading the spec file.
444sub prep {
445 # Replace some things here just to make sure.
446 $prepscript = expandmacros($prepscript,'gp');
447
448 # create script filename
449 my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
450 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
451 or die $!;
452 print PREPSCRIPT $scriptletbase;
453 print PREPSCRIPT $prepscript;
454 close PREPSCRIPT;
455
456 # execute
457 print "Calling \%prep script $prepscriptfile...\n";
458 system("/bin/sh -e $prepscriptfile") == 0
459 or die "Can't exec: $!\n";
460
461 # and clean up
462 unlink $prepscriptfile;
463} # end prep()
464
465
466## build()
467# Writes and executes the %build script (mostly) built while reading the spec file.
468sub build {
469 # Expand the macros
470 $buildscript = expandmacros($buildscript,'cgbp');
471
472 # create script filename
473 my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
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
483 or die "Can't exec: $!\n";
484
485 # and clean up
486 unlink $buildscriptfile;
487} # end build()
488
489
490## install()
491# Writes and executes the %install script (mostly) built while reading the spec file.
492sub install {
493 # Expand the macros
494 $installscript = expandmacros($installscript,'igbp');
495
496 # create script filename
497 my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
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
508 or die "Can't exec: $!\n";
509
510 # and clean up
511 unlink $installscriptfile;
512} # end install()
513
514
515## binpackage()
516# Creates the binary .deb package from the installed tree in $buildroot.
517# Writes and executes a shell script to do so.
518# Creates miscellaneous files required by dpkg-deb to actually build the package file.
519sub binpackage {
520 # Make sure we have somewhere to write the .deb file
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 }
525
526 # Gotta do this first, otherwise the control file has nowhere to go. >:(
527 mkdir "$buildroot/DEBIAN";
528
529 # create script filename
530 my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
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".
535 "fakeroot dpkg-deb -b $buildroot $topdir/DEBS/i386/$pkgdata{main}{name}_$pkgdata{main}{version}-$pkgdata{main}{release}_i386.deb\n";
536 # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
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
567 or die "Can't exec: $!\n";
568
569 # and clean up
570 unlink $debscriptfile;
571} # end binpackage()
572
573
574sub srcpackage {}
575
576
577## expandmacros()
578# Expands all %{blah} macros in the passed string
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.
581sub expandmacros {
582 my $macrostring = shift;
583 my $section = shift;
584
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}.
591 if ($section =~ /c/) {
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/) {
611# Don't know what it's for, don't have a useful default replacement
612# --program-prefix=%{_program_prefix} \
613 $macrostring =~ s'%{fhs}'--host=$DEB_HOST_GNU_TYPE \
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
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.
633
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
639 $macrostring =~ s|%{_includedir}|$prefix%{_prefix\}/include|g; #/usr/include
640 $macrostring =~ s|%{_libdir}|$prefix%{_exec_prefix}/%{_lib}|g; #/usr/lib
641 $macrostring =~ s|%{_lib}|lib|g; #?
642 $macrostring =~ s|%{_localstatedir}|$prefix/var|g; #/var
643 $macrostring =~ s|%{_sharedstatedir}|$prefix%{_prefix}/com|g; #/usr/com WTF?
644 $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g; #/etc
645 $macrostring =~ s|%{_datadir}|$prefix%{_prefix}/share|g; #/usr/share
646 $macrostring =~ s|%{_libexecdir}|$prefix%{_exec_prefix}/libexec|g; #/usr/libexec
647 $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g; #/usr/sbin
648 $macrostring =~ s|%{_bindir}|$prefix%{_exec_prefix}/bin|g; #/usr/bin
649 $macrostring =~ s|%{_exec_prefix}|$prefix%{_prefix}|g; #/usr
650 $macrostring =~ s|%{_prefix}|/usr|g; #/usr
651 } # done with config section
652
653 # Package data
654 if ($section =~ /p/) {
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;
660 }
661
662 # Globals, and not-so-globals
663 if ($section =~ /g/) {
664 $macrostring =~ s/\%\{_topdir\}/$topdir/g;
665 $macrostring =~ s|%{_tmppath}|$tmpdir|g;
666 $macrostring =~ s'%{_docdir}'/usr/share/doc'g;
667 } # done with globals section
668
669 return $macrostring;
670} # end expandmacros()
Note: See TracBrowser for help on using the repository browser.