Changeset 7
- Timestamp:
- 11/01/05 16:09:06 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/debbuild
r6 r7 13 13 use strict; 14 14 use warnings; 15 use Fcntl; # for sysopen flags 15 16 16 17 # Program flow: … … 33 34 my $tarball; 34 35 my $srcpkg; 36 my $cmdbuildroot; 37 my $tarballdir; # This should really be initialized, but the coding makes it, um, ugly. 35 38 36 39 # Initialized globals … … 41 44 ); 42 45 my $topdir = "/usr/src/debian"; 46 my $buildroot = "/var/tmp/%{name}-%{version}-%{release}.root".int(rand(99998)+1); 43 47 44 48 # "Constants" … … 85 89 my $buildscript; 86 90 my $installscript; 91 my $cleanscript; 87 92 88 93 # Functions … … 92 97 die "Not enough arguments\n" if #$argv == 0; 93 98 99 ##main 100 94 101 load_userconfig(); 95 102 parse_cmd(); 96 103 104 if ($cmdopts{type} eq 'b') { 105 # Need to read the spec file to find the tarball. Note that 106 # this also generates most of the shell script required. 107 parse_spec(); 108 } 109 97 110 # Hokay. Need to: 98 111 # Execute prep if *not* --short-circuit 99 prep() if ($cmdopts{short} ne 'y'); 100 101 if ($cmdopts{stage} =~ /ciab/) { 102 # Execute build if bc 103 # Execute build if bi, ba, bb and NOT --short-circuit 104 build() if ( ($cmdopts{stage} eq 'c') || 105 (($cmdopts{stage} =~ /iab/) && ($cmdopts{short} ne 'y')) 106 ); 107 108 # -> Execute 109 install() if ($cmdopts{short} ne 'y'); 112 if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) { 113 prep(); 114 } 115 if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) { 116 build(); 117 } 118 if ($cmdopts{stage} =~ /[ilabs]/) { 119 install(); 120 } 121 if ($cmdopts{stage} eq 'a') { 110 122 binpackage(); 111 } 112 113 srcpackage(); 114 115 123 srcpackage(); 124 } 125 if ($cmdopts{stage} eq 'b') { 126 binpackage(); 127 } 128 if ($cmdopts{stage} eq 's') { 129 srcpackage(); 130 } 116 131 117 132 # Just in case. … … 128 143 open USERMACROS,"<$homedir/.debmacros"; 129 144 while (<USERMACROS>) { 130 # And we also only handle the %_topdir macroat the moment.145 # And we also only handle a few macros at the moment. 131 146 if (/^\%_topdir/) { 132 147 my (undef,$tmp) = split /\s+/, $_; … … 152 167 foreach (@ARGV) { 153 168 chomp; 154 $prevopt = $_; 169 155 170 # Is it an option? 156 171 if (/^-/) { 172 157 173 # Is it a long option? 158 174 if (/^--/) { … … 185 201 # on which one we meet. 186 202 if ($prevopt eq '--buildroot') { 187 # Set buildroot203 $cmdbuildroot = $_; 188 204 } else { 189 205 if ($cmdopts{type} eq 's') { 190 206 # Source package 191 if (!/\.src\.(deb|rpm)$/) {207 if (!/\.src\.(deb|rpm)$/) { 192 208 die "Can't --rebuild with $_\n"; 193 209 } … … 200 216 } 201 217 } 202 } 218 $prevopt = $_; 219 } # foreach @ARGV 203 220 204 221 # Some cross-checks. rpmbuild limits --short-circuit to just … … 245 262 246 263 247 ## prep()248 # Unpacks the tarball from the SOURCES directory to the BUILD directory.249 # Speaks gzip and bzip2.250 # Finishes by applying patches in %prep section of spec file251 sub prep {252 if ($cmdopts{type} eq 'b') {253 # Need to read the spec file to find the tarball254 parse_spec();255 256 # Need to find the filename part of the tarball. In theory, we257 # could go out to the URL and retrieve it, but that's Messy.258 # want to make this local259 $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;260 261 if ($pkgdata{main}{source} =~ /(.+)\.tar\.gz$/) {262 -e "$topdir/BUILD/$1" && system "rm -rf $topdir/BUILD/$1";263 # system "cd $topdir/BUILD;tar -zxvvf $topdir/SOURCES/$pkgdata{main}{source}";264 } elsif ($pkgdata{main}{source} =~ /(.+)\.tar\.bz2$/) {265 -e "$topdir/BUILD/$1" && system "rm -rf $topdir/BUILD/$1";266 system "cd $topdir/BUILD;tar -jxvvf $topdir/SOURCES/$pkgdata{main}{source}";267 } else {268 die "Unknown source tarball format\n";269 }270 # And now for patches. (not)271 }272 } # end prep()273 274 275 264 ## parse_spec() 276 265 # Parse the .spec file once we've.... uh.... … … 298 287 # Parse out the %setup macro. Note that we aren't supporting 299 288 # most of RPM's %setup features. 300 $prepscript .= "cd $topdir/BUILD\n". 301 ( /\s+-n\s+([^\s]+)\s+/ ? 302 "rm -rf $1\n" : "rm -rf $pkgdata{main}{name}-$pkgdata{main}{version}\n" ). 303 "tar -". 289 $prepscript .= "cd $topdir/BUILD\n"; 290 if ( /\s+-n\s+([^\s]+)\s+/ ) { 291 $tarballdir = $1; 292 } else { 293 $tarballdir = "$pkgdata{main}{name}-$pkgdata{main}{version}"; 294 } 295 $prepscript .= "rm -rf $tarballdir\ntar -". 304 296 ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ). 305 297 ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ). … … 324 316 # %build. This is pretty much just a shell script. There 325 317 # *are* a few macros, but we're not going to deal with them yet. 318 $buildscript .= "cd $tarballdir\n"; 326 319 while (<SPECFILE>) { 327 320 redo LINE if /^\%/; … … 330 323 } 331 324 if (/^\%install/) { 325 $installscript .= "cd $tarballdir\n"; 332 326 while (<SPECFILE>) { 333 327 redo LINE if /^\%/; … … 336 330 } 337 331 if (/^\%clean/) { 332 while (<SPECFILE>) { 333 redo LINE if /^\%/; 334 $cleanscript .= $_; 335 } 338 336 } 339 337 if (/^\%post/) { … … 361 359 } elsif (/^packager:\s+(.+)/i) { 362 360 $pkgdata{main}{packager} = $1; 361 } elsif (/^buildroot:\s+(.+)/i) { 362 $buildroot = $1; 363 363 } elsif (/^source:\s+(.+)/i) { 364 364 $pkgdata{main}{source} = $1; … … 378 378 } 379 379 } 380 # Parse and replace macros in $pkgdata{}{}380 # Parse and replace macros 381 381 # Start with the ones I use 382 $pkgdata{main}{source} =~ s/\%\{name\}/$pkgdata{main}{name}/; 383 $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/; 382 # $pkgdata{main}{source} =~ s/\%\{name\}/$pkgdata{main}{name}/; 383 # $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/; 384 385 # Scriptlet core. Use /g to make sure all occurrences get tweaked. 386 # "real" globals (apply to all packages the same way) 387 $scriptletbase =~ s/\%\{_topdir\}/$topdir/g; 388 389 # "fake" globals (may be tweaked by package) 390 $buildroot = $cmdbuildroot if $cmdbuildroot; 391 $scriptletbase =~ s/\%\{buildroot\}/$buildroot/g; 392 393 # sub-package(compatible) stuff 394 $scriptletbase =~ s/\%\{name\}/$pkgdata{main}{name}/g; 395 $scriptletbase =~ s/\%\{version\}/$pkgdata{main}{version}/g; 396 $scriptletbase =~ s/\%\{release\}/$pkgdata{main}{release}/g; 397 384 398 } # end parse_spec() 399 400 401 ## prep() 402 # Unpacks the tarball from the SOURCES directory to the BUILD directory. 403 # Speaks gzip and bzip2. 404 # Finishes by applying patches in %prep section of spec file 405 sub prep { 406 { 407 # create script filename 408 my $prepscriptfile = "/var/tmp/deb-tmp.prep.".int(rand(99998)+1); 409 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW) 410 or die $!; 411 print PREPSCRIPT $scriptletbase; 412 print PREPSCRIPT $prepscript; 413 close PREPSCRIPT; 414 415 # execute 416 print "Calling \%prep script $prepscriptfile...\n"; 417 system("/bin/sh -e $prepscriptfile") == 0 418 or die "Can't exec: $!\nalso: $?"; 419 420 # and clean up 421 unlink $prepscriptfile; 422 } 423 } # end prep() 385 424 386 425 … … 389 428 # to do as rpm does and actually create a little shell script. 390 429 sub build { 430 # create script filename 431 my $buildscriptfile = "/var/tmp/deb-tmp.build.".int(rand(99998)+1); 432 sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW) 433 or die $!; 434 print BUILDSCRIPT $scriptletbase; 435 print BUILDSCRIPT $buildscript; 436 close BUILDSCRIPT; 437 438 # execute 439 print "Calling \%build script $buildscriptfile...\n"; 440 system("/bin/sh -e $buildscriptfile") == 0 441 or die "Can't exec: $!\nalso: $?"; 442 443 # and clean up 444 unlink $buildscriptfile; 391 445 } # end build() 392 446 393 447 394 sub install {} 448 ## install() 449 # Creates and executes %install script(let) 450 sub install { 451 # create script filename 452 my $installscriptfile = "/var/tmp/deb-tmp.inst.".int(rand(99998)+1); 453 sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW) 454 or die $!; 455 print INSTSCRIPT $scriptletbase; 456 print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it. 457 print INSTSCRIPT $installscript; 458 close INSTSCRIPT; 459 460 # execute 461 print "Calling \%install script $installscriptfile...\n"; 462 system("/bin/sh -e $installscriptfile") == 0 463 or die "Can't exec: $!\nalso: $?"; 464 465 # and clean up 466 unlink $installscriptfile; 467 } # end install() 468 469 395 470 sub binpackage {} 396 471 sub srcpackage {}
Note:
See TracChangeset
for help on using the changeset viewer.