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