Changeset 7 for trunk


Ignore:
Timestamp:
11/01/05 16:09:06 (19 years ago)
Author:
kdeugau
Message:

/trunk

Checkpoint.
%prep, %build, and %install functionality is (should be) complete.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r6 r7  
    1313use strict;
    1414use warnings;
     15use Fcntl;      # for sysopen flags
    1516
    1617# Program flow:
     
    3334my $tarball;
    3435my $srcpkg;
     36my $cmdbuildroot;
     37my $tarballdir; # This should really be initialized, but the coding makes it, um, ugly.
    3538
    3639# Initialized globals
     
    4144        );
    4245my $topdir = "/usr/src/debian";
     46my $buildroot = "/var/tmp/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
    4347
    4448# "Constants"
     
    8589my $buildscript;
    8690my $installscript;
     91my $cleanscript;
    8792
    8893# Functions
     
    9297die "Not enough arguments\n" if #$argv == 0;
    9398
     99##main
     100
    94101load_userconfig();
    95102parse_cmd();
    96103
     104if ($cmdopts{type} eq 'b') {
     105  # Need to read the spec file to find the tarball.  Note that
     106  # this also generates most of the shell script required.
     107  parse_spec();
     108}
     109
    97110# Hokay.  Need to:
    98111# Execute prep if *not* --short-circuit
    99 prep() if ($cmdopts{short} ne 'y');
    100 
    101 if ($cmdopts{stage} =~ /ciab/) {
    102   # Execute build if bc
    103   # Execute build if bi, ba, bb and NOT --short-circuit
    104   build() if ( ($cmdopts{stage} eq 'c') ||
    105         (($cmdopts{stage} =~ /iab/) && ($cmdopts{short} ne 'y'))
    106         );
    107 
    108   # -> Execute
    109   install() if ($cmdopts{short} ne 'y');
     112if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
     113  prep();
     114}
     115if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
     116  build();
     117}
     118if ($cmdopts{stage} =~ /[ilabs]/) {
     119  install();
     120}
     121if ($cmdopts{stage} eq 'a') {
    110122  binpackage();
    111 }
    112 
    113 srcpackage();
    114 
    115 
     123  srcpackage();
     124}
     125if ($cmdopts{stage} eq 'b') {
     126  binpackage();
     127}
     128if ($cmdopts{stage} eq 's') {
     129  srcpackage();
     130}
    116131
    117132# Just in case.
     
    128143    open USERMACROS,"<$homedir/.debmacros";
    129144    while (<USERMACROS>) {
    130       # And we also only handle the %_topdir macro at the moment.
     145      # And we also only handle a few macros at the moment.
    131146      if (/^\%_topdir/) {
    132147        my (undef,$tmp) = split /\s+/, $_;
     
    152167  foreach (@ARGV) {
    153168    chomp;
    154     $prevopt = $_;
     169
    155170    # Is it an option?
    156171    if (/^-/) {
     172
    157173      # Is it a long option?
    158174      if (/^--/) {
     
    185201      # on which one we meet.
    186202      if ($prevopt eq '--buildroot') {
    187         # Set buildroot
     203        $cmdbuildroot = $_;
    188204      } else {
    189205        if ($cmdopts{type} eq 's') {
    190206          # Source package
    191           if (!/\.src\.(deb|rpm)$/) {
     207          if (!/\.src\.(deb|rpm)$/) {
    192208            die "Can't --rebuild with $_\n";
    193209          }
     
    200216      }
    201217    }
    202   }
     218    $prevopt = $_;
     219  } # foreach @ARGV
    203220
    204221  # Some cross-checks.  rpmbuild limits --short-circuit to just
     
    245262
    246263
    247 ## prep()
    248 # Unpacks the tarball from the SOURCES directory to the BUILD directory.
    249 # Speaks gzip and bzip2.
    250 # Finishes by applying patches in %prep section of spec file
    251 sub prep {
    252   if ($cmdopts{type} eq 'b') {
    253     # Need to read the spec file to find the tarball
    254     parse_spec();
    255 
    256     # Need to find the filename part of the tarball.  In theory, we
    257     # could go out to the URL and retrieve it, but that's Messy.
    258 # want to make this local
    259     $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
    260 
    261     if ($pkgdata{main}{source} =~ /(.+)\.tar\.gz$/) {
    262       -e "$topdir/BUILD/$1" && system "rm -rf $topdir/BUILD/$1";
    263 #      system "cd $topdir/BUILD;tar -zxvvf $topdir/SOURCES/$pkgdata{main}{source}";
    264     } elsif ($pkgdata{main}{source} =~ /(.+)\.tar\.bz2$/) {
    265       -e "$topdir/BUILD/$1" && system "rm -rf $topdir/BUILD/$1";
    266       system "cd $topdir/BUILD;tar -jxvvf $topdir/SOURCES/$pkgdata{main}{source}";
    267     } else {
    268       die "Unknown source tarball format\n";
    269     }
    270     # And now for patches.  (not)
    271   }
    272 } # end prep()
    273 
    274 
    275264## parse_spec()
    276265# Parse the .spec file once we've.... uh....
     
    298287            # Parse out the %setup macro.  Note that we aren't supporting
    299288            # most of RPM's %setup features.
    300             $prepscript .= "cd $topdir/BUILD\n".
    301                 ( /\s+-n\s+([^\s]+)\s+/ ?
    302                   "rm -rf $1\n" : "rm -rf $pkgdata{main}{name}-$pkgdata{main}{version}\n" ).
    303                 "tar -".
     289            $prepscript .= "cd $topdir/BUILD\n";
     290            if ( /\s+-n\s+([^\s]+)\s+/ ) {
     291              $tarballdir = $1;
     292            } else {
     293              $tarballdir = "$pkgdata{main}{name}-$pkgdata{main}{version}";
     294            }
     295            $prepscript .= "rm -rf $tarballdir\ntar -".
    304296                ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
    305297                ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
     
    324316        # %build.  This is pretty much just a shell script.  There
    325317        # *are* a few macros, but we're not going to deal with them yet.
     318        $buildscript .= "cd $tarballdir\n";
    326319        while (<SPECFILE>) {
    327320          redo LINE if /^\%/;
     
    330323      }
    331324      if (/^\%install/) {
     325        $installscript .= "cd $tarballdir\n";
    332326        while (<SPECFILE>) {
    333327          redo LINE if /^\%/;
     
    336330      }
    337331      if (/^\%clean/) {
     332        while (<SPECFILE>) {
     333          redo LINE if /^\%/;
     334          $cleanscript .= $_;
     335        }
    338336      }
    339337      if (/^\%post/) {
     
    361359      } elsif (/^packager:\s+(.+)/i) {
    362360        $pkgdata{main}{packager} = $1;
     361      } elsif (/^buildroot:\s+(.+)/i) {
     362        $buildroot = $1;
    363363      } elsif (/^source:\s+(.+)/i) {
    364364        $pkgdata{main}{source} = $1;
     
    378378    }
    379379  }
    380   # Parse and replace macros in $pkgdata{}{}
     380  # Parse and replace macros
    381381  # Start with the ones I use
    382   $pkgdata{main}{source} =~ s/\%\{name\}/$pkgdata{main}{name}/;
    383   $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/;
     382#  $pkgdata{main}{source} =~ s/\%\{name\}/$pkgdata{main}{name}/;
     383#  $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/;
     384
     385# Scriptlet core.  Use /g to make sure all occurrences get tweaked.
     386  # "real" globals (apply to all packages the same way)
     387  $scriptletbase =~ s/\%\{_topdir\}/$topdir/g;
     388
     389  # "fake" globals (may be tweaked by package)
     390  $buildroot = $cmdbuildroot if $cmdbuildroot;
     391  $scriptletbase =~ s/\%\{buildroot\}/$buildroot/g;
     392
     393  # sub-package(compatible) stuff
     394  $scriptletbase =~ s/\%\{name\}/$pkgdata{main}{name}/g;
     395  $scriptletbase =~ s/\%\{version\}/$pkgdata{main}{version}/g;
     396  $scriptletbase =~ s/\%\{release\}/$pkgdata{main}{release}/g;
     397
    384398} # end parse_spec()
     399
     400
     401## prep()
     402# Unpacks the tarball from the SOURCES directory to the BUILD directory.
     403# Speaks gzip and bzip2.
     404# Finishes by applying patches in %prep section of spec file
     405sub prep {
     406  {
     407    # create script filename
     408    my $prepscriptfile = "/var/tmp/deb-tmp.prep.".int(rand(99998)+1);
     409    sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
     410        or die $!;
     411    print PREPSCRIPT $scriptletbase;
     412    print PREPSCRIPT $prepscript;
     413    close PREPSCRIPT;
     414
     415    # execute
     416    print "Calling \%prep script $prepscriptfile...\n";
     417    system("/bin/sh -e $prepscriptfile") == 0
     418        or die "Can't exec: $!\nalso: $?";
     419
     420    # and clean up
     421    unlink $prepscriptfile;
     422  }
     423} # end prep()
    385424
    386425
     
    389428# to do as rpm does and actually create a little shell script.
    390429sub build {
     430  # create script filename
     431  my $buildscriptfile = "/var/tmp/deb-tmp.build.".int(rand(99998)+1);
     432  sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
     433        or die $!;
     434  print BUILDSCRIPT $scriptletbase;
     435  print BUILDSCRIPT $buildscript;
     436  close BUILDSCRIPT;
     437
     438  # execute
     439  print "Calling \%build script $buildscriptfile...\n";
     440  system("/bin/sh -e $buildscriptfile") == 0
     441        or die "Can't exec: $!\nalso: $?";
     442
     443  # and clean up
     444  unlink $buildscriptfile;
    391445} # end build()
    392446
    393447
    394 sub install {}
     448## install()
     449# Creates and executes %install script(let)
     450sub install {
     451  # create script filename
     452  my $installscriptfile = "/var/tmp/deb-tmp.inst.".int(rand(99998)+1);
     453  sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
     454        or die $!;
     455  print INSTSCRIPT $scriptletbase;
     456  print INSTSCRIPT $cleanscript;        # Clean up our install target before installing into it.
     457  print INSTSCRIPT $installscript;
     458  close INSTSCRIPT;
     459
     460  # execute
     461  print "Calling \%install script $installscriptfile...\n";
     462  system("/bin/sh -e $installscriptfile") == 0
     463        or die "Can't exec: $!\nalso: $?";
     464
     465  # and clean up
     466  unlink $installscriptfile;
     467} # end install()
     468
     469
    395470sub binpackage {}
    396471sub srcpackage {}
Note: See TracChangeset for help on using the changeset viewer.