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