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