Changeset 14


Ignore:
Timestamp:
11/07/05 17:00:38 (19 years ago)
Author:
kdeugau
Message:

/trunk

Cleanup and commenting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r13 r14  
    7676  export RPM_BUILD_ROOT
    7777);
    78 #my $tmp = `dpkg-architecture`; # Debian buildarch goop.
    79 #$tmp =~ s/^(.*)$/  $1/g;
    80 #print $tmp;
    8178foreach (`dpkg-architecture`) {
    8279  s/=(.+)/="$1"/;
     
    103100my $cleanscript;
    104101
    105 # Functions
    106 sub prep;
    107 sub parse_spec;
    108 
    109102die "Not enough arguments\n" if #$argv == 0;
    110103
     
    129122
    130123# Hokay.  Need to:
    131 # Execute prep if *not* --short-circuit
     124# -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
    132125if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
    133126  prep();
    134127}
     128# -> build if -.c OR (-.[ilabs] AND !--short-circuit)
    135129if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
    136130  build();
    137131}
     132# -> install if -.[ilabs]
    138133if ($cmdopts{stage} =~ /[ilabs]/) {
    139134  install();
    140135}
     136# -> binpkg and srcpkg if -.a
    141137if ($cmdopts{stage} eq 'a') {
    142138  binpackage();
    143139  srcpackage();
    144140}
     141# -> binpkg if -.b
    145142if ($cmdopts{stage} eq 'b') {
    146143  binpackage();
    147144}
     145# -> srcpkg if -.s
    148146if ($cmdopts{stage} eq 's') {
    149147  srcpackage();
     
    201199        }
    202200      } else {
     201        # Not a long option
    203202        if (/^-[bt]/) {
    204203          if ($cmdopts{stage} eq 's') {
     
    206205            die "Can't use $_ with --rebuild\n";
    207206          } else {
     207            # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
    208208            ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
    209209            ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
     
    215215        }
    216216      }
    217     } else {
     217
     218    } else { # Not an option argument
     219
    218220      # --buildroot is the only option that takes an argument
    219221      # Therefore, any *other* bare arguments are the spec file,
     
    241243  # Some cross-checks.  rpmbuild limits --short-circuit to just
    242244  # the "compile" and "install" targets - with good reason IMO.
     245  # Note that --short-circuit with -.p is not really an error, just redundant.
    243246  # NB - this is NOT fatal, just ignored!
    244247  if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
     
    246249    $cmdopts{short} = 'n';
    247250  }
     251
    248252  # Valid options, with example arguments (if any):
    249253# Build from .spec file; mutually exclusive:
     
    283287
    284288## parse_spec()
    285 # Parse the .spec file once we've.... uh....
     289# Parse the .spec file.
    286290sub parse_spec {
    287291  open SPECFILE,"<$specfile";
    288292
    289293LINE: while (<SPECFILE>) {
    290     next if /^#/;
    291     next if /^\s+$/;
     294    next if /^#/;       # Ignore comments...
     295    next if /^\s+$/;    # ... and blank lines.
     296
    292297    if (/^\%/) {
    293298      # A macro that needs further processing.
     299
    294300      if (/^\%description/) {
    295301        $pkgdata{main}{desc} .= $_;
     
    308314
    309315        # 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');
    312317
    313318PREPSCRIPT: while (<SPECFILE>) {
    314319          if (/^\%setup/) {
    315320            # Parse out the %setup macro.  Note that we aren't supporting
    316             # most of RPM's %setup features.
     321            # many of RPM's %setup features.
    317322            $prepscript .= "cd $topdir/BUILD\n";
    318323            if ( /\s+-n\s+([^\s]+)\s+/ ) {
     
    362367          if (/^\%makeinstall/) {
    363368            $installscript .= expandmacros($_,'igbp');
    364 print $installscript;
    365 #print "\n$tmp\n"; die;
    366 #            $installscript .= $tmp;
    367369          } else {
    368370            last INSTALLSCRIPT if /^\%/;
     
    386388        # Danger! Danger!
    387389      }
    388     } else {
     390
     391    } else {    # Data from the spec file "header"
     392
    389393      if (/^summary:\s+(.+)/i) {
    390394        $pkgdata{main}{summary} = $1;
     
    424428    }
    425429  }
    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.
    430432
    431433  # Expand macros as necessary.
     
    439441
    440442## 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.
    444444sub prep {
    445445  # Replace some things here just to make sure.
     
    457457  print "Calling \%prep script $prepscriptfile...\n";
    458458  system("/bin/sh -e $prepscriptfile") == 0
    459         or die "Can't exec: $!\nalso: $?";
     459        or die "Can't exec: $!\n";
    460460
    461461  # and clean up
     
    465465
    466466## 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.
    469468sub build {
    470469  # Expand the macros
     
    479478  close BUILDSCRIPT;
    480479
    481 #print "'$scriptletbase$buildscript'";
    482 #exit 0;
    483480  # execute
    484481  print "Calling \%build script $buildscriptfile...\n";
    485482  system("/bin/sh -e $buildscriptfile") == 0
    486         or die "Can't exec: $!\nalso: $?";
     483        or die "Can't exec: $!\n";
    487484
    488485  # and clean up
     
    492489
    493490## install()
    494 # Creates and executes %install script(let)
     491# Writes and executes the %install script (mostly) built while reading the spec file.
    495492sub install {
    496493  # Expand the macros
     
    509506  print "Calling \%install script $installscriptfile...\n";
    510507  system("/bin/sh -e $installscriptfile") == 0
    511         or die "Can't exec: $!\nalso: $?";
     508        or die "Can't exec: $!\n";
    512509
    513510  # and clean up
     
    518515## binpackage()
    519516# 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.
    520519sub binpackage {
    521   # Some checks on the .deb file location
     520  # Make sure we have somewhere to write the .deb file
    522521  if (!-e "$topdir/DEBS/i386") {
    523522#       "if [ -e $topdir/DEBS/i386 ]; then\n\tmkdir $topdir/DEBS/i386\nfi\n".
    524523    mkdir "$topdir/DEBS/i386";
    525524  }
     525
    526526  # Gotta do this first, otherwise the control file has nowhere to go.  >:(
    527527  mkdir "$buildroot/DEBIAN";
     
    534534  print DEBSCRIPT "tree $buildroot\n".
    535535        "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.  >:(
    537537  close DEBSCRIPT;
    538538
     
    545545        "Description: $pkgdata{main}{desc}\n";
    546546
    547 eval {
    548547  open CONTROL, ">$buildroot/DEBIAN/control";
    549548  print CONTROL $control;
    550549  close CONTROL;
    551 };
    552 if ($@) {
    553   print $@;
    554 }
    555550
    556551#Package: httpd
     
    567562# http://home.samfundet.no/~sesse/mpm-itk/.
    568563
    569 
    570564  # execute
    571565  print "Creating .deb for $pkgdata{main}{name}...\n";
    572566  system("/bin/sh -e $debscriptfile") == 0
    573         or die "Can't exec: $!\nalso: $?";
     567        or die "Can't exec: $!\n";
    574568
    575569  # and clean up
    576570  unlink $debscriptfile;
    577 
    578571} # end binpackage()
    579572
     
    584577## expandmacros()
    585578# 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.
    586581sub expandmacros {
    587582  my $macrostring = shift;
    588   my $section = shift;  # We'll want to split things up a bit eventually.
     583  my $section = shift;
    589584
    590585  # To allow the FHS-ish %configure, %make, and %makeinstall to work The Right Way.
     
    637632    # over the "default" ones.
    638633
    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
    642639    $macrostring =~ s|%{_includedir}|$prefix%{_prefix\}/include|g;      #/usr/include
    643640    $macrostring =~ s|%{_libdir}|$prefix%{_exec_prefix}/%{_lib}|g;      #/usr/lib
    644     $macrostring =~ s|%{_lib}|lib|g;                                            #?
     641    $macrostring =~ s|%{_lib}|lib|g;                                    #?
    645642    $macrostring =~ s|%{_localstatedir}|$prefix/var|g;                  #/var
    646643    $macrostring =~ s|%{_sharedstatedir}|$prefix%{_prefix}/com|g;       #/usr/com WTF?
    647     $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g;                             #/etc
     644    $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g;                     #/etc
    648645    $macrostring =~ s|%{_datadir}|$prefix%{_prefix}/share|g;            #/usr/share
    649646    $macrostring =~ s|%{_libexecdir}|$prefix%{_exec_prefix}/libexec|g;  #/usr/libexec
    650     $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g;                #/usr/sbin
     647    $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g;        #/usr/sbin
    651648    $macrostring =~ s|%{_bindir}|$prefix%{_exec_prefix}/bin|g;          #/usr/bin
    652649    $macrostring =~ s|%{_exec_prefix}|$prefix%{_prefix}|g;              #/usr
    653     $macrostring =~ s|%{_prefix}|/usr|g;                        #/usr
     650    $macrostring =~ s|%{_prefix}|/usr|g;                                #/usr
    654651  } # done with config section
    655652
Note: See TracChangeset for help on using the changeset viewer.