1 # Library functions for debhelper programs.
3 # Joey Hess, GPL copyright 1997, 1998.
5 # Run a command, and display the command to stdout if verbose mode is on.
6 # All commands that modifiy files in $TMP should be ran via this
8 # Note that this cannot handle complex commands, especially anything
9 # involving redirection. Use complex_doit instead.
12 if [ ! "$DH_NO_ACT" ]; then
18 # This is an identical command to doit, except the parameter passed to it
19 # are evaled with double quotes. This version can handle compound commands.
22 if [ ! "$DH_NO_ACT" ]; then
27 # Echo something if the verbose flag is on.
29 if [ "$DH_VERBOSE" ]; then
34 # Echo an error message and exit.
36 echo `basename $0`": $1" >&2
42 echo `basename $0`": $1" >&2
45 # Pass it a name of a binary package, it returns the name of the tmp dir to
46 # use, for that package.
47 # This is for back-compatability with the debian/tmp tradition.
49 if [ "$DH_TMPDIR" ]; then
51 elif [ "$1" = "$MAINPACKAGE" ]; then
54 echo "debian/$PACKAGE"
58 # Pass this the name of a binary package, and the name of the file wanted
59 # for the package, and it will return the actual filename to use. For
60 # example if the package is foo, and the file is somefile, it will look for
61 # debian/somefile, and if found return that, otherwise, if the package is
62 # the main package, it will look for debian/foo, and if found, return that.
63 # Failing that, it will return nothing.
65 if [ -e "debian/$1.$2" ]; then
67 elif [ "$1" = "$MAINPACKAGE" -a -e "debian/$2" ]; then
72 # Pass it a name of a binary package, it returns the name to prefix to files
73 # in debian for this package.
75 if [ "$1" != "$MAINPACKAGE" ]; then
80 # Returns 1 if the package is a native debian package, null otherwise.
81 # As a side effect, sets $VERSION to the version of this package.
82 # Caches return code so it only needs to run dpkg-parsechangelog once.
84 if [ -z "$DH_ISNATIVE" ]; then
85 # Make sure we look at the correct changelog.
86 isnative_changelog=`pkgfile $PACKAGE changelog`
87 if [ ! "$isnative_changelog" ]; then
88 isnative_changelog=debian/changelog
90 # Get the package version.
91 # Note that the 2>/dev/null is because a bug in dpkg-parsechangelog makes it
92 # output a bogus error message to stderr.
93 # If it actually has a real error, then the expr will fail, and this whole
94 # script will come crashing to a halt, which is good enough to inform
95 # the user something's wrong. :-)
96 VERSION=`expr "\`dpkg-parsechangelog -l$isnative_changelog 2>/dev/null\`" : \
97 '.*Version: \(.*\).*Distribution:'`
98 # Is this a native Debian package?
99 if expr "$VERSION" : '.*-' >/dev/null; then
106 return "$DH_ISNATIVE"
109 # Automatically add a shell script snippet to a debian script.
110 # Only works if the script has #DEBHELPER# in it.
113 # 1: script to add to
114 # 2: filename of snippet
115 # 3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
118 autoscript_filename=$2
120 autoscript_debscript=debian/`pkgext $PACKAGE`$autoscript_script.debhelper
122 if [ -e "$DH_AUTOSCRIPTDIR/$autoscript_filename" ]; then
123 autoscript_filename="$DH_AUTOSCRIPTDIR/$autoscript_filename"
125 if [ -e "/usr/lib/debhelper/autoscripts/$autoscript_filename" ]; then
126 autoscript_filename="/usr/lib/debhelper/autoscripts/$autoscript_filename"
128 error "/usr/lib/debhelper/autoscripts/$autoscript_filename does not exist"
132 complex_doit "echo \"# Automatically added by `basename $0`\" >> $autoscript_debscript"
133 complex_doit "sed \"$autoscript_sed\" $autoscript_filename >> $autoscript_debscript"
134 complex_doit "echo '# End automatically added section' >> $autoscript_debscript"
137 # Argument processing and global variable initialization is below.
139 # If DH_OPTIONS is set, prepend it to the command line.
140 if [ "$DH_OPTIONS" ]; then
141 set -- $DH_OPTIONS $@
144 # Check to see if an argument on the command line starts with a dash.
145 # if so, we need to pass this off to the resource intensive perl.
147 if expr "$arg" : '-' >/dev/null ; then
152 if [ "$parseopt" ]; then
154 # Parse command line. I wrote a perl program to do this becuase
155 # getopt(1) is so broken. Note: the quotes around $@ are very
157 eval `dh_getopt.pl "$@"`
158 if [ "$DH_PARSE_ERROR" ]; then
159 error "$DH_PARSE_ERROR"
163 # Get the name of the main binary package (first one listed in
165 MAINPACKAGE=`grep ^Package: debian/control | cut -d " " -f 2 | head -1`
167 # Check if packages to build have been specified, if not, fall back to
168 # the default, doing them all.
169 if [ ! "$DH_DOPACKAGES" ]; then
170 if [ "$DH_DOINDEP" -o "$DH_DOARCH" -o "$DH_DOSAME" ]; then
171 error "I have no package to build."
173 DH_DOPACKAGES=`grep ^Package: debian/control | cut -d " " -f 2 | tr "\n" " "`
176 # Check to see if -P was specified. If so, we can only act on a single
178 if [ "$DH_TMPDIR" ] && echo "$DH_DOPACKAGES" | egrep -q '.+ .+' ; then
179 error "-P was specified, but multiple packages would be acted on."
182 # Figure out which package is the first one we were instructed to build.
183 # This package gets special treatement, files and directories specified on
184 # the command line may effect it.
185 for PACKAGE in $DH_DOPACKAGES ; do
186 DH_FIRSTPACKAGE="$PACKAGE"