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