[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: 2005-11-14 21:29:35 +0000 (Mon, 14 Nov 2005) $
|
---|
| 9 | # SVN revision $Rev: 19 $
|
---|
| 10 | # Last update by $Author: kdeugau $
|
---|
| 11 | ###
|
---|
| 12 |
|
---|
[19] | 13 | =head1 NAME
|
---|
| 14 |
|
---|
| 15 | debbuild - Build Debian-compatible packages from RPM spec files
|
---|
| 16 |
|
---|
| 17 | =head1 SYNOPSIS
|
---|
| 18 |
|
---|
| 19 | debbuild {-ba|-bb|-bp|-bc|-bi|-bl|-bs} [build-options] file.spec
|
---|
| 20 |
|
---|
| 21 | debbuild {-ta|-tb|-tp|-tc|-ti|-tl|-ts} [build-options] file.tar.{gz|bz2}
|
---|
| 22 |
|
---|
| 23 | debbuild --rebuild file.src.{rpm|deb}
|
---|
| 24 |
|
---|
| 25 | =head1 DESCRIPTION
|
---|
| 26 |
|
---|
| 27 | This script attempts to build Debian-friendly semi-native packages
|
---|
| 28 | from RPM spec files, RPM-friendly tarballs, and RPM source packages
|
---|
| 29 | (.src.rpm). It accepts I<most> of the options rpmbuild does, and
|
---|
| 30 | should be able to interpret most spec files usefully. Perl modules
|
---|
| 31 | should be handled via CPAN+dh-make-perl instead; Debian's conventions
|
---|
| 32 | for such things do not lend themselves to automated conversion.
|
---|
| 33 |
|
---|
| 34 | As far as possible, the command-line options are identical to those
|
---|
| 35 | from rpmbuild, although several rpmbuild options are not supported.
|
---|
| 36 |
|
---|
| 37 | =cut
|
---|
| 38 |
|
---|
[5] | 39 | use strict;
|
---|
[6] | 40 | use warnings;
|
---|
[7] | 41 | use Fcntl; # for sysopen flags
|
---|
[5] | 42 |
|
---|
[10] | 43 | # regex debugger
|
---|
| 44 | #use re "debug";
|
---|
| 45 |
|
---|
[3] | 46 | # Program flow:
|
---|
| 47 | # -> Parse/execute "system" config/macros (if any - should be rare)
|
---|
| 48 | # -> Parse/execute "user" config/macros (if any - *my* requirement is %_topdir)
|
---|
| 49 | # -> Parse command line for options, spec file/tarball/.src.deb (NB - also accept .src.rpm)
|
---|
| 50 |
|
---|
[2] | 51 | # User's prefs for dirs, environment, etc,etc,etc.
|
---|
| 52 | # config file ~/.debmacros
|
---|
| 53 | # Default ordered search paths for config/macros:
|
---|
| 54 | # /usr/lib/rpm/rpmrc /usr/lib/rpm/redhat/rpmrc /etc/rpmrc ~/.rpmrc
|
---|
| 55 | # /usr/lib/rpm/macros /usr/lib/rpm/redhat/macros /etc/rpm/macros ~/.rpmmacros
|
---|
| 56 | # **NOTE: May be possible to (ab)use bits of debhelper
|
---|
| 57 |
|
---|
| 58 | # Build tree
|
---|
| 59 | # default is /usr/src/debian/{BUILD,SOURCES,SPECS,DEBS,SDEBS}
|
---|
| 60 |
|
---|
[3] | 61 | # Globals
|
---|
| 62 | my $specfile;
|
---|
| 63 | my $tarball;
|
---|
| 64 | my $srcpkg;
|
---|
[7] | 65 | my $cmdbuildroot;
|
---|
| 66 | my $tarballdir; # This should really be initialized, but the coding makes it, um, ugly.
|
---|
[6] | 67 |
|
---|
| 68 | # Initialized globals
|
---|
[3] | 69 | my $verbosity = 0;
|
---|
[4] | 70 | my %cmdopts = (type => '',
|
---|
| 71 | stage => 'a',
|
---|
| 72 | short => 'n'
|
---|
| 73 | );
|
---|
[6] | 74 | my $topdir = "/usr/src/debian";
|
---|
[13] | 75 | my $buildroot = "%{_tmppath}/%{name}-%{version}-%{release}.root".int(rand(99998)+1);
|
---|
[6] | 76 |
|
---|
| 77 | # "Constants"
|
---|
[4] | 78 | my %targets = ('p' => 'Prep',
|
---|
| 79 | 'c' => 'Compile',
|
---|
| 80 | 'i' => 'Install',
|
---|
| 81 | 'l' => 'Verify %files',
|
---|
| 82 | 'a' => 'Build binary and source',
|
---|
| 83 | 'b' => 'Build binary',
|
---|
| 84 | 's' => 'Build source'
|
---|
| 85 | );
|
---|
[6] | 86 | my $scriptletbase =
|
---|
| 87 | q(#!/bin/sh
|
---|
[3] | 88 |
|
---|
[6] | 89 | RPM_SOURCE_DIR="%{_topdir}/SOURCES"
|
---|
| 90 | RPM_BUILD_DIR="%{_topdir}/BUILD"
|
---|
| 91 | RPM_OPT_FLAGS="-O2 -g -march=i386 -mcpu=i686"
|
---|
| 92 | RPM_ARCH="i386"
|
---|
| 93 | RPM_OS="linux"
|
---|
| 94 | export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
|
---|
| 95 | RPM_DOC_DIR="/usr/share/doc"
|
---|
| 96 | export RPM_DOC_DIR
|
---|
| 97 | RPM_PACKAGE_NAME="%{name}"
|
---|
| 98 | RPM_PACKAGE_VERSION="%{version}"
|
---|
| 99 | RPM_PACKAGE_RELEASE="%{release}"
|
---|
| 100 | export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
|
---|
| 101 | RPM_BUILD_ROOT="%{buildroot}"
|
---|
| 102 | export RPM_BUILD_ROOT
|
---|
[10] | 103 | );
|
---|
| 104 | foreach (`dpkg-architecture`) {
|
---|
| 105 | s/=(.+)/="$1"/;
|
---|
| 106 | $scriptletbase .= " $_";
|
---|
| 107 | }
|
---|
| 108 | $scriptletbase .=
|
---|
| 109 | q(
|
---|
[6] | 110 | set -x
|
---|
| 111 | umask 022
|
---|
| 112 | cd %{_topdir}/BUILD
|
---|
| 113 | );
|
---|
| 114 |
|
---|
[5] | 115 | # Package data
|
---|
| 116 | # This is the form of $pkgdata{pkgname}{meta}
|
---|
| 117 | # meta includes Summary, Name, Version, Release, Group, Copyright,
|
---|
| 118 | # Source, URL, Packager, BuildRoot, Description
|
---|
[6] | 119 | # 10/31/2005 Maybe this should be flatter? -kgd
|
---|
[5] | 120 | my %pkgdata;
|
---|
| 121 |
|
---|
[6] | 122 | # Scriptlets
|
---|
| 123 | my $prepscript;
|
---|
| 124 | my $buildscript;
|
---|
| 125 | my $installscript;
|
---|
[7] | 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 |
|
---|
[7] | 148 | if ($cmdopts{type} eq 'b') {
|
---|
| 149 | # Need to read the spec file to find the tarball. Note that
|
---|
| 150 | # this also generates most of the shell script required.
|
---|
| 151 | parse_spec();
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[4] | 154 | # Hokay. Need to:
|
---|
[14] | 155 | # -> prep if -.p OR (-.[cilabs] AND !--short-circuit)
|
---|
[7] | 156 | if ($cmdopts{stage} eq 'p' || ($cmdopts{stage} =~ /[cilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 157 | prep();
|
---|
| 158 | }
|
---|
[14] | 159 | # -> build if -.c OR (-.[ilabs] AND !--short-circuit)
|
---|
[7] | 160 | if ($cmdopts{stage} eq 'c' || ($cmdopts{stage} =~ /[ilabs]/ && $cmdopts{short} ne 'y')) {
|
---|
| 161 | build();
|
---|
| 162 | }
|
---|
[14] | 163 | # -> install if -.[ilabs]
|
---|
[7] | 164 | if ($cmdopts{stage} =~ /[ilabs]/) {
|
---|
| 165 | install();
|
---|
| 166 | }
|
---|
[14] | 167 | # -> binpkg and srcpkg if -.a
|
---|
[7] | 168 | if ($cmdopts{stage} eq 'a') {
|
---|
[4] | 169 | binpackage();
|
---|
[7] | 170 | srcpackage();
|
---|
[4] | 171 | }
|
---|
[14] | 172 | # -> binpkg if -.b
|
---|
[7] | 173 | if ($cmdopts{stage} eq 'b') {
|
---|
| 174 | binpackage();
|
---|
| 175 | }
|
---|
[14] | 176 | # -> srcpkg if -.s
|
---|
[7] | 177 | if ($cmdopts{stage} eq 's') {
|
---|
| 178 | srcpackage();
|
---|
| 179 | }
|
---|
[4] | 180 |
|
---|
| 181 | # Just in case.
|
---|
| 182 | exit 0;
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 | ## load_userconfig()
|
---|
| 186 | # Loads user configuration (if any)
|
---|
| 187 | # Currently only handles .debmacros
|
---|
| 188 | # Needs to handle "other files"
|
---|
| 189 | sub load_userconfig {
|
---|
[5] | 190 | my (undef,undef,undef,undef,undef,undef,undef,$homedir,undef) = getpwuid($<);
|
---|
[4] | 191 | if (-e "$homedir/.debmacros") {
|
---|
| 192 | open USERMACROS,"<$homedir/.debmacros";
|
---|
| 193 | while (<USERMACROS>) {
|
---|
[7] | 194 | # And we also only handle a few macros at the moment.
|
---|
[4] | 195 | if (/^\%_topdir/) {
|
---|
[5] | 196 | my (undef,$tmp) = split /\s+/, $_;
|
---|
| 197 | $topdir = $tmp;
|
---|
[4] | 198 | }
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | } # end load_userconfig()
|
---|
| 202 |
|
---|
| 203 |
|
---|
[3] | 204 | ## parse_cmd()
|
---|
[4] | 205 | # Parses command line into global hash %cmdopts, other globals
|
---|
[3] | 206 | # Options based on rpmbuild's options
|
---|
| 207 | sub parse_cmd {
|
---|
| 208 | # Don't feel like coding my own option parser...
|
---|
| 209 | #use Getopt::Long;
|
---|
| 210 | # ... but I may have to: (OTOH, rpm uses popt, so maybe we can too.)
|
---|
| 211 | #use Getopt::Popt qw(:all);
|
---|
[4] | 212 | # Or not. >:( Stupid Debian lack of findable Perl module names in packages.
|
---|
[3] | 213 |
|
---|
| 214 | # Stuff it.
|
---|
[4] | 215 | my $prevopt = '';
|
---|
[3] | 216 | foreach (@ARGV) {
|
---|
| 217 | chomp;
|
---|
[7] | 218 |
|
---|
[3] | 219 | # Is it an option?
|
---|
| 220 | if (/^-/) {
|
---|
[7] | 221 |
|
---|
[3] | 222 | # Is it a long option?
|
---|
| 223 | if (/^--/) {
|
---|
[4] | 224 | if (/^--short-circuit/) {
|
---|
| 225 | $cmdopts{short} = 'y';
|
---|
[5] | 226 | } elsif (/^--rebuild/) {
|
---|
| 227 | $cmdopts{type} = 's';
|
---|
[4] | 228 | } else {
|
---|
| 229 | print "Long opt $_\n";
|
---|
| 230 | }
|
---|
[3] | 231 | } else {
|
---|
[14] | 232 | # Not a long option
|
---|
[5] | 233 | if (/^-[bt]/) {
|
---|
| 234 | if ($cmdopts{stage} eq 's') {
|
---|
| 235 | # Mutually exclusive options.
|
---|
| 236 | die "Can't use $_ with --rebuild\n";
|
---|
| 237 | } else {
|
---|
[14] | 238 | # Capture the type (from "bare" files or tarball) and the stage (prep, build, etc)
|
---|
[5] | 239 | ($cmdopts{stage}) = (/^-[bt]([pcilabs])/);
|
---|
| 240 | ($cmdopts{type}) = (/^-([bt])[pcilabs]/);
|
---|
| 241 | }
|
---|
[4] | 242 | } elsif (/^-v/) {
|
---|
| 243 | # bump verbosity. Not sure what I'll actually do here...
|
---|
| 244 | } else {
|
---|
| 245 | die "Bad option $_\n";
|
---|
| 246 | }
|
---|
[3] | 247 | }
|
---|
[14] | 248 |
|
---|
| 249 | } else { # Not an option argument
|
---|
| 250 |
|
---|
[5] | 251 | # --buildroot is the only option that takes an argument
|
---|
| 252 | # Therefore, any *other* bare arguments are the spec file,
|
---|
| 253 | # tarball, or source package we're operating on - depending
|
---|
| 254 | # on which one we meet.
|
---|
| 255 | if ($prevopt eq '--buildroot') {
|
---|
[7] | 256 | $cmdbuildroot = $_;
|
---|
[5] | 257 | } else {
|
---|
| 258 | if ($cmdopts{type} eq 's') {
|
---|
| 259 | # Source package
|
---|
[7] | 260 | if (!/\.src\.(deb|rpm)$/) {
|
---|
[5] | 261 | die "Can't --rebuild with $_\n";
|
---|
| 262 | }
|
---|
| 263 | } elsif ($cmdopts{type} eq 'b') {
|
---|
| 264 | $specfile = $_;
|
---|
| 265 | # Spec file
|
---|
| 266 | } else {
|
---|
| 267 | # Tarball
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
[3] | 270 | }
|
---|
[7] | 271 | $prevopt = $_;
|
---|
| 272 | } # foreach @ARGV
|
---|
[4] | 273 |
|
---|
| 274 | # Some cross-checks. rpmbuild limits --short-circuit to just
|
---|
| 275 | # the "compile" and "install" targets - with good reason IMO.
|
---|
[14] | 276 | # Note that --short-circuit with -.p is not really an error, just redundant.
|
---|
[4] | 277 | # NB - this is NOT fatal, just ignored!
|
---|
[10] | 278 | if ($cmdopts{short} eq 'y' && $cmdopts{stage} =~ /[labs]/) {
|
---|
[4] | 279 | warn "Can't use --short-circuit for $targets{$cmdopts{stage}} stage. Ignoring.\n";
|
---|
| 280 | $cmdopts{short} = 'n';
|
---|
| 281 | }
|
---|
[14] | 282 |
|
---|
[3] | 283 | # Valid options, with example arguments (if any):
|
---|
| 284 | # Build from .spec file; mutually exclusive:
|
---|
| 285 | # -bp
|
---|
| 286 | # -bc
|
---|
| 287 | # -bi
|
---|
| 288 | # -bl
|
---|
| 289 | # -ba
|
---|
| 290 | # -bb
|
---|
| 291 | # -bs
|
---|
| 292 | # Build from tarball; mutually exclusive:
|
---|
| 293 | # -tp
|
---|
| 294 | # -tc
|
---|
| 295 | # -ti
|
---|
| 296 | # -ta
|
---|
| 297 | # -tb
|
---|
| 298 | # -ts
|
---|
| 299 | # Build from .src.(deb|rpm)
|
---|
| 300 | # --rebuild
|
---|
| 301 | # --recompile
|
---|
| 302 |
|
---|
| 303 | # General options
|
---|
| 304 | # --buildroot=DIRECTORY
|
---|
| 305 | # --clean
|
---|
| 306 | # --nobuild
|
---|
| 307 | # --nodeps
|
---|
| 308 | # --nodirtokens
|
---|
| 309 | # --rmsource
|
---|
| 310 | # --rmspec
|
---|
| 311 | # --short-circuit
|
---|
| 312 | # --target=CPU-VENDOR-OS
|
---|
| 313 |
|
---|
| 314 | #my $popt = new Getopt::Popt(argv => \@ARGV, options => \@optionsTable);
|
---|
| 315 |
|
---|
| 316 | } # end parse_cmd()
|
---|
| 317 |
|
---|
[4] | 318 |
|
---|
[5] | 319 | ## parse_spec()
|
---|
[14] | 320 | # Parse the .spec file.
|
---|
[5] | 321 | sub parse_spec {
|
---|
| 322 | open SPECFILE,"<$specfile";
|
---|
| 323 |
|
---|
[6] | 324 | LINE: while (<SPECFILE>) {
|
---|
[14] | 325 | next if /^#/; # Ignore comments...
|
---|
| 326 | next if /^\s+$/; # ... and blank lines.
|
---|
| 327 |
|
---|
[5] | 328 | if (/^\%/) {
|
---|
| 329 | # A macro that needs further processing.
|
---|
[14] | 330 |
|
---|
[8] | 331 | if (/^\%description/) {
|
---|
| 332 | $pkgdata{main}{desc} .= $_;
|
---|
| 333 | while (<SPECFILE>) {
|
---|
| 334 | redo LINE if /^\%/;
|
---|
| 335 | $pkgdata{main}{desc} .= " $_";
|
---|
| 336 | }
|
---|
[18] | 337 | }
|
---|
[8] | 338 |
|
---|
[6] | 339 | if (/^\%prep/) {
|
---|
| 340 | # %prep section. May have %setup macro; may include %patch tags,
|
---|
| 341 | # may be just a bare shell script.
|
---|
| 342 |
|
---|
| 343 | # This really should be local-ish, but we need just the filename for the source
|
---|
| 344 | $pkgdata{main}{source} =~ s|.+/([^/]+)$|$1|;
|
---|
| 345 |
|
---|
| 346 | # Replace some core macros
|
---|
[14] | 347 | $pkgdata{main}{source} = expandmacros($pkgdata{main}{source},'gp');
|
---|
[6] | 348 |
|
---|
| 349 | PREPSCRIPT: while (<SPECFILE>) {
|
---|
| 350 | if (/^\%setup/) {
|
---|
| 351 | # Parse out the %setup macro. Note that we aren't supporting
|
---|
[14] | 352 | # many of RPM's %setup features.
|
---|
[7] | 353 | $prepscript .= "cd $topdir/BUILD\n";
|
---|
| 354 | if ( /\s+-n\s+([^\s]+)\s+/ ) {
|
---|
| 355 | $tarballdir = $1;
|
---|
| 356 | } else {
|
---|
| 357 | $tarballdir = "$pkgdata{main}{name}-$pkgdata{main}{version}";
|
---|
| 358 | }
|
---|
| 359 | $prepscript .= "rm -rf $tarballdir\ntar -".
|
---|
[6] | 360 | ( $pkgdata{main}{source} =~ /\.tar\.gz$/ ? "z" : "" ).
|
---|
| 361 | ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "j" : "" ).
|
---|
| 362 | "x".( /\s+-q\s+/ ? '' : 'vv' )."f ".
|
---|
| 363 | "$topdir/SOURCES/$pkgdata{main}{source}\n".
|
---|
| 364 | qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n exit \$STATUS\nfi\n).
|
---|
| 365 | ( /\s+-n\s+([^\s]+)\s+/ ?
|
---|
| 366 | "cd $1\n" : "cd $pkgdata{main}{name}-$pkgdata{main}{version}\n" ).
|
---|
| 367 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
|
---|
| 368 | qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
|
---|
| 369 | qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
|
---|
[10] | 370 | } elsif (/^\%patch([^:]+)\s+(.+)$/) {
|
---|
| 371 | $prepscript .= "patch $2 <$topdir/SOURCES/".$pkgdata{main}{"patch$1"}."\n";
|
---|
[6] | 372 | } else {
|
---|
| 373 | last PREPSCRIPT if /^\%/;
|
---|
| 374 | $prepscript .= $_;
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
| 377 | redo LINE;
|
---|
| 378 | }
|
---|
[12] | 379 | if (/^\%build/) {
|
---|
[6] | 380 | # %build. This is pretty much just a shell script. There
|
---|
| 381 | # *are* a few macros, but we're not going to deal with them yet.
|
---|
[7] | 382 | $buildscript .= "cd $tarballdir\n";
|
---|
[10] | 383 | BUILDSCRIPT: while (<SPECFILE>) {
|
---|
| 384 | if (/^\%configure/) {
|
---|
[12] | 385 | $buildscript .= expandmacros($_,'cgbp');
|
---|
| 386 | } elsif (/^\%\{(__)?make\}/) {
|
---|
| 387 | $buildscript .= expandmacros($_,'mgbp');
|
---|
[10] | 388 | } else {
|
---|
| 389 | last BUILDSCRIPT if /^\%/;
|
---|
| 390 | $buildscript .= $_;
|
---|
| 391 | }
|
---|
[6] | 392 | }
|
---|
[10] | 393 | redo LINE;
|
---|
[5] | 394 | }
|
---|
[6] | 395 | if (/^\%install/) {
|
---|
[7] | 396 | $installscript .= "cd $tarballdir\n";
|
---|
[12] | 397 | INSTALLSCRIPT: while (<SPECFILE>) {
|
---|
| 398 | if (/^\%makeinstall/) {
|
---|
| 399 | $installscript .= expandmacros($_,'igbp');
|
---|
| 400 | } else {
|
---|
| 401 | last INSTALLSCRIPT if /^\%/;
|
---|
| 402 | $installscript .= $_;
|
---|
| 403 | }
|
---|
| 404 | }
|
---|
| 405 | redo LINE;
|
---|
[6] | 406 | }
|
---|
| 407 | if (/^\%clean/) {
|
---|
[7] | 408 | while (<SPECFILE>) {
|
---|
| 409 | redo LINE if /^\%/;
|
---|
| 410 | $cleanscript .= $_;
|
---|
| 411 | }
|
---|
[12] | 412 | $cleanscript = expandmacros($cleanscript,'gp');
|
---|
[6] | 413 | }
|
---|
[16] | 414 | # pre/post (un)install scripts
|
---|
| 415 | if (/^\%pre\b/) {
|
---|
| 416 | while (<SPECFILE>) {
|
---|
| 417 | redo LINE if /^\%/;
|
---|
| 418 | $preinstscript .= $_;
|
---|
| 419 | }
|
---|
[6] | 420 | }
|
---|
[16] | 421 | if (/^\%post\b/) {
|
---|
| 422 | while (<SPECFILE>) {
|
---|
| 423 | redo LINE if /^\%/;
|
---|
| 424 | $postinstscript .= $_;
|
---|
| 425 | }
|
---|
[6] | 426 | }
|
---|
[16] | 427 | if (/^\%preun\b/) {
|
---|
| 428 | while (<SPECFILE>) {
|
---|
| 429 | redo LINE if /^\%/;
|
---|
| 430 | $preuninstscript .= $_;
|
---|
| 431 | }
|
---|
| 432 | }
|
---|
| 433 | if (/^\%postun\b/) {
|
---|
| 434 | while (<SPECFILE>) {
|
---|
| 435 | redo LINE if /^\%/;
|
---|
| 436 | $postuninstscript .= $_;
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
[6] | 439 | if (/^\%files/) {
|
---|
| 440 | # Danger! Danger!
|
---|
| 441 | }
|
---|
[18] | 442 | if (/^\%changelog/) {
|
---|
| 443 | $pkgdata{main}{changelog} = '';
|
---|
| 444 | while (<SPECFILE>) {
|
---|
| 445 | redo LINE if /^\%/;
|
---|
| 446 | $pkgdata{main}{changelog} .= $_;
|
---|
| 447 | }
|
---|
| 448 | }
|
---|
[14] | 449 |
|
---|
| 450 | } else { # Data from the spec file "header"
|
---|
| 451 |
|
---|
[5] | 452 | if (/^summary:\s+(.+)/i) {
|
---|
| 453 | $pkgdata{main}{summary} = $1;
|
---|
| 454 | } elsif (/^name:\s+(.+)/i) {
|
---|
| 455 | $pkgdata{main}{name} = $1;
|
---|
| 456 | } elsif (/^version:\s+(.+)/i) {
|
---|
| 457 | $pkgdata{main}{version} = $1;
|
---|
| 458 | } elsif (/^release:\s+(.+)/i) {
|
---|
| 459 | $pkgdata{main}{release} = $1;
|
---|
| 460 | } elsif (/^group:\s+(.+)/i) {
|
---|
| 461 | $pkgdata{main}{group} = $1;
|
---|
| 462 | } elsif (/^copyright:\s+(.+)/i) {
|
---|
| 463 | $pkgdata{main}{copyright} = $1;
|
---|
| 464 | } elsif (/^url:\s+(.+)/i) {
|
---|
| 465 | $pkgdata{main}{url} = $1;
|
---|
| 466 | } elsif (/^packager:\s+(.+)/i) {
|
---|
| 467 | $pkgdata{main}{packager} = $1;
|
---|
[7] | 468 | } elsif (/^buildroot:\s+(.+)/i) {
|
---|
| 469 | $buildroot = $1;
|
---|
[5] | 470 | } elsif (/^source:\s+(.+)/i) {
|
---|
| 471 | $pkgdata{main}{source} = $1;
|
---|
[6] | 472 | die "Unknown tarball format $1\n" if $1 !~ /\.tar\.(?:gz|bz2)$/;
|
---|
[15] | 473 | } elsif (/^source([0-9]+):\s+(.+)/i) {
|
---|
| 474 | $pkgdata{sources}{$1} = $2;
|
---|
[10] | 475 | } elsif (/^patch([^:]+):\s+(.+)$/i) {
|
---|
| 476 | $pkgdata{main}{"patch$1"} = $2;
|
---|
[5] | 477 | }
|
---|
| 478 | #Name: suwrap
|
---|
| 479 | #Version: 0.04
|
---|
| 480 | #Release: 3
|
---|
| 481 | #Group: Applications/System
|
---|
| 482 | #Copyright: WebHart internal ONLY. :(
|
---|
| 483 | #BuildArchitectures: i386
|
---|
| 484 | #BuildRoot: /tmp/%{name}-%{version}
|
---|
| 485 | #Url: http://virtual.webhart.net
|
---|
| 486 | #Packager: Kris Deugau <kdeugau@deepnet.cx>
|
---|
| 487 | #Source: ftp://virtual.webhart.net/%{name}-%{version}.tar.gz
|
---|
| 488 |
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
[7] | 491 |
|
---|
[14] | 492 | # Parse and replace some more macros. More will be replaced even later.
|
---|
| 493 |
|
---|
[10] | 494 | # Expand macros as necessary.
|
---|
[12] | 495 | $scriptletbase = expandmacros($scriptletbase,'gp');
|
---|
[7] | 496 |
|
---|
| 497 | $buildroot = $cmdbuildroot if $cmdbuildroot;
|
---|
[12] | 498 | $buildroot = expandmacros($buildroot,'gp');
|
---|
[7] | 499 |
|
---|
[16] | 500 | close SPECFILE;
|
---|
[5] | 501 | } # end parse_spec()
|
---|
| 502 |
|
---|
| 503 |
|
---|
[7] | 504 | ## prep()
|
---|
[14] | 505 | # Writes and executes the %prep script (mostly) built while reading the spec file.
|
---|
[7] | 506 | sub prep {
|
---|
[10] | 507 | # Replace some things here just to make sure.
|
---|
[12] | 508 | $prepscript = expandmacros($prepscript,'gp');
|
---|
[10] | 509 |
|
---|
| 510 | # create script filename
|
---|
[13] | 511 | my $prepscriptfile = "$tmpdir/deb-tmp.prep.".int(rand(99998)+1);
|
---|
[10] | 512 | sysopen(PREPSCRIPT, $prepscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
[7] | 513 | or die $!;
|
---|
[10] | 514 | print PREPSCRIPT $scriptletbase;
|
---|
| 515 | print PREPSCRIPT $prepscript;
|
---|
| 516 | close PREPSCRIPT;
|
---|
[7] | 517 |
|
---|
[10] | 518 | # execute
|
---|
| 519 | print "Calling \%prep script $prepscriptfile...\n";
|
---|
| 520 | system("/bin/sh -e $prepscriptfile") == 0
|
---|
[14] | 521 | or die "Can't exec: $!\n";
|
---|
[7] | 522 |
|
---|
[10] | 523 | # and clean up
|
---|
| 524 | unlink $prepscriptfile;
|
---|
[7] | 525 | } # end prep()
|
---|
| 526 |
|
---|
| 527 |
|
---|
[5] | 528 | ## build()
|
---|
[14] | 529 | # Writes and executes the %build script (mostly) built while reading the spec file.
|
---|
[5] | 530 | sub build {
|
---|
[12] | 531 | # Expand the macros
|
---|
| 532 | $buildscript = expandmacros($buildscript,'cgbp');
|
---|
| 533 |
|
---|
[7] | 534 | # create script filename
|
---|
[13] | 535 | my $buildscriptfile = "$tmpdir/deb-tmp.build.".int(rand(99998)+1);
|
---|
[7] | 536 | sysopen(BUILDSCRIPT, $buildscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
| 537 | or die $!;
|
---|
| 538 | print BUILDSCRIPT $scriptletbase;
|
---|
| 539 | print BUILDSCRIPT $buildscript;
|
---|
| 540 | close BUILDSCRIPT;
|
---|
| 541 |
|
---|
| 542 | # execute
|
---|
| 543 | print "Calling \%build script $buildscriptfile...\n";
|
---|
| 544 | system("/bin/sh -e $buildscriptfile") == 0
|
---|
[14] | 545 | or die "Can't exec: $!\n";
|
---|
[7] | 546 |
|
---|
| 547 | # and clean up
|
---|
| 548 | unlink $buildscriptfile;
|
---|
[5] | 549 | } # end build()
|
---|
| 550 |
|
---|
| 551 |
|
---|
[7] | 552 | ## install()
|
---|
[14] | 553 | # Writes and executes the %install script (mostly) built while reading the spec file.
|
---|
[7] | 554 | sub install {
|
---|
[12] | 555 | # Expand the macros
|
---|
| 556 | $installscript = expandmacros($installscript,'igbp');
|
---|
| 557 |
|
---|
[7] | 558 | # create script filename
|
---|
[13] | 559 | my $installscriptfile = "$tmpdir/deb-tmp.inst.".int(rand(99998)+1);
|
---|
[7] | 560 | sysopen(INSTSCRIPT, $installscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
| 561 | or die $!;
|
---|
| 562 | print INSTSCRIPT $scriptletbase;
|
---|
| 563 | print INSTSCRIPT $cleanscript; # Clean up our install target before installing into it.
|
---|
| 564 | print INSTSCRIPT $installscript;
|
---|
| 565 | close INSTSCRIPT;
|
---|
| 566 |
|
---|
| 567 | # execute
|
---|
| 568 | print "Calling \%install script $installscriptfile...\n";
|
---|
| 569 | system("/bin/sh -e $installscriptfile") == 0
|
---|
[14] | 570 | or die "Can't exec: $!\n";
|
---|
[7] | 571 |
|
---|
| 572 | # and clean up
|
---|
| 573 | unlink $installscriptfile;
|
---|
| 574 | } # end install()
|
---|
| 575 |
|
---|
| 576 |
|
---|
[8] | 577 | ## binpackage()
|
---|
| 578 | # Creates the binary .deb package from the installed tree in $buildroot.
|
---|
[14] | 579 | # Writes and executes a shell script to do so.
|
---|
| 580 | # Creates miscellaneous files required by dpkg-deb to actually build the package file.
|
---|
[8] | 581 | sub binpackage {
|
---|
[14] | 582 | # Make sure we have somewhere to write the .deb file
|
---|
[9] | 583 | if (!-e "$topdir/DEBS/i386") {
|
---|
| 584 | # "if [ -e $topdir/DEBS/i386 ]; then\n\tmkdir $topdir/DEBS/i386\nfi\n".
|
---|
| 585 | mkdir "$topdir/DEBS/i386";
|
---|
| 586 | }
|
---|
[14] | 587 |
|
---|
[8] | 588 | # Gotta do this first, otherwise the control file has nowhere to go. >:(
|
---|
| 589 | mkdir "$buildroot/DEBIAN";
|
---|
| 590 |
|
---|
| 591 | # create script filename
|
---|
[13] | 592 | my $debscriptfile = "$tmpdir/deb-tmp.pkg.".int(rand(99998)+1);
|
---|
[8] | 593 | sysopen(DEBSCRIPT, $debscriptfile, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW)
|
---|
| 594 | or die $!;
|
---|
| 595 | print DEBSCRIPT $scriptletbase;
|
---|
[16] | 596 | print DEBSCRIPT "fakeroot dpkg-deb -b $buildroot $topdir/DEBS/i386/".
|
---|
| 597 | "$pkgdata{main}{name}_$pkgdata{main}{version}-$pkgdata{main}{release}_i386.deb\n";
|
---|
[14] | 598 | # %$&$%@#@@#%@@@ Debian and their horrible ugly package names. >:(
|
---|
[8] | 599 | close DEBSCRIPT;
|
---|
| 600 |
|
---|
| 601 | my $control = "Package: $pkgdata{main}{name}\n".
|
---|
| 602 | "Version: $pkgdata{main}{version}-$pkgdata{main}{release}\n".
|
---|
| 603 | "Section: unknown\n".
|
---|
| 604 | "Priority: optional\n".
|
---|
| 605 | "Architecture: i386\n".
|
---|
| 606 | "Maintainer: $pkgdata{main}{packager}\n".
|
---|
| 607 | "Description: $pkgdata{main}{desc}\n";
|
---|
| 608 |
|
---|
| 609 | open CONTROL, ">$buildroot/DEBIAN/control";
|
---|
| 610 | print CONTROL $control;
|
---|
| 611 | close CONTROL;
|
---|
| 612 |
|
---|
[16] | 613 | if ($preinstscript ne '') {
|
---|
| 614 | open PREINST, ">$buildroot/DEBIAN/preinst";
|
---|
| 615 | print PREINST "#!/bin/sh\nset -e\n\n";
|
---|
| 616 | print PREINST $preinstscript;
|
---|
| 617 | close PREINST;
|
---|
| 618 | `chmod 0755 $buildroot/DEBIAN/preinst`;
|
---|
| 619 | }
|
---|
| 620 | if ($postinstscript ne '') {
|
---|
| 621 | open POSTINST, ">$buildroot/DEBIAN/postinst";
|
---|
| 622 | print POSTINST "#!/bin/sh\nset -e\n\n";
|
---|
| 623 | print POSTINST $postinstscript;
|
---|
| 624 | close POSTINST;
|
---|
| 625 | `chmod 0755 $buildroot/DEBIAN/postinst`;
|
---|
| 626 | }
|
---|
| 627 | if ($preuninstscript ne '') {
|
---|
| 628 | open PREUNINST, ">$buildroot/DEBIAN/prerm";
|
---|
| 629 | print PREUNINST "#!/bin/sh\nset -e\n\n";
|
---|
| 630 | print PREUNINST $preuninstscript;
|
---|
| 631 | close PREUNINST;
|
---|
| 632 | `chmod 0755 $buildroot/DEBIAN/prerm`;
|
---|
| 633 | }
|
---|
| 634 | if ($postuninstscript ne '') {
|
---|
| 635 | open POSTUNINST, ">$buildroot/DEBIAN/postrm";
|
---|
| 636 | print POSTUNINST "#!/bin/sh\nset -e\n\n";
|
---|
| 637 | print POSTUNINST $postuninstscript;
|
---|
| 638 | close POSTUNINST;
|
---|
| 639 | `chmod 0755 $buildroot/DEBIAN/postrm`;
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 | print `ls -l $buildroot/DEBIAN`;
|
---|
| 643 |
|
---|
[8] | 644 | #Package: httpd
|
---|
| 645 | #Version: 2.0.54-7via
|
---|
| 646 | #Section: unknown
|
---|
| 647 | #Priority: optional
|
---|
| 648 | #Architecture: i386
|
---|
| 649 | #Depends: libc6 (>= 2.3.2.ds1-21), libdb4.2, libexpat1 (>= 1.95.8), libssl0.9.7, libapr0
|
---|
| 650 | #Replaces: apache2
|
---|
| 651 | #Installed-Size: 3076
|
---|
| 652 | #Maintainer: Kris Deugau <kdeugau@vianet.ca>
|
---|
| 653 | #Description: apache2 for ViaNet
|
---|
| 654 | # apache2 for ViaNet. Includes per-vhost setuid patches from
|
---|
| 655 | # http://home.samfundet.no/~sesse/mpm-itk/.
|
---|
| 656 |
|
---|
| 657 | # execute
|
---|
[16] | 658 | print "Calling package creation script $debscriptfile for $pkgdata{main}{name}...\n";
|
---|
[8] | 659 | system("/bin/sh -e $debscriptfile") == 0
|
---|
[14] | 660 | or die "Can't exec: $!\n";
|
---|
[8] | 661 |
|
---|
| 662 | # and clean up
|
---|
| 663 | unlink $debscriptfile;
|
---|
| 664 | } # end binpackage()
|
---|
| 665 |
|
---|
| 666 |
|
---|
[4] | 667 | sub srcpackage {}
|
---|
[10] | 668 |
|
---|
| 669 |
|
---|
| 670 | ## expandmacros()
|
---|
| 671 | # Expands all %{blah} macros in the passed string
|
---|
[14] | 672 | # Split up a bit with some sections so we don't spend time trying to
|
---|
| 673 | # expand macros that are only used in a few specific places.
|
---|
[10] | 674 | sub expandmacros {
|
---|
| 675 | my $macrostring = shift;
|
---|
[14] | 676 | my $section = shift;
|
---|
[10] | 677 |
|
---|
[12] | 678 | # To allow the FHS-ish %configure, %make, and %makeinstall to work The Right Way.
|
---|
| 679 | # (Without clobbering the global $buildroot.)
|
---|
| 680 | my $prefix = '';
|
---|
| 681 |
|
---|
[17] | 682 | # %configure, %make, and %makeinstall all share quite a pile - almost. GRR.
|
---|
| 683 | # I call it the FHS block, so it gets pushed forward as %{fhs}. Note that
|
---|
| 684 | # %configure doesn't use this because of the -- bits.
|
---|
[11] | 685 | if ($section =~ /c/) {
|
---|
[12] | 686 | # %configure macro
|
---|
[17] | 687 | # Don't know what it's for, don't have a useful default replacement
|
---|
| 688 | # --program-prefix=%{_program_prefix} \
|
---|
| 689 | $macrostring =~ s'%configure'./configure --host=$DEB_HOST_GNU_TYPE \
|
---|
| 690 | --build=$DEB_BUILD_GNU_TYPE \
|
---|
| 691 | --prefix=%{_prefix} \
|
---|
| 692 | --exec-prefix=%{_exec_prefix} \
|
---|
| 693 | --bindir=%{_bindir} \
|
---|
| 694 | --sbindir=%{_sbindir} \
|
---|
| 695 | --sysconfdir=%{_sysconfdir} \
|
---|
| 696 | --datadir=%{_datadir} \
|
---|
| 697 | --includedir=%{_includedir} \
|
---|
| 698 | --libdir=%{_libdir} \
|
---|
| 699 | --libexecdir=%{_libexecdir} \
|
---|
| 700 | --localstatedir=%{_localstatedir} \
|
---|
| 701 | --sharedstatedir=%{_sharedstatedir} \
|
---|
| 702 | --mandir=%{_mandir} \
|
---|
| 703 | --infodir=%{_infodir} ';
|
---|
[12] | 704 | } # done %configure
|
---|
| 705 |
|
---|
| 706 | if ($section =~ /m/) {
|
---|
| 707 | $macrostring =~ s'%make'make %{fhs}';
|
---|
| 708 | $macrostring =~ s'%{__make}'make ';
|
---|
| 709 | } # done %make
|
---|
| 710 |
|
---|
| 711 | if ($section =~ /i/) {
|
---|
| 712 | # This is where we need to mangle $prefix.
|
---|
| 713 | $macrostring =~ s'%makeinstall'make %{fhs}
|
---|
| 714 | install';
|
---|
| 715 | $prefix = $buildroot;
|
---|
| 716 | } # done %install and/or %makeinstall
|
---|
| 717 |
|
---|
| 718 | # Build data
|
---|
| 719 | # Note that these are processed in reverse order to get the substitution order right
|
---|
| 720 | if ($section =~ /b/) {
|
---|
[17] | 721 | $macrostring =~ s'%{fhs}'host=$DEB_HOST_GNU_TYPE \
|
---|
| 722 | build=$DEB_BUILD_GNU_TYPE \
|
---|
| 723 | prefix=%{_prefix} \
|
---|
| 724 | exec-prefix=%{_exec_prefix} \
|
---|
| 725 | bindir=%{_bindir} \
|
---|
| 726 | sbindir=%{_sbindir} \
|
---|
| 727 | sysconfdir=%{_sysconfdir} \
|
---|
| 728 | datadir=%{_datadir} \
|
---|
| 729 | includedir=%{_includedir} \
|
---|
| 730 | libdir=%{_libdir} \
|
---|
| 731 | libexecdir=%{_libexecdir} \
|
---|
| 732 | localstatedir=%{_localstatedir} \
|
---|
| 733 | sharedstatedir=%{_sharedstatedir} \
|
---|
| 734 | mandir=%{_mandir} \
|
---|
| 735 | infodir=%{_infodir} \
|
---|
| 736 | ';
|
---|
[10] | 737 |
|
---|
| 738 | # Note that the above regex terminates with the extra space
|
---|
[12] | 739 | # "Just In Case" of user additions, which will then get neatly
|
---|
| 740 | # tagged on the end where they take precedence (supposedly)
|
---|
| 741 | # over the "default" ones.
|
---|
[10] | 742 |
|
---|
[14] | 743 | # Now we cascade the macros introduced above. >_<
|
---|
| 744 | # Wot ot to go theah:
|
---|
| 745 | $macrostring =~ s|%{_mandir}|%{_datadir}/man|g; #/usr/share/man
|
---|
| 746 | $macrostring =~ s|%{_infodir}|%{_datadir}/info|g; #/usr/share/info
|
---|
| 747 | $macrostring =~ s|%{_oldincludedir}|$prefix/usr/include|g; #/usr/include
|
---|
[12] | 748 | $macrostring =~ s|%{_includedir}|$prefix%{_prefix\}/include|g; #/usr/include
|
---|
| 749 | $macrostring =~ s|%{_libdir}|$prefix%{_exec_prefix}/%{_lib}|g; #/usr/lib
|
---|
[14] | 750 | $macrostring =~ s|%{_lib}|lib|g; #?
|
---|
[12] | 751 | $macrostring =~ s|%{_localstatedir}|$prefix/var|g; #/var
|
---|
| 752 | $macrostring =~ s|%{_sharedstatedir}|$prefix%{_prefix}/com|g; #/usr/com WTF?
|
---|
[14] | 753 | $macrostring =~ s|%{_sysconfdir}|$prefix/etc|g; #/etc
|
---|
[12] | 754 | $macrostring =~ s|%{_datadir}|$prefix%{_prefix}/share|g; #/usr/share
|
---|
| 755 | $macrostring =~ s|%{_libexecdir}|$prefix%{_exec_prefix}/libexec|g; #/usr/libexec
|
---|
[14] | 756 | $macrostring =~ s|%{_sbindir}|$prefix%{_exec_prefix}/sbin|g; #/usr/sbin
|
---|
[12] | 757 | $macrostring =~ s|%{_bindir}|$prefix%{_exec_prefix}/bin|g; #/usr/bin
|
---|
| 758 | $macrostring =~ s|%{_exec_prefix}|$prefix%{_prefix}|g; #/usr
|
---|
[14] | 759 | $macrostring =~ s|%{_prefix}|/usr|g; #/usr
|
---|
[10] | 760 | } # done with config section
|
---|
| 761 |
|
---|
[12] | 762 | # Package data
|
---|
| 763 | if ($section =~ /p/) {
|
---|
[15] | 764 | $macrostring =~ s/\%\{buildroot\}/$buildroot/gi;
|
---|
| 765 | foreach my $source (keys %{$pkgdata{sources}}) {
|
---|
| 766 | $macrostring =~ s/\%\{source$source\}/$topdir\/SOURCES\/$pkgdata{sources}{$source}/gi;
|
---|
| 767 | }
|
---|
| 768 | $macrostring =~ s/\%\{name\}/$pkgdata{main}{name}/gi;
|
---|
| 769 | $macrostring =~ s/\%\{version\}/$pkgdata{main}{version}/gi;
|
---|
| 770 | $macrostring =~ s/\%\{release\}/$pkgdata{main}{release}/gi;
|
---|
[12] | 771 | }
|
---|
| 772 |
|
---|
| 773 | # Globals, and not-so-globals
|
---|
| 774 | if ($section =~ /g/) {
|
---|
| 775 | $macrostring =~ s/\%\{_topdir\}/$topdir/g;
|
---|
[13] | 776 | $macrostring =~ s|%{_tmppath}|$tmpdir|g;
|
---|
[12] | 777 | $macrostring =~ s'%{_docdir}'/usr/share/doc'g;
|
---|
[10] | 778 | } # done with globals section
|
---|
| 779 |
|
---|
| 780 | return $macrostring;
|
---|
| 781 | } # end expandmacros()
|
---|