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