[93] | 1 | #!/usr/bin/perl -w
|
---|
[2] | 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: 2011-02-01 22:21:11 +0000 (Tue, 01 Feb 2011) $
|
---|
| 9 | # SVN revision $Rev: 157 $
|
---|
| 10 | # Last update by $Author: kdeugau $
|
---|
| 11 | ###
|
---|
[140] | 12 | # Copyright 2005-2008 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
|
---|
[113] | 32 | use Config;
|
---|
[5] | 33 |
|
---|
[10] | 34 | # regex debugger
|
---|
| 35 | #use re "debug";
|
---|
| 36 |
|
---|
[130] | 37 | die "No .spec file to work with! Exiting.\n" if scalar(@ARGV) == 0;
|
---|
| 38 |
|
---|
[3] | 39 | # Program flow:
|
---|
| 40 | # -> Parse/execute "system" config/macros (if any - should be rare)
|
---|
| 41 | # -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
|
---|
| 42 | # -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
|
---|
| 43 |
|
---|
[30] | 44 | sub expandmacros;
|
---|
| 45 |
|
---|
[2] | 46 | # User's prefs for dirs, environment, etc,etc,etc.
|
---|
| 47 | # config file ~/.debmacros
|
---|
| 48 | # Default ordered search paths for config/macros:
|
---|
| 49 | # /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
|
---|
| 50 | # /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
|
---|
| 51 | # **NOTE: May be possible to (ab)use bits of debhelper
|
---|
| 52 |
|
---|
| 53 | # Build tree
|
---|
| 54 | # default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
|
---|
| 55 |
|
---|
[3] | 56 | # Globals
|
---|
[77] | 57 | my $finalmessages = ''; # A place to stuff messages that I want printed at the *very* end of any processing.
|
---|
[3] | 58 | my $specfile;
|
---|
| 59 | my $tarball;
|
---|
| 60 | my $srcpkg;
|
---|
[7] | 61 | my $cmdbuildroot;
|
---|
[95] | 62 | my $tarballdir = '%{name}-%{version}'; # We do this in case of a spec file not using %setup...
|
---|
[23] | 63 | my %specglobals; # For %define's in specfile, among other things.
|
---|
[6] | 64 |
|
---|
[98] | 65 | $specglobals{'_vendor'} = 'debbuild';
|
---|
[148] | 66 | $specglobals{'vendor'} = 'debbuild';
|
---|
[98] | 67 |
|
---|
[6] | 68 | # Initialized globals
|
---|
[3] | 69 | my $verbosity = 0;
|
---|
[112] | 70 | my $NoAutoReq = 0;
|
---|
[4] | 71 | my %cmdopts = (type => '',
|
---|
| 72 | stage => 'a',
|
---|
| 73 | short => 'n'
|
---|
| 74 | );
|
---|
[6] | 75 | my $topdir = "/usr/src/debian";
|
---|
[136] | 76 | #my $specglobals{buildroot} = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
|
---|
| 77 | $specglobals{buildroot} = '';
|
---|
[6] | 78 |
|
---|
| 79 | # "Constants"
|
---|
[4] | 80 | my %targets = ('p' => 'Prep',
|
---|
| 81 | 'c' => 'Compile',
|
---|
| 82 | 'i' => 'Install',
|
---|
| 83 | 'l' => 'Verify %files',
|
---|
| 84 | 'a' => 'Build binary and source',
|
---|
| 85 | 'b' => 'Build binary',
|
---|
| 86 | 's' => 'Build source'
|
---|
| 87 | );
|
---|
[87] | 88 | # Ah, the joys of multiple architectures. :( Feh.
|
---|
| 89 | # As copied from rpm
|
---|
| 90 | my %optflags = ( 'i386' => '-O2 -g -march=i386 -mcpu=i686',
|
---|
| 91 | 'amd64' => '-O2 -g'
|
---|
| 92 | );
|
---|
| 93 | my $hostarch; # we set this later...
|
---|
[6] | 94 | my $scriptletbase =
|
---|
| 95 | q(#!/bin/sh
|
---|
[3] | 96 |
|
---|
[6] | 97 | RPM_SOURCE_DIR="%{_topdir}/SOURCES"
|
---|
| 98 | RPM_BUILD_DIR="%{_topdir}/BUILD"
|
---|
[87] | 99 | RPM_OPT_FLAGS="%{optflags}"
|
---|
| 100 | RPM_ARCH="%{_arch}"
|
---|
[6] | 101 | RPM_OS="linux"
|
---|
| 102 | export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
|
---|
| 103 | RPM_DOC_DIR="/usr/share/doc"
|
---|
| 104 | export RPM_DOC_DIR
|
---|
| 105 | RPM_PACKAGE_NAME="%{name}"
|
---|
| 106 | RPM_PACKAGE_VERSION="%{version}"
|
---|
| 107 | RPM_PACKAGE_RELEASE="%{release}"
|
---|
| 108 | export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
|
---|
| 109 | RPM_BUILD_ROOT="%{buildroot}"
|
---|
| 110 | export RPM_BUILD_ROOT
|
---|
[10] | 111 | );
|
---|
| 112 | foreach (`dpkg-architecture`) {
|
---|
| 113 | s/=(.+)/="$1"/;
|
---|
| 114 | $scriptletbase .= " $_";
|
---|
[90] | 115 | ($hostarch) = (/^DEB_HOST_ARCH="(.+)"$/) if /DEB_HOST_ARCH=/;
|
---|
[10] | 116 | }
|
---|
| 117 | $scriptletbase .=
|
---|
| 118 | q(
|
---|
[6] | 119 | set -x
|
---|
| 120 | umask 022
|
---|
| 121 | cd %{_topdir}/BUILD
|
---|
| 122 | );
|
---|
| 123 |
|
---|
[102] | 124 | # Hackery to try to bring some semblance of sanity to packages built for more
|
---|
| 125 | # than one Debian version at the same time. Whee.
|
---|
| 126 | # /etc/debian-version
|
---|
| 127 | my %distmap = (
|
---|
| 128 | "3.1.9ubuntu7.1" => "dapper",
|
---|
| 129 | "4ubuntu2" => "feisty",
|
---|
| 130 | "3.0" => "woody",
|
---|
| 131 | "3.1" => "sarge",
|
---|
| 132 | "4" => "etch",
|
---|
[151] | 133 | "5" => "lenny",
|
---|
| 134 | "5.0.0" => "squeeze",
|
---|
| 135 | "99" => "sid");
|
---|
[102] | 136 | # Enh. There doesn't seem to be any better way to do this... :(
|
---|
| 137 | {
|
---|
[151] | 138 | # could theoretically also do something with this... it's about as stable as "dpkg-query ..." below... :(
|
---|
| 139 | # my $releasever = qx { cat /etc/debian_version };
|
---|
| 140 | # chomp $releasever;
|
---|
| 141 | my $basever;
|
---|
[102] | 142 |
|
---|
[151] | 143 | if ( ! -e '/usr/bin/dpkg-query' ) {
|
---|
| 144 | # call it woody, since sarge and newer have dpkg-query, and we don't much care about obsolete^n releases
|
---|
| 145 | $basever = "3.0";
|
---|
| 146 | } else {
|
---|
| 147 |
|
---|
| 148 | # for the lazy copy-paster: dpkg-query --showformat '${version}\n' -W base-files
|
---|
| 149 | # avoid shellisms
|
---|
| 150 | if (open BASEGETTER, "-|", "dpkg-query", "--showformat", '${version}', "-W", "base-files") {
|
---|
| 151 | $basever = <BASEGETTER>;
|
---|
| 152 | close BASEGETTER;
|
---|
| 153 |
|
---|
| 154 | if ($basever =~ /^\d\.\d\.\d$/) {
|
---|
| 155 | # sarge, possibly squeeze O_o (5.0.0 as of 2010/02/03)
|
---|
| 156 | $basever =~ s/\.\d$//;
|
---|
| 157 | }
|
---|
| 158 | $basever = 5 if ($basever =~ /lenny/);
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | } # got dpkg-query?
|
---|
| 162 |
|
---|
[102] | 163 | $specglobals{"debdist"} = $distmap{$basever};
|
---|
[151] | 164 | $specglobals{"debver"} = $basever; # this may have trouble with Ubuntu versions?
|
---|
[102] | 165 |
|
---|
[151] | 166 | } # done trying to set debian dist/version
|
---|
| 167 |
|
---|
[5] | 168 | # Package data
|
---|
| 169 | # This is the form of $pkgdata{pkgname}{meta}
|
---|
| 170 | # meta includes Summary, Name, Version, Release, Group, Copyright,
|
---|
[138] | 171 | # Source, URL, Packager, BuildRoot, Description, BuildRequires,
|
---|
[38] | 172 | # Requires, Provides
|
---|
[6] | 173 | # 10/31/2005 Maybe this should be flatter? -kgd
|
---|
[5] | 174 | my %pkgdata;
|
---|
[27] | 175 | my @pkglist = ('main'); #sigh
|
---|
[23] | 176 | # Files listing. Embedding this in %pkgdata would be, um, messy.
|
---|
| 177 | my %filelist;
|
---|
[110] | 178 | my %doclist;
|
---|
[40] | 179 | my $buildreq = '';
|
---|
[5] | 180 |
|
---|
[6] | 181 | # Scriptlets
|
---|
[48] | 182 | my $prepscript = '';
|
---|
| 183 | my $buildscript = '';
|
---|
[23] | 184 | # %install doesn't need the full treatment from %clean; just an empty place to install to.
|
---|
| 185 | # NB - rpm doesn't do this; is it really necessary?
|
---|
| 186 | my $installscript = '[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT'."\n";
|
---|
[48] | 187 | my $cleanscript = '';
|
---|
[6] | 188 |
|
---|
[13] | 189 | # Snag some environment data
|
---|
| 190 | my $tmpdir;
|
---|
| 191 | if (defined $ENV{TMP} && $ENV{TMP} =~ /^(\/var)?\/tmp$/) {
|
---|
| 192 | $tmpdir = $ENV{TMP};
|
---|
| 193 | } else {
|
---|
| 194 | $tmpdir = "/var/tmp";
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[7] | 197 | ##main
|
---|
| 198 |
|
---|
[4] | 199 | load_userconfig();
|
---|
[3] | 200 | parse_cmd();
|
---|
| 201 |
|
---|
[50] | 202 | if ($cmdopts{install}) {
|
---|
| 203 | install_sdeb();
|
---|
| 204 | exit 0;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[81] | 207 | # output stage of --showpkgs
|
---|
[71] | 208 | if ($cmdopts{type} eq 'd') {
|
---|
| 209 | parse_spec();
|
---|
| 210 | foreach my $pkg (@pkglist) {
|
---|
| 211 | $pkgdata{$pkg}{name} =~ tr/_/-/;
|
---|
| 212 |
|
---|
[111] | 213 | my $pkgfullname = "$pkgdata{$pkg}{name}_".
|
---|
| 214 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 215 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb";
|
---|
[71] | 216 |
|
---|
[76] | 217 | print "$pkgfullname\n" if $filelist{$pkg};
|
---|
[79] | 218 |
|
---|
[71] | 219 | }
|
---|
[80] | 220 | # Source package
|
---|
[111] | 221 | print "$pkgdata{main}{name}-".
|
---|
| 222 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 223 | "$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb\n";
|
---|
[71] | 224 | exit 0;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
[50] | 227 | # Stick --rebuild handling in here - basically install_sdeb()
|
---|
| 228 | # followed by tweaking options to run with -ba
|
---|
[54] | 229 | if ($cmdopts{type} eq 's') {
|
---|
[55] | 230 | if ($srcpkg =~ /\.src\.rpm$/) {
|
---|
[58] | 231 | my @srclist = qx { rpm -qlp $srcpkg };
|
---|
[55] | 232 | foreach (@srclist) {
|
---|
[54] | 233 | chomp;
|
---|
[55] | 234 | $specfile = "$topdir/SPECS/$_" if /\.spec$/;
|
---|
[54] | 235 | }
|
---|
[55] | 236 | qx { rpm -i $srcpkg };
|
---|
| 237 | } else {
|
---|
| 238 | install_sdeb();
|
---|
| 239 | my @srclist = qx { pax < $srcpkg };
|
---|
| 240 | foreach (@srclist) {
|
---|
| 241 | chomp;
|
---|
| 242 | $specfile = "$topdir/$_" if /SPECS/;
|
---|
| 243 | }
|
---|
[54] | 244 | }
|
---|
[55] | 245 | $cmdopts{type} = 'b';
|
---|
| 246 | $cmdopts{stage} = 'a';
|
---|
[54] | 247 | }
|
---|
[50] | 248 |
|
---|
[7] | 249 | if ($cmdopts{type} eq 'b') {
|
---|
| 250 | # Need to read the spec file to find the tarball. Note that
|
---|
| 251 | # this also generates most of the shell script required.
|
---|
| 252 | parse_spec();
|
---|
[38] | 253 | die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
|
---|
| 254 | if !checkbuildreq();
|
---|
[7] | 255 | }
|
---|
| 256 |
|
---|
[65] | 257 | if ($cmdopts{type} eq 't') {
|
---|
| 258 | # Need to unpack the tarball to find the spec file. Sort of the inverse of -b above.
|
---|
| 259 | # zcat $tarball |tar -t |grep .spec
|
---|
| 260 | # collect some info about the tarball
|
---|
[99] | 261 | $specfile = "$topdir/BUILD/". qx { zcat $tarball |tar -t |grep -e '[\.]spec\$' };
|
---|
[65] | 262 | chomp $specfile;
|
---|
| 263 | my ($fileonly, $dirname) = ($tarball =~ /(([a-zA-Z0-9._-]+)\.tar\.(?:gz|bz2))$/);
|
---|
| 264 |
|
---|
| 265 | $tarball = abs_path($tarball);
|
---|
| 266 | my $unpackcmd = "cd $topdir/BUILD; tar -".
|
---|
| 267 | ( $tarball =~ /\.tar\.gz$/ ? "z" : "" ).
|
---|
| 268 | ( $tarball =~ /\.tar\.bz2$/ ? "j" : "" ). "xf $tarball";
|
---|
| 269 | system "$unpackcmd";
|
---|
| 270 | system "cp $tarball $topdir/SOURCES/$fileonly";
|
---|
| 271 | system "cp $specfile $topdir/SPECS/";
|
---|
| 272 | parse_spec();
|
---|
| 273 | die "Can't build $pkgdata{main}{name}: build requirements not met.\n"
|
---|
| 274 | if !checkbuildreq();
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[35] | 277 | # -> srcpkg if -.s
|
---|
| 278 | if ($cmdopts{stage} eq 's') {
|
---|
| 279 | srcpackage();
|
---|
| 280 | exit 0;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[4] | 283 | # Hokay. Need to:
|
---|
[14] | 284 | # -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
|
---|
[7] | 285 | if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 286 | prep();
|
---|
| 287 | }
|
---|
[14] | 288 | # -> build if -.c OR (-.[ilabs] AND !--short-circuit)
|
---|
[7] | 289 | if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 290 | build();
|
---|
| 291 | }
|
---|
[14] | 292 | # -> install if -.[ilabs]
|
---|
[28] | 293 | #if ($cmdopts{stage} eq 'i' || ($cmdopts{stage} =~ /[labs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 294 | if ($cmdopts{stage} =~ /[ilabs]/) {
|
---|
[7] | 295 | install();
|
---|
[30] | 296 | #foreach my $pkg (@pkglist) {
|
---|
| 297 | # print "files in $pkg:\n ".$filelist{$pkg}."\n";
|
---|
| 298 | #}
|
---|
| 299 |
|
---|
[7] | 300 | }
|
---|
[14] | 301 | # -> binpkg and srcpkg if -.a
|
---|
[7] | 302 | if ($cmdopts{stage} eq 'a') {
|
---|
[4] | 303 | binpackage();
|
---|
[7] | 304 | srcpackage();
|
---|
[97] | 305 | clean();
|
---|
[4] | 306 | }
|
---|
[14] | 307 | # -> binpkg if -.b
|
---|
[7] | 308 | if ($cmdopts{stage} eq 'b') {
|
---|
| 309 | binpackage();
|
---|
[97] | 310 | clean();
|
---|
[7] | 311 | }
|
---|
[4] | 312 |
|
---|
[77] | 313 | # Spit out any closing remarks
|
---|
| 314 | print $finalmessages;
|
---|
| 315 |
|
---|
[4] | 316 | # Just in case.
|
---|
| 317 | exit 0;
|
---|
| 318 |
|
---|
| 319 |
|
---|
| 320 | ## load_userconfig()
|
---|
| 321 | # Loads user configuration (if any)
|
---|
| 322 | # Currently only handles .debmacros
|
---|
| 323 | # Needs to handle "other files"
|
---|
| 324 | sub load_userconfig {
|
---|
[96] | 325 | my $homedir = (getpwuid($<))[7];
|
---|
[4] | 326 | if (-e "$homedir/.debmacros") {
|
---|
| 327 | open USERMACROS,"<$homedir/.debmacros";
|
---|
| 328 | while (<USERMACROS>) {
|
---|
[7] | 329 | # And we also only handle a few macros at the moment.
|
---|
[4] | 330 | if (/^\%_topdir/) {
|
---|
[5] | 331 | my (undef,$tmp) = split /\s+/, $_;
|
---|
| 332 | $topdir = $tmp;
|
---|
[4] | 333 | }
|
---|
[96] | 334 | next if /^\%_/;
|
---|
| 335 | # Allow arbitrary definitions. Note that we're only doing simple defs here for now.
|
---|
| 336 | if (/^\%([a-z0-9]+)\s+(.+)$/) {
|
---|
| 337 | $specglobals{$1} = $2;
|
---|
| 338 | }
|
---|
[4] | 339 | }
|
---|
| 340 | }
|
---|
| 341 | } # end load_userconfig()
|
---|
| 342 |
|
---|
| 343 |
|
---|
[3] | 344 | ## parse_cmd()
|
---|
[4] | 345 | # Parses command line into global hash %cmdopts, other globals
|
---|
[3] | 346 | # Options based on rpmbuild's options
|
---|
| 347 | sub parse_cmd {
|
---|
| 348 | # Don't feel like coding my own option parser...
|
---|
| 349 | #use Getopt::Long;
|
---|
| 350 | # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
|
---|
| 351 | #use Getopt::Popt qw(:all);
|
---|
[4] | 352 | # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
|
---|
[3] | 353 |
|
---|
| 354 | # Stuff it.
|
---|
[4] | 355 | my $prevopt = '';
|
---|
[3] | 356 | foreach (@ARGV) {
|
---|
| 357 | chomp;
|
---|
[7] | 358 |
|
---|
[3] | 359 | # Is it an option?
|
---|
| 360 | if (/^-/) {
|
---|
[7] | 361 |
|
---|
[3] | 362 | # Is it a long option?
|
---|
| 363 | if (/^--/) {
|
---|
[4] | 364 | if (/^--short-circuit/) {
|
---|
| 365 | $cmdopts{short} = 'y';
|
---|
[5] | 366 | } elsif (/^--rebuild/) {
|
---|
| 367 | $cmdopts{type} = 's';
|
---|
[71] | 368 | } elsif (/^--showpkgs/) {
|
---|
| 369 | $cmdopts{type} = 'd'; # d for 'diagnostic' or 'debug' or 'dump'
|
---|
[94] | 370 | } elsif (/^--define/) {
|
---|
| 371 | # nothing to do? Can't see anything needed, we handle the actual definition later.
|
---|
[122] | 372 | ##fixme
|
---|
| 373 | # add --self-package here
|
---|
| 374 | # deps build-essential pax fakeroot
|
---|
[4] | 375 | } else {
|
---|
[93] | 376 | print "Long option $_ not handled\n";
|
---|
[4] | 377 | }
|
---|
[3] | 378 | } else {
|
---|
[14] | 379 | # Not a long option
|
---|
[5] | 380 | if (/^-[bt]/) {
|
---|
| 381 | if ($cmdopts{stage} eq 's') {
|
---|
| 382 | # Mutually exclusive options.
|
---|
| 383 | die "Can't use $_ with --rebuild\n";
|
---|
| 384 | } else {
|
---|
[14] | 385 | # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
|
---|
[5] | 386 | ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
|
---|
| 387 | ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
|
---|
| 388 | }
|
---|
[4] | 389 | } elsif (/^-v/) {
|
---|
| 390 | # bump verbosity. Not sure what I'll actually do here...
|
---|
[50] | 391 | } elsif (/^-i/) {
|
---|
| 392 | $cmdopts{install} = 1;
|
---|
| 393 | $prevopt = '-i';
|
---|
[4] | 394 | } else {
|
---|
| 395 | die "Bad option $_\n";
|
---|
| 396 | }
|
---|
[3] | 397 | }
|
---|
[14] | 398 |
|
---|
| 399 | } else { # Not an option argument
|
---|
| 400 |
|
---|
[5] | 401 | # --buildroot is the only option that takes an argument
|
---|
| 402 | # Therefore, any *other* bare arguments are the spec file,
|
---|
| 403 | # tarball, or source package we're operating on - depending
|
---|
| 404 | # on which one we meet.
|
---|
| 405 | if ($prevopt eq '--buildroot') {
|
---|
[7] | 406 | $cmdbuildroot = $_;
|
---|
[94] | 407 | } elsif ($prevopt eq '--define') {
|
---|
[118] | 408 | my ($macro,$value) = (/([a-z0-9_.-]+)(?:\s+(.+))?/i);
|
---|
[127] | 409 | if ($value ne '') {
|
---|
[94] | 410 | $specglobals{$macro} = $value;
|
---|
| 411 | } else {
|
---|
| 412 | warn "WARNING: missing value for macro $macro in --define! Ignoring.\n";
|
---|
| 413 | }
|
---|
[50] | 414 | } elsif ($prevopt eq '-i') {
|
---|
| 415 | $srcpkg = $_;
|
---|
[5] | 416 | } else {
|
---|
| 417 | if ($cmdopts{type} eq 's') {
|
---|
| 418 | # Source package
|
---|
[50] | 419 | if (!/(sdeb|\.src\.rpm)$/) {
|
---|
[5] | 420 | die "Can't --rebuild with $_\n";
|
---|
| 421 | }
|
---|
[50] | 422 | $srcpkg = $_;
|
---|
[71] | 423 | } elsif ($cmdopts{type} eq 'b' || $cmdopts{type} eq 'd') {
|
---|
[65] | 424 | # Spec file
|
---|
[5] | 425 | $specfile = $_;
|
---|
| 426 | } else {
|
---|
[65] | 427 | # Tarball build. Need to extract tarball to find spec file. Whee.
|
---|
| 428 | $tarball = $_;
|
---|
[5] | 429 | }
|
---|
| 430 | }
|
---|
[3] | 431 | }
|
---|
[7] | 432 | $prevopt = $_;
|
---|
| 433 | } # foreach @ARGV
|
---|
[4] | 434 |
|
---|
| 435 | # Some cross-checks. rpmbuild limits --short-circuit to just
|
---|
| 436 | # the "compile" and "install" targets - with good reason IMO.
|
---|
[14] | 437 | # Note that --short-circuit with -.p is not really an error, just redundant.
|
---|
[4] | 438 | # NB - this is NOT fatal, just ignored!
|
---|
[10] | 439 | if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
|
---|
[4] | 440 | warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
|
---|
[28] | 441 | $cmdopts{short} = 'n';
|
---|
[4] | 442 | }
|
---|
[14] | 443 |
|
---|
[3] | 444 | # Valid options, with example arguments (if any):
|
---|
| 445 | # Build from .spec file; mutually exclusive:
|
---|
| 446 | # -bp
|
---|
| 447 | # -bc
|
---|
| 448 | # -bi
|
---|
| 449 | # -bl
|
---|
| 450 | # -ba
|
---|
| 451 | # -bb
|
---|
| 452 | # -bs
|
---|
| 453 | # Build from tarball; mutually exclusive:
|
---|
| 454 | # -tp
|
---|
| 455 | # -tc
|
---|
| 456 | # -ti
|
---|
| 457 | # -ta
|
---|
| 458 | # -tb
|
---|
| 459 | # -ts
|
---|
| 460 | # Build from .src.(deb|rpm)
|
---|
| 461 | # --rebuild
|
---|
| 462 | # --recompile
|
---|
| 463 |
|
---|
| 464 | # General options
|
---|
| 465 | # --buildroot=DIRECTORY
|
---|
| 466 | # --clean
|
---|
| 467 | # --nobuild
|
---|
| 468 | # --nodeps
|
---|
| 469 | # --nodirtokens
|
---|
| 470 | # --rmsource
|
---|
| 471 | # --rmspec
|
---|
| 472 | # --short-circuit
|
---|
| 473 | # --target=CPU-VENDOR-OS
|
---|
| 474 |
|
---|
| 475 | #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
|
---|
| 476 |
|
---|
| 477 | } # end parse_cmd()
|
---|
| 478 |
|
---|
[4] | 479 |
|
---|
[5] | 480 | ## parse_spec()
|
---|
[14] | 481 | # Parse the .spec file.
|
---|
[5] | 482 | sub parse_spec {
|
---|
[130] | 483 | die "No .spec file specified! Exiting.\n" if !$specfile;
|
---|
[65] | 484 | open SPECFILE,"<$specfile" or die "specfile ($specfile) barfed: $!";
|
---|
[5] | 485 |
|
---|
[95] | 486 | my $iflevel = 0;
|
---|
[87] | 487 | my $buildarch = $hostarch;
|
---|
[88] | 488 | $pkgdata{main}{arch} = $hostarch;
|
---|
[87] | 489 |
|
---|
[103] | 490 | my $stage = 'preamble';
|
---|
| 491 | my $subname = 'main';
|
---|
| 492 | my $scriptlet;
|
---|
[14] | 493 |
|
---|
[103] | 494 | # Basic algorithm:
|
---|
| 495 | # For each line
|
---|
| 496 | # if it's a member of an %if construct, branch and see which segment of the
|
---|
| 497 | # spec file we need to parse and which one gets discarded, then
|
---|
| 498 | # short-circuit back to the top of the loop.
|
---|
| 499 | # if it's a %section, bump the stage. Preparse addons to the %section line
|
---|
| 500 | # (eg subpackage) and stuff them in suitable loop-global variables, then
|
---|
| 501 | # short-circuit back to the top of the loop.
|
---|
| 502 | # Otherwise, parse the line according to which section we're supposedly
|
---|
| 503 | # parsing right now
|
---|
[14] | 504 |
|
---|
[103] | 505 | LINE: while (<SPECFILE>) {
|
---|
[109] | 506 | next if /^#/ && $stage eq 'preamble'; # Ignore comments...
|
---|
| 507 | next if /^\s*$/ && $stage eq 'preamble'; # ... and blank lines.
|
---|
[23] | 508 |
|
---|
[119] | 509 | # no sense in continuing if we find something we don't grok
|
---|
| 510 | # Yes, this is really horribly fugly. But it's a cheap crosscheck against invalid
|
---|
| 511 | # %-tags which also make rpmbuild barf. In theory.
|
---|
| 512 | # notes: some of these are not *entirely* case-sensitive (%ifxxx), but most are.
|
---|
| 513 | # Extracted from the Maximum RPM online doc via:
|
---|
| 514 | # grep -h %[a-z] *|perl -e 'while (<>) { /\%([a-z0-9]+)\b/; print "$1|\n"; }'|sort -u
|
---|
| 515 | if (/^%[a-z]/ &&
|
---|
[120] | 516 | $_ !~ /^%(?:attr|build|changelog|check|clean|config|configure|defattr|define|description|
|
---|
[119] | 517 | dir|doc|docdir|else|endif|files|ghost|if|ifarch|ifn|ifnarch|ifnos|ifnxxx|fos|ifxxx|
|
---|
[133] | 518 | install|makeinstall|package|patch\d+|post|postun|pre|prep|preun|readme|setup|
|
---|
[119] | 519 | triggerin|triggerpostun|triggerun|verify|verifyscript)\b/x
|
---|
| 520 | ) {
|
---|
| 521 | my ($badtag) = (/^%([a-z]+)/i);
|
---|
| 522 | die "Unknown tag \%$badtag at line $. of $specfile\n";
|
---|
| 523 | }
|
---|
| 524 |
|
---|
[103] | 525 | # preprocess %define's
|
---|
| 526 | if (my ($key, $def) = (/^\%define\s+([^\s]+)\s+(.+)$/) ) {
|
---|
| 527 | $specglobals{$key} = expandmacros($def,'g');
|
---|
| 528 | }
|
---|
[98] | 529 |
|
---|
[103] | 530 | if (/^\%if/) {
|
---|
| 531 | s/^\%if//;
|
---|
| 532 | chomp;
|
---|
| 533 | my $expr = expandmacros($_, 'g');
|
---|
| 534 | $iflevel++;
|
---|
[98] | 535 |
|
---|
[103] | 536 | if ($expr !~ /^\s*\d+\s*$/) {
|
---|
| 537 | # gots a logic statement we want to turn into a 1 or a 0. most likely by eval'ing it.
|
---|
[98] | 538 |
|
---|
[103] | 539 | $expr =~ s/\s+//g;
|
---|
[98] | 540 |
|
---|
[104] | 541 | # For Great w00tness! New and Improved multilayered logic handling.
|
---|
| 542 |
|
---|
| 543 | my @bits = split /\b/, $expr;
|
---|
| 544 | $expr = '';
|
---|
| 545 | foreach my $bit (@bits) {
|
---|
| 546 | next if $bit eq '"';
|
---|
| 547 | $bit =~ s/"//g;
|
---|
| 548 | $expr .= qq("$bit") if $bit =~ /^\w+$/;
|
---|
| 549 | $expr .= $bit if $bit !~ /^\w+$/;
|
---|
| 550 | }
|
---|
| 551 |
|
---|
[103] | 552 | # Done in this order so we don't cascade incorrectly. Yes, those spaces ARE correct in the replacements!
|
---|
[104] | 553 | $expr =~ s/==/ eq /g;
|
---|
| 554 | $expr =~ s/!=/ ne /g;
|
---|
| 555 | $expr =~ s/<=>/ cmp /g;
|
---|
| 556 | $expr =~ s/<=/ le /g;
|
---|
| 557 | $expr =~ s/>=/ ge /g;
|
---|
| 558 | $expr =~ s/</ lt /g;
|
---|
| 559 | $expr =~ s/>/ gt /g;
|
---|
[98] | 560 |
|
---|
[103] | 561 | # Turn it into something that eval's to a number. Maybe not needed? O_o
|
---|
| 562 | #$expr = "( $expr ? 1 : 0 )";
|
---|
[98] | 563 |
|
---|
[103] | 564 | $expr = eval $expr;
|
---|
[95] | 565 | }
|
---|
[103] | 566 |
|
---|
| 567 | next LINE if $expr != 0; # This appears to be the only case we call false.
|
---|
| 568 | while (<SPECFILE>) {
|
---|
| 569 | if (/^\%endif/) {
|
---|
| 570 | $iflevel--;
|
---|
| 571 | next LINE;
|
---|
| 572 | } elsif (/^\%else/) {
|
---|
| 573 | next LINE;
|
---|
| 574 | }
|
---|
[95] | 575 | }
|
---|
[103] | 576 | }
|
---|
| 577 | if (/^\%else/) {
|
---|
| 578 | while (<SPECFILE>) {
|
---|
| 579 | if (/^\%endif/) {
|
---|
| 580 | $iflevel--;
|
---|
| 581 | next LINE;
|
---|
| 582 | }
|
---|
[95] | 583 | }
|
---|
[103] | 584 | }
|
---|
| 585 | if (/^\%endif/) {
|
---|
| 586 | $iflevel--;
|
---|
| 587 | next LINE;
|
---|
| 588 | } # %if/%else/%endif
|
---|
[95] | 589 |
|
---|
[126] | 590 | if (/^\%{echo:(.+)}/) {
|
---|
| 591 | my $output = expandmacros($1, 'gp');
|
---|
[136] | 592 | print "$output";
|
---|
[126] | 593 | }
|
---|
| 594 |
|
---|
[105] | 595 | # now we pick out the sections and set "state" to parse that section. Fugly but I can't see a better way. >:(
|
---|
| 596 |
|
---|
[103] | 597 | if (/^\%description(?:\s+(?:-n\s+)?(.+))?/) {
|
---|
[105] | 598 | $stage = 'desc';
|
---|
[103] | 599 | $subname = "main";
|
---|
| 600 | if ($1) { # Magic to add entries to the right package
|
---|
[153] | 601 | my $tmp = expandmacros("$1", 'gp');
|
---|
[103] | 602 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
[18] | 603 | }
|
---|
[105] | 604 | next LINE;
|
---|
[103] | 605 | } # %description
|
---|
| 606 |
|
---|
| 607 | if (/^\%package\s+(?:-n\s+)?(.+)/) {
|
---|
| 608 | $stage = 'package';
|
---|
| 609 | if ($1) { # Magic to add entries to the right package
|
---|
[153] | 610 | my $tmp = expandmacros("$1", 'gp');
|
---|
[103] | 611 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
| 612 | }
|
---|
| 613 | push @pkglist, $subname;
|
---|
| 614 | $pkgdata{$subname}{name} = $subname;
|
---|
| 615 | $pkgdata{$subname}{version} = $pkgdata{main}{version};
|
---|
[87] | 616 | # Build "same arch as previous package found" by default. Where rpm just picks the
|
---|
| 617 | # *very* last one, we want to allow arch<native>+arch-all
|
---|
| 618 | # (eg, Apache is i386, but apache-manual is all)
|
---|
[103] | 619 | $pkgdata{$subname}{arch} = $buildarch; # Since it's likely subpackages will NOT have a BuildArch line...
|
---|
| 620 | next LINE;
|
---|
| 621 | } # %package
|
---|
| 622 |
|
---|
| 623 | if (/^\%prep/) {
|
---|
| 624 | $stage = 'prep';
|
---|
| 625 | # This really should be local-ish, but we need just the filename for the source
|
---|
| 626 | $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
|
---|
| 627 | # Replace some core macros
|
---|
| 628 | $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
|
---|
| 629 | next LINE;
|
---|
| 630 | } # %prep
|
---|
| 631 |
|
---|
| 632 | if (/^\%build/) {
|
---|
| 633 | $stage = 'build';
|
---|
| 634 | $buildscript .= "cd $tarballdir\n";
|
---|
| 635 | next LINE;
|
---|
| 636 | } # %build
|
---|
| 637 |
|
---|
| 638 | if (/^\%install/) {
|
---|
| 639 | $stage = 'install';
|
---|
| 640 | $installscript .= "cd $tarballdir\n";
|
---|
| 641 | next LINE;
|
---|
| 642 | } # %install
|
---|
| 643 |
|
---|
| 644 | if (/^\%clean/) {
|
---|
| 645 | $stage = 'clean';
|
---|
| 646 | $cleanscript .= "cd $tarballdir\n";
|
---|
| 647 | next LINE;
|
---|
| 648 | } # %clean
|
---|
| 649 |
|
---|
| 650 | if (/^\%(pre|post|preun|postun)\b(?:\s+(?:-n\s+)?(.+))?/i) {
|
---|
| 651 | $stage = 'prepost';
|
---|
| 652 | $scriptlet = lc $1;
|
---|
| 653 | $subname = 'main';
|
---|
| 654 | if ($2) { # Magic to add entries to the right package
|
---|
| 655 | my $tmp = expandmacros("$2", 'g');
|
---|
| 656 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
[27] | 657 | }
|
---|
[103] | 658 | next LINE;
|
---|
| 659 | } # %pre/%post/%preun/%postun
|
---|
[8] | 660 |
|
---|
[103] | 661 | if (/^\%files(?:\s+(?:-n\s+)?(.+))?/) {
|
---|
| 662 | $stage = 'files';
|
---|
| 663 | $subname = 'main';
|
---|
| 664 | if ($1) { # Magic to add entries to the right list of files
|
---|
[153] | 665 | my $tmp = expandmacros("$1", 'gp');
|
---|
[103] | 666 | if (/-n/) { $subname = $tmp; } else { $subname = "$pkgdata{main}{name}-$tmp"; }
|
---|
| 667 | }
|
---|
| 668 | next LINE;
|
---|
| 669 | } # %files
|
---|
[6] | 670 |
|
---|
[103] | 671 | if (/^\%changelog/) {
|
---|
| 672 | $stage = 'changelog';
|
---|
| 673 | $pkgdata{main}{changelog} = '';
|
---|
| 674 | next LINE;
|
---|
| 675 | }
|
---|
[6] | 676 |
|
---|
[103] | 677 | # now we handle individual lines from the various sections
|
---|
[6] | 678 |
|
---|
[105] | 679 | if ($stage eq 'desc') {
|
---|
| 680 | $pkgdata{$subname}{desc} .= " $_";
|
---|
| 681 | } # description
|
---|
| 682 |
|
---|
[103] | 683 | if ($stage eq 'package') {
|
---|
| 684 | # gotta expand %defines here. Whee.
|
---|
[129] | 685 | # Note that we look for the Debian-specific Recommends, Suggests, and Replaces,
|
---|
| 686 | # although they will have to be wrapped in '%if %{_vendor} == "debbuild"' for
|
---|
| 687 | # an rpmbuild-compatible .spec file
|
---|
| 688 | # NB: NOT going to support Pre-Depends, since it's a "Don't Use" (mis)feature, and
|
---|
| 689 | # RPM's support for a similar tag (PreReq) has been recently dropped.
|
---|
[145] | 690 | if (my ($dname,$dvalue) = (/^(Recommends|Suggests|Enhances|Replaces|Summary|Group|Version|Requires|Conflicts|Provides|BuildArch(?:itecture)?):\s+(.+)$/i)) {
|
---|
[103] | 691 | $dname =~ tr/[A-Z]/[a-z]/;
|
---|
| 692 | if ($dname =~ /^BuildArch/i) {
|
---|
| 693 | $dvalue =~ s/^noarch/all/ig;
|
---|
| 694 | $buildarch = $dvalue; # Emulate rpm's behaviour to a degree
|
---|
| 695 | $dname = 'arch';
|
---|
| 696 | }
|
---|
| 697 | $pkgdata{$subname}{$dname} = expandmacros($dvalue, 'gp');
|
---|
| 698 | }
|
---|
| 699 | } # package
|
---|
| 700 |
|
---|
| 701 | if ($stage eq 'prep') {
|
---|
| 702 | # Actual handling for %prep section. May have %setup macro; may
|
---|
| 703 | # include %patch tags, may be just a bare shell script.
|
---|
| 704 | if (/^\%setup/) {
|
---|
| 705 | # Parse out the %setup macro. Note that we aren't supporting
|
---|
| 706 | # many of RPM's %setup features.
|
---|
| 707 | $prepscript .= "cd $topdir/BUILD\n";
|
---|
| 708 | if ( /\s+-n\s+([^\s]+)\s+/ ) {
|
---|
| 709 | $tarballdir = $1;
|
---|
| 710 | }
|
---|
| 711 | $tarballdir = expandmacros($tarballdir,'gp');
|
---|
| 712 | $prepscript .= "rm -rf $tarballdir\n";
|
---|
| 713 | if (/\s+-c\s+/) {
|
---|
| 714 | $prepscript .= "mkdir $tarballdir\ncd $tarballdir\n";
|
---|
| 715 | }
|
---|
| 716 | $prepscript .= "tar -".
|
---|
[6] | 717 | ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
|
---|
| 718 | ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
|
---|
[21] | 719 | ( /\s+-q\s+/ ? '' : 'vv' )."xf ".
|
---|
| 720 | "$topdir/SOURCES/$pkgdata{main}{source}\n".
|
---|
[6] | 721 | qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
|
---|
[69] | 722 | "cd $topdir/BUILD/$tarballdir\n".
|
---|
[6] | 723 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
|
---|
| 724 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
|
---|
| 725 | qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
|
---|
[103] | 726 | } elsif ( my ($patchnum,$patchopts) = (/^\%patch([^\s]+)(\s+.+)?$/) ) {
|
---|
| 727 | chomp $patchnum;
|
---|
[155] | 728 | $prepscript .= qq(echo "Patch #$patchnum ($pkgdata{main}{"patch$patchnum"}):"\n);
|
---|
| 729 | # If there are options passed, use'em.
|
---|
| 730 | # Otherwise, catch a bare %patch and ASS-U-ME it's '-p0'-able.
|
---|
| 731 | # Will break on options that don't provide -pnn, but what the hell.
|
---|
| 732 | # Need to decompress .bz2 and .gz patches on the fly. Not sure why one
|
---|
| 733 | # would ever have such things, but there they are... and rpmbuild supports 'em
|
---|
| 734 | # patch originally suggested by Lucian Cristian for .bz2
|
---|
| 735 | # reworked and expanded to support .Z/.gz as well
|
---|
| 736 | if ( $pkgdata{main}{"patch$patchnum"} =~ /\.(?:Z|gz|bz2)$/ ) {
|
---|
| 737 | my $decompressor;
|
---|
| 738 | $decompressor = 'gzip' if $pkgdata{main}{"patch$patchnum"} =~ /\.(?:Z|gz)$/;
|
---|
| 739 | $decompressor = 'bzip2' if $pkgdata{main}{"patch$patchnum"} =~ /\.bz2$/;
|
---|
| 740 | $prepscript .= qq(/bin/$decompressor -d < $topdir/SOURCES/$pkgdata{main}{"patch$patchnum"} | patch );
|
---|
| 741 | $prepscript .= $patchopts if $patchopts;
|
---|
| 742 | $prepscript .= "-p0" if !$patchopts;
|
---|
| 743 | $prepscript .= qq( -s\nSTATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n);
|
---|
| 744 | } else {
|
---|
| 745 | $prepscript .= "patch ";
|
---|
| 746 | $prepscript .= $patchopts if $patchopts;
|
---|
| 747 | $prepscript .= "-p0" if !$patchopts;
|
---|
| 748 | $prepscript .= " -s <$topdir/SOURCES/".$pkgdata{main}{"patch$patchnum"}."\n";
|
---|
| 749 | }
|
---|
[103] | 750 | } else {
|
---|
[107] | 751 | $prepscript .= expandmacros($_,'gp');
|
---|
[6] | 752 | }
|
---|
[103] | 753 | next LINE;
|
---|
| 754 | } # prep
|
---|
| 755 |
|
---|
| 756 | if ($stage eq 'build') {
|
---|
| 757 | # %build. This is pretty much just a shell script. There
|
---|
| 758 | # aren't many local macros to deal with.
|
---|
| 759 | if (/^\%configure/) {
|
---|
| 760 | $buildscript .= expandmacros($_,'cgbp');
|
---|
| 761 | } elsif (/^\%\{__make\}/) {
|
---|
| 762 | $buildscript .= expandmacros($_,'mgbp');
|
---|
| 763 | } else {
|
---|
[108] | 764 | $buildscript .= expandmacros($_,'gp');
|
---|
[5] | 765 | }
|
---|
[103] | 766 | next LINE;
|
---|
| 767 | } # build
|
---|
[29] | 768 |
|
---|
[103] | 769 | if ($stage eq 'install') {
|
---|
| 770 | if (/^\%makeinstall/) {
|
---|
| 771 | $installscript .= expandmacros($_,'igbp');
|
---|
| 772 | } else {
|
---|
[107] | 773 | $installscript .= expandmacros($_,'gp');
|
---|
[6] | 774 | }
|
---|
[103] | 775 | next LINE;
|
---|
| 776 | } # install
|
---|
[29] | 777 |
|
---|
[103] | 778 | if ($stage eq 'clean') {
|
---|
[107] | 779 | $cleanscript .= expandmacros($_,'gp');
|
---|
[103] | 780 | next LINE;
|
---|
| 781 | } # clean
|
---|
[37] | 782 |
|
---|
[103] | 783 | if ($stage eq 'prepost') {
|
---|
[107] | 784 | $pkgdata{$subname}{$scriptlet} .= expandmacros($_,'gp');
|
---|
[103] | 785 | next LINE;
|
---|
| 786 | } # prepost
|
---|
[37] | 787 |
|
---|
[103] | 788 | if ($stage eq 'files') {
|
---|
[121] | 789 | # need to deal with these someday
|
---|
[103] | 790 | next LINE if /^\%dir/;
|
---|
| 791 | next LINE if /^\%defattr/;
|
---|
[121] | 792 | next LINE if /^\%verify/;
|
---|
| 793 | # dunno what to do with this; not sure if there's space in Debian's package structure for it.
|
---|
| 794 | next LINE if /^\%ghost/;
|
---|
[103] | 795 | # Debian dpkg doesn't speak "%docdir". Meh.
|
---|
| 796 | next LINE if /^\%docdir/;
|
---|
[121] | 797 | # my $singleton = 0; # don't recall what this was for
|
---|
| 798 |
|
---|
| 799 | # create and initialize flags
|
---|
| 800 | my ($perms, $owner, $group, $conf, $filesline);
|
---|
| 801 | $perms = $owner = $group = $conf = '-';
|
---|
| 802 |
|
---|
| 803 | $filesline = $_;
|
---|
| 804 |
|
---|
| 805 | # strip and flag %attr constructs
|
---|
| 806 | if ($filesline =~ /\%attr\b/) {
|
---|
| 807 | # Extract %attr...
|
---|
| 808 | my ($args) = (/(\%attr\s*\(\s*[\d-]+\s*,\s*["a-zA-Z0-9-]+\s*,\s*["a-zA-Z0-9-]+\s*\))/);
|
---|
| 809 | $args =~ s/\s+//g;
|
---|
| 810 | $args =~ s/"//g; # don't think quotes are ever necessary, but they're *allowed*
|
---|
| 811 | # ... and parse it ...
|
---|
| 812 | ($perms,$owner,$group) = ($args =~ /\(([\d-]+),([a-zA-Z0-9-]+),([a-zA-Z0-9-]+)/);
|
---|
| 813 | # ... and wipe it when we're done.
|
---|
| 814 | $filesline =~ s/\%attr\s*\(\s*[\d-]+\s*,\s*["a-zA-Z0-9-]+\s*,\s*["a-zA-Z0-9-]+\s*\)//;
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 | # Conffiles. Note that Debian and RH have similar, but not
|
---|
| 818 | # *quite* identical ideas of what constitutes a conffile. Nrgh.
|
---|
| 819 | # Note that dpkg will always ask if you want to replace the file - noreplace
|
---|
| 820 | # is more or less permanently enabled.
|
---|
[76] | 821 | ##fixme
|
---|
[121] | 822 | # also need to handle missingok (file that doesn't exist, but should be removed on uninstall)
|
---|
| 823 | # hmm. not sure if such is **POSSIBLE** with Debian... maybe an addition to %post?
|
---|
| 824 | if ($filesline =~ /\%config\b(?:\s*\(\s*noreplace\s*\)\s*)?/) {
|
---|
| 825 | $pkgdata{$subname}{conffiles} = 1; # Flag it for later
|
---|
| 826 | $conf = 'y';
|
---|
| 827 | $filesline =~ s/\%config\b(?:\s*\(\s*noreplace\s*\)\s*)?//;
|
---|
[18] | 828 | }
|
---|
[121] | 829 |
|
---|
[110] | 830 | # %doc needs extra processing, because it can be a space-separated list, and may
|
---|
| 831 | # include both full and partial pathnames. The partial pathnames must be fiddled
|
---|
| 832 | # into place in the %install script, because Debian doesn't really have the concept
|
---|
| 833 | # of "documentation file" that rpm does. (Debian "documentation files" are files
|
---|
| 834 | # in /usr/share/doc/<packagename>.)
|
---|
[121] | 835 | ##fixme: unhandled case: %doc %defattr. Eeep.
|
---|
| 836 | # don't really know what to do with %defattr, generally. :(
|
---|
| 837 | if ($filesline =~ /\%doc\b/) {
|
---|
| 838 | $filesline =~ s/\s*\%doc\s+//;
|
---|
[110] | 839 |
|
---|
[121] | 840 | # this could probably go elsewhere.
|
---|
| 841 | my $pkgname = $pkgdata{$subname}{name};
|
---|
| 842 | $pkgname =~ tr/_/-/;
|
---|
| 843 |
|
---|
| 844 | # have to extract the partial pathnames that %doc installs automagically
|
---|
| 845 | foreach (split /\s+/, $filesline) {
|
---|
| 846 | if (! (/^\%/ or m|^/|) ) {
|
---|
[110] | 847 | $doclist{$subname} .= " $_";
|
---|
[121] | 848 | my ($element) = m|([^/\s]+/?)$|;
|
---|
| 849 | $filesline =~ s|$_|\%{_docdir}/$pkgname/$element|;
|
---|
[110] | 850 | }
|
---|
[121] | 851 | }
|
---|
| 852 | } # $filesline =~ /\%doc\b/
|
---|
| 853 |
|
---|
| 854 | $filesline =~ s/^\s*//; # Just In Case. For, uh, neatness.
|
---|
| 855 |
|
---|
| 856 | # due to Debian's total lack of real permissions-processing in its actual package
|
---|
| 857 | # handling component (dpkg-deb), this can't really be done "properly". We'll have
|
---|
| 858 | # to add chown/chmod commands to the postinst instead. Feh.
|
---|
| 859 | $pkgdata{$subname}{'post'} .= "chown $owner $filesline\n" if $owner ne '-';
|
---|
| 860 | $pkgdata{$subname}{'post'} .= "chgrp $group $filesline\n" if $group ne '-';
|
---|
| 861 | $pkgdata{$subname}{'post'} .= "chmod $perms $filesline\n" if $perms ne '-';
|
---|
| 862 |
|
---|
[115] | 863 | ##fixme
|
---|
[121] | 864 | # need hackery to assure only one filespec per %config. NB: "*" is one filespec. <g>
|
---|
| 865 | push @{$pkgdata{$subname}{conflist}}, $filesline if $conf ne '-';
|
---|
| 866 |
|
---|
| 867 | # now that we've got the specials out of the way, we can add things to the appropriate list of files.
|
---|
[103] | 868 | # ... and finally everything else
|
---|
[121] | 869 | $filelist{$subname} .= " $filesline";
|
---|
| 870 |
|
---|
[103] | 871 | next LINE;
|
---|
| 872 | } # files
|
---|
[14] | 873 |
|
---|
[103] | 874 | if ($stage eq 'changelog') {
|
---|
[107] | 875 | # this is one of the few places we do NOT generally want to replace macros...
|
---|
[103] | 876 | $pkgdata{main}{changelog} .= $_;
|
---|
| 877 | }
|
---|
[14] | 878 |
|
---|
[103] | 879 | if ($stage eq 'preamble') {
|
---|
[135] | 880 | if (/^summary:\s*(.+)/i) {
|
---|
[103] | 881 | $pkgdata{main}{summary} = $1;
|
---|
[135] | 882 | } elsif (/^name:\s*(.+)/i) {
|
---|
[103] | 883 | $pkgdata{main}{name} = expandmacros($1,'g');
|
---|
[135] | 884 | } elsif (/^epoch:\s*(.+)/i) {
|
---|
[111] | 885 | $pkgdata{main}{epoch} = expandmacros($1,'g');
|
---|
[135] | 886 | } elsif (/^version:\s*(.+)/i) {
|
---|
[103] | 887 | $pkgdata{main}{version} = expandmacros($1,'g');
|
---|
[135] | 888 | } elsif (/^release:\s*(.+)/i) {
|
---|
[103] | 889 | $pkgdata{main}{release} = expandmacros($1,'g');
|
---|
[135] | 890 | } elsif (/^group:\s*(.+)/i) {
|
---|
[103] | 891 | $pkgdata{main}{group} = $1;
|
---|
[135] | 892 | } elsif (/^copyright:\s*(.+)/i) {
|
---|
[103] | 893 | $pkgdata{main}{copyright} = $1;
|
---|
[135] | 894 | } elsif (/^url:\s*(.+)/i) {
|
---|
[103] | 895 | $pkgdata{main}{url} = $1;
|
---|
[135] | 896 | } elsif (/^packager:\s*(.+)/i) {
|
---|
[103] | 897 | $pkgdata{main}{packager} = $1;
|
---|
[135] | 898 | } elsif (/^buildroot:\s*(.+)/i) {
|
---|
[136] | 899 | $specglobals{buildroot} = $1;
|
---|
[135] | 900 | } elsif (/^source0?:\s*(.+)/i) {
|
---|
[103] | 901 | $pkgdata{main}{source} = $1;
|
---|
[149] | 902 | # .tar, .tar.gz, .tar.bz2, .tgz
|
---|
| 903 | die "Unknown tarball format $1\n" if $1 !~ /\.(?:tar(?:\.(?:gz|bz2))?|tgz)$/;
|
---|
[135] | 904 | } elsif (/^source([0-9]+):\s*(.+)/i) {
|
---|
[103] | 905 | $pkgdata{sources}{$1} = $2;
|
---|
[135] | 906 | } elsif (/^patch([^:]+):\s*(.+)$/i) {
|
---|
[103] | 907 | my $patchname = "patch$1";
|
---|
| 908 | $pkgdata{main}{$patchname} = $2;
|
---|
| 909 | if ($pkgdata{main}{$patchname} =~ /\//) {
|
---|
| 910 | # URL-style patch. Rare but not unheard-of.
|
---|
| 911 | my @patchbits = split '/', $pkgdata{main}{$patchname};
|
---|
| 912 | $pkgdata{main}{$patchname} = $patchbits[$#patchbits];
|
---|
| 913 | }
|
---|
| 914 | chomp $pkgdata{main}{$patchname};
|
---|
[135] | 915 | } elsif (/^buildarch(?:itecture)?:\s*(.+)/i) {
|
---|
[103] | 916 | $pkgdata{main}{arch} = $1;
|
---|
| 917 | $pkgdata{main}{arch} =~ s/^noarch$/all/;
|
---|
| 918 | $buildarch = $pkgdata{main}{arch};
|
---|
[138] | 919 | } elsif (/^buildrequires:\s*(.+)/i) {
|
---|
[103] | 920 | $buildreq .= ", $1";
|
---|
[135] | 921 | } elsif (/^requires:\s*(.+)/i) {
|
---|
[103] | 922 | $pkgdata{main}{requires} .= ", ".expandmacros("$1", 'gp');
|
---|
[135] | 923 | } elsif (/^provides:\s*(.+)/i) {
|
---|
[103] | 924 | $pkgdata{main}{provides} .= ", $1";
|
---|
[135] | 925 | } elsif (/^conflicts:\s*(.+)/i) {
|
---|
[103] | 926 | $pkgdata{main}{conflicts} .= ", $1";
|
---|
[135] | 927 | } elsif (/^recommends:\s*(.+)/i) {
|
---|
[129] | 928 | $pkgdata{main}{recommends} .= ", $1";
|
---|
| 929 | warn "Warning: Debian-specific 'Recommends:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[135] | 930 | } elsif (/^suggests:\s*(.+)/i) {
|
---|
[129] | 931 | $pkgdata{main}{suggests} .= ", $1";
|
---|
| 932 | warn "Warning: Debian-specific 'Suggests:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[145] | 933 | } elsif (/^enhances:\s*(.+)/i) {
|
---|
| 934 | $pkgdata{main}{enhances} .= ", $1";
|
---|
| 935 | warn "Warning: Debian-specific 'Enahnces:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[135] | 936 | } elsif (/^replaces:\s*(.+)/i) {
|
---|
[129] | 937 | $pkgdata{main}{replaces} .= ", $1";
|
---|
| 938 | warn "Warning: Debian-specific 'Replaces:' outside \%if wrapper\n" if $iflevel == 0;
|
---|
[135] | 939 | } elsif (/^autoreq(?:prov)?:\s*(.+)/i) {
|
---|
[112] | 940 | # we don't handle auto-provides (yet)
|
---|
| 941 | $NoAutoReq = 1 if $1 =~ /(?:no|0)/i;
|
---|
[5] | 942 | }
|
---|
[103] | 943 | next LINE;
|
---|
| 944 | } # preamble
|
---|
[5] | 945 |
|
---|
[103] | 946 | } # while <SPEC>
|
---|
[7] | 947 |
|
---|
[14] | 948 | # Parse and replace some more macros. More will be replaced even later.
|
---|
| 949 |
|
---|
[10] | 950 | # Expand macros as necessary.
|
---|
[12] | 951 | $scriptletbase = expandmacros($scriptletbase,'gp');
|
---|
[7] | 952 |
|
---|
[103] | 953 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
| 954 |
|
---|
[136] | 955 | $specglobals{buildroot} = $cmdbuildroot if $cmdbuildroot;
|
---|
| 956 | $specglobals{buildroot} = expandmacros($specglobals{buildroot},'gp');
|
---|
[7] | 957 |
|
---|
[16] | 958 | close SPECFILE;
|
---|
[5] | 959 | } # end parse_spec()
|
---|
| 960 |
|
---|
| 961 |
|
---|
[7] | 962 | ## prep()
|
---|
[14] | 963 | # Writes and executes the %prep script (mostly) built while reading the spec file.
|
---|
[7] | 964 | sub prep {
|
---|
[10] | 965 | # Replace some things here just to make sure.
|
---|
[12] | 966 | $prepscript = expandmacros($prepscript,'gp');
|
---|
[10] | 967 |
|
---|
| 968 | # create script filename
|
---|
[13] | 969 | my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
|
---|
[10] | 970 | sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 971 | or die "Can't open/create prep script file $prepscriptfile: $!\n";
|
---|
[10] | 972 | print PREPSCRIPT $scriptletbase;
|
---|
| 973 | print PREPSCRIPT $prepscript;
|
---|
| 974 | close PREPSCRIPT;
|
---|
[7] | 975 |
|
---|
[10] | 976 | # execute
|
---|
| 977 | print "Calling \%prep script $prepscriptfile...\n";
|
---|
| 978 | system("/bin/sh -e $prepscriptfile") == 0
|
---|
[14] | 979 | or die "Can't exec: $!\n";
|
---|
[7] | 980 |
|
---|
[10] | 981 | # and clean up
|
---|
| 982 | unlink $prepscriptfile;
|
---|
[7] | 983 | } # end prep()
|
---|
| 984 |
|
---|
| 985 |
|
---|
[5] | 986 | ## build()
|
---|
[14] | 987 | # Writes and executes the %build script (mostly) built while reading the spec file.
|
---|
[5] | 988 | sub build {
|
---|
[12] | 989 | # Expand the macros
|
---|
| 990 | $buildscript = expandmacros($buildscript,'cgbp');
|
---|
| 991 |
|
---|
[7] | 992 | # create script filename
|
---|
[13] | 993 | my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
|
---|
[7] | 994 | sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 995 | or die "Can't open/create build script file $buildscriptfile: $!\n";
|
---|
[7] | 996 | print BUILDSCRIPT $scriptletbase;
|
---|
| 997 | print BUILDSCRIPT $buildscript;
|
---|
| 998 | close BUILDSCRIPT;
|
---|
| 999 |
|
---|
| 1000 | # execute
|
---|
| 1001 | print "Calling \%build script $buildscriptfile...\n";
|
---|
| 1002 | system("/bin/sh -e $buildscriptfile") == 0
|
---|
[14] | 1003 | or die "Can't exec: $!\n";
|
---|
[7] | 1004 |
|
---|
| 1005 | # and clean up
|
---|
| 1006 | unlink $buildscriptfile;
|
---|
[5] | 1007 | } # end build()
|
---|
| 1008 |
|
---|
| 1009 |
|
---|
[7] | 1010 | ## install()
|
---|
[14] | 1011 | # Writes and executes the %install script (mostly) built while reading the spec file.
|
---|
[7] | 1012 | sub install {
|
---|
[110] | 1013 |
|
---|
| 1014 | # munge %doc entries into place
|
---|
| 1015 | # rpm handles this with a separate executed %doc script, we're not going to bother.
|
---|
| 1016 | foreach my $docpkg (keys %doclist) {
|
---|
| 1017 | my $pkgname = $pkgdata{$docpkg}{name};
|
---|
| 1018 | $pkgname =~ s/_/-/g;
|
---|
| 1019 |
|
---|
| 1020 | $installscript .= "DOCDIR=\$RPM_BUILD_ROOT\%{_docdir}/$pkgname\nexport DOCDIR\n";
|
---|
| 1021 | $installscript .= "mkdir -p \$DOCDIR\n";
|
---|
| 1022 | $doclist{$docpkg} =~ s/^\s*//;
|
---|
| 1023 | foreach (split(' ',$doclist{$docpkg})) {
|
---|
| 1024 | $installscript .= "cp -pr $_ \$DOCDIR/\n";
|
---|
| 1025 | }
|
---|
| 1026 | }
|
---|
| 1027 |
|
---|
[12] | 1028 | # Expand the macros
|
---|
| 1029 | $installscript = expandmacros($installscript,'igbp');
|
---|
| 1030 |
|
---|
[7] | 1031 | # create script filename
|
---|
[13] | 1032 | my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
|
---|
[7] | 1033 | sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 1034 | or die "Can't open/create install script file $installscriptfile: $!\n";
|
---|
[7] | 1035 | print INSTSCRIPT $scriptletbase;
|
---|
| 1036 | print INSTSCRIPT $installscript;
|
---|
| 1037 | close INSTSCRIPT;
|
---|
| 1038 |
|
---|
| 1039 | # execute
|
---|
| 1040 | print "Calling \%install script $installscriptfile...\n";
|
---|
| 1041 | system("/bin/sh -e $installscriptfile") == 0
|
---|
[14] | 1042 | or die "Can't exec: $!\n";
|
---|
[7] | 1043 |
|
---|
| 1044 | # and clean up
|
---|
| 1045 | unlink $installscriptfile;
|
---|
[132] | 1046 |
|
---|
| 1047 | # final bit: compress manpages if present
|
---|
| 1048 | # done here cuz I don't grok shell well
|
---|
| 1049 | # should probably error-check all kinds of things. <g>
|
---|
[136] | 1050 | if (opendir MANROOT, "$specglobals{buildroot}/usr/share/man") {
|
---|
[132] | 1051 | my @mansects = readdir MANROOT;
|
---|
| 1052 | closedir MANROOT;
|
---|
| 1053 | foreach my $mandir (@mansects) {
|
---|
| 1054 | next if $mandir !~ /^man/;
|
---|
[136] | 1055 | opendir MANPAGES, "$specglobals{buildroot}/usr/share/man/$mandir";
|
---|
[132] | 1056 | my @pagelist = readdir MANPAGES;
|
---|
| 1057 | closedir MANPAGES; # Slightly safer to to this; no accidental recursion. O_o
|
---|
| 1058 | foreach my $manpage (@pagelist) {
|
---|
[136] | 1059 | $manpage = "$specglobals{buildroot}/usr/share/man/$mandir/$manpage";
|
---|
[132] | 1060 | if ( -f $manpage) {
|
---|
| 1061 | if ($manpage =~ /^(.+)\.(?:Z|gz|bz2)\n?$/) {
|
---|
| 1062 | my $newpage = $1;
|
---|
| 1063 | `gunzip $manpage` if $manpage =~ /\.(?:Z|gz)$/;
|
---|
| 1064 | `bunzip2 $manpage` if $manpage =~ /\.bz2$/;
|
---|
| 1065 | $manpage = $newpage;
|
---|
| 1066 | }
|
---|
| 1067 | `gzip -9 -n $manpage`;
|
---|
| 1068 | } elsif ( -l $manpage) {
|
---|
| 1069 | my $linkdest = readlink $manpage;
|
---|
| 1070 | $linkdest =~ s/\.(?:Z|gz|bz2)//;
|
---|
| 1071 | unlink $manpage;
|
---|
| 1072 | $manpage =~ s/\.(?:Z|gz|bz2)//;
|
---|
| 1073 | symlink "$linkdest.gz", "$manpage.gz" or print "DEBUG: wibble: symlinking manpage failed: $!\n";
|
---|
| 1074 | }
|
---|
| 1075 | }
|
---|
| 1076 | }
|
---|
| 1077 | } # if opendir MANROOT
|
---|
[7] | 1078 | } # end install()
|
---|
| 1079 |
|
---|
| 1080 |
|
---|
[8] | 1081 | ## binpackage()
|
---|
[136] | 1082 | # Creates the binary .deb package from the installed tree in $specglobals{buildroot}.
|
---|
[14] | 1083 | # Writes and executes a shell script to do so.
|
---|
| 1084 | # Creates miscellaneous files required by dpkg-deb to actually build the package file.
|
---|
[27] | 1085 | # Should handle simple subpackages
|
---|
[8] | 1086 | sub binpackage {
|
---|
[14] | 1087 |
|
---|
[27] | 1088 | foreach my $pkg (@pkglist) {
|
---|
[8] | 1089 |
|
---|
[87] | 1090 | $pkgdata{$pkg}{arch} = $hostarch if !$pkgdata{$pkg}{arch}; # Just In Case.
|
---|
| 1091 |
|
---|
| 1092 | # Make sure we have somewhere to write the .deb file
|
---|
| 1093 | if (!-e "$topdir/DEBS/$pkgdata{$pkg}{arch}") {
|
---|
| 1094 | mkdir "$topdir/DEBS/$pkgdata{$pkg}{arch}";
|
---|
| 1095 | }
|
---|
| 1096 |
|
---|
[73] | 1097 | # Skip building a package if it doesn't actually have any files. NB: This
|
---|
| 1098 | # differs slightly from rpm's behaviour where a package *will* be built -
|
---|
| 1099 | # even without any files - if %files is specified anywhere. I can think
|
---|
| 1100 | # of odd corner cases where that *may* be desireable.
|
---|
[74] | 1101 | next if (!$filelist{$pkg} or $filelist{$pkg} =~ /^\s*$/);
|
---|
[73] | 1102 |
|
---|
[27] | 1103 | # Gotta do this first, otherwise we don't have a place to move files from %files
|
---|
[136] | 1104 | mkdir "$specglobals{buildroot}/$pkg";
|
---|
[28] | 1105 |
|
---|
[30] | 1106 | # Eliminate any lingering % macros
|
---|
| 1107 | $filelist{$pkg} = expandmacros $filelist{$pkg}, 'g';
|
---|
| 1108 |
|
---|
[27] | 1109 | my @pkgfilelist = split ' ', $filelist{$pkg};
|
---|
| 1110 | foreach my $pkgfile (@pkgfilelist) {
|
---|
[37] | 1111 | $pkgfile = expandmacros($pkgfile, 'gp');
|
---|
[117] | 1112 |
|
---|
| 1113 | # Feh. Manpages don't **NEED** to be gzipped, but rpmbuild does, and so shall we.
|
---|
[153] | 1114 | # ... and your little info page too!
|
---|
| 1115 | if ($pkgfile =~ m{/usr/share/(?:man/man|info)}) {
|
---|
[117] | 1116 | # need to check to see if manpage is gzipped
|
---|
[136] | 1117 | if (-e "$specglobals{buildroot}$pkgfile") {
|
---|
[153] | 1118 | # if we've just been pointed to a manpage section with "many" pages,
|
---|
| 1119 | # we need to gzip them all.
|
---|
| 1120 | # fortunately, we do NOT need to explicitly track each file for the
|
---|
| 1121 | # purpose of stuffing them in the package... the original %files
|
---|
| 1122 | # entry will do just fine.
|
---|
| 1123 | if ( -d "$specglobals{buildroot}$pkgfile") {
|
---|
| 1124 | foreach my $globfile (glob("$specglobals{buildroot}$pkgfile/*")) {
|
---|
| 1125 | gzip $globfile if $globfile !~ m|\.gz$|;
|
---|
| 1126 | }
|
---|
| 1127 | } else {
|
---|
| 1128 | if ($pkgfile !~ m|\.gz$|) {
|
---|
| 1129 | qx { gzip $specglobals{buildroot}$pkgfile };
|
---|
| 1130 | $pkgfile .= ".gz";
|
---|
| 1131 | }
|
---|
[117] | 1132 | }
|
---|
| 1133 | } else {
|
---|
| 1134 | if ($pkgfile !~ m|\.gz$|) {
|
---|
| 1135 | $pkgfile .= ".gz";
|
---|
| 1136 | } else {
|
---|
| 1137 | $pkgfile =~ s/\.gz$//;
|
---|
[136] | 1138 | qx { gzip $specglobals{buildroot}$pkgfile };
|
---|
[117] | 1139 | $pkgfile .= ".gz";
|
---|
| 1140 | }
|
---|
| 1141 | }
|
---|
| 1142 | }
|
---|
| 1143 |
|
---|
[124] | 1144 | my ($fpath,$fname) = ($pkgfile =~ m|(.+?/?)?([^/]+/?)$|); # We don't need $fname now, but we might.
|
---|
[136] | 1145 | qx { mkdir -p $specglobals{buildroot}/$pkg$fpath }
|
---|
[44] | 1146 | if $fpath && $fpath ne '';
|
---|
[136] | 1147 | qx { mv $specglobals{buildroot}$pkgfile $specglobals{buildroot}/$pkg$fpath };
|
---|
[27] | 1148 | }
|
---|
[28] | 1149 |
|
---|
[38] | 1150 | # Get the "Depends" (Requires) a la RPM. Ish. We strip the leading
|
---|
| 1151 | # comma and space here (if needed) in case there were "Requires" specified
|
---|
| 1152 | # in the spec file - those would precede these.
|
---|
[136] | 1153 | $pkgdata{$pkg}{requires} .= getreqs("$specglobals{buildroot}/$pkg") if ! $NoAutoReq;
|
---|
[38] | 1154 |
|
---|
[64] | 1155 | # magic needed to properly version dependencies...
|
---|
| 1156 | # only provided deps will really be included
|
---|
[65] | 1157 | $pkgdata{$pkg}{requires} =~ s/^, //; # Still have to do this here.
|
---|
[64] | 1158 | $pkgdata{$pkg}{requires} =~ s/\s+//g;
|
---|
| 1159 | my @deps = split /,/, $pkgdata{$pkg}{requires};
|
---|
| 1160 | my $tmp = '';
|
---|
| 1161 | foreach my $dep (@deps) {
|
---|
[68] | 1162 | # Hack up the perl(Class::SubClass) deps into something dpkg can understand.
|
---|
| 1163 | # May or may not be versioned.
|
---|
| 1164 | # We do this first so the version rewriter can do its magic next.
|
---|
| 1165 | if (my ($mod,$ver) = ($dep =~ /^perl\(([A-Za-z0-9\:\-]+)\)([><=]+.+)?/) ) {
|
---|
| 1166 | $mod =~ s/^perl\(//;
|
---|
| 1167 | $mod =~ s/\)$//;
|
---|
| 1168 | $mod =~ s/::/-/g;
|
---|
| 1169 | $mod =~ tr/A-Z/a-z/;
|
---|
| 1170 | $mod = "lib$mod-perl";
|
---|
| 1171 | $mod .= $ver if $ver;
|
---|
| 1172 | $dep = $mod;
|
---|
| 1173 | }
|
---|
[64] | 1174 | if (my ($name,$rel,$value) = ($dep =~ /^([a-zA-Z0-9._-]+)([><=]+)([a-zA-Z0-9._-]+)$/)) {
|
---|
| 1175 | $tmp .= ", $name ($rel $value)";
|
---|
| 1176 | } else {
|
---|
| 1177 | $tmp .= ", $dep";
|
---|
| 1178 | }
|
---|
| 1179 | }
|
---|
| 1180 | ($pkgdata{$pkg}{requires} = $tmp) =~ s/^, //;
|
---|
| 1181 |
|
---|
[38] | 1182 | # Do this here since we're doing {depends}...
|
---|
[41] | 1183 | if (defined($pkgdata{$pkg}{provides})) {
|
---|
| 1184 | $pkgdata{$pkg}{provides} =~ s/^, //;
|
---|
| 1185 | $pkgdata{$pkg}{provides} = expandmacros($pkgdata{$pkg}{provides},'gp');
|
---|
| 1186 | }
|
---|
[51] | 1187 | if (defined($pkgdata{$pkg}{conflicts})) {
|
---|
| 1188 | $pkgdata{$pkg}{conflicts} =~ s/^, //;
|
---|
| 1189 | $pkgdata{$pkg}{conflicts} = expandmacros($pkgdata{$pkg}{conflicts},'gp');
|
---|
| 1190 | }
|
---|
[38] | 1191 |
|
---|
[129] | 1192 | # These are Debian-specific!
|
---|
| 1193 | if (defined($pkgdata{$pkg}{recommends})) {
|
---|
| 1194 | $pkgdata{$pkg}{recommends} =~ s/^, //;
|
---|
| 1195 | $pkgdata{$pkg}{recommends} = expandmacros($pkgdata{$pkg}{recommends},'gp');
|
---|
| 1196 | }
|
---|
| 1197 | if (defined($pkgdata{$pkg}{suggests})) {
|
---|
| 1198 | $pkgdata{$pkg}{suggests} =~ s/^, //;
|
---|
| 1199 | $pkgdata{$pkg}{suggests} = expandmacros($pkgdata{$pkg}{suggests},'gp');
|
---|
| 1200 | }
|
---|
[145] | 1201 | if (defined($pkgdata{$pkg}{enhances})) {
|
---|
| 1202 | $pkgdata{$pkg}{enhances} =~ s/^, //;
|
---|
| 1203 | $pkgdata{$pkg}{enhances} = expandmacros($pkgdata{$pkg}{enhances},'gp');
|
---|
| 1204 | }
|
---|
[129] | 1205 | if (defined($pkgdata{$pkg}{replaces})) {
|
---|
| 1206 | $pkgdata{$pkg}{replaces} =~ s/^, //;
|
---|
| 1207 | $pkgdata{$pkg}{replaces} = expandmacros($pkgdata{$pkg}{replaces},'gp');
|
---|
| 1208 | }
|
---|
| 1209 |
|
---|
[27] | 1210 | # Gotta do this next, otherwise the control file has nowhere to go. >:(
|
---|
[136] | 1211 | mkdir "$specglobals{buildroot}/$pkg/DEBIAN";
|
---|
[27] | 1212 |
|
---|
[33] | 1213 | # Hack the filename for the package into a Debian-tool-compatible format. GRRRRRR!!!!!
|
---|
| 1214 | # Have I mentioned I hate Debian Policy?
|
---|
| 1215 | $pkgdata{$pkg}{name} =~ tr/_/-/;
|
---|
| 1216 |
|
---|
[27] | 1217 | # create script filename
|
---|
| 1218 | my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
|
---|
| 1219 | sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[157] | 1220 | or die "Can't open/create package-creation script file $debscriptfile: $!\n";
|
---|
[27] | 1221 | print DEBSCRIPT $scriptletbase;
|
---|
[136] | 1222 | print DEBSCRIPT "fakeroot dpkg-deb -b $specglobals{buildroot}/$pkg $topdir/DEBS/$pkgdata{$pkg}{arch}/".
|
---|
[111] | 1223 | "$pkgdata{$pkg}{name}_".
|
---|
| 1224 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1225 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb\n";
|
---|
[27] | 1226 | # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
|
---|
| 1227 | close DEBSCRIPT;
|
---|
[8] | 1228 |
|
---|
[27] | 1229 | my $control = "Package: $pkgdata{$pkg}{name}\n".
|
---|
[111] | 1230 | "Version: ".
|
---|
| 1231 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1232 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}\n".
|
---|
[27] | 1233 | "Section: $pkgdata{$pkg}{group}\n".
|
---|
[8] | 1234 | "Priority: optional\n".
|
---|
[87] | 1235 | "Architecture: $pkgdata{$pkg}{arch}\n".
|
---|
[8] | 1236 | "Maintainer: $pkgdata{main}{packager}\n".
|
---|
[47] | 1237 | ( $pkgdata{$pkg}{requires} ne '' ? "Depends: $pkgdata{$pkg}{requires}\n" : '' ).
|
---|
[39] | 1238 | ( defined($pkgdata{$pkg}{provides}) ? "Provides: $pkgdata{$pkg}{provides}\n" : '' ).
|
---|
[51] | 1239 | ( defined($pkgdata{$pkg}{conflicts}) ? "Conflicts: $pkgdata{$pkg}{conflicts}\n" : '' ).
|
---|
[129] | 1240 | ( defined($pkgdata{$pkg}{recommends}) ? "Recommends: $pkgdata{$pkg}{recommends}\n" : '' ).
|
---|
| 1241 | ( defined($pkgdata{$pkg}{suggests}) ? "Suggests: $pkgdata{$pkg}{suggests}\n" : '' ).
|
---|
[145] | 1242 | ( defined($pkgdata{$pkg}{enhances}) ? "Enhances: $pkgdata{$pkg}{enhances}\n" : '' ).
|
---|
[129] | 1243 | ( defined($pkgdata{$pkg}{replaces}) ? "Replaces: $pkgdata{$pkg}{replaces}\n" : '' ).
|
---|
[27] | 1244 | "Description: $pkgdata{$pkg}{summary}\n";
|
---|
| 1245 | $control .= "$pkgdata{$pkg}{desc}\n";
|
---|
[8] | 1246 |
|
---|
[136] | 1247 | open CONTROL, ">$specglobals{buildroot}/$pkg/DEBIAN/control";
|
---|
[27] | 1248 | print CONTROL $control;
|
---|
| 1249 | close CONTROL;
|
---|
[8] | 1250 |
|
---|
[37] | 1251 | # Iff there are conffiles (as specified in the %files list(s), add'em
|
---|
| 1252 | # in so dpkg-deb can tag them.
|
---|
| 1253 | if ($pkgdata{$pkg}{conffiles}) {
|
---|
[136] | 1254 | open CONFLIST, ">$specglobals{buildroot}/$pkg/DEBIAN/conffiles";
|
---|
[37] | 1255 | foreach my $conffile (@{$pkgdata{$pkg}{conflist}}) {
|
---|
[125] | 1256 | $conffile = expandmacros($conffile, 'g');
|
---|
[136] | 1257 | my @tmp = glob "$specglobals{buildroot}/$pkg/$conffile";
|
---|
[106] | 1258 | foreach (@tmp) {
|
---|
[136] | 1259 | s|$specglobals{buildroot}/$pkg/||g; # nrgl. gotta be a better way to do this...
|
---|
[106] | 1260 | s/\s+/\n/g; # Not gonna support spaces in filenames. Ewww.
|
---|
| 1261 | print CONFLIST "$_\n";
|
---|
| 1262 | }
|
---|
[37] | 1263 | }
|
---|
| 1264 | close CONFLIST;
|
---|
| 1265 | }
|
---|
| 1266 |
|
---|
[75] | 1267 | # found the point of scripts on subpackages.
|
---|
| 1268 | if ($pkgdata{$pkg}{'pre'}) {
|
---|
| 1269 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'pre'},'gp');
|
---|
[136] | 1270 | open PREINST, ">$specglobals{buildroot}/$pkg/DEBIAN/preinst";
|
---|
[75] | 1271 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1272 | print PREINST $pkgdata{$pkg}{'pre'};
|
---|
| 1273 | close PREINST;
|
---|
[136] | 1274 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/preinst";
|
---|
[27] | 1275 | }
|
---|
[75] | 1276 | if ($pkgdata{$pkg}{'post'}) {
|
---|
| 1277 | $pkgdata{$pkg}{'post'} = expandmacros($pkgdata{$pkg}{'post'},'gp');
|
---|
[136] | 1278 | open POSTINST, ">$specglobals{buildroot}/$pkg/DEBIAN/postinst";
|
---|
[131] | 1279 | print POSTINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1280 | print POSTINST $pkgdata{$pkg}{'post'};
|
---|
| 1281 | close POSTINST;
|
---|
[136] | 1282 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/postinst";
|
---|
[75] | 1283 | }
|
---|
| 1284 | if ($pkgdata{$pkg}{'preun'}) {
|
---|
| 1285 | $pkgdata{$pkg}{'pre'} = expandmacros($pkgdata{$pkg}{'preun'},'gp');
|
---|
[136] | 1286 | open PREUNINST, ">$specglobals{buildroot}/$pkg/DEBIAN/prerm";
|
---|
[131] | 1287 | print PREUNINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1288 | print PREUNINST $pkgdata{$pkg}{'preun'};
|
---|
| 1289 | close PREUNINST;
|
---|
[136] | 1290 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/prerm";
|
---|
[75] | 1291 | }
|
---|
| 1292 | if ($pkgdata{$pkg}{'postun'}) {
|
---|
| 1293 | $pkgdata{$pkg}{'postun'} = expandmacros($pkgdata{$pkg}{'postun'},'gp');
|
---|
[136] | 1294 | open POSTUNINST, ">$specglobals{buildroot}/$pkg/DEBIAN/postrm";
|
---|
[131] | 1295 | print POSTUNINST "#!/bin/sh\nset -e\n\n";
|
---|
| 1296 | print POSTUNINST $pkgdata{$pkg}{'postun'};
|
---|
| 1297 | close POSTUNINST;
|
---|
[136] | 1298 | chmod 0755, "$specglobals{buildroot}/$pkg/DEBIAN/postrm";
|
---|
[75] | 1299 | }
|
---|
[16] | 1300 |
|
---|
[27] | 1301 | # execute
|
---|
| 1302 | print "Calling package creation script $debscriptfile for $pkgdata{$pkg}{name}...\n";
|
---|
| 1303 | system("/bin/sh -e $debscriptfile") == 0
|
---|
[14] | 1304 | or die "Can't exec: $!\n";
|
---|
[8] | 1305 |
|
---|
[77] | 1306 | $finalmessages .= "Wrote binary package ".
|
---|
[111] | 1307 | "$pkgdata{$pkg}{name}_".
|
---|
| 1308 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1309 | "$pkgdata{$pkg}{version}-$pkgdata{main}{release}_$pkgdata{$pkg}{arch}.deb".
|
---|
[87] | 1310 | " in $topdir/DEBS/$pkgdata{$pkg}{arch}\n";
|
---|
[27] | 1311 | # and clean up
|
---|
| 1312 | unlink $debscriptfile;
|
---|
| 1313 |
|
---|
| 1314 | } # subpackage loop
|
---|
| 1315 |
|
---|
[8] | 1316 | } # end binpackage()
|
---|
| 1317 |
|
---|
| 1318 |
|
---|
[35] | 1319 | ## srcpackage()
|
---|
| 1320 | # Builds a .src.deb source package. Note that Debian's idea of
|
---|
| 1321 | # a "source package" is seriously flawed IMO, because you can't
|
---|
| 1322 | # easily copy it as-is.
|
---|
[36] | 1323 | # Not quite identical to RPM, but Good Enough (TM).
|
---|
[35] | 1324 | sub srcpackage {
|
---|
[54] | 1325 | # In case we were called with -bs.
|
---|
| 1326 | $pkgdata{main}{name} =~ tr/_/-/;
|
---|
[111] | 1327 | my $pkgsrcname = "$pkgdata{main}{name}-".
|
---|
| 1328 | (defined($pkgdata{main}{epoch}) ? "$pkgdata{main}{epoch}:" : '').
|
---|
| 1329 | "$pkgdata{main}{version}-$pkgdata{main}{release}.sdeb";
|
---|
[36] | 1330 |
|
---|
| 1331 | my $paxcmd;
|
---|
| 1332 |
|
---|
| 1333 | # We'll definitely need this later, and *may* need it sooner.
|
---|
| 1334 | (my $barespec = $specfile) =~ s|.+/([^/]+)$|$1|;
|
---|
| 1335 |
|
---|
| 1336 | # Copy the specfile to the build tree, but only if it's not there already.
|
---|
| 1337 | ##buglet: need to deal with silly case where silly user has put the spec
|
---|
| 1338 | # file in a subdir of %{_topdir}/SPECS. Ewww. Silly user!
|
---|
| 1339 | if (abs_path($specfile) !~ /^$topdir\/SPECS/) {
|
---|
| 1340 | $paxcmd .= "cp $specfile %{_topdir}/SPECS/; \n"
|
---|
| 1341 | }
|
---|
| 1342 |
|
---|
[35] | 1343 | # use pax -w [file] [file] ... >outfile.sdeb
|
---|
[36] | 1344 | $paxcmd = "cd $topdir; pax -w ";
|
---|
[10] | 1345 |
|
---|
[35] | 1346 | # tweak source entry into usable form. Need it locally somewhere along the line.
|
---|
| 1347 | (my $pkgsrc = $pkgdata{main}{source}) =~ s|.+/([^/]+)$|$1|;
|
---|
[36] | 1348 | $paxcmd .= "SOURCES/$pkgsrc ";
|
---|
[10] | 1349 |
|
---|
[35] | 1350 | # create file list: Source[nn], Patch[nn]
|
---|
| 1351 | foreach my $specbit (keys %{$pkgdata{main}} ) {
|
---|
| 1352 | next if $specbit eq 'source';
|
---|
[53] | 1353 | $paxcmd .= "SOURCES/$pkgdata{main}{$specbit} " if $specbit =~ /^patch/;
|
---|
[36] | 1354 | ##buglet: need to deal with case where patches are listed as URLs?
|
---|
| 1355 | # or other extended pathnames? Silly !@$%^&!%%!%!! user!
|
---|
[35] | 1356 | }
|
---|
| 1357 |
|
---|
[53] | 1358 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
| 1359 | $paxcmd .= "SOURCES/$pkgdata{sources}{$source} ";
|
---|
| 1360 | }
|
---|
| 1361 |
|
---|
[36] | 1362 | # add the spec file, source package destination, and cd back where we came from.
|
---|
| 1363 | $paxcmd .= "SPECS/$barespec > $topdir/SDEBS/$pkgsrcname; cd -";
|
---|
[35] | 1364 |
|
---|
[36] | 1365 | # In case of %-macros...
|
---|
[35] | 1366 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
| 1367 |
|
---|
[36] | 1368 | system "$paxcmd";
|
---|
[77] | 1369 | $finalmessages .= "Wrote source package $pkgsrcname in $topdir/SDEBS.\n";
|
---|
[97] | 1370 | } # end srcpackage()
|
---|
[35] | 1371 |
|
---|
| 1372 |
|
---|
[97] | 1373 | ## clean()
|
---|
| 1374 | # Writes and executes the %clean script (mostly) built while reading the spec file.
|
---|
| 1375 | sub clean {
|
---|
| 1376 | # Replace some things here just to make sure.
|
---|
| 1377 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
| 1378 |
|
---|
| 1379 | # create script filename
|
---|
| 1380 | my $cleanscriptfile = "$tmpdir/deb-tmp.clean.".int(rand(99998)+1);
|
---|
| 1381 | sysopen(CLEANSCRIPT, $cleanscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
| 1382 | or die $!;
|
---|
| 1383 | print CLEANSCRIPT $scriptletbase;
|
---|
| 1384 | print CLEANSCRIPT $cleanscript;
|
---|
| 1385 | close CLEANSCRIPT;
|
---|
| 1386 |
|
---|
| 1387 | # execute
|
---|
| 1388 | print "Calling \%clean script $cleanscriptfile...\n";
|
---|
| 1389 | system("/bin/sh -e $cleanscriptfile") == 0
|
---|
| 1390 | or die "Can't exec: $!\n";
|
---|
| 1391 |
|
---|
| 1392 | # and clean up
|
---|
| 1393 | unlink $cleanscriptfile;
|
---|
| 1394 | } # end clean()
|
---|
| 1395 |
|
---|
| 1396 |
|
---|
[38] | 1397 | ## checkbuildreq()
|
---|
| 1398 | # Checks the build requirements (if any)
|
---|
| 1399 | # Spits out a rude warning and returns a true-false error if any
|
---|
| 1400 | # requirements are not met.
|
---|
| 1401 | sub checkbuildreq {
|
---|
[40] | 1402 | return 1 if $buildreq eq ''; # No use doing extra work.
|
---|
[38] | 1403 |
|
---|
[52] | 1404 | if ( ! -e "/usr/bin/dpkg-query" ) {
|
---|
| 1405 | print "**WARNING** dpkg-query not found. Can't check build-deps.\n".
|
---|
| 1406 | " Required for sucessful build:\n".$buildreq."\n".
|
---|
| 1407 | " Continuing anyway.\n";
|
---|
| 1408 | return 1;
|
---|
| 1409 | }
|
---|
| 1410 |
|
---|
[38] | 1411 | my $reqflag = 1; # unset iff a buildreq is missing
|
---|
| 1412 |
|
---|
| 1413 | $buildreq =~ s/^, //; # Strip the leading comma and space
|
---|
| 1414 | my @reqlist = split /,\s+/, $buildreq;
|
---|
| 1415 |
|
---|
| 1416 | foreach my $req (@reqlist) {
|
---|
| 1417 | my ($pkg,$rel,$ver);
|
---|
| 1418 |
|
---|
| 1419 | # We have two classes of requirements - versioned and unversioned.
|
---|
| 1420 | if ($req =~ /[><=]/) {
|
---|
| 1421 | # Pick up the details of versioned buildreqs
|
---|
| 1422 | ($pkg,$rel,$ver) = ($req =~ /([a-z0-9._-]+)\s+([><=]+)\s+([a-z0-9._-]+)/);
|
---|
| 1423 | } else {
|
---|
| 1424 | # And the unversioned ones.
|
---|
| 1425 | $pkg = $req;
|
---|
| 1426 | $rel = '>=';
|
---|
| 1427 | $ver = 0;
|
---|
| 1428 | }
|
---|
| 1429 |
|
---|
| 1430 | my @pkglist = qx { dpkg-query --showformat '\${status}\t\${version}\n' -W $pkg };
|
---|
| 1431 | # need to check if no lines returned - means a bad buildreq
|
---|
[154] | 1432 | if (!$pkglist[0]) {
|
---|
[38] | 1433 | print " * Missing build-dependency $pkg!\n";
|
---|
| 1434 | $reqflag = 0;
|
---|
| 1435 | } else {
|
---|
[154] | 1436 | my ($reqstat,undef,undef,$reqver) = split /\s+/, $pkglist[0];
|
---|
| 1437 | if ($reqstat !~ /install/) {
|
---|
| 1438 | print " * Missing build-dependency $pkg!\n";
|
---|
[38] | 1439 | $reqflag = 0;
|
---|
[154] | 1440 | } else {
|
---|
| 1441 | my ($resp) = qx { dpkg --compare-versions $reqver '$rel' $ver && echo "ok" };
|
---|
| 1442 | if ($resp !~ /^ok/) {
|
---|
| 1443 | $reqflag = 0;
|
---|
| 1444 | print " * Buildreq $pkg is installed, but wrong version ($reqver): Need $ver\n"
|
---|
| 1445 | }
|
---|
| 1446 | } # end not installed/installed check
|
---|
| 1447 | }
|
---|
[38] | 1448 | } # end req loop
|
---|
| 1449 |
|
---|
| 1450 | return $reqflag;
|
---|
| 1451 | } # end checkbuildreq()
|
---|
| 1452 |
|
---|
| 1453 |
|
---|
| 1454 | ## getreqs()
|
---|
| 1455 | # Find out which libraries/packages are required for any
|
---|
| 1456 | # executables and libs in a given file tree.
|
---|
| 1457 | # (Debian doesn't have soname-level deps; just package-level)
|
---|
[41] | 1458 | # Returns an empty string if the tree contains no binaries.
|
---|
| 1459 | # Doesn't work well on shell scripts. but those *should* be
|
---|
| 1460 | # fine anyway. (Yeah, right...)
|
---|
[38] | 1461 | sub getreqs() {
|
---|
| 1462 | my $pkgtree = $_[0];
|
---|
| 1463 |
|
---|
[39] | 1464 | print "Checking library requirements...\n";
|
---|
[43] | 1465 | my @binlist = qx { find $pkgtree -type f -perm 755 };
|
---|
[38] | 1466 |
|
---|
[41] | 1467 | if (scalar(@binlist) == 0) {
|
---|
| 1468 | return '';
|
---|
| 1469 | }
|
---|
| 1470 |
|
---|
| 1471 | my @reqlist;
|
---|
| 1472 | foreach (@binlist) {
|
---|
| 1473 | push @reqlist, qx { ldd $_ };
|
---|
| 1474 | }
|
---|
| 1475 |
|
---|
| 1476 | # Get the list of libs provided by this package. Still doesn't
|
---|
| 1477 | # handle the case where the lib gets stuffed into a subpackage. :/
|
---|
| 1478 | my @intprovlist = qx { find $pkgtree -type f -name "*.so*" };
|
---|
| 1479 | my $provlist = '';
|
---|
| 1480 | foreach (@intprovlist) {
|
---|
| 1481 | s/$pkgtree//;
|
---|
| 1482 | $provlist .= "$_";
|
---|
| 1483 | }
|
---|
| 1484 |
|
---|
[38] | 1485 | my %reqs;
|
---|
[43] | 1486 | my $reqlibs = '';
|
---|
[38] | 1487 |
|
---|
| 1488 | foreach (@reqlist) {
|
---|
| 1489 | next if /^$pkgtree/;
|
---|
[42] | 1490 | next if /not a dynamic executable/;
|
---|
[139] | 1491 | next if m|/lib(?:64)?/ld-linux|; # Hack! Hack! PTHBTT! (libc suxx0rz)
|
---|
[100] | 1492 | next if /linux-gate.so/; # Kernel hackery for teh W1n!!1!1eleventy-one!1 (Don't ask. Feh.)
|
---|
[151] | 1493 | next if /linux-vdso.so/; # More kernel hackery. Whee!
|
---|
[38] | 1494 |
|
---|
[147] | 1495 | my ($req) = (m|=\>\s+([a-z0-9._/-]+)|); # dig out the actual library (so)name.
|
---|
| 1496 | # And feh, we need the *path*, since I've discovered a new edge case where
|
---|
| 1497 | # the same libnnn.1.2.3 *file*name is found across *several* lib dirs. >:(
|
---|
[41] | 1498 |
|
---|
| 1499 | # Ignore libs provided by this package. Note that we don't match
|
---|
| 1500 | # on word-boundary at the *end* of the lib we're looking for, as the
|
---|
| 1501 | # looked-for lib may not have the full soname version. (ie, it may
|
---|
| 1502 | # "just" point to one of the symlinks that get created somewhere.)
|
---|
| 1503 | next if $provlist =~ /\b$req/;
|
---|
| 1504 |
|
---|
[38] | 1505 | $reqlibs .= " $req";
|
---|
| 1506 | }
|
---|
| 1507 |
|
---|
[43] | 1508 | if ($reqlibs ne '') {
|
---|
| 1509 | foreach (qx { dpkg -S $reqlibs }) {
|
---|
| 1510 | my ($libpkg,undef) = split /:\s+/;
|
---|
| 1511 | $reqs{$libpkg} = 1;
|
---|
| 1512 | }
|
---|
[38] | 1513 | }
|
---|
| 1514 |
|
---|
[43] | 1515 | my $deplist = '';
|
---|
[38] | 1516 | foreach (keys %reqs) {
|
---|
| 1517 | $deplist .= ", $_";
|
---|
| 1518 | }
|
---|
| 1519 |
|
---|
| 1520 | # For now, we're done. We're not going to meddle with versions yet.
|
---|
| 1521 | # Among other things, it's messier than handling "simple" yes/no "do
|
---|
| 1522 | # we have this lib?" deps. >:(
|
---|
| 1523 |
|
---|
| 1524 | return $deplist;
|
---|
| 1525 | } # end getreqs()
|
---|
| 1526 |
|
---|
| 1527 |
|
---|
[50] | 1528 | ## install_sdeb()
|
---|
| 1529 | # Extracts .sdeb contents to %_topdir as appropriate
|
---|
| 1530 | sub install_sdeb {
|
---|
[92] | 1531 | $srcpkg = abs_path($srcpkg);
|
---|
| 1532 |
|
---|
[50] | 1533 | my $paxcmd = "cd $topdir; pax -r <$srcpkg; cd -";
|
---|
| 1534 |
|
---|
| 1535 | # In case of %-macros...
|
---|
| 1536 | $paxcmd = expandmacros($paxcmd,'gp');
|
---|
| 1537 |
|
---|
| 1538 | system "$paxcmd";
|
---|
| 1539 | print "Extracted source package $srcpkg to $topdir.\n";
|
---|
| 1540 | } # end install_sdeb()
|
---|
| 1541 |
|
---|
| 1542 |
|
---|
[10] | 1543 | ## expandmacros()
|
---|
| 1544 | # Expands all %{blah} macros in the passed string
|
---|
[14] | 1545 | # Split up a bit with some sections so we don't spend time trying to
|
---|
| 1546 | # expand macros that are only used in a few specific places.
|
---|
[10] | 1547 | sub expandmacros {
|
---|
| 1548 | my $macrostring = shift;
|
---|
[14] | 1549 | my $section = shift;
|
---|
[10] | 1550 |
|
---|
[25] | 1551 | # To allow the FHS-ish %configure and %makeinstall to work The Right Way.
|
---|
[136] | 1552 | # (Without clobbering the global $specglobals{buildroot}.)
|
---|
[12] | 1553 | my $prefix = '';
|
---|
| 1554 |
|
---|
[11] | 1555 | if ($section =~ /c/) {
|
---|
[12] | 1556 | # %configure macro
|
---|
[17] | 1557 | # Don't know what it's for, don't have a useful default replacement
|
---|
| 1558 | # --program-prefix=%{_program_prefix} \
|
---|
| 1559 | $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
|
---|
| 1560 | --build=$DEB_BUILD_GNU_TYPE \
|
---|
| 1561 | --prefix=%{_prefix} \
|
---|
| 1562 | --exec-prefix=%{_exec_prefix} \
|
---|
| 1563 | --bindir=%{_bindir} \
|
---|
| 1564 | --sbindir=%{_sbindir} \
|
---|
| 1565 | --sysconfdir=%{_sysconfdir} \
|
---|
| 1566 | --datadir=%{_datadir} \
|
---|
| 1567 | --includedir=%{_includedir} \
|
---|
| 1568 | --libdir=%{_libdir} \
|
---|
| 1569 | --libexecdir=%{_libexecdir} \
|
---|
| 1570 | --localstatedir=%{_localstatedir} \
|
---|
| 1571 | --sharedstatedir=%{_sharedstatedir} \
|
---|
| 1572 | --mandir=%{_mandir} \
|
---|
| 1573 | --infodir=%{_infodir} ';
|
---|
[12] | 1574 | } # done %configure
|
---|
| 1575 |
|
---|
| 1576 | if ($section =~ /m/) {
|
---|
| 1577 | $macrostring =~ s'%{__make}'make ';
|
---|
[25] | 1578 | } # done make
|
---|
[12] | 1579 |
|
---|
[136] | 1580 | # %makeinstall expands with recursive macros in rpm. whee.
|
---|
[12] | 1581 | if ($section =~ /i/) {
|
---|
| 1582 | # This is where we need to mangle $prefix.
|
---|
[136] | 1583 | $macrostring =~ s'%makeinstall'make \
|
---|
| 1584 | prefix=%{?buildroot:%{buildroot}}%{_prefix} \
|
---|
| 1585 | exec_prefix=%{?buildroot:%{buildroot}}%{_exec_prefix} \
|
---|
| 1586 | bindir=%{?buildroot:%{buildroot}}%{_bindir} \
|
---|
| 1587 | sbindir=%{?buildroot:%{buildroot}}%{_sbindir} \
|
---|
| 1588 | sysconfdir=%{?buildroot:%{buildroot}}%{_sysconfdir} \
|
---|
| 1589 | datadir=%{?buildroot:%{buildroot}}%{_datadir} \
|
---|
| 1590 | includedir=%{?buildroot:%{buildroot}}%{_includedir} \
|
---|
| 1591 | libdir=%{?buildroot:%{buildroot}}%{_libdir} \
|
---|
| 1592 | libexecdir=%{?buildroot:%{buildroot}}%{_libexecdir} \
|
---|
| 1593 | localstatedir=%{?buildroot:%{buildroot}}%{_localstatedir} \
|
---|
| 1594 | sharedstatedir=%{?buildroot:%{buildroot}}%{_sharedstatedir} \
|
---|
| 1595 | mandir=%{?buildroot:%{buildroot}}%{_mandir} \
|
---|
| 1596 | infodir=%{?buildroot:%{buildroot}}%{_infodir} \
|
---|
| 1597 | install ';
|
---|
| 1598 | $prefix = $specglobals{buildroot};
|
---|
[12] | 1599 | } # done %install and/or %makeinstall
|
---|
| 1600 |
|
---|
| 1601 | # Build data
|
---|
| 1602 | # Note that these are processed in reverse order to get the substitution order right
|
---|
| 1603 | if ($section =~ /b/) {
|
---|
[24] | 1604 | # $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
|
---|
| 1605 | # build=$DEB_BUILD_GNU_TYPE \
|
---|
| 1606 | $macrostring =~ s'%{fhs}'prefix=%{_prefix} \
|
---|
[17] | 1607 | exec-prefix=%{_exec_prefix} \
|
---|
| 1608 | bindir=%{_bindir} \
|
---|
| 1609 | sbindir=%{_sbindir} \
|
---|
| 1610 | sysconfdir=%{_sysconfdir} \
|
---|
| 1611 | datadir=%{_datadir} \
|
---|
| 1612 | includedir=%{_includedir} \
|
---|
| 1613 | libdir=%{_libdir} \
|
---|
| 1614 | libexecdir=%{_libexecdir} \
|
---|
| 1615 | localstatedir=%{_localstatedir} \
|
---|
| 1616 | sharedstatedir=%{_sharedstatedir} \
|
---|
| 1617 | mandir=%{_mandir} \
|
---|
| 1618 | infodir=%{_infodir} \
|
---|
| 1619 | ';
|
---|
[10] | 1620 |
|
---|
| 1621 | # Note that the above regex terminates with the extra space
|
---|
[12] | 1622 | # "Just In Case" of user additions, which will then get neatly
|
---|
| 1623 | # tagged on the end where they take precedence (supposedly)
|
---|
| 1624 | # over the "default" ones.
|
---|
[10] | 1625 |
|
---|
[14] | 1626 | # Now we cascade the macros introduced above. >_<
|
---|
| 1627 | # Wot ot to go theah:
|
---|
| 1628 | $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
|
---|
| 1629 | $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
|
---|
[25] | 1630 | $macrostring =~ s|%{_oldincludedir}|/usr/include|g; #/usr/include
|
---|
[84] | 1631 | $macrostring =~ s|%{_includedir}|%{_prefix}/include|g; #/usr/include
|
---|
[25] | 1632 | $macrostring =~ s|%{_libdir}|%{_exec_prefix}/%{_lib}|g; #/usr/lib
|
---|
[14] | 1633 | $macrostring =~ s|%{_lib}|lib|g; #?
|
---|
[25] | 1634 | $macrostring =~ s|%{_localstatedir}|/var|g; #/var
|
---|
| 1635 | $macrostring =~ s|%{_sharedstatedir}|%{_prefix}/com|g; #/usr/com WTF?
|
---|
| 1636 | $macrostring =~ s|%{_sysconfdir}|/etc|g; #/etc
|
---|
| 1637 | $macrostring =~ s|%{_datadir}|%{_prefix}/share|g; #/usr/share
|
---|
| 1638 | $macrostring =~ s|%{_libexecdir}|%{_exec_prefix}/libexec|g; #/usr/libexec
|
---|
| 1639 | $macrostring =~ s|%{_sbindir}|%{_exec_prefix}/sbin|g; #/usr/sbin
|
---|
| 1640 | $macrostring =~ s|%{_bindir}|%{_exec_prefix}/bin|g; #/usr/bin
|
---|
| 1641 | $macrostring =~ s|%{_exec_prefix}|%{_prefix}|g; #/usr
|
---|
[14] | 1642 | $macrostring =~ s|%{_prefix}|/usr|g; #/usr
|
---|
[10] | 1643 | } # done with config section
|
---|
| 1644 |
|
---|
[12] | 1645 | # Package data
|
---|
| 1646 | if ($section =~ /p/) {
|
---|
[136] | 1647 | $macrostring =~ s/\%\{buildroot\}/$specglobals{buildroot}/gi;
|
---|
[149] | 1648 | $macrostring =~ s/\%\{source0?}/$topdir\/SOURCES\/$pkgdata{main}{source}/gi;
|
---|
[15] | 1649 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
| 1650 | $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
|
---|
| 1651 | }
|
---|
| 1652 | $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
|
---|
| 1653 | $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
|
---|
| 1654 | $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
|
---|
[12] | 1655 | }
|
---|
| 1656 |
|
---|
| 1657 | # Globals, and not-so-globals
|
---|
| 1658 | if ($section =~ /g/) {
|
---|
[60] | 1659 |
|
---|
[29] | 1660 | $macrostring =~ s|%{_builddir}|%{_topdir}/BUILD|g;
|
---|
| 1661 | $macrostring =~ s|%{_topdir}|$topdir|g;
|
---|
[13] | 1662 | $macrostring =~ s|%{_tmppath}|$tmpdir|g;
|
---|
[84] | 1663 | $macrostring =~ s'%{_docdir}'%{_datadir}/doc'g;
|
---|
[23] | 1664 |
|
---|
[31] | 1665 | # Standard FHS locations. More or less.
|
---|
[30] | 1666 | $macrostring =~ s'%{_bindir}'/usr/bin'g;
|
---|
[31] | 1667 | $macrostring =~ s'%{_sbindir}'/usr/sbin'g;
|
---|
[84] | 1668 | $macrostring =~ s'%{_mandir}'%{_datadir}/man'g;
|
---|
[153] | 1669 | $macrostring =~ s'%{_infodir}'%{_datadir}/info'g;
|
---|
[30] | 1670 | $macrostring =~ s'%{_includedir}'/usr/include'g;
|
---|
[31] | 1671 | $macrostring =~ s'%{_libdir}'/usr/lib'g;
|
---|
| 1672 | $macrostring =~ s'%{_sysconfdir}'/etc'g;
|
---|
| 1673 | $macrostring =~ s'%{_localstatedir}'/var'g;
|
---|
[30] | 1674 |
|
---|
[84] | 1675 | # FHS-ish locations that aren't quite actually FHS-specified.
|
---|
| 1676 | $macrostring =~ s'%{_datadir}'/usr/share'g;
|
---|
| 1677 |
|
---|
[96] | 1678 | # special %define's. Handle the general case where we eval anything.
|
---|
| 1679 | # Even more general: %(...) is a spec-parse-time shell code wrapper.
|
---|
| 1680 | # Prime example:
|
---|
| 1681 | #%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
|
---|
| 1682 | if ($macrostring =~ /\%\((.+)\)/) {
|
---|
| 1683 | my $shellstr = $1;
|
---|
| 1684 | # Oy vey this gets silly for the perl bits. Executing a shell to
|
---|
| 1685 | # call Perl to get the vendorlib/sitelib/whatever "core" globals.
|
---|
| 1686 | # This can do more, but... eww.
|
---|
| 1687 | $shellstr = qx { /bin/sh -c '$shellstr' }; # Yay! ' characters apparently get properly exscapededed.
|
---|
| 1688 | $macrostring =~ s/\%\(.+\)/$shellstr/;
|
---|
| 1689 | }
|
---|
| 1690 |
|
---|
[95] | 1691 | # support for **some** %if constructs. Note that this breaks somewhat if
|
---|
| 1692 | # there's no value specified... but so does rpm.
|
---|
[136] | 1693 |
|
---|
| 1694 | my $tmpcount = 0; # runaway shutdown. Not really sure how else to avoid getting stuck.
|
---|
| 1695 | while ($macrostring =~ m/\%\{([?!]+)([a-z0-9_.-]+)(?:\:([a-z0-9_.\/\-\\]+)?)?\}/g) { #Whew....
|
---|
[116] | 1696 | my $qex = $1;
|
---|
| 1697 | my $macro = $2;
|
---|
[136] | 1698 | my $value = (defined($3) ? $3 : '');
|
---|
[114] | 1699 |
|
---|
| 1700 | my $neg = '1' if $qex =~ /\!/;
|
---|
[95] | 1701 | if ($specglobals{$macro}) {
|
---|
| 1702 | $value = '' if $neg;
|
---|
| 1703 | } else {
|
---|
| 1704 | $value = '' if !$neg;
|
---|
| 1705 | }
|
---|
[136] | 1706 | $macrostring =~ s/\%\{[?!]+[a-z0-9_.-]+(?:\:([a-z0-9_.\/\-\\]+)?)?\}/$value/;
|
---|
[95] | 1707 |
|
---|
[114] | 1708 | # not certain about this, but I don't want to run away. It *can* happen if planned carefully. :/
|
---|
| 1709 | $tmpcount++;
|
---|
[136] | 1710 | # %makeinstall has 13 occurrences. D'Oh!
|
---|
| 1711 | die "excessive recursive macro replacement; dying.\n" if $tmpcount > 14;
|
---|
[114] | 1712 |
|
---|
| 1713 | } # while()
|
---|
| 1714 |
|
---|
[123] | 1715 | # Misc expansions
|
---|
| 1716 | $macrostring =~ s|%{_arch}|$hostarch|g;
|
---|
| 1717 | $macrostring =~ s|%{optflags}|$optflags{$hostarch}|g;
|
---|
[125] | 1718 | $macrostring =~ s|%{_vendor}|$specglobals{'_vendor'}|g;
|
---|
[123] | 1719 |
|
---|
[116] | 1720 | # should probably stick a "no runaway" flag in here... Just In Case...
|
---|
| 1721 | # %define's
|
---|
| 1722 | while (my ($key) = ($macrostring =~ /%{([a-z0-9]+)}/i) ) {
|
---|
[123] | 1723 | # hrm. This needs thinking.
|
---|
| 1724 | #die "A horrible death! \%{$key}, '$macrostring'\n" if !$specglobals{$key};
|
---|
[116] | 1725 | $macrostring =~ s|%{$key}|$specglobals{$key}|g;
|
---|
| 1726 | # wanna limit this to "... if $specglobals{$key}", but need more magic
|
---|
| 1727 | }
|
---|
| 1728 |
|
---|
[23] | 1729 | # system programs. RPM uses a global config file for these; we'll just
|
---|
| 1730 | # ASS-U-ME and make life a little simpler.
|
---|
| 1731 | if ($macrostring =~ /\%\{\_\_([a-z0-9_-]+)\}/) {
|
---|
| 1732 | $macrostring =~ s|%{__([a-z0-9_-]+)}|$1|g;
|
---|
| 1733 | }
|
---|
[87] | 1734 |
|
---|
[113] | 1735 | # Perl @INC/...lib locations, and other related bits.
|
---|
| 1736 | $macrostring =~ s|%{perl_archlib}|$Config{installarchlib}|g;
|
---|
| 1737 | $macrostring =~ s|%{perl_sitelib}|$Config{installsitelib}|g;
|
---|
| 1738 | $macrostring =~ s|%{perl_sitearch}|$Config{installsitearch}|g;
|
---|
| 1739 | $macrostring =~ s|%{perl_vendorlib}|$Config{installvendorlib}|g;
|
---|
| 1740 | $macrostring =~ s|%{perl_vendorarch}|$Config{installvendorarch}|g;
|
---|
| 1741 |
|
---|
[10] | 1742 | } # done with globals section
|
---|
| 1743 |
|
---|
| 1744 | return $macrostring;
|
---|
| 1745 | } # end expandmacros()
|
---|
[22] | 1746 |
|
---|
| 1747 |
|
---|
| 1748 |
|
---|
[38] | 1749 | __END__
|
---|
| 1750 |
|
---|
| 1751 |
|
---|
| 1752 |
|
---|
[22] | 1753 | =head1 NAME
|
---|
| 1754 |
|
---|
[140] | 1755 | debbuild - Build Debian-compatible .deb packages from RPM .spec files
|
---|
[22] | 1756 |
|
---|
| 1757 | =head1 SYNOPSIS
|
---|
| 1758 |
|
---|
| 1759 | debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
|
---|
| 1760 |
|
---|
| 1761 | debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2}
|
---|
| 1762 |
|
---|
[55] | 1763 | debbuild --rebuild file.{src.rpm|sdeb}
|
---|
[22] | 1764 |
|
---|
[89] | 1765 | debbuild --showpkgs
|
---|
| 1766 |
|
---|
[22] | 1767 | =head1 DESCRIPTION
|
---|
| 1768 |
|
---|
[140] | 1769 | debbuild attempts to build Debian-friendly semi-native packages from RPM spec files,
|
---|
[55] | 1770 | RPM-friendly tarballs, and RPM source packages (.src.rpm files). It accepts I<most> of the
|
---|
| 1771 | options rpmbuild does, and should be able to interpret most spec files usefully. Perl
|
---|
[140] | 1772 | modules should be handled via CPAN+dh-make-perl instead as it's simpler than even tweaking
|
---|
| 1773 | a .spec template.
|
---|
[22] | 1774 |
|
---|
[55] | 1775 | As far as possible, the command-line options are identical to those from rpmbuild, although
|
---|
[57] | 1776 | several rpmbuild options are not supported:
|
---|
[22] | 1777 |
|
---|
[57] | 1778 | --recompile
|
---|
| 1779 | --showrc
|
---|
| 1780 | --buildroot
|
---|
| 1781 | --clean
|
---|
| 1782 | --nobuild
|
---|
| 1783 | --rmsource
|
---|
| 1784 | --rmspec
|
---|
| 1785 | --sign
|
---|
| 1786 | --target
|
---|
| 1787 |
|
---|
| 1788 | Some of these could probably be trivially added. Feel free to send me a patch. ;)
|
---|
| 1789 |
|
---|
| 1790 | Complex spec files will most likely not work well, if at all. Rewrite them from scratch -
|
---|
| 1791 | you'll have to make heavy modifications anyway.
|
---|
| 1792 |
|
---|
| 1793 | If you see something you don't like, mail me. Send a patch if you feel inspired. I don't
|
---|
| 1794 | promise I'll do anything other than say "Yup, that's broken" or "Got your message".
|
---|
| 1795 |
|
---|
[55] | 1796 | =head1 ASSUMPTIONS
|
---|
| 1797 |
|
---|
| 1798 | As with rpmbuild, debbuild makes some assumptions about your system.
|
---|
| 1799 |
|
---|
| 1800 | =over 4
|
---|
| 1801 |
|
---|
| 1802 | =item *
|
---|
| 1803 |
|
---|
| 1804 | Either you have rights to do as you please under /usr/src/debian, or you have created a file
|
---|
| 1805 | ~/.debmacros containing a suitable %_topdir definition.
|
---|
| 1806 |
|
---|
[57] | 1807 | Both rpmbuild and debbuild require the directories %_topdir/{BUILD,SOURCES,SPECS}. However,
|
---|
| 1808 | where rpmbuild requires the %_topdir/{RPMS,SRPMS} directories, debbuild
|
---|
| 1809 | requires %_topdir/{DEBS,SDEBS} instead. Create them in advance;
|
---|
[55] | 1810 | some subdirectories are created automatically as needed, but most are not.
|
---|
| 1811 |
|
---|
| 1812 | =item *
|
---|
| 1813 |
|
---|
| 1814 | /var/tmp must allow script execution - rpmbuild and debbuild both rely on creating and
|
---|
| 1815 | executing shell scripts for much of their functionality. By default, debbuild also creates
|
---|
| 1816 | install trees under /var/tmp - however this is (almost) entirely under the control of the
|
---|
| 1817 | package's .spec file.
|
---|
| 1818 |
|
---|
| 1819 | =item *
|
---|
| 1820 |
|
---|
| 1821 | If you wish to --rebuild a .src.rpm, your %_topdir for both debbuild and rpmbuild must either
|
---|
| 1822 | match, or be suitably symlinked one direction or another so that both programs are effectively
|
---|
| 1823 | working in the same tree. (Or you could just manually wrestle files around your system.)
|
---|
| 1824 |
|
---|
| 1825 | You could symlink ~/.rpmmacros to ~/.debmacros (or vice versa) and save yourself some hassle
|
---|
| 1826 | if you need to rebuild .src.rpm packages on a regular basis. Currently debbuild only uses the
|
---|
| 1827 | %_topdir macro definition, although there are many more things that rpmbuild can use from
|
---|
| 1828 | ~/.rpmmacros.
|
---|
| 1829 |
|
---|
| 1830 | =back
|
---|
| 1831 |
|
---|
[89] | 1832 | =head1 ERRATA
|
---|
| 1833 |
|
---|
| 1834 | debbuild deliberately does a few things differently from rpm.
|
---|
| 1835 |
|
---|
| 1836 | =head2 BuildArch or BuildArchitecture
|
---|
| 1837 |
|
---|
| 1838 | rpm takes the last BuildArch entry it finds in the .spec file, whatever it is, and runs with
|
---|
| 1839 | that for all packages. Debian's repository system is fairly heavily designed around the
|
---|
| 1840 | assumption that a single source package may generate small binary (executable) packages
|
---|
| 1841 | for each arch, and large binary arch-all packages containing shared data.
|
---|
| 1842 |
|
---|
| 1843 | debbuild allows this by using the architecture specified by (in order of preference):
|
---|
| 1844 |
|
---|
| 1845 | =over 4
|
---|
| 1846 |
|
---|
| 1847 | =item * Host architecture
|
---|
| 1848 |
|
---|
| 1849 | =item * BuildArch specified in .spec file preamble
|
---|
| 1850 |
|
---|
| 1851 | =item * "Last specified" BuildArch for packages with several subpackages
|
---|
| 1852 |
|
---|
| 1853 | =item * BuildArch specified in the %package section for that subpackage
|
---|
| 1854 |
|
---|
| 1855 | =back
|
---|
| 1856 |
|
---|
| 1857 | =head2 Finding out what packages should be built (--showpkgs)
|
---|
| 1858 |
|
---|
| 1859 | rpmbuild does not include any convenient method I know of to list the packages a spec file
|
---|
| 1860 | will produce. Since I needed this ability for another tool, I added it.
|
---|
| 1861 |
|
---|
| 1862 | It requires the .spec file for the package, and produces a list of full package filenames
|
---|
| 1863 | (without path data) that would be generated by one of --rebuild, -ta, -tb, -ba, or -bb.
|
---|
| 1864 | This includes the .sdeb source package.
|
---|
| 1865 |
|
---|
[57] | 1866 | =head1 AUTHOR
|
---|
[55] | 1867 |
|
---|
[57] | 1868 | debbuild was written by Kris Deugau <kdeugau@deepnet.cx>. A version that approximates
|
---|
| 1869 | current is available at http://www.deepnet.cx/debbuild/.
|
---|
[55] | 1870 |
|
---|
| 1871 | =head1 BUGS
|
---|
| 1872 |
|
---|
[57] | 1873 | Funky Things Happen if you forget a command-line option or two. I've been too lazy to bother
|
---|
| 1874 | fixing this.
|
---|
[55] | 1875 |
|
---|
[57] | 1876 | Many macro expansions are unsupported or incompletely supported.
|
---|
| 1877 |
|
---|
| 1878 | The generated scriptlets don't quite match those from rpmbuild exactly. There are extra
|
---|
| 1879 | environment variables and preprocessing that I haven't needed (yet).
|
---|
| 1880 |
|
---|
| 1881 | Dcumentation, such as it is, will likely remain perpetually out of date.
|
---|
| 1882 |
|
---|
| 1883 | %_topdir and the five "working" directories under %_topdir could arguably be created by
|
---|
| 1884 | debbuild. However, rpmbuild doesn't create these directories either.
|
---|
| 1885 |
|
---|
| 1886 | =head1 SEE ALSO
|
---|
| 1887 |
|
---|
| 1888 | rpm(8), rpmbuild(8), and pretty much any document describing how to write a .spec file.
|
---|
| 1889 |
|
---|
[22] | 1890 | =cut
|
---|