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