- Timestamp:
- 11/03/05 18:10:26 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/debbuild
r9 r10 14 14 use warnings; 15 15 use Fcntl; # for sysopen flags 16 17 # regex debugger 18 #use re "debug"; 16 19 17 20 # Program flow: … … 72 75 RPM_BUILD_ROOT="%{buildroot}" 73 76 export RPM_BUILD_ROOT 74 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( 75 87 set -x 76 88 umask 022 … … 222 234 # the "compile" and "install" targets - with good reason IMO. 223 235 # NB - this is NOT fatal, just ignored! 224 if ($cmdopts{short} eq 'y' ) {236 if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) { 225 237 warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n"; 226 238 $cmdopts{short} = 'n'; … … 312 324 qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n). 313 325 qq(/bin/chmod -Rf a+rX,g-w,o-w .\n); 314 } elsif (/^\%patch /) {315 print "patch macro\n";326 } elsif (/^\%patch([^:]+)\s+(.+)$/) { 327 $prepscript .= "patch $2 <$topdir/SOURCES/".$pkgdata{main}{"patch$1"}."\n"; 316 328 } else { 317 329 last PREPSCRIPT if /^\%/; … … 321 333 redo LINE; 322 334 } 323 335 if (/^\%build/) { 324 336 # %build. This is pretty much just a shell script. There 325 337 # *are* a few macros, but we're not going to deal with them yet. 326 338 $buildscript .= "cd $tarballdir\n"; 327 while (<SPECFILE>) { 328 redo LINE if /^\%/; 329 $buildscript .= $_; 339 BUILDSCRIPT: while (<SPECFILE>) { 340 if (/^\%configure/) { 341 my $tmp = expandmacros($_,'configure'); 342 $buildscript .= $tmp; 343 } else { 344 # Need to handle %make 345 last BUILDSCRIPT if /^\%/; 346 $buildscript .= $_; 347 } 330 348 } 349 redo LINE; 331 350 } 332 351 if (/^\%install/) { 333 352 $installscript .= "cd $tarballdir\n"; 334 353 while (<SPECFILE>) { 354 # Need to handle %makeinstall 335 355 redo LINE if /^\%/; 336 356 $installscript .= $_; … … 372 392 $pkgdata{main}{source} = $1; 373 393 die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/; 394 } elsif (/^patch([^:]+):\s+(.+)$/i) { 395 $pkgdata{main}{"patch$1"} = $2; 374 396 } 375 397 #Name: suwrap … … 391 413 # $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/; 392 414 393 # Scriptlet core. Use /g to make sure all occurrences get tweaked. 394 # "real" globals (apply to all packages the same way) 395 $scriptletbase =~ s/\%\{_topdir\}/$topdir/g; 396 397 # "fake" globals (may be tweaked by package) 415 # Expand macros as necessary. 416 $scriptletbase = expandmacros($scriptletbase,'globals'); 417 398 418 $buildroot = $cmdbuildroot if $cmdbuildroot; 399 $scriptletbase =~ s/\%\{buildroot\}/$buildroot/g; 400 401 # sub-package(compatible) stuff 402 $scriptletbase =~ s/\%\{name\}/$pkgdata{main}{name}/g; 403 $scriptletbase =~ s/\%\{version\}/$pkgdata{main}{version}/g; 404 $scriptletbase =~ s/\%\{release\}/$pkgdata{main}{release}/g; 405 406 # Some more macro substitution. Nrgh. 407 $buildroot =~ s/\%\{name\}/$pkgdata{main}{name}/g; 408 $buildroot =~ s/\%\{version\}/$pkgdata{main}{version}/g; 409 $buildroot =~ s/\%\{release\}/$pkgdata{main}{release}/g; 419 $buildroot = expandmacros($buildroot,'pkgdata'); 420 410 421 } # end parse_spec() 411 422 … … 416 427 # Finishes by applying patches in %prep section of spec file 417 428 sub prep { 418 { 419 # create script filename 420 my $prepscriptfile = "/var/tmp/deb-tmp.prep.".int(rand(99998)+1); 421 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW) 429 # Replace some things here just to make sure. 430 $prepscript =~ s/\%\{name\}/$pkgdata{main}{name}/g; 431 432 # create script filename 433 my $prepscriptfile = "/var/tmp/deb-tmp.prep.".int(rand(99998)+1); 434 sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW) 422 435 or die $!; 423 424 425 426 427 428 429 436 print PREPSCRIPT $scriptletbase; 437 print PREPSCRIPT $prepscript; 438 close PREPSCRIPT; 439 440 # execute 441 print "Calling \%prep script $prepscriptfile...\n"; 442 system("/bin/sh -e $prepscriptfile") == 0 430 443 or die "Can't exec: $!\nalso: $?"; 431 444 432 # and clean up 433 unlink $prepscriptfile; 434 } 445 # and clean up 446 unlink $prepscriptfile; 435 447 } # end prep() 436 448 … … 445 457 or die $!; 446 458 print BUILDSCRIPT $scriptletbase; 459 460 $buildscript = expandmacros($buildscript,'configure'); 447 461 print BUILDSCRIPT $buildscript; 448 462 close BUILDSCRIPT; 449 463 464 #print "'$scriptletbase$buildscript'"; 465 #exit 0; 450 466 # execute 451 467 print "Calling \%build script $buildscriptfile...\n"; … … 544 560 545 561 sub srcpackage {} 562 563 564 ## expandmacros() 565 # Expands all %{blah} macros in the passed string 566 sub expandmacros { 567 my $macrostring = shift; 568 my $section = shift; # We'll want to split things up a bit eventually. 569 570 if ($section eq 'configure') { 571 # %configure-ish macros 572 # Note that these are processed in reverse order to get the substitution order right 573 # Foistly, %configure itself: 574 # Don't know what it's for, don't have a useful default replacement 575 # --program-prefix=%{_program_prefix} \ 576 # Coding Q: Why does this not work if I move the subst string into its own isolated quotes? 577 $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \ 578 --build=$DEB_BUILD_GNU_TYPE \ 579 --prefix=%{_prefix} \ 580 --exec-prefix=%{_exec_prefix} \ 581 --bindir=%{_bindir} \ 582 --sbindir=%{_sbindir} \ 583 --sysconfdir=%{_sysconfdir} \ 584 --datadir=%{_datadir} \ 585 --includedir=%{_includedir} \ 586 --libdir=%{_libdir} \ 587 --libexecdir=%{_libexecdir} \ 588 --localstatedir=%{_localstatedir} \ 589 --sharedstatedir=%{_sharedstatedir} \ 590 --mandir=%{_mandir} \ 591 --infodir=%{_infodir} '; 592 593 # Note that the above regex terminates with the extra space 594 # "Just In Case" of user additions to the %configure line, 595 # which will then get neatly tagged on the end where they 596 # take precedence (supposedly) over the "default" ones. 597 598 $macrostring =~ s'%{_mandir}'%{_prefix}/man'g; 599 $macrostring =~ s'%{_infodir}'%{_prefix}/info'g; 600 $macrostring =~ s'%{_oldincludedir}'/usr/include'g; 601 $macrostring =~ s'%{_includedir}'%{_prefix}/include'g; 602 $macrostring =~ s'%{_libdir}'%{_exec_prefix}/%{_lib}'g; 603 $macrostring =~ s'%{_lib}'lib'g; 604 $macrostring =~ s'%{_localstatedir}'%{_prefix}/var'g; 605 $macrostring =~ s'%{_sharedstatedir}'%{_prefix}/com'g; 606 $macrostring =~ s'%{_sysconfdir}'%{_prefix}/etc'g; 607 $macrostring =~ s'%{_datadir}'%{_prefix}/share'g; 608 $macrostring =~ s'%{_libexecdir}'%{_exec_prefix}/libexec'g; 609 $macrostring =~ s'%{_sbindir}'%{_exec_prefix}/sbin'g; 610 $macrostring =~ s'%{_bindir}'%{_exec_prefix}/bin'g; 611 $macrostring =~ s'%{_exec_prefix}'%{_prefix}'g; 612 $macrostring =~ s'%{_prefix}'/usr'g; 613 } # done with config section 614 615 if ($section eq 'globals') { 616 $macrostring =~ s/\%\{_topdir\}/$topdir/g; 617 618 # "fake" globals (may be tweaked by package) 619 $macrostring =~ s/\%\{buildroot\}/$buildroot/g; 620 621 # sub-package(compatible) stuff 622 $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/g; 623 $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/g; 624 $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/g; 625 } # done with globals section 626 627 if ($section eq 'pkgdata') { 628 $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/g; 629 $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/g; 630 $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/g; 631 } 632 633 return $macrostring; 634 } # end expandmacros()
Note:
See TracChangeset
for help on using the changeset viewer.