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