Changeset 10


Ignore:
Timestamp:
11/03/05 18:10:26 (19 years ago)
Author:
kdeugau
Message:

/trunk

Checkpoint
%configure works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r9 r10  
    1414use warnings;
    1515use Fcntl;      # for sysopen flags
     16
     17# regex debugger
     18#use re "debug";
    1619
    1720# Program flow:
     
    7275  RPM_BUILD_ROOT="%{buildroot}"
    7376  export RPM_BUILD_ROOT
    74 
     77);
     78#my $tmp = `dpkg-architecture`; # Debian buildarch goop.
     79#$tmp =~ s/^(.*)$/  $1/g;
     80#print $tmp;
     81foreach (`dpkg-architecture`) {
     82  s/=(.+)/="$1"/;
     83  $scriptletbase .= "  $_";
     84}
     85$scriptletbase .=
     86q(
    7587  set -x
    7688  umask 022
     
    222234  # the "compile" and "install" targets - with good reason IMO.
    223235  # NB - this is NOT fatal, just ignored!
    224   if ($cmdopts{short} eq 'y') {
     236  if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
    225237    warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage.  Ignoring.\n";
    226238    $cmdopts{short} = 'n';
     
    312324                qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
    313325                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";
    316328          } else {
    317329            last PREPSCRIPT if /^\%/;
     
    321333        redo LINE;
    322334      }
    323       if (/^\%build/) {
     335        if (/^\%build/) {
    324336        # %build.  This is pretty much just a shell script.  There
    325337        # *are* a few macros, but we're not going to deal with them yet.
    326338        $buildscript .= "cd $tarballdir\n";
    327         while (<SPECFILE>) {
    328           redo LINE if /^\%/;
    329           $buildscript .= $_;
     339BUILDSCRIPT: 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          }
    330348        }
     349        redo LINE;
    331350      }
    332351      if (/^\%install/) {
    333352        $installscript .= "cd $tarballdir\n";
    334353        while (<SPECFILE>) {
     354        # Need to handle %makeinstall
    335355          redo LINE if /^\%/;
    336356          $installscript .= $_;
     
    372392        $pkgdata{main}{source} = $1;
    373393        die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
     394      } elsif (/^patch([^:]+):\s+(.+)$/i) {
     395        $pkgdata{main}{"patch$1"} = $2;
    374396      }
    375397#Name: suwrap
     
    391413#  $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/;
    392414
    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
    398418  $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
    410421} # end parse_spec()
    411422
     
    416427# Finishes by applying patches in %prep section of spec file
    417428sub 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)
    422435        or die $!;
    423     print PREPSCRIPT $scriptletbase;
    424     print PREPSCRIPT $prepscript;
    425     close PREPSCRIPT;
    426 
    427     # execute
    428     print "Calling \%prep script $prepscriptfile...\n";
    429     system("/bin/sh -e $prepscriptfile") == 0
     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
    430443        or die "Can't exec: $!\nalso: $?";
    431444
    432     # and clean up
    433     unlink $prepscriptfile;
    434   }
     445  # and clean up
     446  unlink $prepscriptfile;
    435447} # end prep()
    436448
     
    445457        or die $!;
    446458  print BUILDSCRIPT $scriptletbase;
     459
     460  $buildscript = expandmacros($buildscript,'configure');
    447461  print BUILDSCRIPT $buildscript;
    448462  close BUILDSCRIPT;
    449463
     464#print "'$scriptletbase$buildscript'";
     465#exit 0;
    450466  # execute
    451467  print "Calling \%build script $buildscriptfile...\n";
     
    544560
    545561sub srcpackage {}
     562
     563
     564## expandmacros()
     565# Expands all %{blah} macros in the passed string
     566sub 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.