#!/usr/bin/perl ############################################################################### # mkdeb ############################################################################### # # This generates a Debian package 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); $retval = $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 contents for the package control file, as a hash reference. In the # referenced hash, there is one key for each line of the control file. The # key and value in the hash are the key and value for the line of the control # file. #----------------------------------------------------------------------------- # Because developers of some of the dependent libraries frequently switch # to distributing versions not backward compatible with what they # previously distributed, and Debian always packages the currently # distributed version, it is virtually impossible to produce a Netpbm # package that works in multiple Debian versions. This program is coded # to create a package that works on the Debian system the Netpbm # maintainer currently uses to build the Debian packages he distributes. # If you are building for any other version of Debian, you'll have to # modify this code. # Note that the backward incompatibility is usually only at a binary # level, not source level. And sometimes the only incompatibility for # Netpbm purposes is that the soname has changed so that Linux will refuse # to run a Netpbm program built for Debian N on Debian N-1. # The following is for Debian 9. 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, ' . 'libpng16-16, ' . 'libtiff5, ' . 'libx11-6, ' . 'libxml2, ' . 'zlib1g, ' . 'ghostscript, ' . 'perl, ' . 'perl-base, ' . 'bash' ; # Note: Instead of libjpeg62, Debian 10 has libjpeg62-turbo and Ubuntu 18 # has libjpeg-turbo8. $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 =