From a3cef81be46dbc0bdcaa6634ab9ff6f9bdea796f Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 5 Jan 2014 18:17:48 +0000 Subject: Add tools for creating Debian packages git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2103 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- buildtools/debian/README | 36 ++++ buildtools/debian/mkdeb | 527 +++++++++++++++++++++++++++++++++++++++++++++ buildtools/debian/postinst | 5 + buildtools/debian/postrm | 5 + 4 files changed, 573 insertions(+) create mode 100644 buildtools/debian/README create mode 100755 buildtools/debian/mkdeb create mode 100755 buildtools/debian/postinst create mode 100755 buildtools/debian/postrm (limited to 'buildtools') diff --git a/buildtools/debian/README b/buildtools/debian/README new file mode 100644 index 00000000..18ba488f --- /dev/null +++ b/buildtools/debian/README @@ -0,0 +1,36 @@ +Files in this directory are for creating a Debian package (.deb file), +which one can use to install Netpbm on a Debian system (or a system running +a derivative of Debian, such as Ubuntu or Mint). + +You can of course install on one of these systems by running 'installnetpbm', +or otherwise inserting all the files in the proper place in your system file +tree, but having a Debian package allows you to manage those files using +Debian's normal package management. The package management system will know +where the Netpbm files came from, and you can upgrade or remove Netpbm easily. +The package management system will also be aware of prerequisites of Netpbm +and ensure that you don't have Debian's own inferior version of Netpbm +installed (which would cause conflicts). + +The package we create is named 'netpbm-sf' (where the "sf" is from +"SourceForge"), to be distinct from the package named "netpbm" which is part +of Debian. + +To install Netpbm as a Debian package: + + 1) Follow the regular instructions to build and package Netpbm + (configure, make, make package). + + 2) $ BUILDTOOLS=netpbm-src/buildtools + + (netpbm-src is a Netpbm source tree). + + 3) $ $BUILDTOOLS/debian/mkdeb -buildtools=$BUILDTOOLS + + (This defaults to getting Netpbm from /tmp/netpbm, which is also where + 'make package' defaults to putting it). + + 4) $ dpkg --install netpbm-sfXXXX.deb + + (netpbm-sfXXXX.deb is the file created by 'makedeb', in the current + directory). + diff --git a/buildtools/debian/mkdeb b/buildtools/debian/mkdeb new file mode 100755 index 00000000..fbe5d99a --- /dev/null +++ b/buildtools/debian/mkdeb @@ -0,0 +1,527 @@ +#!/usr/bin/perl +############################################################################### +# mkdeb +############################################################################### +# +# This generates a Debian packge file (.deb) to install Sourceforge +# Netpbm on a Debian system. +# +# This is especially useful because Debian does not have a good Debian +# package (what Debian contains is derived from Sourceforge Netpbm ca. +# 2002). +# +############################################################################### + +use strict; +use warnings; +use English; +use Getopt::Long; + +my $TRUE=1; my $FALSE = 0; + + + +sub parseCommandLine(@) { + + local @ARGV = @_; # GetOptions takes input from @ARGV only + + my %cmdline; + + my $validOptions = GetOptions(\%cmdline, + "buildtools=s", + "arch=s", + "pkgdir=s", + ); + + if (!$validOptions) { + print(STDERR "Invalid option syntax.\n"); + exit(1); + } + if (@ARGV > 0) { + print(STDERR "This program takes no non-option arguments. " . + "You specified ", + scalar(@ARGV), "\n"); + exit(1); + } + + return(\%cmdline); +} + + + +sub writeFile($$$$) { + my ($fileLinesR, $fileName, $executable, $errorR) = @_; + + my $success = open(FILE, ">$fileName"); + if ($success) { + if ($executable eq 'EXECUTABLE') { + chmod(0755, $fileName); + } else { + chmod(0644, $fileName); + } + foreach (@{$fileLinesR}) { print FILE; } + close(FILE); + } else { + $$errorR = "Unable to open the file " . + "'$fileName' for writing. Errno=$ERRNO\n"; + } +} + + + +sub netpbmVersion($) { + my ($pkgdir) = @_; + + my $versionFileName = "$pkgdir/VERSION"; + + my $versionOpened = open(VERSION, "<$versionFileName"); + + my $retval; + my $error; + + if (!$versionOpened) { + $error = "Unable to open '$versionFileName' for reading. " . + "Errno=$ERRNO\n"; + } else { + my $version = ; + chomp($version); + + if ($version =~ m{^Netpbm (\S*)}) { + my ($versionNumber) = ($1); + $retval = $versionNumber; + } else { + die("Can't understand format of '$versionFileName': '$version'"); + } + close(VERSION); + } + + if ($error) { + print("Failed to determine the version of Netpbm from the package, " + . "so that will not be correct in netpbm.config and netpbm.pc. " + . $error . "\n"); + $retval = "???"; + } + return $retval; +} + + + +sub control($$) { + my ($release, $architecture) = @_; + + my %control; + + my $debianNativeNetpbm = + 'netpbm, ' . + 'libnetpbm10, ' . + 'libnetpbm10-dev, ' . + 'netpbm-dev, ' . + 'netpbm-nonfree, ' . + 'pbmwbmp, ' . + 'pnmtopng, ' . + 'ucbmpeg'; + + $control{'Package'} = 'netpbm-sf'; + $control{'Version'} = $release; + $control{'Architecture'} = $architecture; + $control{'Maintainer'} = 'Bryan Henderson '; + $control{'Installed-Size'} = '6164'; + $control{'Depends'} = + 'libc6, ' . + 'libjpeg62, ' . + 'libpng12-0, ' . + 'libtiff4, ' . + 'zlib1g, ' . + 'ghostscript, ' . + 'perl, ' . + 'perl-base, ' . + 'bash' + ; + $control{'Recommends'} = ''; + $control{'Recommends'} = ''; + $control{'Conflicts'} = $debianNativeNetpbm; + $control{'Replaces'} = $debianNativeNetpbm; + $control{'Provides'} = 'netpbm, pbmwbmp, pnmtopng'; + $control{'Section'} = 'graphics'; + $control{'Priority'} = 'optional'; + $control{'Section'} = 'graphics'; + $control{'Description'} = 'Graphics conversion tools between image formats + Netpbm is a toolkit for manipulation of graphic images, including + conversion of images between a variety of different formats. There + are over 300 separate tools in the package including converters for + more than 80 graphics formats. This is the Super Stable version from + the Sourceforge Netpbm project, unmodified.'; + + return \%control; +} + + + +sub writeControlFile($$) { + my ($controlR, $fileName) = @_; + + open(CTL, '>', $fileName) + or die "Can't open '$fileName': $ERRNO"; + + while (my ($key, $value) = each %{$controlR}) { + print CTL ("$key: $value\n"); + } + + close(CTL); +} + + + +sub createScripts($$) { + my ($dpkgDirName, $buildToolsDir) = @_; + + my @scriptList = ('postinst', 'postrm'); + + my @scriptFileList = map("$buildToolsDir/debian/$_", @scriptList); + + system('cp', @scriptFileList, "$dpkgDirName/DEBIAN/") && + die("Failed to copy postinst, etc. to '$dpkgDirName/DEBIAN'."); + + my @createdFileList = map("$dpkgDirName/DEBIAN/$_", @scriptList); + + chmod(0755, @createdFileList); +} + + + +sub createDirOrDie($) { + my ($newDirName) = @_; + + mkdir($newDirName) + or die("Couldn't create directory '$newDirName'. $ERRNO"); + + chmod(0755, $newDirName); +} + + + +sub +processTemplate($$$) { + my ($templateR, $infoR, $outputR) = @_; + + my @output; + + foreach (@{$templateR}) { + if (m{^@}) { + # Comment -- ignore it. + } else { + if (defined($infoR->{VERSION})) { + s/\@VERSION\@/$infoR->{VERSION}/; + } + if (defined($infoR->{BINDIR})) { + s/\@BINDIR@/$infoR->{BINDIR}/; + } + if (defined($infoR->{LIBDIR})) { + s/\@LIBDIR@/$infoR-.{LIBDIR}/; + } + if (defined($infoR->{LINKDIR})) { + s/\@LINKDIR@/$infoR->{LINKDIR}/; + } + if (defined($infoR->{DATADIR})) { + s/\@DATADIR@/$infoR->{DATADIR}/; + } + if (defined($infoR->{INCLUDEDIR})) { + s/\@INCLUDEDIR@/$infoR->{INCLUDEDIR}/; + } + if (defined($infoR->{MANDIR})) { + s/\@MANDIR@/$infoR->{MANDIR}/; + } + push(@output, $_); + } + } + $$outputR = \@output; +} + + + + + +sub makeConfig($$$) { + my ($fileName, $templateSubsR, $netpbmPkgDir) = @_; +#----------------------------------------------------------------------------- +# Install 'netpbm-config' -- a program you run to tell you things about +# how Netpbm is installed. +#----------------------------------------------------------------------------- + my $error; + + my $configTemplateFilename = $netpbmPkgDir . "/config_template"; + + my $templateOpened = open(TEMPLATE, "<$configTemplateFilename"); + if (!$templateOpened) { + $error = "Can't open template file '$configTemplateFilename'.\n"; + } else { + my @template =