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