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