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