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