#!/usr/bin/perl # # em_make -- Prepare an Emdebian package from Debian source. # # Copies upstream debian/* files into a $package.old directory # makes changes for emdebian and then creates relevant patches. # # Copyright (C) 2006,2007,2009 Neil Williams # Copyright (C) 1998-2006 Craig Small # # This package is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # use Cwd; use File::HomeDir; use Debian::Debhelper::Dh_Lib; use Parse::DebControl; use Debian::DpkgCross; use Cache::Apt::Config; use Emdebian::Tools; use Term::ANSIColor qw(:constants); use strict; use warnings; use vars qw/ @packages $username $email $date $native $emdebvers $emN $progname $ourversion $verbose $source $home $arch $forceold %binaries %xbinaries %source %xsource $parser $data $xdata $msg $options $vendor $vname $vcross /; $ourversion = &tools_version(); $verbose = 1; &read_config(); $arch = &get_architecture(); $forceold = 0; $progname = basename($0); sub usageversion { print(STDERR <= 1); &check_toolchains($arch, $target_gnu_type) unless ($omitarchcheck == 0); # for non-standard toolchains. if (($forceold == 1) && ($check eq "false")) { my $fmsg = "Old or missing toolchain detected but '--forceold' used.\n"; $fmsg .= "This setup is not supported by emdebian-tools, some scripts\n"; $fmsg .= "(including this one) may not function correctly.\n"; $fmsg .= "Packages built with this setup should not be uploaded to\n"; $fmsg .= "Emdebian repositories.\n"; print GREEN, $fmsg, RESET; $check = "true"; } my $msg = qq/Unable to locate the cross-building toolchain, please run emsetup.\n/; die (RED, $msg, RESET) if ($check eq "false"); &check_emdebian_control; &init; @packages = &getpackages(); my $parse = `parsechangelog`; $parse =~ /Source: (.*)\n/; $source = $1; $native = isnative($dh{MAINPACKAGE}); $source = $dh{MAINPACKAGE} if (!$source); # create a changelog entry my $log = `dpkg-parsechangelog`; $log =~ /(Version: .*)\n/; die RED, "\n$0 : $source has already been emdebianised.\n", RESET if (&extract_emdebversion($1) ne ""); print GREEN, "Preparing source for patching.\n", RESET if ($verbose >= 2); &prepare_pristine($source); # get the dpkg-vendor value and put into the changelog. $vendor = $ENV{"DEB_VENDOR"} if (defined $ENV{"DEB_VENDOR"} and (not defined $vendor)); $vendor = "emdebian-crush" if (not defined $vendor); $vname = `dpkg-vendor --vendor $vendor --query vendor-name`; chomp ($vname); $vcross = `dpkg-vendor --vendor $vendor --query Cross-Compiling`; chomp ($vcross); my $crossbuilt = ($vcross eq lc("yes")) ? " Cross-build." : ""; my $vers = &emdeb_versionstring("new"); print GREEN, "Setting emdebian version: $vers for '$vname'.\n", RESET if ($verbose >= 1); system "dch -p -v $vers \"New release for ${vname}.${crossbuilt}\""; # if emxcontrol is installed and debian/xcontrol exists, update it: system ("emxcontrol") if (-x "/usr/bin/emxcontrol" and -f "debian/xcontrol"); # create or update patches for all @patchfiles print GREEN, "Creating initial patches for '$source'.\n", RESET if ($verbose >= 2); &create_patches($source); # Read xcontrol data here. # also use dch to append to changelog describing actions taken. $parser = new Parse::DebControl; die ("ERROR: no debian control file found.\n") if (not -f "./debian/control"); my $control_data = "./debian/control"; $data = $parser->parse_file($control_data, $options); if (-f "./debian/xcontrol") { my $xcontrol_data = "./debian/xcontrol"; $xdata = $parser->parse_file($xcontrol_data, $options); } # collate the data into source and binary package stanzas %source=(); %binaries=(); %xsource=(); %xbinaries=(); foreach my $stanza (@$data) { if (exists $$stanza{'Source'}) { %source = %$stanza; } elsif (exists $$stanza{'Package'}) { $binaries{$$stanza{'Package'}} = \%$stanza; } else { die ("malformed control file!\n"); } } foreach my $stanza (@$xdata) { if (exists $$stanza{'Source'}) { %xsource = %$stanza; } elsif (exists $$stanza{'Package'}) { $xbinaries{$$stanza{'Package'}} = \%$stanza; } else { die ("malformed or outdated xcontrol file!\n"); } } # TODO: migrate this check into Emdebian::Tools to call from emdebuild. if (exists $xsource{'Cross-Compiling'}) { die RED, "Unsupported source package", RESET, "\n" if ($xsource{'Cross-Compiling'} eq 'no'); } foreach my $pkg (keys %xbinaries) { system ("dch -a xcontrol: adding '$pkg' binary package.\n") if (not exists $binaries{$pkg}); } # TODO: this actually needs to be based on Blacklist and Whitelist. foreach my $pkg (keys %binaries) { system ("dch -a xcontrol: omitting binary package '$pkg'.\n") if (defined $xbinaries{$pkg}{'Optional'} and $xbinaries{$pkg}{'Optional'} eq 'yes'); system ("dch -a xcontrol: omitting blacklisted binary package '$pkg'.\n") if (defined $xbinaries{$pkg}{'Cross-Compiling'} and $xbinaries{$pkg}{'Cross-Compiling'} eq 'no'); } # end exit 0;