Changeset 5 for trunk


Ignore:
Timestamp:
10/28/05 18:04:31 (19 years ago)
Author:
kdeugau
Message:

/trunk

checkpoint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/debbuild

    r4 r5  
    1010# Last update by $Author$
    1111###
     12
     13use strict;
    1214
    1315# Program flow:
     
    4547my $topdir = "/usr/src/debian";
    4648
     49# Package data
     50# This is the form of $pkgdata{pkgname}{meta}
     51# meta includes Summary, Name, Version, Release, Group, Copyright,
     52#       Source, URL, Packager, BuildRoot, Description
     53my %pkgdata;
     54
     55# Functions
     56sub prep;
     57sub parse_spec;
     58
     59die "Not enough arguments\n" if #$argv == 0;
     60
    4761load_userconfig();
    4862parse_cmd();
     
    7791# Needs to handle "other files"
    7892sub load_userconfig {
    79   (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
     93  my (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
    8094  if (-e "$homedir/.debmacros") {
    8195    open USERMACROS,"<$homedir/.debmacros";
     
    8397      # And we also only handle the %_topdir macro at the moment.
    8498      if (/^\%_topdir/) {
    85         (undef,$tmp) = split /\s+/, $_;
     99        my (undef,$tmp) = split /\s+/, $_;
     100        $topdir = $tmp;
    86101      }
    87102    }
     
    111126        if (/^--short-circuit/) {
    112127          $cmdopts{short} = 'y';
     128        } elsif (/^--rebuild/) {
     129          $cmdopts{type} = 's';
    113130        } else {
    114131          print "Long opt $_\n";
    115132        }
    116133      } else {
    117         if (/^-[bts]/) {
    118           ($cmdopts{stage}) = (/^-[bts]([pcilabs])/);
    119           ($cmdopts{type}) = (/^-([bts])[pcilabs]/);
     134        if (/^-[bt]/) {
     135          if ($cmdopts{stage} eq 's') {
     136            # Mutually exclusive options.
     137            die "Can't use $_ with --rebuild\n";
     138          } else {
     139            ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
     140            ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
     141          }
    120142        } elsif (/^-v/) {
    121143          # bump verbosity.  Not sure what I'll actually do here...
     
    125147      }
    126148    } else {
    127       print "Non-option arg $_\n";
     149      # --buildroot is the only option that takes an argument
     150      # Therefore, any *other* bare arguments are the spec file,
     151      # tarball, or source package we're operating on - depending
     152      # on which one we meet.
     153      if ($prevopt eq '--buildroot') {
     154        # Set buildroot
     155      } else {
     156        if ($cmdopts{type} eq 's') {
     157          # Source package
     158          if (!/\.src\.(deb|rpm)$/) {
     159            die "Can't --rebuild with $_\n";
     160          }
     161        } elsif ($cmdopts{type} eq 'b') {
     162          $specfile = $_;
     163          # Spec file
     164        } else {
     165          # Tarball
     166        }
     167      }
    128168    }
    129169  }
     
    175215# Unpacks the tarball from the SOURCES directory to the BUILD directory.
    176216# Speaks gzip and bzip2.
    177 # Requires the "package name"
    178217# Finishes by applying patches in %prep section of spec file
    179218sub prep {
    180   my $pkgname = shift;
    181  
     219  if ($cmdopts{type} eq 'b') {
     220    # Need to read the spec file to find the tarball
     221    parse_spec();
     222
     223    # Need to find the filename part of the tarball.  In theory, we
     224    # could go out to the URL and retrieve it, but that's Messy.
     225# want to make this local
     226    $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
     227
     228    if ($pkgdata{main}{source} =~ /(.+)\.tar\.gz$/) {
     229      -e "$topdir/BUILD/$1" && system "rm -rf $topdir/BUILD/$1";
     230      system "cd $topdir/BUILD;tar -zxvf $topdir/SOURCES/$pkgdata{main}{source}";
     231    } elsif ($pkgdata{main}{source} =~ /(.+)\.tar\.bz2$/) {
     232      -e "$topdir/BUILD/$1" && system "rm -rf $topdir/BUILD/$1";
     233      system "cd $topdir/BUILD;tar -jxvf $topdir/SOURCES/$pkgdata{main}{source}";
     234    } else {
     235      die "Unknown source tarball format\n";
     236    }
     237    # And now for patches.  (not)
     238  }
    182239} # end prep()
    183240
    184241
    185 sub build {}
     242## parse_spec()
     243# Parse the .spec file once we've.... uh....
     244sub parse_spec {
     245  open SPECFILE,"<$specfile";
     246
     247  while (<SPECFILE>) {
     248    next if /^#/;
     249    next if /^\s+$/;
     250    if (/^\%/) {
     251      # A macro that needs further processing.
     252      if (/^\%build/) {
     253        # %build.  This is pretty much just a shell script.
     254      }
     255    } else {
     256      if (/^summary:\s+(.+)/i) {
     257        $pkgdata{main}{summary} = $1;
     258      } elsif (/^name:\s+(.+)/i) {
     259        $pkgdata{main}{name} = $1;
     260      } elsif (/^version:\s+(.+)/i) {
     261        $pkgdata{main}{version} = $1;
     262      } elsif (/^release:\s+(.+)/i) {
     263        $pkgdata{main}{release} = $1;
     264      } elsif (/^group:\s+(.+)/i) {
     265        $pkgdata{main}{group} = $1;
     266      } elsif (/^copyright:\s+(.+)/i) {
     267        $pkgdata{main}{copyright} = $1;
     268      } elsif (/^url:\s+(.+)/i) {
     269        $pkgdata{main}{url} = $1;
     270      } elsif (/^packager:\s+(.+)/i) {
     271        $pkgdata{main}{packager} = $1;
     272      } elsif (/^source:\s+(.+)/i) {
     273        $pkgdata{main}{source} = $1;
     274      }
     275#Name: suwrap
     276#Version: 0.04
     277#Release: 3
     278#Group: Applications/System
     279#Copyright: WebHart internal ONLY.  :(
     280#BuildArchitectures: i386
     281#BuildRoot: /tmp/%{name}-%{version}
     282#Url: http://virtual.webhart.net
     283#Packager: Kris Deugau <kdeugau@deepnet.cx>
     284#Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
     285
     286    }
     287  }
     288  # Parse and replace macros in $pkgdata{}{}
     289  # Start with the ones I use
     290  $pkgdata{main}{source} =~ s/\%\{name\}/$pkgdata{main}{name}/;
     291  $pkgdata{main}{source} =~ s/\%\{version\}/$pkgdata{main}{version}/;
     292} # end parse_spec()
     293
     294
     295## build()
     296# Execute commands provided as a shell script.  It may prove simpler
     297# to do as rpm does and actually create a little shell script.
     298sub build {
     299} # end build()
     300
     301
    186302sub install {}
    187303sub binpackage {}
Note: See TracChangeset for help on using the changeset viewer.