#!/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). # # The dependencies this package declares are those that can be satisfied by # Debian 8 (Jessie) and Debian 9 (Stretch). Netpbm works fine on other # versions of Debian, but you may have to change the dependencies in this # program or ignore dependencies at install time. ############################################################################### 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) = @_; # The Debian packaging system doesn't provide a way to express Netpbm's actual # prerequisites. For example, Netpbm needs Version 6.2 or better of Libjpeg, # but there is no way to state that here. Instead, we state Libjpeg 6.2 # exactly. This makes the Netpbm package less useful. 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 | libpng16-16, ' . 'libtiff5, ' . 'libx11-6, ' . 'libxml2, ' . 'zlib1g, ' . 'ghostscript, ' . 'perl, ' . 'perl-base, ' . 'bash' ; $control{'Recommends'} = ''; $control{'Recommends'} = ''; $control{'Conflicts'} = $debianNativeNetpbm; $control{'Replaces'} = $debianNativeNetpbm; $control{'Provides'} = 'netpbm, ' . 'pbmwbmp, ' . 'pnmtopng, ' . 'netpbm-dev, ' . 'libnetpbm10' ; $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 =