From a4caa9e05bc2b7e4ea034026cf0b2cda3461d4b2 Mon Sep 17 00:00:00 2001 From: joey Date: Tue, 17 Aug 1999 04:56:23 +0000 Subject: [PATCH] r103: Initial revision --- Dh_Getopt.pm | 148 +++++++++++++++++++++ Dh_Lib.pm | 248 +++++++++++++++++++++++++++++++++++ autoscripts/postinst-emacsen | 1 + autoscripts/prerm-emacsen | 1 + debhelper.1 | 104 +++++++++++++++ debian/cron.d | 0 debian/cron.daily | 0 debian/docs | 1 + debian/menu | 0 dh_installemacsen | 34 +++++ dh_installemacsen.1 | 42 ++++++ dh_testversion | 24 ++++ 12 files changed, 603 insertions(+) create mode 100644 Dh_Getopt.pm create mode 100644 Dh_Lib.pm create mode 100644 autoscripts/postinst-emacsen create mode 100644 autoscripts/prerm-emacsen create mode 100644 debhelper.1 create mode 100644 debian/cron.d create mode 100644 debian/cron.daily create mode 100644 debian/docs create mode 100644 debian/menu create mode 100755 dh_installemacsen create mode 100644 dh_installemacsen.1 create mode 100755 dh_testversion diff --git a/Dh_Getopt.pm b/Dh_Getopt.pm new file mode 100644 index 0000000..eb6aef9 --- /dev/null +++ b/Dh_Getopt.pm @@ -0,0 +1,148 @@ +#!/usr/bin/perl -w +# +# Debhelper option processing library. +# +# Joey Hess GPL copyright 1998. + +package Dh_Getopt; +use strict; + +use Exporter; +my @ISA=qw(Exporter); +my @EXPORT=qw(&parseopts); + +use Dh_Lib; +use Getopt::Long; + +my (%options, %exclude_package); + +# Passed an option name and an option value, adds packages to the list +# of packages. We need this so the list will be built up in the right +# order. +sub AddPackage { my($option,$value)=@_; + if ($option eq 'i' or $option eq 'indep') { + push @{$options{DOPACKAGES}}, GetPackages('indep'); + $options{DOINDEP}=1; + } + elsif ($option eq 'a' or $option eq 'arch') { + push @{$options{DOPACKAGES}}, GetPackages('arch'); + $options{DOARCH}=1; + } + elsif ($option eq 'p' or $option eq 'package') { + push @{$options{DOPACKAGES}}, $value; + } + else { + error("bad option $option - should never happen!\n"); + } +} + +# Add a package to a list of packages that should not be acted on. +sub ExcludePackage { my($option,$value)=@_; + $exclude_package{$value}=1; +} + +# Add another item to the exclude list. +sub AddExclude { my($option,$value)=@_; + push @{$options{EXCLUDE}},$value; +} + +sub import { + # Enable bundling of short command line options. + Getopt::Long::config("bundling"); +} + +# Parse options and return a hash of the values. +sub parseopts { + undef %options; + + my $ret=GetOptions( + "v" => \$options{VERBOSE}, + "verbose" => \$options{VERBOSE}, + + "i" => \&AddPackage, + "indep" => \&AddPackage, + + "a" => \&AddPackage, + "arch" => \&AddPackage, + + "p=s" => \&AddPackage, + "package=s" => \&AddPackage, + + "N=s" => \&ExcludePackage, + "no-package=s" => \&ExcludePackage, + + "n" => \$options{NOSCRIPTS}, +# "noscripts" => \$options(NOSCRIPTS}, + + "x" => \$options{INCLUDE_CONFFILES}, # is -x for some unknown historical reason.. + "include-conffiles" => \$options{INCLUDE_CONFFILES}, + + "X=s" => \&AddExclude, + "exclude=s" => \&AddExclude, + + "d" => \$options{D_FLAG}, + "remove-d" => \$options{D_FLAG}, + + "r" => \$options{R_FLAG}, + "no-restart-on-upgrade" => \$options{R_FLAG}, + + "k" => \$options{K_FLAG}, + "keep" => \$options{K_FLAG}, + + "P=s" => \$options{TMPDIR}, + "tmpdir=s" => \$options{TMPDIR}, + + "u=s", => \$options{U_PARAMS}, + "update-rcd-params=s", => \$options{U_PARAMS}, + "dpkg-shlibdeps-params=s", => \$options{U_PARAMS}, + + "m=s", => \$options{M_PARAMS}, + "major=s" => \$options{M_PARAMS}, + + "V:s", => \$options{V_FLAG}, + "version-info:s" => \$options{V_FLAG}, + + "A" => \$options{PARAMS_ALL}, + "all" => \$options{PARAMS_ALL}, + + "no-act" => \$options{NO_ACT}, + + "init-script=s" => \$options{INIT_SCRIPT}, + ); + + if (!$ret) { + error("unknown option; aborting"); + } + + # Check to see if -V was specified. If so, but no parameters were + # passed, the variable will be defined but empty. + if (defined($options{V_FLAG})) { + $options{V_FLAG_SET}=1; + } + + # Check to see if DH_VERBOSE environment variable was set, if so, + # make sure verbose is on. + if ($ENV{DH_VERBOSE} ne undef) { + $options{VERBOSE}=1; + } + + # Check to see if DH_NO_ACT environment variable was set, if so, + # make sure no act mode is on. + if ($ENV{DH_NO_ACT} ne undef) { + $options{NO_ACT}=1; + } + + # Remove excluded packages from the list of packages to act on. + my @package_list; + my $package; + foreach $package (@{$options{DOPACKAGES}}) { + if (! $exclude_package{$package}) { + push @package_list, $package; + } + } + @{$options{DOPACKAGES}}=@package_list; + + return %options; +} + +1 diff --git a/Dh_Lib.pm b/Dh_Lib.pm new file mode 100644 index 0000000..c9b964c --- /dev/null +++ b/Dh_Lib.pm @@ -0,0 +1,248 @@ +#!/usr/bin/perl -w +# +# Library functions for debhelper programs, perl version. +# +# Joey Hess, GPL copyright 1997, 1998. + +package Dh_Lib; + +use Exporter; +use vars qw(%dh); +@ISA=qw(Exporter); +@EXPORT=qw(&init &doit &complex_doit &verbose_print &error &warning &tmpdir + &pkgfile &pkgext &isnative &autoscript &filearray &GetPackages + %dh); + +sub init { + # Check to see if an argument on the command line starts with a dash. + # if so, we need to pass this off to the resource intensive Getopt::Long, + # which I'd prefer to avoid loading at all if possible. + my $parseopt=undef; + foreach $arg (@ARGV) { + if ($arg=~m/^-/) { + $parseopt=1; + last; + } + } + if ($parseopt) { + eval "use Dh_Getopt"; + error($!) if $@; + %dh=Dh_Getopt::parseopts(); + } + + # Get the name of the main binary package (first one listed in + # debian/control). + my @allpackages=GetPackages(); + $dh{MAINPACKAGE}=$allpackages[0]; + + # Check if packages to build have been specified, if not, fall back to + # the default, doing them all. + if (! @{$dh{DOPACKAGES}}) { + if ($dh{DH_DOINDEP} || $dh{DH_DOARCH}) { + error("I have no package to build."); + } + push @{$dh{DOPACKAGES}},@allpackages; + } + + # Check to see if -P was specified. If so, we can only act on a single + # package. + if ($dh{TMPDIR} || $#{$dh{DOPACKAGES}} > 0) { + error("-P was specified, but multiple packages would be acted on."); + } + + # Figure out which package is the first one we were instructed to build. + # This package gets special treatement: files and directories specified on + # the command line may affect it. + $dh{FIRSTPACKAGE}=${$dh{DOPACKAGES}}[0]; +} + +# Run a command, and display the command to stdout if verbose mode is on. +# All commands that modifiy files in $TMP should be ran via this +# function. +# +# Note that this cannot handle complex commands, especially anything +# involving redirection. Use complex_doit instead. +sub doit { + verbose_print(join(" ",,@_)); + + if (! $dh{NO_ACT}) { + system(@_) == 0 + || error("command returned error code"); + + } +} + +# This is an identical command to doit, except the parameters passed to it +# can include complex shell stull like redirection and compound commands. +sub complex_doit { + error("complex_doit() not yet supported"); +} + +# Print something if the verbose flag is on. +sub verbose_print { my $message=shift; + if ($dh{VERBOSE}) { + print "\t$message\n"; + } +} + +# Output an error message and exit. +sub error { my $message=shift; + warning($message); + exit 1; +} + +# Output a warning. +sub warning { my $message=shift; + my $fn=$0; + $fn=~s:.*/(.*?):$1:; + print STDERR "$fn: $message\n"; +} + +# Pass it a name of a binary package, it returns the name of the tmp dir to +# use, for that package. +# This is for back-compatability with the debian/tmp tradition. +sub tmpdir { my $package=shift; + if ($dh{TMPDIR}) { + return $dh{TMPDIR}; + } + elsif ($package eq $dh{MAINPACKAGE}) { + return "debian/tmp"; + } + else { + return "debian/$package"; + } +} + +# Pass this the name of a binary package, and the name of the file wanted +# for the package, and it will return the actual filename to use. For +# example if the package is foo, and the file is somefile, it will look for +# debian/somefile, and if found return that, otherwise, if the package is +# the main package, it will look for debian/foo, and if found, return that. +# Failing that, it will return nothing. +sub pkgfile { my $package=shift; my $filename=shift; + if (-e "debian/$package.$filename") { + return "debian/$package.$filename"; + } + elsif ($package eq $dh{MAINPACKAGE} && -e "debian/$filename") { + return "debian/$filename"; + } + return ""; +} + +# Pass it a name of a binary package, it returns the name to prefix to files +# in debian for this package. +sub pkgext { my $package=shift; + if ($package ne $MAINPACKAGE) { + return "$package."; + } + return ""; +} + +# Returns 1 if the package is a native debian package, null otherwise. +# As a side effect, sets $dh{VERSION} to the version of this package. +{ + # Caches return code so it only needs to run dpkg-parsechangelog once. + my $isnative_cache; + + sub isnative { my $package=shift; + if ($isnative_cache eq undef) { + # Make sure we look at the correct changelog. + my $isnative_changelog=pkgfile($package,"changelog"); + if (! $isnative_changelog) { + $isnative_changelog="debian/changelog"; + } + + # Get the package version. + my $version=`dpkg-parsechangelog -l$isnative_changelog`; + ($dh{VERSION})=$version=~s/[^|\n]Version: \(.*\)\n//m; + + # Is this a native Debian package? + if ($dh{VERSION}=~m/.*-/) { + $isnative_cache=1; + } + else { + $isnative_cache=0; + } + } + + return $isnative_cache; + } +} + +# Automatically add a shell script snippet to a debian script. +# Only works if the script has #DEBHELPER# in it. +# +# Parameters: +# 1: script to add to +# 2: filename of snippet +# 3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/ +sub autoscript { + error "autoscript() not yet implemented (lazy, lazy!)"; +# autoscript_script=$1 +# autoscript_filename=$2 +# autoscript_sed=$3 +# autoscript_debscript=debian/`pkgext $PACKAGE`$autoscript_script.debhelper +# +# if [ -e "$DH_AUTOSCRIPTDIR/$autoscript_filename" ]; then +# autoscript_filename="$DH_AUTOSCRIPTDIR/$autoscript_filename" +# else +# if [ -e "/usr/lib/debhelper/autoscripts/$autoscript_filename" ]; then +# autoscript_filename="/usr/lib/debhelper/autoscripts/$autoscript_filename" +# else +# error "/usr/lib/debhelper/autoscripts/$autoscript_filename does not exist" +# fi +# fi +# +# complex_doit "echo \"# Automatically added by `basename $0`\" >> $autoscript_debscript" +# complex_doit "sed \"$autoscript_sed\" $autoscript_filename >> $autoscript_debscript" +# complex_doit "echo '# End automatically added section' >> $autoscript_debscript" +} + +# Reads in the specified file, one word at a time, and returns an array of +# the result. +sub filearray { $file=shift; + my @ret; + open (DH_FARRAY_IN,"<$file") || error("cannot read $file: $1"); + while () { + push @ret,split(/\s/,$_); + } + close DH_ARRAY; + + return @ret; +} + +# Returns a list of packages in the control file. +# Must pass "arch" or "indep" to specify arch-dependant or -independant +# packages. If nothing is specified, returns all packages. +sub GetPackages { $type=shift; + my $package; + my $arch; + my @list; + open (CONTROL,") { + chomp; + s/\s+$//; + if (/^Package:\s+(.*)/) { + $package=$1; + } + if (/^Architecture:\s+(.*)/) { + $arch=$1; + } + if (!$_ or eof) { # end of stanza. + if ($package && + (($type eq 'indep' && $arch eq 'all') || + ($type eq 'arch' && $arch ne 'all') || + ! $type)) { + push @list, $package; + undef $package; + undef $arch; + } + } + } + close CONTROL; + + return @list; +} + +1 diff --git a/autoscripts/postinst-emacsen b/autoscripts/postinst-emacsen new file mode 100644 index 0000000..45f1dee --- /dev/null +++ b/autoscripts/postinst-emacsen @@ -0,0 +1 @@ +/usr/lib/emacsen-common/emacs-package-install #PACKAGE# diff --git a/autoscripts/prerm-emacsen b/autoscripts/prerm-emacsen new file mode 100644 index 0000000..d11dafa --- /dev/null +++ b/autoscripts/prerm-emacsen @@ -0,0 +1 @@ +/usr/lib/emacsen-common/emacs-package-remove #PACKAGE# diff --git a/debhelper.1 b/debhelper.1 new file mode 100644 index 0000000..f329666 --- /dev/null +++ b/debhelper.1 @@ -0,0 +1,104 @@ +.TH DEBHELPER 1 "" "Debhelper Commands" "Debhelper Commands" +.SH NAME +debhelper \- overview of the debhelper commands +.SH SYNOPSIS +.B dh_* +.I "[-v] [-a] [-i] [--no-act] [-ppackage] [-Npackage] [-Ptmpdir]" +.SH "DESCRIPTION" +Debhelper is a collection of programs that can be used in debian/rules files +to automate common tasks related to building debian binary packages. All the +debhelper commands accept a set of options, and this man page is here to +document those options and to document debhelper as a whole. For additional +options, and documentation for each individual command, see the commands' own +man pages. +.SH "SHARED DEBHLPER OPTIONS" +.TP +.B \-v, \--verbose +Verbose mode: show all commands that modify the package build directory. +.TP +.B \--no-act +Do not really do anything. If used with -v, the result is that the command +will output a list of what it would have done. +.TP +.B \-a, \--arch +Act on all architecture dependent packages. +.TP +.B \-i, \--indep +Act on all architecture independent packages. +.TP +.B \-ppackage, \--package=package +Act on the package named "package". +.TP +.B \-Npackage, \--no-package=package +Do not act on the specified package even if an -a, -i, or -p option lists +the package as one that should be acted on. +.TP +.B \-Ptmpdir, \--tmpdir=tmpdir +Use "tmpdir" for package build directory. +.SH NOTES +.TP +.B Multiple binary package support +.RS +If your source package generates more than one binary package, debhelper +programs will default to acting on all binary packages when run. If your +source package happens to generate one architecture dependent package, and +another architecture independent package, this is not the correct behavior, +because you need to generate the architecture dependent packages in the +binary-arch debian/rules target, and the architecture independent packages +in the binary-indep debian/rules target. + +To facilitate this, as well as give you more control over which packages +are acted on by debhelper programs, all debhelper programs accept the +.B -a +, +.B -i +, and +.B -p +parameters. These parameters are cumulative. If none are given, +debhelper programs default to acting on all packages listed in the control +file. +.P +See +.BR /usr/doc/debhelper/examples/rules.multi +for an example of how to use this. +.RE +.TP +.B Package build directories +.RS +By default, all debhelper programs assume that the temporary directory used +for assembling the tree of files in a package is debian/tmp for the first +package listed in debian/control, and debian/ for each +additional package. +.P +Sometimes, you might want to use some other temporary directory. This is +supported by the +.B -P +flag. For example, "dh_installdocs -Pdebian/tmp", will use debian/tmp as the +temporary directory. Note that if you use -P, the debhelper programs can only +be acting on a single package at a time. So if you have a package that builds +many binary packages, you will need to use the -p flag to specify which +binary package the debhelper program will act on. +.RE +.TP +.B Other notes +In general, if any debhelper program needs a directory to exist under +debian/, it will create it. I haven't bothered to document this in all the +man pages, but for example, dh_installdeb knows to make debian/tmp/DEBIAN/ +before trying to put files there, dh_installmenu knows you need a +debian/tmp/usr/lib/menu/ before installing the menu files, etc. +.SH ENVIRONMENT +.TP +.I DH_VERBOSE +Enables verbose mode. +.TP +.I DH_NO_ACT +Enables no-act mode. +.SH "SEE ALSO" +.TP +.BR /usr/doc/debhelper/README +An introduction to debhelper. +.TP +.BR /usr/doc/debhelper/examples/ +A set of example debian/rules files that use debhelper. +.SH AUTHOR +Joey Hess diff --git a/debian/cron.d b/debian/cron.d new file mode 100644 index 0000000..e69de29 diff --git a/debian/cron.daily b/debian/cron.daily new file mode 100644 index 0000000..e69de29 diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/debian/docs @@ -0,0 +1 @@ + diff --git a/debian/menu b/debian/menu new file mode 100644 index 0000000..e69de29 diff --git a/dh_installemacsen b/dh_installemacsen new file mode 100755 index 0000000..e87cece --- /dev/null +++ b/dh_installemacsen @@ -0,0 +1,34 @@ +#!/bin/sh -e +# +# Registration with emacsen-common. + +PATH=debian:$PATH:/usr/lib/debhelper +. dh_lib + +for PACKAGE in $DH_DOPACKAGES; do + TMP=`tmpdir $PACKAGE` + + emacsen_install=`pkgfile $PACKAGE emacsen-install` + emacsen_remove=`pkgfile $PACKAGE emacsen-remove` + + if [ "$emacsen_install" ]; then + if [ ! -d "$TMP/usr/lib/emacsen-common/packages/install" ]; then + doit "install -d $TMP/usr/lib/emacsen-common/packages/install" + fi + doit "install $emacsen_install $TMP/usr/lib/emacsen-common/packages/install/$PACKAGE" + fi + + if [ "$emacsen_remove" ]; then + if [ ! -d "$TMP/usr/lib/emacsen-common/packages/remove" ]; then + doit "install -d $TMP/usr/lib/emacsen-common/packages/remove" + fi + doit "install $emacsen_remove $TMP/usr/lib/emacsen-common/packages/remove/$PACKAGE" + fi + + if [ "$emacsen_install" -o "$emacsen_remove" ]; then + if [ ! "$DH_NOSCRIPTS" ]; then + autoscript "postinst" "postinst-emacsen" + autoscript "prerm" "prerm-emacsen" + fi + fi +done diff --git a/dh_installemacsen.1 b/dh_installemacsen.1 new file mode 100644 index 0000000..15ec575 --- /dev/null +++ b/dh_installemacsen.1 @@ -0,0 +1,42 @@ +.TH DH_INSTALLEMACSEN 1 "" "Debhelper Commands" "Debhelper Commands" +.SH NAME +dh_installemacsen \- register an emacs add on package +.SH SYNOPSIS +.B dh_installemacsen +.I "[debhelper options] [-n]" +.SH "DESCRIPTION" +dh_installemacsen is a debhelper program that is responsible for installing +files used by the debian emacsen-common package into package build directories. +.P +It also automatically generates the postinst and prerm commands needed to +register a package as an emacs add on package. See +.BR dh_installdeb (1) +for an explanation of how this works. +.P +If a file named debian/package.emacsen-install exists, then it is installed into +usr/lib/emacsen-common/packages/install/package in the package build +directory. Similarly, debian/package.emacsen-remove is installed into +usr/lib/emacsen-common/packages/remove/package +.P +For the first first binary package listed in the control file, you may use +debian/emacsen-install and debian/emacsen-remove instead. +.SH OPTIONS +.TP +.B debhelper options +See +.BR debhelper (1) +for a list of options common to all debhelper commands. +.TP +.B \-n, \--noscripts +Do not modify postinst/prerm scripts. +.SH ENVIRONMENT +See +.BR debhelper (1) +for a list of environment variables that affect all debhelper commands. +.SH "SEE ALSO" +.TP +.BR debhelper (1) +.TP +.BR /usr/doc/emacsen-common/debian-emacs-policy.gz +.SH AUTHOR +Joey Hess diff --git a/dh_testversion b/dh_testversion new file mode 100755 index 0000000..57c0e58 --- /dev/null +++ b/dh_testversion @@ -0,0 +1,24 @@ +#!/usr/bin/perl -w +# +# Debhelper version check. + +BEGIN { push @INC, "debian", "/usr/lib/debhelper" } +use Dh_Lib; +use Dh_Version; # contains the version number of debhelper. +init(); + +my($compare, $ver); + +if ($#ARGV > 0) { + $compare=shift; + $ver=shift; +} +elsif ($#ARGV eq 0) { + $compare=">="; + $ver=shift; +} + +if (defined $compare and defined $ver) { + system('dpkg','--compare-versions',$Dh_Version::version,$compare,$ver) == 0 || + error("debhelper version $Dh_Version::version is installed, but a version $compare $ver is needed to build this package."); +} -- 2.39.2