Changeset 136 for trunk


Ignore:
Timestamp:
11/07/07 15:17:21 (17 years ago)
Author:
kdeugau
Message:

/trunk

Fix %makeinstall macro expansion to match rpm's behaviour

  • required upping the recursion limit to allow replacing all of the %{?...} expansions in %makeinstall
  • also required fixing slightly broken %{?...} logic-expression expansion, which required turning $buildroot into $specglobals{buildroot}
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r135 r136  
    7373        );
    7474my $topdir = "/usr/src/debian";
    75 my $buildroot = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
     75#my $specglobals{buildroot} = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
     76$specglobals{buildroot} = '';
    7677
    7778# "Constants"
     
    569570    if (/^\%{echo:(.+)}/) {
    570571      my $output = expandmacros($1, 'gp');
    571       print "$output\n";
     572      print "$output";
    572573    }
    573574
     
    862863        $pkgdata{main}{packager} = $1;
    863864      } elsif (/^buildroot:\s*(.+)/i) {
    864         $buildroot = $1;
     865        $specglobals{buildroot} = $1;
    865866      } elsif (/^source0?:\s*(.+)/i) {
    866867        $pkgdata{main}{source} = $1;
     
    914915  $cleanscript = expandmacros($cleanscript,'gp');
    915916
    916   $buildroot = $cmdbuildroot if $cmdbuildroot;
    917   $buildroot = expandmacros($buildroot,'gp');
     917  $specglobals{buildroot} = $cmdbuildroot if $cmdbuildroot;
     918  $specglobals{buildroot} = expandmacros($specglobals{buildroot},'gp');
    918919
    919920  close SPECFILE;
     
    10091010  # done here cuz I don't grok shell well
    10101011  # should probably error-check all kinds of things.  <g>
    1011   if (opendir MANROOT, "$buildroot/usr/share/man") {
     1012  if (opendir MANROOT, "$specglobals{buildroot}/usr/share/man") {
    10121013    my @mansects = readdir MANROOT;
    10131014    closedir MANROOT;
    10141015    foreach my $mandir (@mansects) {
    10151016      next if $mandir !~ /^man/;
    1016       opendir MANPAGES, "$buildroot/usr/share/man/$mandir";
     1017      opendir MANPAGES, "$specglobals{buildroot}/usr/share/man/$mandir";
    10171018      my @pagelist = readdir MANPAGES;
    10181019      closedir MANPAGES;                        # Slightly safer to to this;  no accidental recursion.  O_o
    10191020      foreach my $manpage (@pagelist) {
    1020         $manpage = "$buildroot/usr/share/man/$mandir/$manpage";
     1021        $manpage = "$specglobals{buildroot}/usr/share/man/$mandir/$manpage";
    10211022        if ( -f $manpage) {
    10221023          if ($manpage =~ /^(.+)\.(?:Z|gz|bz2)\n?$/) {
     
    10411042
    10421043## binpackage()
    1043 # Creates the binary .deb package from the installed tree in $buildroot.
     1044# Creates the binary .deb package from the installed tree in $specglobals{buildroot}.
    10441045# Writes and executes a shell script to do so.
    10451046# Creates miscellaneous files required by dpkg-deb to actually build the package file.
     
    10631064
    10641065    # Gotta do this first, otherwise we don't have a place to move files from %files
    1065     mkdir "$buildroot/$pkg";
     1066    mkdir "$specglobals{buildroot}/$pkg";
    10661067
    10671068    # Eliminate any lingering % macros
     
    10751076      if ($pkgfile =~ m|/usr/share/man/man|) {
    10761077        # need to check to see if manpage is gzipped
    1077         if (-e "$buildroot$pkgfile") {
     1078        if (-e "$specglobals{buildroot}$pkgfile") {
    10781079          if ($pkgfile !~ m|\.gz$|) {
    1079             qx { gzip $buildroot$pkgfile };
     1080            qx { gzip $specglobals{buildroot}$pkgfile };
    10801081            $pkgfile .= ".gz";
    10811082          }
     
    10851086          } else {
    10861087            $pkgfile =~ s/\.gz$//;
    1087             qx { gzip $buildroot$pkgfile };
     1088            qx { gzip $specglobals{buildroot}$pkgfile };
    10881089            $pkgfile .= ".gz";
    10891090          }
     
    10921093
    10931094      my ($fpath,$fname) = ($pkgfile =~ m|(.+?/?)?([^/]+/?)$|); # We don't need $fname now, but we might.
    1094       qx { mkdir -p $buildroot/$pkg$fpath }
     1095      qx { mkdir -p $specglobals{buildroot}/$pkg$fpath }
    10951096        if $fpath && $fpath ne '';
    1096       qx { mv $buildroot$pkgfile $buildroot/$pkg$fpath };
     1097      qx { mv $specglobals{buildroot}$pkgfile $specglobals{buildroot}/$pkg$fpath };
    10971098    }
    10981099
     
    11001101    # comma and space here (if needed) in case there were "Requires" specified
    11011102    # in the spec file - those would precede these.
    1102     $pkgdata{$pkg}{requires} .= getreqs("$buildroot/$pkg") if ! $NoAutoReq;
     1103    $pkgdata{$pkg}{requires} .= getreqs("$specglobals{buildroot}/$pkg") if ! $NoAutoReq;
    11031104
    11041105    # magic needed to properly version dependencies...
     
    11541155
    11551156    # Gotta do this next, otherwise the control file has nowhere to go.  >:(
    1156     mkdir "$buildroot/$pkg/DEBIAN";
     1157    mkdir "$specglobals{buildroot}/$pkg/DEBIAN";
    11571158
    11581159    # Hack the filename for the package into a Debian-tool-compatible format.  GRRRRRR!!!!!
     
    11651166        or die $!;
    11661167    print DEBSCRIPT $scriptletbase;
    1167     print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot/$pkg $topdir/DEBS/$pkgdata{$pkg}{arch}/".
     1168    print DEBSCRIPT "fakeroot dpkg-deb -b $specglobals{buildroot}/$pkg $topdir/DEBS/$pkgdata{$pkg}{arch}/".
    11681169        "$pkgdata{$pkg}{name}_".
    11691170        (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
     
    11891190    $control .= "$pkgdata{$pkg}{desc}\n";
    11901191
    1191     open CONTROL, ">$buildroot/$pkg/DEBIAN/control";
     1192    open CONTROL, ">$specglobals{buildroot}/$pkg/DEBIAN/control";
    11921193    print CONTROL $control;
    11931194    close CONTROL;
     
    11961197    # in so dpkg-deb can tag them.
    11971198    if ($pkgdata{$pkg}{conffiles}) {
    1198       open CONFLIST, ">$buildroot/$pkg/DEBIAN/conffiles";
     1199      open CONFLIST, ">$specglobals{buildroot}/$pkg/DEBIAN/conffiles";
    11991200      foreach my $conffile (@{$pkgdata{$pkg}{conflist}}) {
    12001201        $conffile = expandmacros($conffile, 'g');
    1201         my @tmp = glob "$buildroot/$pkg/$conffile";
     1202        my @tmp = glob "$specglobals{buildroot}/$pkg/$conffile";
    12021203        foreach (@tmp) {
    1203           s|$buildroot/$pkg/||g;        # nrgl.  gotta be a better way to do this...
     1204          s|$specglobals{buildroot}/$pkg/||g;   # nrgl.  gotta be a better way to do this...
    12041205          s/\s+/\n/g;   # Not gonna support spaces in filenames.  Ewww.
    12051206          print CONFLIST "$_\n";
     
    12121213    if ($pkgdata{$pkg}{'pre'}) {
    12131214      $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'pre'},'gp');
    1214       open PREINST, ">$buildroot/$pkg/DEBIAN/preinst";
     1215      open PREINST, ">$specglobals{buildroot}/$pkg/DEBIAN/preinst";
    12151216      print PREINST "#!/bin/sh\nset -e\n\n";
    12161217      print PREINST $pkgdata{$pkg}{'pre'};
    12171218      close PREINST;
    1218       chmod 0755, "$buildroot/$pkg/DEBIAN/preinst";
     1219      chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/preinst";
    12191220    }
    12201221    if ($pkgdata{$pkg}{'post'}) {
    12211222      $pkgdata{$pkg}{'post'} = expandmacros($pkgdata{$pkg}{'post'},'gp');
    1222       open POSTINST, ">$buildroot/$pkg/DEBIAN/postinst";
     1223      open POSTINST, ">$specglobals{buildroot}/$pkg/DEBIAN/postinst";
    12231224      print POSTINST "#!/bin/sh\nset -e\n\n";
    12241225      print POSTINST $pkgdata{$pkg}{'post'};
    12251226      close POSTINST;
    1226       chmod 0755, "$buildroot/$pkg/DEBIAN/postinst";
     1227      chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/postinst";
    12271228    }
    12281229    if ($pkgdata{$pkg}{'preun'}) {
    12291230      $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'preun'},'gp');
    1230       open PREUNINST, ">$buildroot/$pkg/DEBIAN/prerm";
     1231      open PREUNINST, ">$specglobals{buildroot}/$pkg/DEBIAN/prerm";
    12311232      print PREUNINST "#!/bin/sh\nset -e\n\n";
    12321233      print PREUNINST $pkgdata{$pkg}{'preun'};
    12331234      close PREUNINST;
    1234       chmod 0755, "$buildroot/$pkg/DEBIAN/prerm";
     1235      chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/prerm";
    12351236    }
    12361237    if ($pkgdata{$pkg}{'postun'}) {
    12371238      $pkgdata{$pkg}{'postun'} = expandmacros($pkgdata{$pkg}{'postun'},'gp');
    1238       open POSTUNINST, ">$buildroot/$pkg/DEBIAN/postrm";
     1239      open POSTUNINST, ">$specglobals{buildroot}/$pkg/DEBIAN/postrm";
    12391240      print POSTUNINST "#!/bin/sh\nset -e\n\n";
    12401241      print POSTUNINST $pkgdata{$pkg}{'postun'};
    12411242      close POSTUNINST;
    1242       chmod 0755, "$buildroot/$pkg/DEBIAN/postrm";
     1243      chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/postrm";
    12431244    }
    12441245
     
    14861487
    14871488  # To allow the FHS-ish %configure and %makeinstall to work The Right Way.
    1488   # (Without clobbering the global $buildroot.)
     1489  # (Without clobbering the global $specglobals{buildroot}.)
    14891490  my $prefix = '';
    14901491
     
    15141515  } # done make
    15151516
     1517# %makeinstall expands with recursive macros in rpm.  whee.
    15161518  if ($section =~ /i/) {
    15171519    # This is where we need to mangle $prefix.
    1518     $macrostring =~ s'%makeinstall'make %{fhs} install';
    1519     $prefix = $buildroot;
     1520    $macrostring =~ s'%makeinstall'make \
     1521        prefix=%{?buildroot:%{buildroot}}%{_prefix} \
     1522        exec_prefix=%{?buildroot:%{buildroot}}%{_exec_prefix} \
     1523        bindir=%{?buildroot:%{buildroot}}%{_bindir} \
     1524        sbindir=%{?buildroot:%{buildroot}}%{_sbindir} \
     1525        sysconfdir=%{?buildroot:%{buildroot}}%{_sysconfdir} \
     1526        datadir=%{?buildroot:%{buildroot}}%{_datadir} \
     1527        includedir=%{?buildroot:%{buildroot}}%{_includedir} \
     1528        libdir=%{?buildroot:%{buildroot}}%{_libdir} \
     1529        libexecdir=%{?buildroot:%{buildroot}}%{_libexecdir} \
     1530        localstatedir=%{?buildroot:%{buildroot}}%{_localstatedir} \
     1531        sharedstatedir=%{?buildroot:%{buildroot}}%{_sharedstatedir} \
     1532        mandir=%{?buildroot:%{buildroot}}%{_mandir} \
     1533        infodir=%{?buildroot:%{buildroot}}%{_infodir} \
     1534  install ';
     1535    $prefix = $specglobals{buildroot};
    15201536  } # done %install and/or %makeinstall
    15211537
     
    15661582  # Package data
    15671583  if ($section =~ /p/) {
    1568     $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
     1584    $macrostring =~ s/\%\{buildroot\}/$specglobals{buildroot}/gi;
    15691585    foreach my $source (keys %{$pkgdata{sources}}) {
    15701586      $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
     
    16101626    # support for **some** %if constructs.  Note that this breaks somewhat if
    16111627    # there's no value specified...  but so does rpm.
    1612 my $tmpcount = 0;
    1613     while ($macrostring =~ /\%\{(!\?|\?!|\?)([a-z0-9_.-]+)(?:\:([a-z0-9_.-]+))?\}/g) {       #Whew....
     1628
     1629    my $tmpcount = 0;   # runaway shutdown.  Not really sure how else to avoid getting stuck.
     1630    while ($macrostring =~ m/\%\{([?!]+)([a-z0-9_.-]+)(?:\:([a-z0-9_.\/\-\\]+)?)?\}/g) {       #Whew....
    16141631      my $qex = $1;
    16151632      my $macro = $2;
    1616       my $value = $3;
     1633      my $value = (defined($3) ? $3 : '');
    16171634
    16181635      my $neg = '1' if $qex =~ /\!/;
     
    16221639        $value = '' if !$neg;
    16231640      }
    1624       $macrostring =~ s/\%\{!?\?\!?[a-z0-9_.-]+(?:\:[a-z0-9_.-]+)?\}/$value/;
     1641      $macrostring =~ s/\%\{[?!]+[a-z0-9_.-]+(?:\:([a-z0-9_.\/\-\\]+)?)?\}/$value/;
    16251642
    16261643# not certain about this, but I don't want to run away.  It *can* happen if planned carefully.  :/
    16271644$tmpcount++;
    1628 die "excessive recursive macro replacement;  dying.\n" if $tmpcount > 6;
     1645# %makeinstall has 13 occurrences.  D'Oh!
     1646die "excessive recursive macro replacement;  dying.\n" if $tmpcount > 14;
    16291647
    16301648    } # while()
Note: See TracChangeset for help on using the changeset viewer.