- Timestamp:
- 11/07/05 17:00:38 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/debbuild
r13 r14 76 76 export RPM_BUILD_ROOT 77 77 ); 78 #my $tmp = `dpkg-architecture`; # Debian buildarch goop.79 #$tmp =~ s/^(.*)$/ $1/g;80 #print $tmp;81 78 foreach (`dpkg-architecture`) { 82 79 s/=(.+)/="$1"/; … … 103 100 my $cleanscript; 104 101 105 # Functions106 sub prep;107 sub parse_spec;108 109 102 die "Not enough arguments\n" if #$argv == 0; 110 103 … … 129 122 130 123 # Hokay. Need to: 131 # Execute prep if *not* --short-circuit124 # -> prep if -.p OR (-.[cilabs] AND !--short-circuit) 132 125 if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) { 133 126 prep(); 134 127 } 128 # -> build if -.c OR (-.[ilabs] AND !--short-circuit) 135 129 if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) { 136 130 build(); 137 131 } 132 # -> install if -.[ilabs] 138 133 if ($cmdopts{stage} =~ /[ilabs]/) { 139 134 install(); 140 135 } 136 # -> binpkg and srcpkg if -.a 141 137 if ($cmdopts{stage} eq 'a') { 142 138 binpackage(); 143 139 srcpackage(); 144 140 } 141 # -> binpkg if -.b 145 142 if ($cmdopts{stage} eq 'b') { 146 143 binpackage(); 147 144 } 145 # -> srcpkg if -.s 148 146 if ($cmdopts{stage} eq 's') { 149 147 srcpackage(); … … 201 199 } 202 200 } else { 201 # Not a long option 203 202 if (/^-[bt]/) { 204 203 if ($cmdopts{stage} eq 's') { … … 206 205 die "Can't use $_ with --rebuild\n"; 207 206 } else { 207 # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc) 208 208 ($cmdopts{stage}) = (/^-[bt]([pcilabs])/); 209 209 ($cmdopts{type}) = (/^-([bt])[pcilabs]/); … … 215 215 } 216 216 } 217 } else { 217 218 } else { # Not an option argument 219 218 220 # --buildroot is the only option that takes an argument 219 221 # Therefore, any *other* bare arguments are the spec file, … … 241 243 # Some cross-checks. rpmbuild limits --short-circuit to just 242 244 # the "compile" and "install" targets - with good reason IMO. 245 # Note that --short-circuit with -.p is not really an error, just redundant. 243 246 # NB - this is NOT fatal, just ignored! 244 247 if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) { … … 246 249 $cmdopts{short} = 'n'; 247 250 } 251 248 252 # Valid options, with example arguments (if any): 249 253 # Build from .spec file; mutually exclusive: … … 283 287 284 288 ## parse_spec() 285 # Parse the .spec file once we've.... uh....289 # Parse the .spec file. 286 290 sub parse_spec { 287 291 open SPECFILE,"<$specfile"; 288 292 289 293 LINE: while (<SPECFILE>) { 290 next if /^#/; 291 next if /^\s+$/; 294 next if /^#/; # Ignore comments... 295 next if /^\s+$/; # ... and blank lines. 296 292 297 if (/^\%/) { 293 298 # A macro that needs further processing. 299 294 300 if (/^\%description/) { 295 301 $pkgdata{main}{desc} .= $_; … … 308 314 309 315 # Replace some core macros 310 $pkgdata{main}{source} =~ s/\%\{name\}/$pkgdata{main}{name}/; 311 $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/; 316 $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp'); 312 317 313 318 PREPSCRIPT: while (<SPECFILE>) { 314 319 if (/^\%setup/) { 315 320 # Parse out the %setup macro. Note that we aren't supporting 316 # m ostof RPM's %setup features.321 # many of RPM's %setup features. 317 322 $prepscript .= "cd $topdir/BUILD\n"; 318 323 if ( /\s+-n\s+([^\s]+)\s+/ ) { … … 362 367 if (/^\%makeinstall/) { 363 368 $installscript .= expandmacros($_,'igbp'); 364 print $installscript;365 #print "\n$tmp\n"; die;366 # $installscript .= $tmp;367 369 } else { 368 370 last INSTALLSCRIPT if /^\%/; … … 386 388 # Danger! Danger! 387 389 } 388 } else { 390 391 } else { # Data from the spec file "header" 392 389 393 if (/^summary:\s+(.+)/i) { 390 394 $pkgdata{main}{summary} = $1; … … 424 428 } 425 429 } 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 # Parse and replace some more macros. More will be replaced even later. 430 432 431 433 # Expand macros as necessary. … … 439 441 440 442 ## 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 443 # Writes and executes the %prep script (mostly) built while reading the spec file. 444 444 sub prep { 445 445 # Replace some things here just to make sure. … … 457 457 print "Calling \%prep script $prepscriptfile...\n"; 458 458 system("/bin/sh -e $prepscriptfile") == 0 459 or die "Can't exec: $!\n also: $?";459 or die "Can't exec: $!\n"; 460 460 461 461 # and clean up … … 465 465 466 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. 467 # Writes and executes the %build script (mostly) built while reading the spec file. 469 468 sub build { 470 469 # Expand the macros … … 479 478 close BUILDSCRIPT; 480 479 481 #print "'$scriptletbase$buildscript'";482 #exit 0;483 480 # execute 484 481 print "Calling \%build script $buildscriptfile...\n"; 485 482 system("/bin/sh -e $buildscriptfile") == 0 486 or die "Can't exec: $!\n also: $?";483 or die "Can't exec: $!\n"; 487 484 488 485 # and clean up … … 492 489 493 490 ## install() 494 # Creates and executes %install script(let)491 # Writes and executes the %install script (mostly) built while reading the spec file. 495 492 sub install { 496 493 # Expand the macros … … 509 506 print "Calling \%install script $installscriptfile...\n"; 510 507 system("/bin/sh -e $installscriptfile") == 0 511 or die "Can't exec: $!\n also: $?";508 or die "Can't exec: $!\n"; 512 509 513 510 # and clean up … … 518 515 ## binpackage() 519 516 # Creates the binary .deb package from the installed tree in $buildroot. 517 # Writes and executes a shell script to do so. 518 # Creates miscellaneous files required by dpkg-deb to actually build the package file. 520 519 sub binpackage { 521 # Some checks on the .deb file location520 # Make sure we have somewhere to write the .deb file 522 521 if (!-e "$topdir/DEBS/i386") { 523 522 # "if [ -e $topdir/DEBS/i386 ]; then\n\tmkdir $topdir/DEBS/i386\nfi\n". 524 523 mkdir "$topdir/DEBS/i386"; 525 524 } 525 526 526 # Gotta do this first, otherwise the control file has nowhere to go. >:( 527 527 mkdir "$buildroot/DEBIAN"; … … 534 534 print DEBSCRIPT "tree $buildroot\n". 535 535 "fakeroot dpkg-deb -b $buildroot $topdir/DEBS/i386/$pkgdata{main}{name}_$pkgdata{main}{version}-$pkgdata{main}{release}_i386.deb\n"; 536 536 # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:( 537 537 close DEBSCRIPT; 538 538 … … 545 545 "Description: $pkgdata{main}{desc}\n"; 546 546 547 eval {548 547 open CONTROL, ">$buildroot/DEBIAN/control"; 549 548 print CONTROL $control; 550 549 close CONTROL; 551 };552 if ($@) {553 print $@;554 }555 550 556 551 #Package: httpd … … 567 562 # http://home.samfundet.no/~sesse/mpm-itk/. 568 563 569 570 564 # execute 571 565 print "Creating .deb for $pkgdata{main}{name}...\n"; 572 566 system("/bin/sh -e $debscriptfile") == 0 573 or die "Can't exec: $!\n also: $?";567 or die "Can't exec: $!\n"; 574 568 575 569 # and clean up 576 570 unlink $debscriptfile; 577 578 571 } # end binpackage() 579 572 … … 584 577 ## expandmacros() 585 578 # Expands all %{blah} macros in the passed string 579 # Split up a bit with some sections so we don't spend time trying to 580 # expand macros that are only used in a few specific places. 586 581 sub expandmacros { 587 582 my $macrostring = shift; 588 my $section = shift; # We'll want to split things up a bit eventually.583 my $section = shift; 589 584 590 585 # To allow the FHS-ish %configure, %make, and %makeinstall to work The Right Way. … … 637 632 # over the "default" ones. 638 633 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 634 # Now we cascade the macros introduced above. >_< 635 # Wot ot to go theah: 636 $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man 637 $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info 638 $macrostring =~ s|%{_oldincludedir}|$prefix/usr/include|g; #/usr/include 642 639 $macrostring =~ s|%{_includedir}|$prefix%{_prefix\}/include|g; #/usr/include 643 640 $macrostring =~ s|%{_libdir}|$prefix%{_exec_prefix}/%{_lib}|g; #/usr/lib 644 $macrostring =~ s|%{_lib}|lib|g; 641 $macrostring =~ s|%{_lib}|lib|g; #? 645 642 $macrostring =~ s|%{_localstatedir}|$prefix/var|g; #/var 646 643 $macrostring =~ s|%{_sharedstatedir}|$prefix%{_prefix}/com|g; #/usr/com WTF? 647 $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g; 644 $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g; #/etc 648 645 $macrostring =~ s|%{_datadir}|$prefix%{_prefix}/share|g; #/usr/share 649 646 $macrostring =~ s|%{_libexecdir}|$prefix%{_exec_prefix}/libexec|g; #/usr/libexec 650 $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g; 647 $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g; #/usr/sbin 651 648 $macrostring =~ s|%{_bindir}|$prefix%{_exec_prefix}/bin|g; #/usr/bin 652 649 $macrostring =~ s|%{_exec_prefix}|$prefix%{_prefix}|g; #/usr 653 $macrostring =~ s|%{_prefix}|/usr|g; #/usr650 $macrostring =~ s|%{_prefix}|/usr|g; #/usr 654 651 } # done with config section 655 652
Note:
See TracChangeset
for help on using the changeset viewer.