Changeset 95


Ignore:
Timestamp:
04/27/07 17:10:19 (18 years ago)
Author:
kdeugau
Message:

/trunk

Add support for basic %if constructs:

%if <expression>
<parse this bit of spec file>
%else
<parse this bit of spec file>
%endif

<expression> will usually be %{?macro:0}%{?!macro:1}, but the
"execute-shell-code" %(<shell code>) expansion can also be used if the
output is suitable. %else is optional. %if's should be nestable
very deeply - probably 231-1 at least.

Also includes a bugfix on the initialization of $tarballdir.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r94 r95  
    5757my $srcpkg;
    5858my $cmdbuildroot;
    59 my $tarballdir; = '%{name}-%{version}'; # We do this in case of a spec file not using %setup...
     59my $tarballdir = '%{name}-%{version}';  # We do this in case of a spec file not using %setup...
    6060my %specglobals;        # For %define's in specfile, among other things.
    6161
     
    418418  open SPECFILE,"<$specfile" or die "specfile ($specfile) barfed: $!";
    419419
     420  my $iflevel = 0;
    420421  my $buildarch = $hostarch;
    421422  $pkgdata{main}{arch} = $hostarch;
     
    430431      if (my ($key, $def) = (/^\%define\s+([^\s]+)\s+(.+)$/) ) {
    431432        $specglobals{$key} = expandmacros($def,'g');
     433      }
     434
     435      if (/^\%if/) {
     436        s/^\%if//;
     437        my $expr = expandmacros($_, 'g');
     438        $iflevel++;
     439        next LINE if $expr != 0;        # This appears to be the only case we call false.
     440        while (<SPECFILE>) {
     441          if (/^\%endif/) {
     442            $iflevel--;
     443            next LINE;
     444          } elsif (/^\%else/) {
     445            next LINE;
     446          }
     447        }
     448      }
     449      if (/^\%else/) {
     450       while (<SPECFILE>) {
     451         if (/^\%endif/) {
     452           $iflevel--;
     453           next LINE;
     454         }
     455       }
     456      }
     457      if (/^\%endif/) {
     458        $iflevel--;
     459        next LINE;
    432460      }
    433461
     
    13261354    }
    13271355
     1356    # support for **some** %if constructs.  Note that this breaks somewhat if
     1357    # there's no value specified...  but so does rpm.
     1358    while ($macrostring =~ /\%\{\?(\!)?([a-z0-9_.-]+)(?:\:([a-z0-9_.-]+))?\}/) {       #Whew....
     1359      my $neg = $1;
     1360      my $macro = $2;
     1361      my $value = $3;
     1362      if ($specglobals{$macro}) {
     1363        $value = '' if $neg;
     1364      } else {
     1365        $value = '' if !$neg;
     1366      }
     1367      $macrostring =~ s/\%\{\?\!?[a-z0-9_.-]+(?:\:[a-z0-9_.-]+)?\}/$value/;
     1368    }
     1369
    13281370    # system programs.  RPM uses a global config file for these;  we'll just
    13291371    # ASS-U-ME and make life a little simpler.
Note: See TracChangeset for help on using the changeset viewer.