[2] | 1 | #!/usr/bin/perl
|
---|
| 2 | # debbuild script
|
---|
[86] | 3 | # Shamelessly steals interface from rpm's "rpmbuild" to create
|
---|
[2] | 4 | # Debian packages. Please note that such packages are highly
|
---|
| 5 | # unlikely to conform to "Debian Policy".
|
---|
| 6 | ###
|
---|
| 7 | # SVN revision info
|
---|
| 8 | # $Date: 2007-04-17 16:18:42 +0000 (Tue, 17 Apr 2007) $
|
---|
| 9 | # SVN revision $Rev: 86 $
|
---|
| 10 | # Last update by $Author: kdeugau $
|
---|
| 11 | ###
|
---|
[86] | 12 | # Copyright 2005-2007 Kris Deugau <kdeugau@deepnet.cx>
|
---|
[56] | 13 | #
|
---|
| 14 | # This program is free software; you can redistribute it and/or modify
|
---|
| 15 | # it under the terms of the GNU General Public License as published by
|
---|
| 16 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 17 | # (at your option) any later version.
|
---|
| 18 | #
|
---|
| 19 | # This program is distributed in the hope that it will be useful,
|
---|
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 22 | # GNU General Public License for more details.
|
---|
| 23 | #
|
---|
| 24 | # You should have received a copy of the GNU General Public License
|
---|
| 25 | # along with this program; if not, write to the Free Software
|
---|
| 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
[2] | 27 |
|
---|
[5] | 28 | use strict;
|
---|
[6] | 29 | use warnings;
|
---|
[7] | 30 | use Fcntl; # for sysopen flags
|
---|
[36] | 31 | use Cwd 'abs_path'; # for finding where files really are
|
---|
[5] | 32 |
|
---|
[10] | 33 | # regex debugger
|
---|
| 34 | #use re "debug";
|
---|
| 35 |
|
---|
[3] | 36 | # Program flow:
|
---|
| 37 | # -> Parse/execute "system" config/macros (if any - should be rare)
|
---|
| 38 | # -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
|
---|
| 39 | # -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
|
---|
| 40 |
|
---|
[30] | 41 | sub expandmacros;
|
---|
| 42 |
|
---|
[2] | 43 | # User's prefs for dirs, environment, etc,etc,etc.
|
---|
| 44 | # config file ~/.debmacros
|
---|
| 45 | # Default ordered search paths for config/macros:
|
---|
| 46 | # /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
|
---|
| 47 | # /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
|
---|
| 48 | # **NOTE: May be possible to (ab)use bits of debhelper
|
---|
| 49 |
|
---|
| 50 | # Build tree
|
---|
| 51 | # default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
|
---|
| 52 |
|
---|
[3] | 53 | # Globals
|
---|
[77] | 54 | my $finalmessages = ''; # A place to stuff messages that I want printed at the *very* end of any processing.
|
---|
[3] | 55 | my $specfile;
|
---|
| 56 | my $tarball;
|
---|
| 57 | my $srcpkg;
|
---|
[7] | 58 | my $cmdbuildroot;
|
---|
| 59 | my $tarballdir; # This should really be initialized, but the coding makes it, um, ugly.
|
---|
[23] | 60 | my %specglobals; # For %define's in specfile, among other things.
|
---|
[6] | 61 |
|
---|
| 62 | # Initialized globals
|
---|
[3] | 63 | my $verbosity = 0;
|
---|
[4] | 64 | my %cmdopts = (type => '',
|
---|
| 65 | stage => 'a',
|
---|
| 66 | short => 'n'
|
---|
| 67 | );
|
---|
[6] | 68 | my $topdir = "/usr/src/debian";
|
---|
[13] | 69 | my $buildroot = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
|
---|
[6] | 70 |
|
---|
| 71 | # "Constants"
|
---|
[4] | 72 | my %targets = ('p' => 'Prep',
|
---|
| 73 | 'c' => 'Compile',
|
---|
| 74 | 'i' => 'Install',
|
---|
| 75 | 'l' => 'Verify %files',
|
---|
| 76 | 'a' => 'Build binary and source',
|
---|
| 77 | 'b' => 'Build binary',
|
---|
| 78 | 's' => 'Build source'
|
---|
| 79 | );
|
---|
[6] | 80 | my $scriptletbase =
|
---|
| 81 | q(#!/bin/sh
|
---|
[3] | 82 |
|
---|
[6] | 83 | RPM_SOURCE_DIR="%{_topdir}/SOURCES"
|
---|
| 84 | RPM_BUILD_DIR="%{_topdir}/BUILD"
|
---|
| 85 | RPM_OPT_FLAGS="-O2 -g -march=i386 -mcpu=i686"
|
---|
| 86 | RPM_ARCH="i386"
|
---|
| 87 | RPM_OS="linux"
|
---|
| 88 | export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
|
---|
| 89 | RPM_DOC_DIR="/usr/share/doc"
|
---|
| 90 | export RPM_DOC_DIR
|
---|
| 91 | RPM_PACKAGE_NAME="%{name}"
|
---|
| 92 | RPM_PACKAGE_VERSION="%{version}"
|
---|
| 93 | RPM_PACKAGE_RELEASE="%{release}"
|
---|
| 94 | export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
|
---|
| 95 | RPM_BUILD_ROOT="%{buildroot}"
|
---|
| 96 | export RPM_BUILD_ROOT
|
---|
[10] | 97 | );
|
---|
| 98 | foreach (`dpkg-architecture`) {
|
---|
| 99 | s/=(.+)/="$1"/;
|
---|
| 100 | $scriptletbase .= " $_";
|
---|
| 101 | }
|
---|
| 102 | $scriptletbase .=
|
---|
| 103 | q(
|
---|
[6] | 104 | set -x
|
---|
| 105 | umask 022
|
---|
| 106 | cd %{_topdir}/BUILD
|
---|
| 107 | );
|
---|
| 108 |
|
---|
[5] | 109 | # Package data
|
---|
| 110 | # This is the form of $pkgdata{pkgname}{meta}
|
---|
| 111 | # meta includes Summary, Name, Version, Release, Group, Copyright,
|
---|
[38] | 112 | # Source, URL, Packager, BuildRoot, Description, BuildReq(uires),
|
---|
| 113 | # Requires, Provides
|
---|
[6] | 114 | # 10/31/2005 Maybe this should be flatter? -kgd
|
---|
[5] | 115 | my %pkgdata;
|
---|
[27] | 116 | my @pkglist = ('main'); #sigh
|
---|
[23] | 117 | # Files listing. Embedding this in %pkgdata would be, um, messy.
|
---|
| 118 | my %filelist;
|
---|
[40] | 119 | my $buildreq = '';
|
---|
[5] | 120 |
|
---|
[6] | 121 | # Scriptlets
|
---|
[48] | 122 | my $prepscript = '';
|
---|
| 123 | my $buildscript = '';
|
---|
[23] | 124 | # %install doesn't need the full treatment from %clean; just an empty place to install to.
|
---|
| 125 | # NB - rpm doesn't do this; is it really necessary?
|
---|
| 126 | my $installscript = '[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT'."\n";
|
---|
[48] | 127 | my $cleanscript = '';
|
---|
[6] | 128 |
|
---|
[5] | 129 | die "Not enough arguments\n" if #$argv == 0;
|
---|
| 130 |
|
---|
[13] | 131 | # Snag some environment data
|
---|
| 132 | my $tmpdir;
|
---|
| 133 | if (defined $ENV{TMP} && $ENV{TMP} =~ /^(\/var)?\/tmp$/) {
|
---|
| 134 | $tmpdir = $ENV{TMP};
|
---|
| 135 | } else {
|
---|
| 136 | $tmpdir = "/var/tmp";
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[7] | 139 | ##main
|
---|
| 140 |
|
---|
[4] | 141 | load_userconfig();
|
---|
[3] | 142 | parse_cmd();
|
---|
| 143 |
|
---|
[50] | 144 | if ($cmdopts{install}) {
|
---|
| 145 | install_sdeb();
|
---|
| 146 | exit 0;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[81] | 149 | # output stage of --showpkgs
|
---|
[71] | 150 | if ($cmdopts{type} eq 'd') {
|
---|
| 151 | parse_spec();
|
---|
| 152 | foreach my $pkg (@pkglist) {
|
---|
| 153 | $pkgdata{$pkg}{name} =~ tr/_/-/;
|
---|
| 154 |
|
---|
| 155 | my $pkgfullname = "$pkgdata{$pkg}{name}_$pkgdata{$pkg}{version}-$pkgdata{main}{release}_i386.deb";
|
---|
| 156 |
|
---|
[76] | 157 | print "$pkgfullname\n" if $filelist{$pkg};
|
---|
[79] | 158 |
|
---|
[71] | 159 | }
|
---|
[80] | 160 | # Source package
|
---|
[85] | 161 | print "$pkgdata{main}{name}-$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb\n";
|
---|
[71] | 162 | exit 0;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[50] | 165 | # Stick --rebuild handling in here - basically install_sdeb()
|
---|
| 166 | # followed by tweaking options to run with -ba
|
---|
[54] | 167 | if ($cmdopts{type} eq 's') {
|
---|
[55] | 168 | if ($srcpkg =~ /\.src\.rpm$/) {
|
---|
[58] | 169 | my @srclist = qx { rpm -qlp $srcpkg };
|
---|
[55] | 170 | foreach (@srclist) {
|
---|
[54] | 171 | chomp;
|
---|
[55] | 172 | $specfile = "$topdir/SPECS/$_" if /\.spec$/;
|
---|
[54] | 173 | }
|
---|
[55] | 174 | qx { rpm -i $srcpkg };
|
---|
| 175 | } else {
|
---|
| 176 | install_sdeb();
|
---|
| 177 | my @srclist = qx { pax < $srcpkg };
|
---|
| 178 | foreach (@srclist) {
|
---|
| 179 | chomp;
|
---|
| 180 | $specfile = "$topdir/$_" if /SPECS/;
|
---|
| 181 | }
|
---|
[54] | 182 | }
|
---|
[55] | 183 | $cmdopts{type} = 'b';
|
---|
| 184 | $cmdopts{stage} = 'a';
|
---|
[54] | 185 | }
|
---|
[50] | 186 |
|
---|
[7] | 187 | if ($cmdopts{type} eq 'b') {
|
---|
| 188 | # Need to read the spec file to find the tarball. Note that
|
---|
| 189 | # this also generates most of the shell script required.
|
---|
| 190 | parse_spec();
|
---|
[38] | 191 | die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
|
---|
| 192 | if !checkbuildreq();
|
---|
[7] | 193 | }
|
---|
| 194 |
|
---|
[65] | 195 | if ($cmdopts{type} eq 't') {
|
---|
| 196 | # Need to unpack the tarball to find the spec file. Sort of the inverse of -b above.
|
---|
| 197 | # zcat $tarball |tar -t |grep .spec
|
---|
| 198 | # collect some info about the tarball
|
---|
| 199 | $specfile = "$topdir/BUILD/". qx { zcat $tarball |tar -t |grep .spec\$ };
|
---|
| 200 | chomp $specfile;
|
---|
| 201 | my ($fileonly, $dirname) = ($tarball =~ /(([a-zA-Z0-9._-]+)\.tar\.(?:gz|bz2))$/);
|
---|
| 202 |
|
---|
| 203 | $tarball = abs_path($tarball);
|
---|
| 204 | my $unpackcmd = "cd $topdir/BUILD; tar -".
|
---|
| 205 | ( $tarball =~ /\.tar\.gz$/ ? "z" : "" ).
|
---|
| 206 | ( $tarball =~ /\.tar\.bz2$/ ? "j" : "" ). "xf $tarball";
|
---|
| 207 | system "$unpackcmd";
|
---|
| 208 | system "cp $tarball $topdir/SOURCES/$fileonly";
|
---|
| 209 | system "cp $specfile $topdir/SPECS/";
|
---|
| 210 | parse_spec();
|
---|
| 211 | die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
|
---|
| 212 | if !checkbuildreq();
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[35] | 215 | # -> srcpkg if -.s
|
---|
| 216 | if ($cmdopts{stage} eq 's') {
|
---|
| 217 | srcpackage();
|
---|
| 218 | exit 0;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[4] | 221 | # Hokay. Need to:
|
---|
[14] | 222 | # -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
|
---|
[7] | 223 | if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 224 | prep();
|
---|
| 225 | }
|
---|
[14] | 226 | # -> build if -.c OR (-.[ilabs] AND !--short-circuit)
|
---|
[7] | 227 | if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 228 | build();
|
---|
| 229 | }
|
---|
[14] | 230 | # -> install if -.[ilabs]
|
---|
[28] | 231 | #if ($cmdopts{stage} eq 'i' || ($cmdopts{stage} =~ /[labs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 232 | if ($cmdopts{stage} =~ /[ilabs]/) {
|
---|
[7] | 233 | install();
|
---|
[30] | 234 | #foreach my $pkg (@pkglist) {
|
---|
| 235 | # print "files in $pkg:\n ".$filelist{$pkg}."\n";
|
---|
| 236 | #}
|
---|
| 237 |
|
---|
[7] | 238 | }
|
---|
[14] | 239 | # -> binpkg and srcpkg if -.a
|
---|
[7] | 240 | if ($cmdopts{stage} eq 'a') {
|
---|
[4] | 241 | binpackage();
|
---|
[7] | 242 | srcpackage();
|
---|
[4] | 243 | }
|
---|
[14] | 244 | # -> binpkg if -.b
|
---|
[7] | 245 | if ($cmdopts{stage} eq 'b') {
|
---|
| 246 | binpackage();
|
---|
| 247 | }
|
---|
[4] | 248 |
|
---|
[77] | 249 | # Spit out any closing remarks
|
---|
| 250 | print $finalmessages;
|
---|
| 251 |
|
---|
[4] | 252 | # Just in case.
|
---|
| 253 | exit 0;
|
---|
| 254 |
|
---|
| 255 |
|
---|
| 256 | ## load_userconfig()
|
---|
| 257 | # Loads user configuration (if any)
|
---|
| 258 | # Currently only handles .debmacros
|
---|
| 259 | # Needs to handle "other files"
|
---|
| 260 | sub load_userconfig {
|
---|
[5] | 261 | my (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
|
---|
[4] | 262 | if (-e "$homedir/.debmacros") {
|
---|
| 263 | open USERMACROS,"<$homedir/.debmacros";
|
---|
| 264 | while (<USERMACROS>) {
|
---|
[7] | 265 | # And we also only handle a few macros at the moment.
|
---|
[4] | 266 | if (/^\%_topdir/) {
|
---|
[5] | 267 | my (undef,$tmp) = split /\s+/, $_;
|
---|
| 268 | $topdir = $tmp;
|
---|
[4] | 269 | }
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
| 272 | } # end load_userconfig()
|
---|
| 273 |
|
---|
| 274 |
|
---|
[3] | 275 | ## parse_cmd()
|
---|
[4] | 276 | # Parses command line into global hash %cmdopts, other globals
|
---|
[3] | 277 | # Options based on rpmbuild's options
|
---|
| 278 | sub parse_cmd {
|
---|
| 279 | # Don't feel like coding my own option parser...
|
---|
| 280 | #use Getopt::Long;
|
---|
| 281 | # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
|
---|
| 282 | #use Getopt::Popt qw(:all);
|
---|
[4] | 283 | # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
|
---|
[3] | 284 |
|
---|
| 285 | # Stuff it.
|
---|
[4] | 286 | my $prevopt = '';
|
---|
[3] | 287 | foreach (@ARGV) {
|
---|
| 288 | chomp;
|
---|
[7] | 289 |
|
---|
[3] | 290 | # Is it an option?
|
---|
| 291 | if (/^-/) {
|
---|
[7] | 292 |
|
---|
[3] | 293 | # Is it a long option?
|
---|
| 294 | if (/^--/) {
|
---|
[4] | 295 | if (/^--short-circuit/) {
|
---|
| 296 | $cmdopts{short} = 'y';
|
---|
[5] | 297 | } elsif (/^--rebuild/) {
|
---|
| 298 | $cmdopts{type} = 's';
|
---|
[71] | 299 | } elsif (/^--showpkgs/) {
|
---|
| 300 | $cmdopts{type} = 'd'; # d for 'diagnostic' or 'debug' or 'dump'
|
---|
[4] | 301 | } else {
|
---|
| 302 | print "Long opt $_\n";
|
---|
| 303 | }
|
---|
[3] | 304 | } else {
|
---|
[14] | 305 | # Not a long option
|
---|
[5] | 306 | if (/^-[bt]/) {
|
---|
| 307 | if ($cmdopts{stage} eq 's') {
|
---|
| 308 | # Mutually exclusive options.
|
---|
| 309 | die "Can't use $_ with --rebuild\n";
|
---|
| 310 | } else {
|
---|
[14] | 311 | # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
|
---|
[5] | 312 | ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
|
---|
| 313 | ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
|
---|
| 314 | }
|
---|
[4] | 315 | } elsif (/^-v/) {
|
---|
| 316 | # bump verbosity. Not sure what I'll actually do here...
|
---|
[50] | 317 | } elsif (/^-i/) {
|
---|
| 318 | $cmdopts{install} = 1;
|
---|
| 319 | $prevopt = '-i';
|
---|
[4] | 320 | } else {
|
---|
| 321 | die "Bad option $_\n";
|
---|
| 322 | }
|
---|
[3] | 323 | }
|
---|
[14] | 324 |
|
---|
| 325 | } else { # Not an option argument
|
---|
| 326 |
|
---|
[5] | 327 | # --buildroot is the only option that takes an argument
|
---|
| 328 | # Therefore, any *other* bare arguments are the spec file,
|
---|
| 329 | # tarball, or source package we're operating on - depending
|
---|
| 330 | # on which one we meet.
|
---|
| 331 | if ($prevopt eq '--buildroot') {
|
---|
[7] | 332 | $cmdbuildroot = $_;
|
---|
[50] | 333 | } elsif ($prevopt eq '-i') {
|
---|
| 334 | $srcpkg = $_;
|
---|
[5] | 335 | } else {
|
---|
| 336 | if ($cmdopts{type} eq 's') {
|
---|
| 337 | # Source package
|
---|
[50] | 338 | if (!/(sdeb|\.src\.rpm)$/) {
|
---|
[5] | 339 | die "Can't --rebuild with $_\n";
|
---|
| 340 | }
|
---|
[50] | 341 | $srcpkg = $_;
|
---|
[71] | 342 | } elsif ($cmdopts{type} eq 'b' || $cmdopts{type} eq 'd') {
|
---|
[65] | 343 | # Spec file
|
---|
[5] | 344 | $specfile = $_;
|
---|
| 345 | } else {
|
---|
[65] | 346 | # Tarball build. Need to extract tarball to find spec file. Whee.
|
---|
| 347 | $tarball = $_;
|
---|
[5] | 348 | }
|
---|
| 349 | }
|
---|
[3] | 350 | }
|
---|
[7] | 351 | $prevopt = $_;
|
---|
| 352 | } # foreach @ARGV
|
---|
[4] | 353 |
|
---|
| 354 | # Some cross-checks. rpmbuild limits --short-circuit to just
|
---|
| 355 | # the "compile" and "install" targets - with good reason IMO.
|
---|
[14] | 356 | # Note that --short-circuit with -.p is not really an error, just redundant.
|
---|
[4] | 357 | # NB - this is NOT fatal, just ignored!
|
---|
[10] | 358 | if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
|
---|
[4] | 359 | warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
|
---|
[28] | 360 | $cmdopts{short} = 'n';
|
---|
[4] | 361 | }
|
---|
[14] | 362 |
|
---|
[3] | 363 | # Valid options, with example arguments (if any):
|
---|
| 364 | # Build from .spec file; mutually exclusive:
|
---|
| 365 | # -bp
|
---|
| 366 | # -bc
|
---|
| 367 | # -bi
|
---|
| 368 | # -bl
|
---|
| 369 | # -ba
|
---|
| 370 | # -bb
|
---|
| 371 | # -bs
|
---|
| 372 | # Build from tarball; mutually exclusive:
|
---|
| 373 | # -tp
|
---|
| 374 | # -tc
|
---|
| 375 | # -ti
|
---|
| 376 | # -ta
|
---|
| 377 | # -tb
|
---|
| 378 | # -ts
|
---|
| 379 | # Build from .src.(deb|rpm)
|
---|
| 380 | # --rebuild
|
---|
| 381 | # --recompile
|
---|
| 382 |
|
---|
| 383 | # General options
|
---|
| 384 | # --buildroot=DIRECTORY
|
---|
| 385 | # --clean
|
---|
| 386 | # --nobuild
|
---|
| 387 | # --nodeps
|
---|
| 388 | # --nodirtokens
|
---|
| 389 | # --rmsource
|
---|
| 390 | # --rmspec
|
---|
| 391 | # --short-circuit
|
---|
| 392 | # --target=CPU-VENDOR-OS
|
---|
| 393 |
|
---|
| 394 | #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
|
---|
| 395 |
|
---|
| 396 | } # end parse_cmd()
|
---|
| 397 |
|
---|
[4] | 398 |
|
---|
[5] | 399 | ## parse_spec()
|
---|
[14] | 400 | # Parse the .spec file.
|
---|
[5] | 401 | sub parse_spec {
|
---|
[65] | 402 | open SPECFILE,"<$specfile" or die "specfile ($specfile) barfed: $!";
|
---|
[5] | 403 |
|
---|
[6] | 404 | LINE: while (<SPECFILE>) {
|
---|
[14] | 405 | next if /^#/; # Ignore comments...
|
---|
| 406 | next if /^\s+$/; # ... and blank lines.
|
---|
| 407 |
|
---|
[5] | 408 | if (/^\%/) {
|
---|
| 409 | # A macro that needs further processing.
|
---|
[14] | 410 |
|
---|
[60] | 411 | if (my ($key, $def) = (/^\%define\s+([^\s]+)\s+(.+)$/) ) {
|
---|
| 412 | $specglobals{$key} = expandmacros($def,'g');
|
---|
[23] | 413 | }
|
---|
| 414 |
|
---|
[62] | 415 | if (/^\%description(?:\s+(?:-n\s+)?(.+))?/) {
|
---|
[27] | 416 | my $subname = "main";
|
---|
| 417 | if ($1) {
|
---|
[62] | 418 | my $tmp = expandmacros("$1", 'g');
|
---|
[49] | 419 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
[27] | 420 | }
|
---|
[8] | 421 | while (<SPECFILE>) {
|
---|
[39] | 422 | next if /^#/; # Messy. Should be possible to do better. :/
|
---|
[8] | 423 | redo LINE if /^\%/;
|
---|
[27] | 424 | $pkgdata{$subname}{desc} .= " $_";
|
---|
[8] | 425 | }
|
---|
[18] | 426 | }
|
---|
[62] | 427 | if (/^\%package\s+(?:-n\s+)?(.+)/) {
|
---|
| 428 | # gotta expand %defines here. Whee.
|
---|
| 429 | my $subname = expandmacros("$1", 'g');
|
---|
[49] | 430 | if (! /-n/) { $subname = "$pkgdata{main}{name}-$1"; }
|
---|
[27] | 431 | push @pkglist, $subname;
|
---|
| 432 | $pkgdata{$subname}{name} = $subname;
|
---|
| 433 | $pkgdata{$subname}{version} = $pkgdata{main}{version};
|
---|
| 434 | while (<SPECFILE>) {
|
---|
| 435 | redo LINE if /^\%/;
|
---|
[38] | 436 | if (my ($dname,$dvalue) = (/^(Summary|Group|Version|Requires|Provides):\s+(.+)$/i)) {
|
---|
[27] | 437 | $dname =~ tr/[A-Z]/[a-z]/;
|
---|
[63] | 438 | $pkgdata{$subname}{$dname} = expandmacros($dvalue, 'gp');
|
---|
[27] | 439 | }
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
[8] | 442 |
|
---|
[6] | 443 | if (/^\%prep/) {
|
---|
| 444 | # %prep section. May have %setup macro; may include %patch tags,
|
---|
| 445 | # may be just a bare shell script.
|
---|
| 446 |
|
---|
| 447 | # This really should be local-ish, but we need just the filename for the source
|
---|
| 448 | $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
|
---|
| 449 |
|
---|
| 450 | # Replace some core macros
|
---|
[14] | 451 | $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
|
---|
[6] | 452 |
|
---|
| 453 | PREPSCRIPT: while (<SPECFILE>) {
|
---|
| 454 | if (/^\%setup/) {
|
---|
| 455 | # Parse out the %setup macro. Note that we aren't supporting
|
---|
[14] | 456 | # many of RPM's %setup features.
|
---|
[7] | 457 | $prepscript .= "cd $topdir/BUILD\n";
|
---|
| 458 | if ( /\s+-n\s+([^\s]+)\s+/ ) {
|
---|
| 459 | $tarballdir = $1;
|
---|
| 460 | } else {
|
---|
| 461 | $tarballdir = "$pkgdata{main}{name}-$pkgdata{main}{version}";
|
---|
| 462 | }
|
---|
[69] | 463 | $tarballdir = expandmacros($tarballdir,'gp');
|
---|
| 464 | $prepscript .= "rm -rf $tarballdir\n";
|
---|
| 465 | if (/\s+-c\s+/) {
|
---|
| 466 | $prepscript .= "mkdir $tarballdir\ncd $tarballdir\n";
|
---|
| 467 | }
|
---|
| 468 | $prepscript .= "tar -".
|
---|
[6] | 469 | ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
|
---|
| 470 | ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
|
---|
[21] | 471 | ( /\s+-q\s+/ ? '' : 'vv' )."xf ".
|
---|
| 472 | "$topdir/SOURCES/$pkgdata{main}{source}\n".
|
---|
[6] | 473 | qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
|
---|
[69] | 474 | "cd $topdir/BUILD/$tarballdir\n".
|
---|
[6] | 475 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
|
---|
| 476 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
|
---|
| 477 | qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
|
---|
[67] | 478 | } elsif ( my ($patchnum,$patchopts) = (/^\%patch([^\s]+)(\s+.+)?$/) ) {
|
---|
| 479 | chomp $patchnum;
|
---|
[70] | 480 | $prepscript .= qq(echo "Patch #$patchnum ($pkgdata{main}{"patch$patchnum"}):"\n).
|
---|
| 481 | "patch ";
|
---|
| 482 | # If there are options passed, use'em.
|
---|
| 483 | # Otherwise, catch a bare %patch and ASS-U-ME it's '-p0'-able.
|
---|
| 484 | # Will break on options that don't provide -pnn, but what the hell.
|
---|
[66] | 485 | $prepscript .= $patchopts if $patchopts;
|
---|
[70] | 486 | $prepscript .= "-p0" if !$patchopts;
|
---|
| 487 | $prepscript .= " -s <$topdir/SOURCES/".$pkgdata{main}{"patch$patchnum"}."\n";
|
---|
[6] | 488 | } else {
|
---|
| 489 | last PREPSCRIPT if /^\%/;
|
---|
| 490 | $prepscript .= $_;
|
---|
| 491 | }
|
---|
| 492 | }
|
---|
| 493 | redo LINE;
|
---|
| 494 | }
|
---|
[12] | 495 | if (/^\%build/) {
|
---|
[6] | 496 | # %build. This is pretty much just a shell script. There
|
---|
| 497 | # *are* a few macros, but we're not going to deal with them yet.
|
---|
[7] | 498 | $buildscript .= "cd $tarballdir\n";
|
---|
[10] | 499 | BUILDSCRIPT: while (<SPECFILE>) {
|
---|
| 500 | if (/^\%configure/) {
|
---|
[12] | 501 | $buildscript .= expandmacros($_,'cgbp');
|
---|
[25] | 502 | } elsif (/^\%\{__make\}/) {
|
---|
[12] | 503 | $buildscript .= expandmacros($_,'mgbp');
|
---|
[10] | 504 | } else {
|
---|
[24] | 505 | last BUILDSCRIPT if /^\%[^{]/;
|
---|
[10] | 506 | $buildscript .= $_;
|
---|
| 507 | }
|
---|
[6] | 508 | }
|
---|
[10] | 509 | redo LINE;
|
---|
[5] | 510 | }
|
---|
[6] | 511 | if (/^\%install/) {
|
---|
[7] | 512 | $installscript .= "cd $tarballdir\n";
|
---|
[12] | 513 | INSTALLSCRIPT: while (<SPECFILE>) {
|
---|
| 514 | if (/^\%makeinstall/) {
|
---|
| 515 | $installscript .= expandmacros($_,'igbp');
|
---|
| 516 | } else {
|
---|
| 517 | last INSTALLSCRIPT if /^\%/;
|
---|
| 518 | $installscript .= $_;
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 | redo LINE;
|
---|
[6] | 522 | }
|
---|
| 523 | if (/^\%clean/) {
|
---|
[7] | 524 | while (<SPECFILE>) {
|
---|
| 525 | redo LINE if /^\%/;
|
---|
| 526 | $cleanscript .= $_;
|
---|
| 527 | }
|
---|
[12] | 528 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
[6] | 529 | }
|
---|
[29] | 530 |
|
---|
[75] | 531 | # pre/post (un)install scripts. Note that we expand macros later anyway, so we'll leave them unexpanded here.
|
---|
| 532 | if (/^\%(pre|post|preun|postun)\b(?:\s+(?:-n\s+)?(.+))?/i) {
|
---|
| 533 | my $scriptlet = lc $1;
|
---|
| 534 | my $pkgname = 'main';
|
---|
| 535 | if ($2) { # Magic to add entries to the right list of files
|
---|
| 536 | my $tmp = expandmacros("$2", 'g');
|
---|
| 537 | if (/-n/) { $pkgname = $tmp; } else { $pkgname = "$pkgdata{main}{name}-$tmp"; }
|
---|
[16] | 538 | }
|
---|
| 539 | while (<SPECFILE>) {
|
---|
| 540 | redo LINE if /^\%/;
|
---|
[75] | 541 | $pkgdata{$pkgname}{$scriptlet} .= $_;
|
---|
[16] | 542 | }
|
---|
[6] | 543 | }
|
---|
[29] | 544 | # done %pre/%post scripts
|
---|
| 545 |
|
---|
[62] | 546 | if (/^\%files(?:\s+(?:-n\s+)?(.+))?/) {
|
---|
[23] | 547 | my $pkgname = 'main';
|
---|
[29] | 548 | if ($1) { # Magic to add entries to the right list of files
|
---|
[62] | 549 | my $tmp = expandmacros("$1", 'g');
|
---|
[49] | 550 | if (/-n/) { $pkgname = $tmp; } else { $pkgname = "$pkgdata{main}{name}-$tmp"; }
|
---|
[23] | 551 | }
|
---|
[37] | 552 |
|
---|
| 553 | # Set this now, so it can be flipped a bit later, and used much later.
|
---|
| 554 | #$pkgdata{$pkgname}{conffiles} = 0;
|
---|
| 555 |
|
---|
[27] | 556 | while (<SPECFILE>) {
|
---|
[29] | 557 | chomp;
|
---|
[45] | 558 | next if /^#/;
|
---|
[29] | 559 | # need to update this to deal (properly) with %dir, %attr, etc
|
---|
| 560 | next if /^\%dir/;
|
---|
| 561 | next if /^\%defattr/;
|
---|
| 562 |
|
---|
[37] | 563 | # Debian dpkg doesn't speak "%docdir". Meh.
|
---|
| 564 | next if /^\%docdir/;
|
---|
| 565 |
|
---|
[76] | 566 | ##fixme
|
---|
| 567 | # Note that big chunks of this section don't match rpm's behaviour; among other things,
|
---|
| 568 | # rpm accepts more than one %-directive on one line for a file or set of files.
|
---|
| 569 | # make sure files get suitable permissions and so on
|
---|
| 570 | if (/^\%attr/) {
|
---|
| 571 | # We're going to collapse whitespace before processing. PTHBT.
|
---|
| 572 | # While this breaks pathnames with spaces, anyone expecting command-line
|
---|
| 573 | # tools with spaces to work (never mind work *properly* or *well*) under
|
---|
| 574 | # any *nix has their head so far up their ass they can see out their mouth.
|
---|
| 575 | my ($args,$filelist) = split /\)/;
|
---|
| 576 | $filelist{$pkgname} .= " $filelist";
|
---|
| 577 | $args =~ s/\s+//g;
|
---|
| 578 | $args =~ s/"//g; # don't think quotes are ever necessary, but they're *allowed*
|
---|
[83] | 579 | my ($perms,$owner,$group) = ($args =~ /\(([\d-]+),([a-zA-Z0-9-]+),([a-zA-Z0-9-]+)/);
|
---|
[76] | 580 | # due to Debian's total lack of real permissions-processing in its actual package
|
---|
| 581 | # handling component (dpkg-deb), this can't really be done "properly". We'll have
|
---|
| 582 | # to add chown/chmod commands to the postinst instead. Feh.
|
---|
| 583 | $pkgdata{$pkgname}{'post'} .= "chown $owner $filelist\n" if $owner ne '-';
|
---|
| 584 | $pkgdata{$pkgname}{'post'} .= "chgrp $group $filelist\n" if $group ne '-';
|
---|
[78] | 585 | $pkgdata{$pkgname}{'post'} .= "chmod $perms $filelist\n" if $perms ne '-';
|
---|
[82] | 586 | next;
|
---|
[76] | 587 | }
|
---|
| 588 |
|
---|
[72] | 589 | # %doc needs extra processing, because it can be a space-separated list.
|
---|
| 590 | if (/^\%doc/) {
|
---|
| 591 | s/^\%doc\s+//;
|
---|
| 592 | foreach (split()) {
|
---|
| 593 | $filelist{$pkgname} .= " %{_docdir}/$_";
|
---|
| 594 | }
|
---|
| 595 | next;
|
---|
| 596 | }
|
---|
| 597 |
|
---|
[37] | 598 | # Conffiles. Note that Debian and RH have similar, but not
|
---|
| 599 | # *quite* identical ideas of what constitutes a conffile. Nrgh.
|
---|
| 600 | if (/^\%config\s+(.+)$/) {
|
---|
| 601 | $pkgdata{$pkgname}{conffiles} = 1; # Flag it for later
|
---|
| 602 | my $tmp = $1; # Now we can mangleificationate it. And we probably need to. :/
|
---|
[46] | 603 | $tmp = expandmacros($tmp, 'gp'); # Expand common macros
|
---|
[37] | 604 | if ($tmp !~ /\s+/) {
|
---|
| 605 | # Simplest case, just a file. Whew.
|
---|
| 606 | push @{$pkgdata{$pkgname}{conflist}}, $tmp;
|
---|
| 607 | $filelist{$pkgname} .= " $tmp";
|
---|
| 608 | } else {
|
---|
| 609 | # Wot? Spaces? That means extra %-macros. Which, for the most part, can be ignored.
|
---|
| 610 | ($tmp) = ($tmp =~ /.+\s([^\s]+)/); # Strip everything before the last space
|
---|
| 611 | push @{$pkgdata{$pkgname}{conflist}}, $tmp;
|
---|
| 612 | $filelist{$pkgname} .= " $tmp";
|
---|
| 613 | }
|
---|
| 614 | next;
|
---|
| 615 | }
|
---|
| 616 |
|
---|
[29] | 617 | # and finally we can fall through %{_<FHS>}-prefixed locations...
|
---|
[30] | 618 | if (/^\%\{_/) {
|
---|
| 619 | $filelist{$pkgname} .= " $_";
|
---|
| 620 | next;
|
---|
| 621 | }
|
---|
| 622 | # EW. Necessary to clear up %define expansions before we exit with redo.
|
---|
| 623 | $_ = expandmacros $_, 'g';
|
---|
[29] | 624 |
|
---|
| 625 | # ... unknown or "next section" % directives ...
|
---|
[27] | 626 | redo LINE if /^\%/;
|
---|
[29] | 627 |
|
---|
| 628 | # ... and "normal" files
|
---|
[27] | 629 | $filelist{$pkgname} .= " $_";
|
---|
| 630 | }
|
---|
[29] | 631 | } # done %file section
|
---|
| 632 |
|
---|
[18] | 633 | if (/^\%changelog/) {
|
---|
| 634 | $pkgdata{main}{changelog} = '';
|
---|
| 635 | while (<SPECFILE>) {
|
---|
| 636 | redo LINE if /^\%/;
|
---|
| 637 | $pkgdata{main}{changelog} .= $_;
|
---|
| 638 | }
|
---|
| 639 | }
|
---|
[14] | 640 |
|
---|
| 641 | } else { # Data from the spec file "header"
|
---|
| 642 |
|
---|
[5] | 643 | if (/^summary:\s+(.+)/i) {
|
---|
| 644 | $pkgdata{main}{summary} = $1;
|
---|
| 645 | } elsif (/^name:\s+(.+)/i) {
|
---|
[24] | 646 | $pkgdata{main}{name} = expandmacros($1,'g');
|
---|
[5] | 647 | } elsif (/^version:\s+(.+)/i) {
|
---|
[24] | 648 | $pkgdata{main}{version} = expandmacros($1,'g');
|
---|
[5] | 649 | } elsif (/^release:\s+(.+)/i) {
|
---|
[24] | 650 | $pkgdata{main}{release} = expandmacros($1,'g');
|
---|
[5] | 651 | } elsif (/^group:\s+(.+)/i) {
|
---|
| 652 | $pkgdata{main}{group} = $1;
|
---|
| 653 | } elsif (/^copyright:\s+(.+)/i) {
|
---|
| 654 | $pkgdata{main}{copyright} = $1;
|
---|
| 655 | } elsif (/^url:\s+(.+)/i) {
|
---|
| 656 | $pkgdata{main}{url} = $1;
|
---|
| 657 | } elsif (/^packager:\s+(.+)/i) {
|
---|
| 658 | $pkgdata{main}{packager} = $1;
|
---|
[7] | 659 | } elsif (/^buildroot:\s+(.+)/i) {
|
---|
| 660 | $buildroot = $1;
|
---|
[59] | 661 | } elsif (/^source0?:\s+(.+)/i) {
|
---|
[5] | 662 | $pkgdata{main}{source} = $1;
|
---|
[6] | 663 | die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
|
---|
[15] | 664 | } elsif (/^source([0-9]+):\s+(.+)/i) {
|
---|
| 665 | $pkgdata{sources}{$1} = $2;
|
---|
[10] | 666 | } elsif (/^patch([^:]+):\s+(.+)$/i) {
|
---|
[26] | 667 | my $patchname = "patch$1";
|
---|
| 668 | $pkgdata{main}{$patchname} = $2;
|
---|
| 669 | if ($pkgdata{main}{$patchname} =~ /\//) {
|
---|
| 670 | # URL-style patch. Rare but not unheard-of.
|
---|
| 671 | my @patchbits = split '/', $pkgdata{main}{$patchname};
|
---|
| 672 | $pkgdata{main}{$patchname} = $patchbits[$#patchbits];
|
---|
| 673 | }
|
---|
[66] | 674 | chomp $pkgdata{main}{$patchname};
|
---|
[38] | 675 | } elsif (/^buildreq(?:uires)?:\s+(.+)/i) {
|
---|
| 676 | $buildreq .= ", $1";
|
---|
| 677 | } elsif (/^requires:\s+(.+)/i) {
|
---|
[63] | 678 | $pkgdata{main}{requires} .= ", ".expandmacros("$1", 'gp');
|
---|
[38] | 679 | } elsif (/^provides:\s+(.+)/i) {
|
---|
| 680 | $pkgdata{main}{provides} .= ", $1";
|
---|
[51] | 681 | } elsif (/^conflicts:\s+(.+)/i) {
|
---|
| 682 | $pkgdata{main}{conflicts} .= ", $1";
|
---|
[5] | 683 | }
|
---|
| 684 | #Name: suwrap
|
---|
| 685 | #Version: 0.04
|
---|
| 686 | #Release: 3
|
---|
| 687 | #Group: Applications/System
|
---|
| 688 | #Copyright: WebHart internal ONLY. :(
|
---|
| 689 | #BuildArchitectures: i386
|
---|
| 690 | #BuildRoot: /tmp/%{name}-%{version}
|
---|
| 691 | #Url: http://virtual.webhart.net
|
---|
| 692 | #Packager: Kris Deugau <kdeugau@deepnet.cx>
|
---|
| 693 | #Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
|
---|
| 694 |
|
---|
| 695 | }
|
---|
| 696 | }
|
---|
[7] | 697 |
|
---|
[14] | 698 | # Parse and replace some more macros. More will be replaced even later.
|
---|
| 699 |
|
---|
[10] | 700 | # Expand macros as necessary.
|
---|
[12] | 701 | $scriptletbase = expandmacros($scriptletbase,'gp');
|
---|
[7] | 702 |
|
---|
| 703 | $buildroot = $cmdbuildroot if $cmdbuildroot;
|
---|
[12] | 704 | $buildroot = expandmacros($buildroot,'gp');
|
---|
[7] | 705 |
|
---|
[16] | 706 | close SPECFILE;
|
---|
[5] | 707 | } # end parse_spec()
|
---|
| 708 |
|
---|
| 709 |
|
---|
[7] | 710 | ## prep()
|
---|
[14] | 711 | # Writes and executes the %prep script (mostly) built while reading the spec file.
|
---|
[7] | 712 | sub prep {
|
---|
[10] | 713 | # Replace some things here just to make sure.
|
---|
[12] | 714 | $prepscript = expandmacros($prepscript,'gp');
|
---|
[10] | 715 |
|
---|
[24] | 716 | #print $prepscript; exit 0;
|
---|
[23] | 717 |
|
---|
[10] | 718 | # create script filename
|
---|
[13] | 719 | my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
|
---|
[10] | 720 | sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[7] | 721 | or die $!;
|
---|
[10] | 722 | print PREPSCRIPT $scriptletbase;
|
---|
| 723 | print PREPSCRIPT $prepscript;
|
---|
| 724 | close PREPSCRIPT;
|
---|
[7] | 725 |
|
---|
[10] | 726 | # execute
|
---|
| 727 | print "Calling \%prep script $prepscriptfile...\n";
|
---|
| 728 | system("/bin/sh -e $prepscriptfile") == 0
|
---|
[14] | 729 | or die "Can't exec: $!\n";
|
---|
[7] | 730 |
|
---|
[10] | 731 | # and clean up
|
---|
| 732 | unlink $prepscriptfile;
|
---|
[7] | 733 | } # end prep()
|
---|
| 734 |
|
---|
| 735 |
|
---|
[5] | 736 | ## build()
|
---|
[14] | 737 | # Writes and executes the %build script (mostly) built while reading the spec file.
|
---|
[5] | 738 | sub build {
|
---|
[12] | 739 | # Expand the macros
|
---|
| 740 | $buildscript = expandmacros($buildscript,'cgbp');
|
---|
| 741 |
|
---|
[7] | 742 | # create script filename
|
---|
[13] | 743 | my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
|
---|
[7] | 744 | sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
| 745 | or die $!;
|
---|
| 746 | print BUILDSCRIPT $scriptletbase;
|
---|
| 747 | print BUILDSCRIPT $buildscript;
|
---|
| 748 | close BUILDSCRIPT;
|
---|
| 749 |
|
---|
| 750 | # execute
|
---|
| 751 | print "Calling \%build script $buildscriptfile...\n";
|
---|
| 752 | system("/bin/sh -e $buildscriptfile") == 0
|
---|
[14] | 753 | or die "Can't exec: $!\n";
|
---|
[7] | 754 |
|
---|
| 755 | # and clean up
|
---|
| 756 | unlink $buildscriptfile;
|
---|
[5] | 757 | } # end build()
|
---|
| 758 |
|
---|
| 759 |
|
---|
[7] | 760 | ## install()
|
---|
[14] | 761 | # Writes and executes the %install script (mostly) built while reading the spec file.
|
---|
[7] | 762 | sub install {
|
---|
[12] | 763 | # Expand the macros
|
---|
| 764 | $installscript = expandmacros($installscript,'igbp');
|
---|
| 765 |
|
---|
[7] | 766 | # create script filename
|
---|
[13] | 767 | my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
|
---|
[7] | 768 | sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
| 769 | or die $!;
|
---|
| 770 | print INSTSCRIPT $scriptletbase;
|
---|
[23] | 771 | # print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it.
|
---|
[7] | 772 | print INSTSCRIPT $installscript;
|
---|
| 773 | close INSTSCRIPT;
|
---|
| 774 |
|
---|
| 775 | # execute
|
---|
| 776 | print "Calling \%install script $installscriptfile...\n";
|
---|
| 777 | system("/bin/sh -e $installscriptfile") == 0
|
---|
[14] | 778 | or die "Can't exec: $!\n";
|
---|
[7] | 779 |
|
---|
| 780 | # and clean up
|
---|
| 781 | unlink $installscriptfile;
|
---|
| 782 | } # end install()
|
---|
| 783 |
|
---|
| 784 |
|
---|
[8] | 785 | ## binpackage()
|
---|
| 786 | # Creates the binary .deb package from the installed tree in $buildroot.
|
---|
[14] | 787 | # Writes and executes a shell script to do so.
|
---|
| 788 | # Creates miscellaneous files required by dpkg-deb to actually build the package file.
|
---|
[27] | 789 | # Should handle simple subpackages
|
---|
[8] | 790 | sub binpackage {
|
---|
[14] | 791 | # Make sure we have somewhere to write the .deb file
|
---|
[9] | 792 | if (!-e "$topdir/DEBS/i386") {
|
---|
| 793 | mkdir "$topdir/DEBS/i386";
|
---|
| 794 | }
|
---|
[14] | 795 |
|
---|
[27] | 796 | foreach my $pkg (@pkglist) {
|
---|
[8] | 797 |
|
---|
[73] | 798 | # Skip building a package if it doesn't actually have any files. NB: This
|
---|
| 799 | # differs slightly from rpm's behaviour where a package *will* be built -
|
---|
| 800 | # even without any files - if %files is specified anywhere. I can think
|
---|
| 801 | # of odd corner cases where that *may* be desireable.
|
---|
[74] | 802 | next if (!$filelist{$pkg} or $filelist{$pkg} =~ /^\s*$/);
|
---|
[73] | 803 |
|
---|
[27] | 804 | # Gotta do this first, otherwise we don't have a place to move files from %files
|
---|
| 805 | mkdir "$buildroot/$pkg";
|
---|
[28] | 806 |
|
---|
[30] | 807 | # Eliminate any lingering % macros
|
---|
| 808 | $filelist{$pkg} = expandmacros $filelist{$pkg}, 'g';
|
---|
| 809 |
|
---|
[27] | 810 | my @pkgfilelist = split ' ', $filelist{$pkg};
|
---|
| 811 | foreach my $pkgfile (@pkgfilelist) {
|
---|
[37] | 812 | $pkgfile = expandmacros($pkgfile, 'gp');
|
---|
[44] | 813 | my ($fpath,$fname) = ($pkgfile =~ m|(.+?/?)?([^/]+)$|); # We don't need $fname now, but we might.
|
---|
| 814 | qx { mkdir -p $buildroot/$pkg$fpath }
|
---|
| 815 | if $fpath && $fpath ne '';
|
---|
| 816 | qx { mv $buildroot$pkgfile $buildroot/$pkg$fpath };
|
---|
[27] | 817 | }
|
---|
[28] | 818 |
|
---|
[38] | 819 | # Get the "Depends" (Requires) a la RPM. Ish. We strip the leading
|
---|
| 820 | # comma and space here (if needed) in case there were "Requires" specified
|
---|
| 821 | # in the spec file - those would precede these.
|
---|
[64] | 822 | $pkgdata{$pkg}{requires} .= getreqs("$buildroot/$pkg");
|
---|
[38] | 823 |
|
---|
[64] | 824 | # magic needed to properly version dependencies...
|
---|
| 825 | # only provided deps will really be included
|
---|
[65] | 826 | $pkgdata{$pkg}{requires} =~ s/^, //; # Still have to do this here.
|
---|
[64] | 827 | $pkgdata{$pkg}{requires} =~ s/\s+//g;
|
---|
| 828 | my @deps = split /,/, $pkgdata{$pkg}{requires};
|
---|
| 829 | my $tmp = '';
|
---|
| 830 | foreach my $dep (@deps) {
|
---|
[68] | 831 | # Hack up the perl(Class::SubClass) deps into something dpkg can understand.
|
---|
| 832 | # May or may not be versioned.
|
---|
| 833 | # We do this first so the version rewriter can do its magic next.
|
---|
| 834 | if (my ($mod,$ver) = ($dep =~ /^perl\(([A-Za-z0-9\:\-]+)\)([><=]+.+)?/) ) {
|
---|
| 835 | $mod =~ s/^perl\(//;
|
---|
| 836 | $mod =~ s/\)$//;
|
---|
| 837 | $mod =~ s/::/-/g;
|
---|
| 838 | $mod =~ tr/A-Z/a-z/;
|
---|
| 839 | $mod = "lib$mod-perl";
|
---|
| 840 | $mod .= $ver if $ver;
|
---|
| 841 | $dep = $mod;
|
---|
| 842 | }
|
---|
[64] | 843 | if (my ($name,$rel,$value) = ($dep =~ /^([a-zA-Z0-9._-]+)([><=]+)([a-zA-Z0-9._-]+)$/)) {
|
---|
| 844 | $tmp .= ", $name ($rel $value)";
|
---|
| 845 | } else {
|
---|
| 846 | $tmp .= ", $dep";
|
---|
| 847 | }
|
---|
| 848 | }
|
---|
| 849 | ($pkgdata{$pkg}{requires} = $tmp) =~ s/^, //;
|
---|
| 850 |
|
---|
[38] | 851 | # Do this here since we're doing {depends}...
|
---|
[41] | 852 | if (defined($pkgdata{$pkg}{provides})) {
|
---|
| 853 | $pkgdata{$pkg}{provides} =~ s/^, //;
|
---|
| 854 | $pkgdata{$pkg}{provides} = expandmacros($pkgdata{$pkg}{provides},'gp');
|
---|
| 855 | }
|
---|
[51] | 856 | if (defined($pkgdata{$pkg}{conflicts})) {
|
---|
| 857 | $pkgdata{$pkg}{conflicts} =~ s/^, //;
|
---|
| 858 | $pkgdata{$pkg}{conflicts} = expandmacros($pkgdata{$pkg}{conflicts},'gp');
|
---|
| 859 | }
|
---|
[38] | 860 |
|
---|
[27] | 861 | # Gotta do this next, otherwise the control file has nowhere to go. >:(
|
---|
| 862 | mkdir "$buildroot/$pkg/DEBIAN";
|
---|
| 863 |
|
---|
[33] | 864 | # Hack the filename for the package into a Debian-tool-compatible format. GRRRRRR!!!!!
|
---|
| 865 | # Have I mentioned I hate Debian Policy?
|
---|
| 866 | $pkgdata{$pkg}{name} =~ tr/_/-/;
|
---|
| 867 |
|
---|
[27] | 868 | # create script filename
|
---|
| 869 | my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
|
---|
| 870 | sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[8] | 871 | or die $!;
|
---|
[27] | 872 | print DEBSCRIPT $scriptletbase;
|
---|
| 873 | print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot/$pkg $topdir/DEBS/i386/".
|
---|
| 874 | "$pkgdata{$pkg}{name}_$pkgdata{$pkg}{version}-$pkgdata{main}{release}_i386.deb\n";
|
---|
| 875 | # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
|
---|
| 876 | close DEBSCRIPT;
|
---|
[8] | 877 |
|
---|
[27] | 878 | my $control = "Package: $pkgdata{$pkg}{name}\n".
|
---|
| 879 | "Version: $pkgdata{$pkg}{version}-$pkgdata{main}{release}\n".
|
---|
| 880 | "Section: $pkgdata{$pkg}{group}\n".
|
---|
[8] | 881 | "Priority: optional\n".
|
---|
| 882 | "Architecture: i386\n".
|
---|
| 883 | "Maintainer: $pkgdata{main}{packager}\n".
|
---|
[47] | 884 | ( $pkgdata{$pkg}{requires} ne '' ? "Depends: $pkgdata{$pkg}{requires}\n" : '' ).
|
---|
[39] | 885 | ( defined($pkgdata{$pkg}{provides}) ? "Provides: $pkgdata{$pkg}{provides}\n" : '' ).
|
---|
[51] | 886 | ( defined($pkgdata{$pkg}{conflicts}) ? "Conflicts: $pkgdata{$pkg}{conflicts}\n" : '' ).
|
---|
[27] | 887 | "Description: $pkgdata{$pkg}{summary}\n";
|
---|
| 888 | $control .= "$pkgdata{$pkg}{desc}\n";
|
---|
[8] | 889 |
|
---|
[27] | 890 | open CONTROL, ">$buildroot/$pkg/DEBIAN/control";
|
---|
| 891 | print CONTROL $control;
|
---|
| 892 | close CONTROL;
|
---|
[8] | 893 |
|
---|
[37] | 894 | # Iff there are conffiles (as specified in the %files list(s), add'em
|
---|
| 895 | # in so dpkg-deb can tag them.
|
---|
| 896 | if ($pkgdata{$pkg}{conffiles}) {
|
---|
| 897 | open CONFLIST, ">$buildroot/$pkg/DEBIAN/conffiles";
|
---|
| 898 | foreach my $conffile (@{$pkgdata{$pkg}{conflist}}) {
|
---|
| 899 | print CONFLIST "$conffile\n";
|
---|
| 900 | }
|
---|
| 901 | close CONFLIST;
|
---|
| 902 | }
|
---|
| 903 |
|
---|
[75] | 904 | # found the point of scripts on subpackages.
|
---|
| 905 | if ($pkgdata{$pkg}{'pre'}) {
|
---|
| 906 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'pre'},'gp');
|
---|
| 907 | open PREINST, ">$buildroot/$pkg/DEBIAN/preinst";
|
---|
| 908 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
| 909 | print PREINST $pkgdata{$pkg}{'pre'};
|
---|
| 910 | close PREINST;
|
---|
| 911 | `chmod 0755 $buildroot/$pkg/DEBIAN/preinst`;
|
---|
[27] | 912 | }
|
---|
[75] | 913 | if ($pkgdata{$pkg}{'post'}) {
|
---|
| 914 | $pkgdata{$pkg}{'post'} = expandmacros($pkgdata{$pkg}{'post'},'gp');
|
---|
| 915 | open PREINST, ">$buildroot/$pkg/DEBIAN/postinst";
|
---|
| 916 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
| 917 | print PREINST $pkgdata{$pkg}{'post'};
|
---|
| 918 | close PREINST;
|
---|
| 919 | `chmod 0755 $buildroot/$pkg/DEBIAN/postinst`;
|
---|
| 920 | }
|
---|
| 921 | if ($pkgdata{$pkg}{'preun'}) {
|
---|
| 922 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'preun'},'gp');
|
---|
| 923 | open PREINST, ">$buildroot/$pkg/DEBIAN/prerm";
|
---|
| 924 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
| 925 | print PREINST $pkgdata{$pkg}{'preun'};
|
---|
| 926 | close PREINST;
|
---|
| 927 | `chmod 0755 $buildroot/$pkg/DEBIAN/prerm`;
|
---|
| 928 | }
|
---|
| 929 | if ($pkgdata{$pkg}{'postun'}) {
|
---|
| 930 | $pkgdata{$pkg}{'postun'} = expandmacros($pkgdata{$pkg}{'postun'},'gp');
|
---|
| 931 | open PREINST, ">$buildroot/$pkg/DEBIAN/postrm";
|
---|
| 932 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
| 933 | print PREINST $pkgdata{$pkg}{'postun'};
|
---|
| 934 | close PREINST;
|
---|
| 935 | `chmod 0755 $buildroot/$pkg/DEBIAN/postrm`;
|
---|
| 936 | }
|
---|
[16] | 937 |
|
---|
[27] | 938 | # execute
|
---|
| 939 | print "Calling package creation script $debscriptfile for $pkgdata{$pkg}{name}...\n";
|
---|
| 940 | system("/bin/sh -e $debscriptfile") == 0
|
---|
[14] | 941 | or die "Can't exec: $!\n";
|
---|
[8] | 942 |
|
---|
[77] | 943 | $finalmessages .= "Wrote binary package ".
|
---|
| 944 | "$pkgdata{$pkg}{name}_$pkgdata{$pkg}{version}-$pkgdata{main}{release}_i386.deb".
|
---|
| 945 | " in $topdir/DEBS/i386\n";
|
---|
[27] | 946 | # and clean up
|
---|
| 947 | unlink $debscriptfile;
|
---|
| 948 |
|
---|
| 949 | } # subpackage loop
|
---|
| 950 |
|
---|
[8] | 951 | } # end binpackage()
|
---|
| 952 |
|
---|
| 953 |
|
---|
[35] | 954 | ## srcpackage()
|
---|
| 955 | # Builds a .src.deb source package. Note that Debian's idea of
|
---|
| 956 | # a "source package" is seriously flawed IMO, because you can't
|
---|
| 957 | # easily copy it as-is.
|
---|
[36] | 958 | # Not quite identical to RPM, but Good Enough (TM).
|
---|
[35] | 959 | sub srcpackage {
|
---|
[54] | 960 | # In case we were called with -bs.
|
---|
| 961 | $pkgdata{main}{name} =~ tr/_/-/;
|
---|
[36] | 962 | my $pkgsrcname = "$pkgdata{main}{name}-$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb";
|
---|
| 963 |
|
---|
| 964 | my $paxcmd;
|
---|
| 965 |
|
---|
| 966 | # We'll definitely need this later, and *may* need it sooner.
|
---|
| 967 | (my $barespec = $specfile) =~ s|.+/([^/]+)$|$1|;
|
---|
| 968 |
|
---|
| 969 | # Copy the specfile to the build tree, but only if it's not there already.
|
---|
| 970 | ##buglet: need to deal with silly case where silly user has put the spec
|
---|
| 971 | # file in a subdir of %{_topdir}/SPECS. Ewww. Silly user!
|
---|
| 972 | if (abs_path($specfile) !~ /^$topdir\/SPECS/) {
|
---|
| 973 | $paxcmd .= "cp $specfile %{_topdir}/SPECS/; \n"
|
---|
| 974 | }
|
---|
| 975 |
|
---|
[35] | 976 | # use pax -w [file] [file] ... >outfile.sdeb
|
---|
[36] | 977 | $paxcmd = "cd $topdir; pax -w ";
|
---|
[10] | 978 |
|
---|
[35] | 979 | # tweak source entry into usable form. Need it locally somewhere along the line.
|
---|
| 980 | (my $pkgsrc = $pkgdata{main}{source}) =~ s|.+/([^/]+)$|$1|;
|
---|
[36] | 981 | $paxcmd .= "SOURCES/$pkgsrc ";
|
---|
[10] | 982 |
|
---|
[35] | 983 | # create file list: Source[nn], Patch[nn]
|
---|
| 984 | foreach my $specbit (keys %{$pkgdata{main}} ) {
|
---|
| 985 | next if $specbit eq 'source';
|
---|
[53] | 986 | $paxcmd .= "SOURCES/$pkgdata{main}{$specbit} " if $specbit =~ /^patch/;
|
---|
[36] | 987 | ##buglet: need to deal with case where patches are listed as URLs?
|
---|
| 988 | # or other extended pathnames? Silly !@$%^&!%%!%!! user!
|
---|
[35] | 989 | }
|
---|
| 990 |
|
---|
[53] | 991 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
| 992 | $paxcmd .= "SOURCES/$pkgdata{sources}{$source} ";
|
---|
| 993 | }
|
---|
| 994 |
|
---|
[36] | 995 | # add the spec file, source package destination, and cd back where we came from.
|
---|
| 996 | $paxcmd .= "SPECS/$barespec > $topdir/SDEBS/$pkgsrcname; cd -";
|
---|
[35] | 997 |
|
---|
[36] | 998 | # In case of %-macros...
|
---|
[35] | 999 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
| 1000 |
|
---|
[36] | 1001 | system "$paxcmd";
|
---|
[77] | 1002 | $finalmessages .= "Wrote source package $pkgsrcname in $topdir/SDEBS.\n";
|
---|
[35] | 1003 | }
|
---|
| 1004 |
|
---|
| 1005 |
|
---|
[38] | 1006 | ## checkbuildreq()
|
---|
| 1007 | # Checks the build requirements (if any)
|
---|
| 1008 | # Spits out a rude warning and returns a true-false error if any
|
---|
| 1009 | # requirements are not met.
|
---|
| 1010 | sub checkbuildreq {
|
---|
[40] | 1011 | return 1 if $buildreq eq ''; # No use doing extra work.
|
---|
[38] | 1012 |
|
---|
[52] | 1013 | if ( ! -e "/usr/bin/dpkg-query" ) {
|
---|
| 1014 | print "**WARNING** dpkg-query not found. Can't check build-deps.\n".
|
---|
| 1015 | " Required for sucessful build:\n".$buildreq."\n".
|
---|
| 1016 | " Continuing anyway.\n";
|
---|
| 1017 | return 1;
|
---|
| 1018 | }
|
---|
| 1019 |
|
---|
[38] | 1020 | my $reqflag = 1; # unset iff a buildreq is missing
|
---|
| 1021 |
|
---|
| 1022 | $buildreq =~ s/^, //; # Strip the leading comma and space
|
---|
| 1023 | my @reqlist = split /,\s+/, $buildreq;
|
---|
| 1024 |
|
---|
| 1025 | foreach my $req (@reqlist) {
|
---|
| 1026 | my ($pkg,$rel,$ver);
|
---|
| 1027 |
|
---|
| 1028 | # We have two classes of requirements - versioned and unversioned.
|
---|
| 1029 | if ($req =~ /[><=]/) {
|
---|
| 1030 | # Pick up the details of versioned buildreqs
|
---|
| 1031 | ($pkg,$rel,$ver) = ($req =~ /([a-z0-9._-]+)\s+([><=]+)\s+([a-z0-9._-]+)/);
|
---|
| 1032 | } else {
|
---|
| 1033 | # And the unversioned ones.
|
---|
| 1034 | $pkg = $req;
|
---|
| 1035 | $rel = '>=';
|
---|
| 1036 | $ver = 0;
|
---|
| 1037 | }
|
---|
| 1038 |
|
---|
| 1039 | my @pkglist = qx { dpkg-query --showformat '\${status}\t\${version}\n' -W $pkg };
|
---|
| 1040 | # need to check if no lines returned - means a bad buildreq
|
---|
| 1041 | my ($reqstat,undef,undef,$reqver) = split /\s+/, $pkglist[0];
|
---|
| 1042 | if ($reqstat !~ /install/) {
|
---|
| 1043 | print " * Missing build-dependency $pkg!\n";
|
---|
| 1044 | $reqflag = 0;
|
---|
| 1045 | } else {
|
---|
| 1046 | # gotta be a better way to do this... :/
|
---|
| 1047 | if ($rel eq '>=' && !($reqver ge $ver)) {
|
---|
| 1048 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
| 1049 | $reqflag = 0;
|
---|
| 1050 | }
|
---|
| 1051 | if ($rel eq '>' && !($reqver gt $ver)) {
|
---|
| 1052 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
| 1053 | $reqflag = 0;
|
---|
| 1054 | }
|
---|
| 1055 | if ($rel eq '<=' && !($reqver le $ver)) {
|
---|
| 1056 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
| 1057 | $reqflag = 0;
|
---|
| 1058 | }
|
---|
| 1059 | if ($rel eq '<' && !($reqver lt $ver)) {
|
---|
| 1060 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
| 1061 | $reqflag = 0;
|
---|
| 1062 | }
|
---|
| 1063 | if ($rel eq '=' && !($reqver eq $ver)) {
|
---|
| 1064 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n";
|
---|
| 1065 | $reqflag = 0;
|
---|
| 1066 | }
|
---|
| 1067 | } # end not installed/installed check
|
---|
| 1068 | } # end req loop
|
---|
| 1069 |
|
---|
| 1070 | return $reqflag;
|
---|
| 1071 | } # end checkbuildreq()
|
---|
| 1072 |
|
---|
| 1073 |
|
---|
| 1074 | ## getreqs()
|
---|
| 1075 | # Find out which libraries/packages are required for any
|
---|
| 1076 | # executables and libs in a given file tree.
|
---|
| 1077 | # (Debian doesn't have soname-level deps; just package-level)
|
---|
[41] | 1078 | # Returns an empty string if the tree contains no binaries.
|
---|
| 1079 | # Doesn't work well on shell scripts. but those *should* be
|
---|
| 1080 | # fine anyway. (Yeah, right...)
|
---|
[38] | 1081 | sub getreqs() {
|
---|
| 1082 | my $pkgtree = $_[0];
|
---|
| 1083 |
|
---|
[39] | 1084 | print "Checking library requirements...\n";
|
---|
[43] | 1085 | my @binlist = qx { find $pkgtree -type f -perm 755 };
|
---|
[38] | 1086 |
|
---|
[41] | 1087 | if (scalar(@binlist) == 0) {
|
---|
| 1088 | return '';
|
---|
| 1089 | }
|
---|
| 1090 |
|
---|
| 1091 | my @reqlist;
|
---|
| 1092 | foreach (@binlist) {
|
---|
| 1093 | push @reqlist, qx { ldd $_ };
|
---|
| 1094 | }
|
---|
| 1095 |
|
---|
| 1096 | # Get the list of libs provided by this package. Still doesn't
|
---|
| 1097 | # handle the case where the lib gets stuffed into a subpackage. :/
|
---|
| 1098 | my @intprovlist = qx { find $pkgtree -type f -name "*.so*" };
|
---|
| 1099 | my $provlist = '';
|
---|
| 1100 | foreach (@intprovlist) {
|
---|
| 1101 | s/$pkgtree//;
|
---|
| 1102 | $provlist .= "$_";
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
[38] | 1105 | my %reqs;
|
---|
[43] | 1106 | my $reqlibs = '';
|
---|
[38] | 1107 |
|
---|
| 1108 | foreach (@reqlist) {
|
---|
| 1109 | next if /^$pkgtree/;
|
---|
[42] | 1110 | next if /not a dynamic executable/;
|
---|
[41] | 1111 | next if m|/lib/ld-linux.so|; # Hack! Hack! PTHBTT! (libc suxx0rz)
|
---|
[38] | 1112 |
|
---|
[41] | 1113 | my ($req) = (/^\s+([a-z0-9._-]+)/); # dig out the actual library (so)name
|
---|
| 1114 |
|
---|
| 1115 | # Ignore libs provided by this package. Note that we don't match
|
---|
| 1116 | # on word-boundary at the *end* of the lib we're looking for, as the
|
---|
| 1117 | # looked-for lib may not have the full soname version. (ie, it may
|
---|
| 1118 | # "just" point to one of the symlinks that get created somewhere.)
|
---|
| 1119 | next if $provlist =~ /\b$req/;
|
---|
| 1120 |
|
---|
[38] | 1121 | $reqlibs .= " $req";
|
---|
| 1122 | }
|
---|
| 1123 |
|
---|
[43] | 1124 | if ($reqlibs ne '') {
|
---|
| 1125 | foreach (qx { dpkg -S $reqlibs }) {
|
---|
| 1126 | my ($libpkg,undef) = split /:\s+/;
|
---|
| 1127 | $reqs{$libpkg} = 1;
|
---|
| 1128 | }
|
---|
[38] | 1129 | }
|
---|
| 1130 |
|
---|
[43] | 1131 | my $deplist = '';
|
---|
[38] | 1132 | foreach (keys %reqs) {
|
---|
| 1133 | $deplist .= ", $_";
|
---|
| 1134 | }
|
---|
| 1135 |
|
---|
| 1136 | # For now, we're done. We're not going to meddle with versions yet.
|
---|
| 1137 | # Among other things, it's messier than handling "simple" yes/no "do
|
---|
| 1138 | # we have this lib?" deps. >:(
|
---|
| 1139 |
|
---|
| 1140 | return $deplist;
|
---|
| 1141 | } # end getreqs()
|
---|
| 1142 |
|
---|
| 1143 |
|
---|
[50] | 1144 | ## install_sdeb()
|
---|
| 1145 | # Extracts .sdeb contents to %_topdir as appropriate
|
---|
| 1146 | sub install_sdeb {
|
---|
| 1147 | my $paxcmd = "cd $topdir; pax -r <$srcpkg; cd -";
|
---|
| 1148 |
|
---|
| 1149 | # In case of %-macros...
|
---|
| 1150 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
| 1151 |
|
---|
| 1152 | system "$paxcmd";
|
---|
| 1153 | print "Extracted source package $srcpkg to $topdir.\n";
|
---|
| 1154 | } # end install_sdeb()
|
---|
| 1155 |
|
---|
| 1156 |
|
---|
[10] | 1157 | ## expandmacros()
|
---|
| 1158 | # Expands all %{blah} macros in the passed string
|
---|
[14] | 1159 | # Split up a bit with some sections so we don't spend time trying to
|
---|
| 1160 | # expand macros that are only used in a few specific places.
|
---|
[10] | 1161 | sub expandmacros {
|
---|
| 1162 | my $macrostring = shift;
|
---|
[14] | 1163 | my $section = shift;
|
---|
[10] | 1164 |
|
---|
[25] | 1165 | # To allow the FHS-ish %configure and %makeinstall to work The Right Way.
|
---|
[12] | 1166 | # (Without clobbering the global $buildroot.)
|
---|
| 1167 | my $prefix = '';
|
---|
| 1168 |
|
---|
[11] | 1169 | if ($section =~ /c/) {
|
---|
[12] | 1170 | # %configure macro
|
---|
[17] | 1171 | # Don't know what it's for, don't have a useful default replacement
|
---|
| 1172 | # --program-prefix=%{_program_prefix} \
|
---|
| 1173 | $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
|
---|
| 1174 | --build=$DEB_BUILD_GNU_TYPE \
|
---|
| 1175 | --prefix=%{_prefix} \
|
---|
| 1176 | --exec-prefix=%{_exec_prefix} \
|
---|
| 1177 | --bindir=%{_bindir} \
|
---|
| 1178 | --sbindir=%{_sbindir} \
|
---|
| 1179 | --sysconfdir=%{_sysconfdir} \
|
---|
| 1180 | --datadir=%{_datadir} \
|
---|
| 1181 | --includedir=%{_includedir} \
|
---|
| 1182 | --libdir=%{_libdir} \
|
---|
| 1183 | --libexecdir=%{_libexecdir} \
|
---|
| 1184 | --localstatedir=%{_localstatedir} \
|
---|
| 1185 | --sharedstatedir=%{_sharedstatedir} \
|
---|
| 1186 | --mandir=%{_mandir} \
|
---|
| 1187 | --infodir=%{_infodir} ';
|
---|
[12] | 1188 | } # done %configure
|
---|
| 1189 |
|
---|
| 1190 | if ($section =~ /m/) {
|
---|
| 1191 | $macrostring =~ s'%{__make}'make ';
|
---|
[25] | 1192 | } # done make
|
---|
[12] | 1193 |
|
---|
| 1194 | if ($section =~ /i/) {
|
---|
| 1195 | # This is where we need to mangle $prefix.
|
---|
[24] | 1196 | $macrostring =~ s'%makeinstall'make %{fhs} install';
|
---|
[12] | 1197 | $prefix = $buildroot;
|
---|
| 1198 | } # done %install and/or %makeinstall
|
---|
| 1199 |
|
---|
| 1200 | # Build data
|
---|
| 1201 | # Note that these are processed in reverse order to get the substitution order right
|
---|
| 1202 | if ($section =~ /b/) {
|
---|
[24] | 1203 | # $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
|
---|
| 1204 | # build=$DEB_BUILD_GNU_TYPE \
|
---|
| 1205 | $macrostring =~ s'%{fhs}'prefix=%{_prefix} \
|
---|
[17] | 1206 | exec-prefix=%{_exec_prefix} \
|
---|
| 1207 | bindir=%{_bindir} \
|
---|
| 1208 | sbindir=%{_sbindir} \
|
---|
| 1209 | sysconfdir=%{_sysconfdir} \
|
---|
| 1210 | datadir=%{_datadir} \
|
---|
| 1211 | includedir=%{_includedir} \
|
---|
| 1212 | libdir=%{_libdir} \
|
---|
| 1213 | libexecdir=%{_libexecdir} \
|
---|
| 1214 | localstatedir=%{_localstatedir} \
|
---|
| 1215 | sharedstatedir=%{_sharedstatedir} \
|
---|
| 1216 | mandir=%{_mandir} \
|
---|
| 1217 | infodir=%{_infodir} \
|
---|
| 1218 | ';
|
---|
[10] | 1219 |
|
---|
| 1220 | # Note that the above regex terminates with the extra space
|
---|
[12] | 1221 | # "Just In Case" of user additions, which will then get neatly
|
---|
| 1222 | # tagged on the end where they take precedence (supposedly)
|
---|
| 1223 | # over the "default" ones.
|
---|
[10] | 1224 |
|
---|
[14] | 1225 | # Now we cascade the macros introduced above. >_<
|
---|
| 1226 | # Wot ot to go theah:
|
---|
| 1227 | $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
|
---|
| 1228 | $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
|
---|
[25] | 1229 | $macrostring =~ s|%{_oldincludedir}|/usr/include|g; #/usr/include
|
---|
[84] | 1230 | $macrostring =~ s|%{_includedir}|%{_prefix}/include|g; #/usr/include
|
---|
[25] | 1231 | $macrostring =~ s|%{_libdir}|%{_exec_prefix}/%{_lib}|g; #/usr/lib
|
---|
[14] | 1232 | $macrostring =~ s|%{_lib}|lib|g; #?
|
---|
[25] | 1233 | $macrostring =~ s|%{_localstatedir}|/var|g; #/var
|
---|
| 1234 | $macrostring =~ s|%{_sharedstatedir}|%{_prefix}/com|g; #/usr/com WTF?
|
---|
| 1235 | $macrostring =~ s|%{_sysconfdir}|/etc|g; #/etc
|
---|
| 1236 | $macrostring =~ s|%{_datadir}|%{_prefix}/share|g; #/usr/share
|
---|
| 1237 | $macrostring =~ s|%{_libexecdir}|%{_exec_prefix}/libexec|g; #/usr/libexec
|
---|
| 1238 | $macrostring =~ s|%{_sbindir}|%{_exec_prefix}/sbin|g; #/usr/sbin
|
---|
| 1239 | $macrostring =~ s|%{_bindir}|%{_exec_prefix}/bin|g; #/usr/bin
|
---|
| 1240 | $macrostring =~ s|%{_exec_prefix}|%{_prefix}|g; #/usr
|
---|
[14] | 1241 | $macrostring =~ s|%{_prefix}|/usr|g; #/usr
|
---|
[10] | 1242 | } # done with config section
|
---|
| 1243 |
|
---|
[12] | 1244 | # Package data
|
---|
| 1245 | if ($section =~ /p/) {
|
---|
[15] | 1246 | $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
|
---|
| 1247 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
| 1248 | $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
|
---|
| 1249 | }
|
---|
| 1250 | $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
|
---|
| 1251 | $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
|
---|
| 1252 | $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
|
---|
[12] | 1253 | }
|
---|
| 1254 |
|
---|
| 1255 | # Globals, and not-so-globals
|
---|
| 1256 | if ($section =~ /g/) {
|
---|
[60] | 1257 |
|
---|
| 1258 | # special %define's. Handle the general case where we eval anything.
|
---|
| 1259 | # Prime example:
|
---|
| 1260 | #%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
|
---|
| 1261 | if ($macrostring =~ /^\%\(eval.+\)$/) {
|
---|
| 1262 | $macrostring =~ s/^\%\(//;
|
---|
| 1263 | $macrostring =~ s/\)$//;
|
---|
| 1264 | # Oy vey this gets silly for the perl bits. Executing a shell to
|
---|
| 1265 | # call Perl to get the vendorlib/sitelib/whatever "core" globals.
|
---|
| 1266 | # This can do more, but... eww.
|
---|
| 1267 | # Next line is non-optimal - what if $macrostring contains ' characters?
|
---|
| 1268 | $macrostring = qx { /bin/sh -c '$macrostring' };
|
---|
| 1269 | }
|
---|
| 1270 |
|
---|
[29] | 1271 | $macrostring =~ s|%{_builddir}|%{_topdir}/BUILD|g;
|
---|
| 1272 | $macrostring =~ s|%{_topdir}|$topdir|g;
|
---|
[13] | 1273 | $macrostring =~ s|%{_tmppath}|$tmpdir|g;
|
---|
[84] | 1274 | $macrostring =~ s'%{_docdir}'%{_datadir}/doc'g;
|
---|
[23] | 1275 |
|
---|
[31] | 1276 | # Standard FHS locations. More or less.
|
---|
[30] | 1277 | $macrostring =~ s'%{_bindir}'/usr/bin'g;
|
---|
[31] | 1278 | $macrostring =~ s'%{_sbindir}'/usr/sbin'g;
|
---|
[84] | 1279 | $macrostring =~ s'%{_mandir}'%{_datadir}/man'g;
|
---|
[30] | 1280 | $macrostring =~ s'%{_includedir}'/usr/include'g;
|
---|
[31] | 1281 | $macrostring =~ s'%{_libdir}'/usr/lib'g;
|
---|
| 1282 | $macrostring =~ s'%{_sysconfdir}'/etc'g;
|
---|
| 1283 | $macrostring =~ s'%{_localstatedir}'/var'g;
|
---|
[30] | 1284 |
|
---|
[84] | 1285 | # FHS-ish locations that aren't quite actually FHS-specified.
|
---|
| 1286 | $macrostring =~ s'%{_datadir}'/usr/share'g;
|
---|
| 1287 |
|
---|
[23] | 1288 | # %define's
|
---|
| 1289 | foreach my $key (keys %specglobals) {
|
---|
| 1290 | $macrostring =~ s|%{$key}|$specglobals{$key}|g;
|
---|
| 1291 | }
|
---|
| 1292 |
|
---|
| 1293 | # system programs. RPM uses a global config file for these; we'll just
|
---|
| 1294 | # ASS-U-ME and make life a little simpler.
|
---|
| 1295 | if ($macrostring =~ /\%\{\_\_([a-z0-9_-]+)\}/) {
|
---|
| 1296 | $macrostring =~ s|%{__([a-z0-9_-]+)}|$1|g;
|
---|
| 1297 | }
|
---|
[10] | 1298 | } # done with globals section
|
---|
| 1299 |
|
---|
| 1300 | return $macrostring;
|
---|
| 1301 | } # end expandmacros()
|
---|
[22] | 1302 |
|
---|
| 1303 |
|
---|
| 1304 |
|
---|
[38] | 1305 | __END__
|
---|
| 1306 |
|
---|
| 1307 |
|
---|
| 1308 |
|
---|
[22] | 1309 | =head1 NAME
|
---|
| 1310 |
|
---|
| 1311 | debbuild - Build Debian-compatible packages from RPM spec files
|
---|
| 1312 |
|
---|
| 1313 | =head1 SYNOPSIS
|
---|
| 1314 |
|
---|
| 1315 | debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
|
---|
| 1316 |
|
---|
| 1317 | debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2}
|
---|
| 1318 |
|
---|
[55] | 1319 | debbuild --rebuild file.{src.rpm|sdeb}
|
---|
[22] | 1320 |
|
---|
| 1321 | =head1 DESCRIPTION
|
---|
| 1322 |
|
---|
[55] | 1323 | This script attempts to build Debian-friendly semi-native packages from RPM spec files,
|
---|
| 1324 | RPM-friendly tarballs, and RPM source packages (.src.rpm files). It accepts I<most> of the
|
---|
| 1325 | options rpmbuild does, and should be able to interpret most spec files usefully. Perl
|
---|
| 1326 | modules should be handled via CPAN+dh-make-perl instead; Debian's conventions for such
|
---|
| 1327 | things do not lend themselves to automated conversion.
|
---|
[22] | 1328 |
|
---|
[55] | 1329 | As far as possible, the command-line options are identical to those from rpmbuild, although
|
---|
[57] | 1330 | several rpmbuild options are not supported:
|
---|
[22] | 1331 |
|
---|
[57] | 1332 | --recompile
|
---|
| 1333 | --showrc
|
---|
| 1334 | --buildroot
|
---|
| 1335 | --clean
|
---|
| 1336 | --nobuild
|
---|
| 1337 | --rmsource
|
---|
| 1338 | --rmspec
|
---|
| 1339 | --sign
|
---|
| 1340 | --target
|
---|
| 1341 |
|
---|
| 1342 | Some of these could probably be trivially added. Feel free to send me a patch. ;)
|
---|
| 1343 |
|
---|
| 1344 | Complex spec files will most likely not work well, if at all. Rewrite them from scratch -
|
---|
| 1345 | you'll have to make heavy modifications anyway.
|
---|
| 1346 |
|
---|
| 1347 | If you see something you don't like, mail me. Send a patch if you feel inspired. I don't
|
---|
| 1348 | promise I'll do anything other than say "Yup, that's broken" or "Got your message".
|
---|
| 1349 |
|
---|
[55] | 1350 | =head1 ASSUMPTIONS
|
---|
| 1351 |
|
---|
| 1352 | As with rpmbuild, debbuild makes some assumptions about your system.
|
---|
| 1353 |
|
---|
| 1354 | =over 4
|
---|
| 1355 |
|
---|
| 1356 | =item *
|
---|
| 1357 |
|
---|
| 1358 | Either you have rights to do as you please under /usr/src/debian, or you have created a file
|
---|
| 1359 | ~/.debmacros containing a suitable %_topdir definition.
|
---|
| 1360 |
|
---|
[57] | 1361 | Both rpmbuild and debbuild require the directories %_topdir/{BUILD,SOURCES,SPECS}. However,
|
---|
| 1362 | where rpmbuild requires the %_topdir/{RPMS,SRPMS} directories, debbuild
|
---|
| 1363 | requires %_topdir/{DEBS,SDEBS} instead. Create them in advance;
|
---|
[55] | 1364 | some subdirectories are created automatically as needed, but most are not.
|
---|
| 1365 |
|
---|
| 1366 | =item *
|
---|
| 1367 |
|
---|
| 1368 | /var/tmp must allow script execution - rpmbuild and debbuild both rely on creating and
|
---|
| 1369 | executing shell scripts for much of their functionality. By default, debbuild also creates
|
---|
| 1370 | install trees under /var/tmp - however this is (almost) entirely under the control of the
|
---|
| 1371 | package's .spec file.
|
---|
| 1372 |
|
---|
| 1373 | =item *
|
---|
| 1374 |
|
---|
| 1375 | If you wish to --rebuild a .src.rpm, your %_topdir for both debbuild and rpmbuild must either
|
---|
| 1376 | match, or be suitably symlinked one direction or another so that both programs are effectively
|
---|
| 1377 | working in the same tree. (Or you could just manually wrestle files around your system.)
|
---|
| 1378 |
|
---|
| 1379 | You could symlink ~/.rpmmacros to ~/.debmacros (or vice versa) and save yourself some hassle
|
---|
| 1380 | if you need to rebuild .src.rpm packages on a regular basis. Currently debbuild only uses the
|
---|
| 1381 | %_topdir macro definition, although there are many more things that rpmbuild can use from
|
---|
| 1382 | ~/.rpmmacros.
|
---|
| 1383 |
|
---|
| 1384 | =back
|
---|
| 1385 |
|
---|
[57] | 1386 | =head1 AUTHOR
|
---|
[55] | 1387 |
|
---|
[57] | 1388 | debbuild was written by Kris Deugau <kdeugau@deepnet.cx>. A version that approximates
|
---|
| 1389 | current is available at http://www.deepnet.cx/debbuild/.
|
---|
[55] | 1390 |
|
---|
| 1391 | =head1 BUGS
|
---|
| 1392 |
|
---|
[57] | 1393 | Funky Things Happen if you forget a command-line option or two. I've been too lazy to bother
|
---|
| 1394 | fixing this.
|
---|
[55] | 1395 |
|
---|
[57] | 1396 | Many macro expansions are unsupported or incompletely supported.
|
---|
| 1397 |
|
---|
| 1398 | The generated scriptlets don't quite match those from rpmbuild exactly. There are extra
|
---|
| 1399 | environment variables and preprocessing that I haven't needed (yet).
|
---|
| 1400 |
|
---|
| 1401 | Dcumentation, such as it is, will likely remain perpetually out of date.
|
---|
| 1402 |
|
---|
| 1403 | %_topdir and the five "working" directories under %_topdir could arguably be created by
|
---|
| 1404 | debbuild. However, rpmbuild doesn't create these directories either.
|
---|
| 1405 |
|
---|
| 1406 | =head1 SEE ALSO
|
---|
| 1407 |
|
---|
| 1408 | rpm(8), rpmbuild(8), and pretty much any document describing how to write a .spec file.
|
---|
| 1409 |
|
---|
[22] | 1410 | =cut
|
---|