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