source: trunk/debbuild@ 68

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

/trunk

Add expansion/rewriting of perl(Class::SubClass) dependencies.
This functionality will necessarily remain limited due to dpkg's
limited dependency system which has NO provision for something
like rpm's direct handling of perl(Class::SubClass) module
requirements.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 41.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: 2006-06-20 17:14:49 +0000 (Tue, 20 Jun 2006) $
9# SVN revision $Rev: 68 $
10# Last update by $Author: kdeugau $
11###
12# Copyright 2005,2006 Kris Deugau <kdeugau@deepnet.cx>
13#
14# This program is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License as published by
16# the Free Software Foundation; either version 2 of the License, or
17# (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
28use strict;
29use warnings;
30use Fcntl; # for sysopen flags
31use Cwd 'abs_path'; # for finding where files really are
32
33# regex debugger
34#use re "debug";
35
36# Program flow:
37# -> Parse/execute "system" config/macros (if any - should be rare)
38# -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
39# -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
40
41sub expandmacros;
42
43# User's prefs for dirs, environment, etc,etc,etc.
44# config file ~/.debmacros
45# Default ordered search paths for config/macros:
46# /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
47# /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
48# **NOTE: May be possible to (ab)use bits of debhelper
49
50# Build tree
51# default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
52
53# Globals
54my $specfile;
55my $tarball;
56my $srcpkg;
57my $cmdbuildroot;
58my $tarballdir; # This should really be initialized, but the coding makes it, um, ugly.
59my %specglobals; # For %define's in specfile, among other things.
60
61# Initialized globals
62my $verbosity = 0;
63my %cmdopts = (type => '',
64 stage => 'a',
65 short => 'n'
66 );
67my $topdir = "/usr/src/debian";
68my $buildroot = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
69
70# "Constants"
71my %targets = ('p' => 'Prep',
72 'c' => 'Compile',
73 'i' => 'Install',
74 'l' => 'Verify %files',
75 'a' => 'Build binary and source',
76 'b' => 'Build binary',
77 's' => 'Build source'
78 );
79my $scriptletbase =
80q(#!/bin/sh
81
82 RPM_SOURCE_DIR="%{_topdir}/SOURCES"
83 RPM_BUILD_DIR="%{_topdir}/BUILD"
84 RPM_OPT_FLAGS="-O2 -g -march=i386 -mcpu=i686"
85 RPM_ARCH="i386"
86 RPM_OS="linux"
87 export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
88 RPM_DOC_DIR="/usr/share/doc"
89 export RPM_DOC_DIR
90 RPM_PACKAGE_NAME="%{name}"
91 RPM_PACKAGE_VERSION="%{version}"
92 RPM_PACKAGE_RELEASE="%{release}"
93 export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
94 RPM_BUILD_ROOT="%{buildroot}"
95 export RPM_BUILD_ROOT
96);
97foreach (`dpkg-architecture`) {
98 s/=(.+)/="$1"/;
99 $scriptletbase .= " $_";
100}
101$scriptletbase .=
102q(
103 set -x
104 umask 022
105 cd %{_topdir}/BUILD
106);
107
108# Package data
109# This is the form of $pkgdata{pkgname}{meta}
110# meta includes Summary, Name, Version, Release, Group, Copyright,
111# Source, URL, Packager, BuildRoot, Description, BuildReq(uires),
112# Requires, Provides
113# 10/31/2005 Maybe this should be flatter? -kgd
114my %pkgdata;
115my @pkglist = ('main'); #sigh
116# Files listing. Embedding this in %pkgdata would be, um, messy.
117my %filelist;
118my $buildreq = '';
119
120# Scriptlets
121my $prepscript = '';
122my $buildscript = '';
123# %install doesn't need the full treatment from %clean; just an empty place to install to.
124# NB - rpm doesn't do this; is it really necessary?
125my $installscript = '[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT'."\n";
126my $cleanscript = '';
127# pre/post (un)install scripts. Note that these will likely barf as-is. :/
128my $preinstscript = '';
129my $postinstscript = '';
130my $preuninstscript = '';
131my $postuninstscript = '';
132
133die "Not enough arguments\n" if #$argv == 0;
134
135# Snag some environment data
136my $tmpdir;
137if (defined $ENV{TMP} && $ENV{TMP} =~ /^(\/var)?\/tmp$/) {
138 $tmpdir = $ENV{TMP};
139} else {
140 $tmpdir = "/var/tmp";
141}
142
143##main
144
145load_userconfig();
146parse_cmd();
147
148if ($cmdopts{install}) {
149 install_sdeb();
150 exit 0;
151}
152
153# Stick --rebuild handling in here - basically install_sdeb()
154# followed by tweaking options to run with -ba
155if ($cmdopts{type} eq 's') {
156 if ($srcpkg =~ /\.src\.rpm$/) {
157 my @srclist = qx { rpm -qlp $srcpkg };
158 foreach (@srclist) {
159 chomp;
160 $specfile = "$topdir/SPECS/$_" if /\.spec$/;
161 }
162 qx { rpm -i $srcpkg };
163 } else {
164 install_sdeb();
165 my @srclist = qx { pax < $srcpkg };
166 foreach (@srclist) {
167 chomp;
168 $specfile = "$topdir/$_" if /SPECS/;
169 }
170 }
171 $cmdopts{type} = 'b';
172 $cmdopts{stage} = 'a';
173}
174
175if ($cmdopts{type} eq 'b') {
176 # Need to read the spec file to find the tarball. Note that
177 # this also generates most of the shell script required.
178 parse_spec();
179 die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
180 if !checkbuildreq();
181}
182
183if ($cmdopts{type} eq 't') {
184 # Need to unpack the tarball to find the spec file. Sort of the inverse of -b above.
185 # zcat $tarball |tar -t |grep .spec
186 # collect some info about the tarball
187 $specfile = "$topdir/BUILD/". qx { zcat $tarball |tar -t |grep .spec\$ };
188 chomp $specfile;
189 my ($fileonly, $dirname) = ($tarball =~ /(([a-zA-Z0-9._-]+)\.tar\.(?:gz|bz2))$/);
190
191 $tarball = abs_path($tarball);
192 my $unpackcmd = "cd $topdir/BUILD; tar -".
193 ( $tarball =~ /\.tar\.gz$/ ? "z" : "" ).
194 ( $tarball =~ /\.tar\.bz2$/ ? "j" : "" ). "xf $tarball";
195 system "$unpackcmd";
196 system "cp $tarball $topdir/SOURCES/$fileonly";
197 system "cp $specfile $topdir/SPECS/";
198 parse_spec();
199 die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
200 if !checkbuildreq();
201}
202
203# -> srcpkg if -.s
204if ($cmdopts{stage} eq 's') {
205 srcpackage();
206 exit 0;
207}
208
209# Hokay. Need to:
210# -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
211if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
212 prep();
213}
214# -> build if -.c OR (-.[ilabs] AND !--short-circuit)
215if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
216 build();
217}
218# -> install if -.[ilabs]
219#if ($cmdopts{stage} eq 'i' || ($cmdopts{stage} =~ /[labs]/ && $cmdopts{short} ne 'y')) {
220if ($cmdopts{stage} =~ /[ilabs]/) {
221 install();
222#foreach my $pkg (@pkglist) {
223# print "files in $pkg:\n ".$filelist{$pkg}."\n";
224#}
225
226}
227# -> binpkg and srcpkg if -.a
228if ($cmdopts{stage} eq 'a') {
229 binpackage();
230 srcpackage();
231}
232# -> binpkg if -.b
233if ($cmdopts{stage} eq 'b') {
234 binpackage();
235}
236
237# Just in case.
238exit 0;
239
240
241## load_userconfig()
242# Loads user configuration (if any)
243# Currently only handles .debmacros
244# Needs to handle "other files"
245sub load_userconfig {
246 my (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
247 if (-e "$homedir/.debmacros") {
248 open USERMACROS,"<$homedir/.debmacros";
249 while (<USERMACROS>) {
250 # And we also only handle a few macros at the moment.
251 if (/^\%_topdir/) {
252 my (undef,$tmp) = split /\s+/, $_;
253 $topdir = $tmp;
254 }
255 }
256 }
257} # end load_userconfig()
258
259
260## parse_cmd()
261# Parses command line into global hash %cmdopts, other globals
262# Options based on rpmbuild's options
263sub parse_cmd {
264 # Don't feel like coding my own option parser...
265 #use Getopt::Long;
266 # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
267 #use Getopt::Popt qw(:all);
268 # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
269
270 # Stuff it.
271 my $prevopt = '';
272 foreach (@ARGV) {
273 chomp;
274
275 # Is it an option?
276 if (/^-/) {
277
278 # Is it a long option?
279 if (/^--/) {
280 if (/^--short-circuit/) {
281 $cmdopts{short} = 'y';
282 } elsif (/^--rebuild/) {
283 $cmdopts{type} = 's';
284 } else {
285 print "Long opt $_\n";
286 }
287 } else {
288 # Not a long option
289 if (/^-[bt]/) {
290 if ($cmdopts{stage} eq 's') {
291 # Mutually exclusive options.
292 die "Can't use $_ with --rebuild\n";
293 } else {
294 # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
295 ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
296 ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
297 }
298 } elsif (/^-v/) {
299 # bump verbosity. Not sure what I'll actually do here...
300 } elsif (/^-i/) {
301 $cmdopts{install} = 1;
302 $prevopt = '-i';
303 } else {
304 die "Bad option $_\n";
305 }
306 }
307
308 } else { # Not an option argument
309
310 # --buildroot is the only option that takes an argument
311 # Therefore, any *other* bare arguments are the spec file,
312 # tarball, or source package we're operating on - depending
313 # on which one we meet.
314 if ($prevopt eq '--buildroot') {
315 $cmdbuildroot = $_;
316 } elsif ($prevopt eq '-i') {
317 $srcpkg = $_;
318 } else {
319 if ($cmdopts{type} eq 's') {
320 # Source package
321 if (!/(sdeb|\.src\.rpm)$/) {
322 die "Can't --rebuild with $_\n";
323 }
324 $srcpkg = $_;
325 } elsif ($cmdopts{type} eq 'b') {
326 # Spec file
327 $specfile = $_;
328 } else {
329 # Tarball build. Need to extract tarball to find spec file. Whee.
330 $tarball = $_;
331 }
332 }
333 }
334 $prevopt = $_;
335 } # foreach @ARGV
336
337 # Some cross-checks. rpmbuild limits --short-circuit to just
338 # the "compile" and "install" targets - with good reason IMO.
339 # Note that --short-circuit with -.p is not really an error, just redundant.
340 # NB - this is NOT fatal, just ignored!
341 if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
342 warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
343 $cmdopts{short} = 'n';
344 }
345
346 # Valid options, with example arguments (if any):
347# Build from .spec file; mutually exclusive:
348 # -bp
349 # -bc
350 # -bi
351 # -bl
352 # -ba
353 # -bb
354 # -bs
355# Build from tarball; mutually exclusive:
356 # -tp
357 # -tc
358 # -ti
359 # -ta
360 # -tb
361 # -ts
362# Build from .src.(deb|rpm)
363 # --rebuild
364 # --recompile
365
366# General options
367 # --buildroot=DIRECTORY
368 # --clean
369 # --nobuild
370 # --nodeps
371 # --nodirtokens
372 # --rmsource
373 # --rmspec
374 # --short-circuit
375 # --target=CPU-VENDOR-OS
376
377 #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
378
379} # end parse_cmd()
380
381
382## parse_spec()
383# Parse the .spec file.
384sub parse_spec {
385 open SPECFILE,"<$specfile" or die "specfile ($specfile) barfed: $!";
386
387LINE: while (<SPECFILE>) {
388 next if /^#/; # Ignore comments...
389 next if /^\s+$/; # ... and blank lines.
390
391 if (/^\%/) {
392 # A macro that needs further processing.
393
394 if (my ($key, $def) = (/^\%define\s+([^\s]+)\s+(.+)$/) ) {
395 $specglobals{$key} = expandmacros($def,'g');
396 }
397
398 if (/^\%description(?:\s+(?:-n\s+)?(.+))?/) {
399 my $subname = "main";
400 if ($1) {
401 my $tmp = expandmacros("$1", 'g');
402 if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
403 }
404 while (<SPECFILE>) {
405 next if /^#/; # Messy. Should be possible to do better. :/
406 redo LINE if /^\%/;
407 $pkgdata{$subname}{desc} .= " $_";
408 }
409 }
410 if (/^\%package\s+(?:-n\s+)?(.+)/) {
411 # gotta expand %defines here. Whee.
412 my $subname = expandmacros("$1", 'g');
413 if (! /-n/) { $subname = "$pkgdata{main}{name}-$1"; }
414 push @pkglist, $subname;
415 $pkgdata{$subname}{name} = $subname;
416 $pkgdata{$subname}{version} = $pkgdata{main}{version};
417 while (<SPECFILE>) {
418 redo LINE if /^\%/;
419 if (my ($dname,$dvalue) = (/^(Summary|Group|Version|Requires|Provides):\s+(.+)$/i)) {
420 $dname =~ tr/[A-Z]/[a-z]/;
421 $pkgdata{$subname}{$dname} = expandmacros($dvalue, 'gp');
422 }
423 }
424 }
425
426 if (/^\%prep/) {
427 # %prep section. May have %setup macro; may include %patch tags,
428 # may be just a bare shell script.
429
430 # This really should be local-ish, but we need just the filename for the source
431 $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
432
433 # Replace some core macros
434 $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
435
436PREPSCRIPT: while (<SPECFILE>) {
437 if (/^\%setup/) {
438 # Parse out the %setup macro. Note that we aren't supporting
439 # many of RPM's %setup features.
440 $prepscript .= "cd $topdir/BUILD\n";
441 if ( /\s+-n\s+([^\s]+)\s+/ ) {
442 $tarballdir = $1;
443 } else {
444 $tarballdir = "$pkgdata{main}{name}-$pkgdata{main}{version}";
445 }
446 $prepscript .= "rm -rf $tarballdir\ntar -".
447 ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
448 ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
449 ( /\s+-q\s+/ ? '' : 'vv' )."xf ".
450 "$topdir/SOURCES/$pkgdata{main}{source}\n".
451 qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
452 ( /\s+-n\s+([^\s]+)\s+/ ?
453 "cd $1\n" : "cd $pkgdata{main}{name}-$pkgdata{main}{version}\n" ).
454 qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
455 qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
456 qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
457 } elsif ( my ($patchnum,$patchopts) = (/^\%patch([^\s]+)(\s+.+)?$/) ) {
458 chomp $patchnum;
459 $prepscript .= "patch ";
460 $prepscript .= $patchopts if $patchopts;
461 $prepscript .= " <$topdir/SOURCES/".$pkgdata{main}{"patch$patchnum"}."\n";
462 } else {
463 last PREPSCRIPT if /^\%/;
464 $prepscript .= $_;
465 }
466 }
467 redo LINE;
468 }
469 if (/^\%build/) {
470 # %build. This is pretty much just a shell script. There
471 # *are* a few macros, but we're not going to deal with them yet.
472 $buildscript .= "cd $tarballdir\n";
473BUILDSCRIPT: while (<SPECFILE>) {
474 if (/^\%configure/) {
475 $buildscript .= expandmacros($_,'cgbp');
476 } elsif (/^\%\{__make\}/) {
477 $buildscript .= expandmacros($_,'mgbp');
478 } else {
479 last BUILDSCRIPT if /^\%[^{]/;
480 $buildscript .= $_;
481 }
482 }
483 redo LINE;
484 }
485 if (/^\%install/) {
486 $installscript .= "cd $tarballdir\n";
487INSTALLSCRIPT: while (<SPECFILE>) {
488 if (/^\%makeinstall/) {
489 $installscript .= expandmacros($_,'igbp');
490 } else {
491 last INSTALLSCRIPT if /^\%/;
492 $installscript .= $_;
493 }
494 }
495 redo LINE;
496 }
497 if (/^\%clean/) {
498 while (<SPECFILE>) {
499 redo LINE if /^\%/;
500 $cleanscript .= $_;
501 }
502 $cleanscript = expandmacros($cleanscript,'gp');
503 }
504
505 # pre/post (un)install scripts
506 if (/^\%pre\b/) {
507 while (<SPECFILE>) {
508 redo LINE if /^\%/;
509 $preinstscript .= $_;
510 }
511 }
512 if (/^\%post\b/) {
513 while (<SPECFILE>) {
514 redo LINE if /^\%/;
515 $postinstscript .= $_;
516 }
517 }
518 if (/^\%preun\b/) {
519 while (<SPECFILE>) {
520 redo LINE if /^\%/;
521 $preuninstscript .= $_;
522 }
523 }
524 if (/^\%postun\b/) {
525 while (<SPECFILE>) {
526 redo LINE if /^\%/;
527 $postuninstscript .= $_;
528 }
529 }
530 # done %pre/%post scripts
531
532 if (/^\%files(?:\s+(?:-n\s+)?(.+))?/) {
533 my $pkgname = 'main';
534 if ($1) { # Magic to add entries to the right list of files
535 my $tmp = expandmacros("$1", 'g');
536 if (/-n/) { $pkgname = $tmp; } else { $pkgname = "$pkgdata{main}{name}-$tmp"; }
537 }
538
539 # Set this now, so it can be flipped a bit later, and used much later.
540 #$pkgdata{$pkgname}{conffiles} = 0;
541
542 while (<SPECFILE>) {
543 chomp;
544 next if /^#/;
545 # need to update this to deal (properly) with %dir, %attr, etc
546 next if /^\%dir/;
547 next if /^\%attr/;
548 next if /^\%defattr/;
549
550 # Debian dpkg doesn't speak "%docdir". Meh.
551 next if /^\%docdir/;
552
553 # Conffiles. Note that Debian and RH have similar, but not
554 # *quite* identical ideas of what constitutes a conffile. Nrgh.
555 if (/^\%config\s+(.+)$/) {
556 $pkgdata{$pkgname}{conffiles} = 1; # Flag it for later
557 my $tmp = $1; # Now we can mangleificationate it. And we probably need to. :/
558 $tmp = expandmacros($tmp, 'gp'); # Expand common macros
559 if ($tmp !~ /\s+/) {
560 # Simplest case, just a file. Whew.
561 push @{$pkgdata{$pkgname}{conflist}}, $tmp;
562 $filelist{$pkgname} .= " $tmp";
563 } else {
564 # Wot? Spaces? That means extra %-macros. Which, for the most part, can be ignored.
565 ($tmp) = ($tmp =~ /.+\s([^\s]+)/); # Strip everything before the last space
566 push @{$pkgdata{$pkgname}{conflist}}, $tmp;
567 $filelist{$pkgname} .= " $tmp";
568 }
569 next;
570 }
571
572 # and finally we can fall through %{_<FHS>}-prefixed locations...
573 if (/^\%\{_/) {
574 $filelist{$pkgname} .= " $_";
575 next;
576 }
577 # EW. Necessary to clear up %define expansions before we exit with redo.
578 $_ = expandmacros $_, 'g';
579
580 # ... unknown or "next section" % directives ...
581 redo LINE if /^\%/;
582
583 # ... and "normal" files
584 $filelist{$pkgname} .= " $_";
585 }
586 $filelist{$pkgname} = expandmacros($filelist{$pkgname}, 'gp');
587 } # done %file section
588
589 if (/^\%changelog/) {
590 $pkgdata{main}{changelog} = '';
591 while (<SPECFILE>) {
592 redo LINE if /^\%/;
593 $pkgdata{main}{changelog} .= $_;
594 }
595 }
596
597 } else { # Data from the spec file "header"
598
599 if (/^summary:\s+(.+)/i) {
600 $pkgdata{main}{summary} = $1;
601 } elsif (/^name:\s+(.+)/i) {
602 $pkgdata{main}{name} = expandmacros($1,'g');
603 } elsif (/^version:\s+(.+)/i) {
604 $pkgdata{main}{version} = expandmacros($1,'g');
605 } elsif (/^release:\s+(.+)/i) {
606 $pkgdata{main}{release} = expandmacros($1,'g');
607 } elsif (/^group:\s+(.+)/i) {
608 $pkgdata{main}{group} = $1;
609 } elsif (/^copyright:\s+(.+)/i) {
610 $pkgdata{main}{copyright} = $1;
611 } elsif (/^url:\s+(.+)/i) {
612 $pkgdata{main}{url} = $1;
613 } elsif (/^packager:\s+(.+)/i) {
614 $pkgdata{main}{packager} = $1;
615 } elsif (/^buildroot:\s+(.+)/i) {
616 $buildroot = $1;
617 } elsif (/^source0?:\s+(.+)/i) {
618 $pkgdata{main}{source} = $1;
619 die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
620 } elsif (/^source([0-9]+):\s+(.+)/i) {
621 $pkgdata{sources}{$1} = $2;
622 } elsif (/^patch([^:]+):\s+(.+)$/i) {
623 my $patchname = "patch$1";
624 $pkgdata{main}{$patchname} = $2;
625 if ($pkgdata{main}{$patchname} =~ /\//) {
626 # URL-style patch. Rare but not unheard-of.
627 my @patchbits = split '/', $pkgdata{main}{$patchname};
628 $pkgdata{main}{$patchname} = $patchbits[$#patchbits];
629 }
630 chomp $pkgdata{main}{$patchname};
631 } elsif (/^buildreq(?:uires)?:\s+(.+)/i) {
632 $buildreq .= ", $1";
633 } elsif (/^requires:\s+(.+)/i) {
634 $pkgdata{main}{requires} .= ", ".expandmacros("$1", 'gp');
635 } elsif (/^provides:\s+(.+)/i) {
636 $pkgdata{main}{provides} .= ", $1";
637 } elsif (/^conflicts:\s+(.+)/i) {
638 $pkgdata{main}{conflicts} .= ", $1";
639 }
640#Name: suwrap
641#Version: 0.04
642#Release: 3
643#Group: Applications/System
644#Copyright: WebHart internal ONLY. :(
645#BuildArchitectures: i386
646#BuildRoot: /tmp/%{name}-%{version}
647#Url: http://virtual.webhart.net
648#Packager: Kris Deugau <kdeugau@deepnet.cx>
649#Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
650
651 }
652 }
653
654 # Parse and replace some more macros. More will be replaced even later.
655
656 # Expand macros as necessary.
657 $scriptletbase = expandmacros($scriptletbase,'gp');
658
659 $buildroot = $cmdbuildroot if $cmdbuildroot;
660 $buildroot = expandmacros($buildroot,'gp');
661
662 close SPECFILE;
663} # end parse_spec()
664
665
666## prep()
667# Writes and executes the %prep script (mostly) built while reading the spec file.
668sub prep {
669 # Replace some things here just to make sure.
670 $prepscript = expandmacros($prepscript,'gp');
671
672#print $prepscript; exit 0;
673
674 # create script filename
675 my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
676 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
677 or die $!;
678 print PREPSCRIPT $scriptletbase;
679 print PREPSCRIPT $prepscript;
680 close PREPSCRIPT;
681
682 # execute
683 print "Calling \%prep script $prepscriptfile...\n";
684 system("/bin/sh -e $prepscriptfile") == 0
685 or die "Can't exec: $!\n";
686
687 # and clean up
688 unlink $prepscriptfile;
689} # end prep()
690
691
692## build()
693# Writes and executes the %build script (mostly) built while reading the spec file.
694sub build {
695 # Expand the macros
696 $buildscript = expandmacros($buildscript,'cgbp');
697
698 # create script filename
699 my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
700 sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
701 or die $!;
702 print BUILDSCRIPT $scriptletbase;
703 print BUILDSCRIPT $buildscript;
704 close BUILDSCRIPT;
705
706 # execute
707 print "Calling \%build script $buildscriptfile...\n";
708 system("/bin/sh -e $buildscriptfile") == 0
709 or die "Can't exec: $!\n";
710
711 # and clean up
712 unlink $buildscriptfile;
713} # end build()
714
715
716## install()
717# Writes and executes the %install script (mostly) built while reading the spec file.
718sub install {
719 # Expand the macros
720 $installscript = expandmacros($installscript,'igbp');
721
722 # create script filename
723 my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
724 sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
725 or die $!;
726 print INSTSCRIPT $scriptletbase;
727# print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it.
728 print INSTSCRIPT $installscript;
729 close INSTSCRIPT;
730
731 # execute
732 print "Calling \%install script $installscriptfile...\n";
733 system("/bin/sh -e $installscriptfile") == 0
734 or die "Can't exec: $!\n";
735
736 # and clean up
737 unlink $installscriptfile;
738} # end install()
739
740
741## binpackage()
742# Creates the binary .deb package from the installed tree in $buildroot.
743# Writes and executes a shell script to do so.
744# Creates miscellaneous files required by dpkg-deb to actually build the package file.
745# Should handle simple subpackages
746sub binpackage {
747 # Make sure we have somewhere to write the .deb file
748 if (!-e "$topdir/DEBS/i386") {
749 mkdir "$topdir/DEBS/i386";
750 }
751
752 foreach my $pkg (@pkglist) {
753
754 # Gotta do this first, otherwise we don't have a place to move files from %files
755 mkdir "$buildroot/$pkg";
756
757 # Eliminate any lingering % macros
758 $filelist{$pkg} = expandmacros $filelist{$pkg}, 'g';
759
760 my @pkgfilelist = split ' ', $filelist{$pkg};
761 foreach my $pkgfile (@pkgfilelist) {
762 $pkgfile = expandmacros($pkgfile, 'gp');
763 my ($fpath,$fname) = ($pkgfile =~ m|(.+?/?)?([^/]+)$|); # We don't need $fname now, but we might.
764 qx { mkdir -p $buildroot/$pkg$fpath }
765 if $fpath && $fpath ne '';
766 qx { mv $buildroot$pkgfile $buildroot/$pkg$fpath };
767 }
768
769 # Get the "Depends" (Requires) a la RPM. Ish. We strip the leading
770 # comma and space here (if needed) in case there were "Requires" specified
771 # in the spec file - those would precede these.
772 $pkgdata{$pkg}{requires} .= getreqs("$buildroot/$pkg");
773
774 # magic needed to properly version dependencies...
775 # only provided deps will really be included
776 $pkgdata{$pkg}{requires} =~ s/^, //; # Still have to do this here.
777 $pkgdata{$pkg}{requires} =~ s/\s+//g;
778 my @deps = split /,/, $pkgdata{$pkg}{requires};
779 my $tmp = '';
780 foreach my $dep (@deps) {
781 # Hack up the perl(Class::SubClass) deps into something dpkg can understand.
782 # May or may not be versioned.
783 # We do this first so the version rewriter can do its magic next.
784 if (my ($mod,$ver) = ($dep =~ /^perl\(([A-Za-z0-9\:\-]+)\)([><=]+.+)?/) ) {
785 $mod =~ s/^perl\(//;
786 $mod =~ s/\)$//;
787 $mod =~ s/::/-/g;
788 $mod =~ tr/A-Z/a-z/;
789 $mod = "lib$mod-perl";
790 $mod .= $ver if $ver;
791 $dep = $mod;
792 }
793 if (my ($name,$rel,$value) = ($dep =~ /^([a-zA-Z0-9._-]+)([><=]+)([a-zA-Z0-9._-]+)$/)) {
794 $tmp .= ", $name ($rel $value)";
795 } else {
796 $tmp .= ", $dep";
797 }
798 }
799 ($pkgdata{$pkg}{requires} = $tmp) =~ s/^, //;
800
801 # Do this here since we're doing {depends}...
802 if (defined($pkgdata{$pkg}{provides})) {
803 $pkgdata{$pkg}{provides} =~ s/^, //;
804 $pkgdata{$pkg}{provides} = expandmacros($pkgdata{$pkg}{provides},'gp');
805 }
806 if (defined($pkgdata{$pkg}{conflicts})) {
807 $pkgdata{$pkg}{conflicts} =~ s/^, //;
808 $pkgdata{$pkg}{conflicts} = expandmacros($pkgdata{$pkg}{conflicts},'gp');
809 }
810
811 # Gotta do this next, otherwise the control file has nowhere to go. >:(
812 mkdir "$buildroot/$pkg/DEBIAN";
813
814 # Hack the filename for the package into a Debian-tool-compatible format. GRRRRRR!!!!!
815 # Have I mentioned I hate Debian Policy?
816 $pkgdata{$pkg}{name} =~ tr/_/-/;
817
818 # create script filename
819 my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
820 sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
821 or die $!;
822 print DEBSCRIPT $scriptletbase;
823 print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot/$pkg $topdir/DEBS/i386/".
824 "$pkgdata{$pkg}{name}_$pkgdata{$pkg}{version}-$pkgdata{main}{release}_i386.deb\n";
825 # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
826 close DEBSCRIPT;
827
828 my $control = "Package: $pkgdata{$pkg}{name}\n".
829 "Version: $pkgdata{$pkg}{version}-$pkgdata{main}{release}\n".
830 "Section: $pkgdata{$pkg}{group}\n".
831 "Priority: optional\n".
832 "Architecture: i386\n".
833 "Maintainer: $pkgdata{main}{packager}\n".
834 ( $pkgdata{$pkg}{requires} ne '' ? "Depends: $pkgdata{$pkg}{requires}\n" : '' ).
835 ( defined($pkgdata{$pkg}{provides}) ? "Provides: $pkgdata{$pkg}{provides}\n" : '' ).
836 ( defined($pkgdata{$pkg}{conflicts}) ? "Conflicts: $pkgdata{$pkg}{conflicts}\n" : '' ).
837 "Description: $pkgdata{$pkg}{summary}\n";
838 $control .= "$pkgdata{$pkg}{desc}\n";
839
840 open CONTROL, ">$buildroot/$pkg/DEBIAN/control";
841 print CONTROL $control;
842 close CONTROL;
843
844 # Iff there are conffiles (as specified in the %files list(s), add'em
845 # in so dpkg-deb can tag them.
846 if ($pkgdata{$pkg}{conffiles}) {
847 open CONFLIST, ">$buildroot/$pkg/DEBIAN/conffiles";
848 foreach my $conffile (@{$pkgdata{$pkg}{conflist}}) {
849 print CONFLIST "$conffile\n";
850 }
851 close CONFLIST;
852 }
853
854 # Can't see much point in scripts on subpackages... although since
855 # it's *possible* I should support it at some point.
856 if ($pkg eq 'main') {
857 if ($preinstscript ne '') {
858 $preinstscript = expandmacros($preinstscript,'g');
859 open PREINST, ">$buildroot/$pkg/DEBIAN/preinst";
860 print PREINST "#!/bin/sh\nset -e\n\n";
861 print PREINST $preinstscript;
862 close PREINST;
863 `chmod 0755 $buildroot/$pkg/DEBIAN/preinst`;
864 }
865 if ($postinstscript ne '') {
866 $postinstscript = expandmacros($postinstscript,'g');
867 open POSTINST, ">$buildroot/$pkg/DEBIAN/postinst";
868 print POSTINST "#!/bin/sh\nset -e\n\n";
869 print POSTINST $postinstscript;
870 close POSTINST;
871 `chmod 0755 $buildroot/$pkg/DEBIAN/postinst`;
872 }
873 if ($preuninstscript ne '') {
874 $preuninstscript = expandmacros($preuninstscript,'g');
875 open PREUNINST, ">$buildroot/$pkg/DEBIAN/prerm";
876 print PREUNINST "#!/bin/sh\nset -e\n\n";
877 print PREUNINST $preuninstscript;
878 close PREUNINST;
879 `chmod 0755 $buildroot/$pkg/DEBIAN/prerm`;
880 }
881 if ($postuninstscript ne '') {
882 $postuninstscript = expandmacros($postuninstscript,'g');
883 open POSTUNINST, ">$buildroot/$pkg/DEBIAN/postrm";
884 print POSTUNINST "#!/bin/sh\nset -e\n\n";
885 print POSTUNINST $postuninstscript;
886 close POSTUNINST;
887 `chmod 0755 $buildroot/$pkg/DEBIAN/postrm`;
888 }
889 }
890
891 # execute
892 print "Calling package creation script $debscriptfile for $pkgdata{$pkg}{name}...\n";
893 system("/bin/sh -e $debscriptfile") == 0
894 or die "Can't exec: $!\n";
895
896 # and clean up
897 unlink $debscriptfile;
898
899 } # subpackage loop
900
901} # end binpackage()
902
903
904## srcpackage()
905# Builds a .src.deb source package. Note that Debian's idea of
906# a "source package" is seriously flawed IMO, because you can't
907# easily copy it as-is.
908# Not quite identical to RPM, but Good Enough (TM).
909sub srcpackage {
910 # In case we were called with -bs.
911 $pkgdata{main}{name} =~ tr/_/-/;
912 my $pkgsrcname = "$pkgdata{main}{name}-$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb";
913
914 my $paxcmd;
915
916 # We'll definitely need this later, and *may* need it sooner.
917 (my $barespec = $specfile) =~ s|.+/([^/]+)$|$1|;
918
919 # Copy the specfile to the build tree, but only if it's not there already.
920##buglet: need to deal with silly case where silly user has put the spec
921# file in a subdir of %{_topdir}/SPECS. Ewww. Silly user!
922 if (abs_path($specfile) !~ /^$topdir\/SPECS/) {
923 $paxcmd .= "cp $specfile %{_topdir}/SPECS/; \n"
924 }
925
926 # use pax -w [file] [file] ... >outfile.sdeb
927 $paxcmd = "cd $topdir; pax -w ";
928
929# tweak source entry into usable form. Need it locally somewhere along the line.
930 (my $pkgsrc = $pkgdata{main}{source}) =~ s|.+/([^/]+)$|$1|;
931 $paxcmd .= "SOURCES/$pkgsrc ";
932
933 # create file list: Source[nn], Patch[nn]
934 foreach my $specbit (keys %{$pkgdata{main}} ) {
935 next if $specbit eq 'source';
936 $paxcmd .= "SOURCES/$pkgdata{main}{$specbit} " if $specbit =~ /^patch/;
937##buglet: need to deal with case where patches are listed as URLs?
938# or other extended pathnames? Silly !@$%^&!%%!%!! user!
939 }
940
941 foreach my $source (keys %{$pkgdata{sources}}) {
942 $paxcmd .= "SOURCES/$pkgdata{sources}{$source} ";
943 }
944
945 # add the spec file, source package destination, and cd back where we came from.
946 $paxcmd .= "SPECS/$barespec > $topdir/SDEBS/$pkgsrcname; cd -";
947
948 # In case of %-macros...
949 $paxcmd = expandmacros($paxcmd,'gp');
950
951 system "$paxcmd";
952 print "Wrote source package $pkgsrcname in $topdir/SDEBS.\n";
953}
954
955
956## checkbuildreq()
957# Checks the build requirements (if any)
958# Spits out a rude warning and returns a true-false error if any
959# requirements are not met.
960sub checkbuildreq {
961 return 1 if $buildreq eq ''; # No use doing extra work.
962
963 if ( ! -e "/usr/bin/dpkg-query" ) {
964 print "**WARNING** dpkg-query not found. Can't check build-deps.\n".
965 " Required for sucessful build:\n".$buildreq."\n".
966 " Continuing anyway.\n";
967 return 1;
968 }
969
970 my $reqflag = 1; # unset iff a buildreq is missing
971
972 $buildreq =~ s/^, //; # Strip the leading comma and space
973 my @reqlist = split /,\s+/, $buildreq;
974
975 foreach my $req (@reqlist) {
976 my ($pkg,$rel,$ver);
977
978 # We have two classes of requirements - versioned and unversioned.
979 if ($req =~ /[><=]/) {
980 # Pick up the details of versioned buildreqs
981 ($pkg,$rel,$ver) = ($req =~ /([a-z0-9._-]+)\s+([><=]+)\s+([a-z0-9._-]+)/);
982 } else {
983 # And the unversioned ones.
984 $pkg = $req;
985 $rel = '>=';
986 $ver = 0;
987 }
988
989 my @pkglist = qx { dpkg-query --showformat '\${status}\t\${version}\n' -W $pkg };
990# need to check if no lines returned - means a bad buildreq
991 my ($reqstat,undef,undef,$reqver) = split /\s+/, $pkglist[0];
992 if ($reqstat !~ /install/) {
993 print " * Missing build-dependency $pkg!\n";
994 $reqflag = 0;
995 } else {
996# gotta be a better way to do this... :/
997 if ($rel eq '>=' && !($reqver ge $ver)) {
998 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
999 $reqflag = 0;
1000 }
1001 if ($rel eq '>' && !($reqver gt $ver)) {
1002 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
1003 $reqflag = 0;
1004 }
1005 if ($rel eq '<=' && !($reqver le $ver)) {
1006 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
1007 $reqflag = 0;
1008 }
1009 if ($rel eq '<' && !($reqver lt $ver)) {
1010 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
1011 $reqflag = 0;
1012 }
1013 if ($rel eq '=' && !($reqver eq $ver)) {
1014 print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
1015 $reqflag = 0;
1016 }
1017 } # end not installed/installed check
1018 } # end req loop
1019
1020 return $reqflag;
1021} # end checkbuildreq()
1022
1023
1024## getreqs()
1025# Find out which libraries/packages are required for any
1026# executables and libs in a given file tree.
1027# (Debian doesn't have soname-level deps; just package-level)
1028# Returns an empty string if the tree contains no binaries.
1029# Doesn't work well on shell scripts. but those *should* be
1030# fine anyway. (Yeah, right...)
1031sub getreqs() {
1032 my $pkgtree = $_[0];
1033
1034 print "Checking library requirements...\n";
1035 my @binlist = qx { find $pkgtree -type f -perm 755 };
1036
1037 if (scalar(@binlist) == 0) {
1038 return '';
1039 }
1040
1041 my @reqlist;
1042 foreach (@binlist) {
1043 push @reqlist, qx { ldd $_ };
1044 }
1045
1046 # Get the list of libs provided by this package. Still doesn't
1047 # handle the case where the lib gets stuffed into a subpackage. :/
1048 my @intprovlist = qx { find $pkgtree -type f -name "*.so*" };
1049 my $provlist = '';
1050 foreach (@intprovlist) {
1051 s/$pkgtree//;
1052 $provlist .= "$_";
1053 }
1054
1055 my %reqs;
1056 my $reqlibs = '';
1057
1058 foreach (@reqlist) {
1059 next if /^$pkgtree/;
1060 next if /not a dynamic executable/;
1061 next if m|/lib/ld-linux.so|; # Hack! Hack! PTHBTT! (libc suxx0rz)
1062
1063 my ($req) = (/^\s+([a-z0-9._-]+)/); # dig out the actual library (so)name
1064
1065 # Ignore libs provided by this package. Note that we don't match
1066 # on word-boundary at the *end* of the lib we're looking for, as the
1067 # looked-for lib may not have the full soname version. (ie, it may
1068 # "just" point to one of the symlinks that get created somewhere.)
1069 next if $provlist =~ /\b$req/;
1070
1071 $reqlibs .= " $req";
1072 }
1073
1074 if ($reqlibs ne '') {
1075 foreach (qx { dpkg -S $reqlibs }) {
1076 my ($libpkg,undef) = split /:\s+/;
1077 $reqs{$libpkg} = 1;
1078 }
1079 }
1080
1081 my $deplist = '';
1082 foreach (keys %reqs) {
1083 $deplist .= ", $_";
1084 }
1085
1086# For now, we're done. We're not going to meddle with versions yet.
1087# Among other things, it's messier than handling "simple" yes/no "do
1088# we have this lib?" deps. >:(
1089
1090 return $deplist;
1091} # end getreqs()
1092
1093
1094## install_sdeb()
1095# Extracts .sdeb contents to %_topdir as appropriate
1096sub install_sdeb {
1097 my $paxcmd = "cd $topdir; pax -r <$srcpkg; cd -";
1098
1099 # In case of %-macros...
1100 $paxcmd = expandmacros($paxcmd,'gp');
1101
1102 system "$paxcmd";
1103 print "Extracted source package $srcpkg to $topdir.\n";
1104} # end install_sdeb()
1105
1106
1107## expandmacros()
1108# Expands all %{blah} macros in the passed string
1109# Split up a bit with some sections so we don't spend time trying to
1110# expand macros that are only used in a few specific places.
1111sub expandmacros {
1112 my $macrostring = shift;
1113 my $section = shift;
1114
1115 # To allow the FHS-ish %configure and %makeinstall to work The Right Way.
1116 # (Without clobbering the global $buildroot.)
1117 my $prefix = '';
1118
1119 if ($section =~ /c/) {
1120 # %configure macro
1121# Don't know what it's for, don't have a useful default replacement
1122# --program-prefix=%{_program_prefix} \
1123 $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
1124 --build=$DEB_BUILD_GNU_TYPE \
1125 --prefix=%{_prefix} \
1126 --exec-prefix=%{_exec_prefix} \
1127 --bindir=%{_bindir} \
1128 --sbindir=%{_sbindir} \
1129 --sysconfdir=%{_sysconfdir} \
1130 --datadir=%{_datadir} \
1131 --includedir=%{_includedir} \
1132 --libdir=%{_libdir} \
1133 --libexecdir=%{_libexecdir} \
1134 --localstatedir=%{_localstatedir} \
1135 --sharedstatedir=%{_sharedstatedir} \
1136 --mandir=%{_mandir} \
1137 --infodir=%{_infodir} ';
1138 } # done %configure
1139
1140 if ($section =~ /m/) {
1141 $macrostring =~ s'%{__make}'make ';
1142 } # done make
1143
1144 if ($section =~ /i/) {
1145 # This is where we need to mangle $prefix.
1146 $macrostring =~ s'%makeinstall'make %{fhs} install';
1147 $prefix = $buildroot;
1148 } # done %install and/or %makeinstall
1149
1150 # Build data
1151 # Note that these are processed in reverse order to get the substitution order right
1152 if ($section =~ /b/) {
1153# $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
1154# build=$DEB_BUILD_GNU_TYPE \
1155 $macrostring =~ s'%{fhs}'prefix=%{_prefix} \
1156 exec-prefix=%{_exec_prefix} \
1157 bindir=%{_bindir} \
1158 sbindir=%{_sbindir} \
1159 sysconfdir=%{_sysconfdir} \
1160 datadir=%{_datadir} \
1161 includedir=%{_includedir} \
1162 libdir=%{_libdir} \
1163 libexecdir=%{_libexecdir} \
1164 localstatedir=%{_localstatedir} \
1165 sharedstatedir=%{_sharedstatedir} \
1166 mandir=%{_mandir} \
1167 infodir=%{_infodir} \
1168';
1169
1170 # Note that the above regex terminates with the extra space
1171 # "Just In Case" of user additions, which will then get neatly
1172 # tagged on the end where they take precedence (supposedly)
1173 # over the "default" ones.
1174
1175 # Now we cascade the macros introduced above. >_<
1176 # Wot ot to go theah:
1177 $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
1178 $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
1179 $macrostring =~ s|%{_oldincludedir}|/usr/include|g; #/usr/include
1180 $macrostring =~ s|%{_includedir}|%{_prefix\}/include|g; #/usr/include
1181 $macrostring =~ s|%{_libdir}|%{_exec_prefix}/%{_lib}|g; #/usr/lib
1182 $macrostring =~ s|%{_lib}|lib|g; #?
1183 $macrostring =~ s|%{_localstatedir}|/var|g; #/var
1184 $macrostring =~ s|%{_sharedstatedir}|%{_prefix}/com|g; #/usr/com WTF?
1185 $macrostring =~ s|%{_sysconfdir}|/etc|g; #/etc
1186 $macrostring =~ s|%{_datadir}|%{_prefix}/share|g; #/usr/share
1187 $macrostring =~ s|%{_libexecdir}|%{_exec_prefix}/libexec|g; #/usr/libexec
1188 $macrostring =~ s|%{_sbindir}|%{_exec_prefix}/sbin|g; #/usr/sbin
1189 $macrostring =~ s|%{_bindir}|%{_exec_prefix}/bin|g; #/usr/bin
1190 $macrostring =~ s|%{_exec_prefix}|%{_prefix}|g; #/usr
1191 $macrostring =~ s|%{_prefix}|/usr|g; #/usr
1192 } # done with config section
1193
1194 # Package data
1195 if ($section =~ /p/) {
1196 $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
1197 foreach my $source (keys %{$pkgdata{sources}}) {
1198 $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
1199 }
1200 $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
1201 $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
1202 $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
1203 }
1204
1205 # Globals, and not-so-globals
1206 if ($section =~ /g/) {
1207
1208 # special %define's. Handle the general case where we eval anything.
1209 # Prime example:
1210 #%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
1211 if ($macrostring =~ /^\%\(eval.+\)$/) {
1212 $macrostring =~ s/^\%\(//;
1213 $macrostring =~ s/\)$//;
1214 # Oy vey this gets silly for the perl bits. Executing a shell to
1215 # call Perl to get the vendorlib/sitelib/whatever "core" globals.
1216 # This can do more, but... eww.
1217 # Next line is non-optimal - what if $macrostring contains ' characters?
1218 $macrostring = qx { /bin/sh -c '$macrostring' };
1219 }
1220
1221 $macrostring =~ s|%{_builddir}|%{_topdir}/BUILD|g;
1222 $macrostring =~ s|%{_topdir}|$topdir|g;
1223 $macrostring =~ s|%{_tmppath}|$tmpdir|g;
1224 $macrostring =~ s'%{_docdir}'/usr/share/doc'g;
1225
1226 # Standard FHS locations. More or less.
1227 $macrostring =~ s'%{_bindir}'/usr/bin'g;
1228 $macrostring =~ s'%{_sbindir}'/usr/sbin'g;
1229 $macrostring =~ s'%{_mandir}'/usr/share/man'g;
1230 $macrostring =~ s'%{_includedir}'/usr/include'g;
1231 $macrostring =~ s'%{_libdir}'/usr/lib'g;
1232 $macrostring =~ s'%{_sysconfdir}'/etc'g;
1233 $macrostring =~ s'%{_localstatedir}'/var'g;
1234
1235 # %define's
1236 foreach my $key (keys %specglobals) {
1237 $macrostring =~ s|%{$key}|$specglobals{$key}|g;
1238 }
1239
1240 # system programs. RPM uses a global config file for these; we'll just
1241 # ASS-U-ME and make life a little simpler.
1242 if ($macrostring =~ /\%\{\_\_([a-z0-9_-]+)\}/) {
1243 $macrostring =~ s|%{__([a-z0-9_-]+)}|$1|g;
1244 }
1245 } # done with globals section
1246
1247 return $macrostring;
1248} # end expandmacros()
1249
1250
1251
1252__END__
1253
1254
1255
1256=head1 NAME
1257
1258debbuild - Build Debian-compatible packages from RPM spec files
1259
1260=head1 SYNOPSIS
1261
1262 debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
1263
1264 debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2}
1265
1266 debbuild --rebuild file.{src.rpm|sdeb}
1267
1268=head1 DESCRIPTION
1269
1270This script attempts to build Debian-friendly semi-native packages from RPM spec files,
1271RPM-friendly tarballs, and RPM source packages (.src.rpm files). It accepts I<most> of the
1272options rpmbuild does, and should be able to interpret most spec files usefully. Perl
1273modules should be handled via CPAN+dh-make-perl instead; Debian's conventions for such
1274things do not lend themselves to automated conversion.
1275
1276As far as possible, the command-line options are identical to those from rpmbuild, although
1277several rpmbuild options are not supported:
1278
1279 --recompile
1280 --showrc
1281 --buildroot
1282 --clean
1283 --nobuild
1284 --rmsource
1285 --rmspec
1286 --sign
1287 --target
1288
1289Some of these could probably be trivially added. Feel free to send me a patch. ;)
1290
1291Complex spec files will most likely not work well, if at all. Rewrite them from scratch -
1292you'll have to make heavy modifications anyway.
1293
1294If you see something you don't like, mail me. Send a patch if you feel inspired. I don't
1295promise I'll do anything other than say "Yup, that's broken" or "Got your message".
1296
1297=head1 ASSUMPTIONS
1298
1299As with rpmbuild, debbuild makes some assumptions about your system.
1300
1301=over 4
1302
1303=item *
1304
1305Either you have rights to do as you please under /usr/src/debian, or you have created a file
1306~/.debmacros containing a suitable %_topdir definition.
1307
1308Both rpmbuild and debbuild require the directories %_topdir/{BUILD,SOURCES,SPECS}. However,
1309where rpmbuild requires the %_topdir/{RPMS,SRPMS} directories, debbuild
1310requires %_topdir/{DEBS,SDEBS} instead. Create them in advance;
1311some subdirectories are created automatically as needed, but most are not.
1312
1313=item *
1314
1315/var/tmp must allow script execution - rpmbuild and debbuild both rely on creating and
1316executing shell scripts for much of their functionality. By default, debbuild also creates
1317install trees under /var/tmp - however this is (almost) entirely under the control of the
1318package's .spec file.
1319
1320=item *
1321
1322If you wish to --rebuild a .src.rpm, your %_topdir for both debbuild and rpmbuild must either
1323match, or be suitably symlinked one direction or another so that both programs are effectively
1324working in the same tree. (Or you could just manually wrestle files around your system.)
1325
1326You could symlink ~/.rpmmacros to ~/.debmacros (or vice versa) and save yourself some hassle
1327if you need to rebuild .src.rpm packages on a regular basis. Currently debbuild only uses the
1328%_topdir macro definition, although there are many more things that rpmbuild can use from
1329~/.rpmmacros.
1330
1331=back
1332
1333=head1 AUTHOR
1334
1335debbuild was written by Kris Deugau <kdeugau@deepnet.cx>. A version that approximates
1336current is available at http://www.deepnet.cx/debbuild/.
1337
1338=head1 BUGS
1339
1340Funky Things Happen if you forget a command-line option or two. I've been too lazy to bother
1341fixing this.
1342
1343Many macro expansions are unsupported or incompletely supported.
1344
1345The generated scriptlets don't quite match those from rpmbuild exactly. There are extra
1346environment variables and preprocessing that I haven't needed (yet).
1347
1348Dcumentation, such as it is, will likely remain perpetually out of date.
1349
1350%_topdir and the five "working" directories under %_topdir could arguably be created by
1351debbuild. However, rpmbuild doesn't create these directories either.
1352
1353=head1 SEE ALSO
1354
1355rpm(8), rpmbuild(8), and pretty much any document describing how to write a .spec file.
1356
1357=cut
Note: See TracBrowser for help on using the repository browser.