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