1 # Library functions for debhelper programs.
3 # Run a command, and display the command to stdout if verbose mode is on.
4 # All commands that modifiy files in $TMP should be ran via this
6 # Note that this cannot handle complex commands, especially anything
7 # involving redirection. Use complex_doit instead.
13 # This is an identical command to doit, except the parameter passed to it
14 # are evaled with double quotes. This version can handle compound commands.
20 # Echo something if the verbose flag is on.
22 if [ "$DH_VERBOSE" ]; then
27 # Echo an error message and exit.
29 echo `basename $0`": $1" >&2
33 # Pass it a name of a binary package, it returns the name of the tmp dir to
34 # use, for that package.
35 # This is for back-compatability with the debian/tmp tradition.
37 if [ "$DH_TMPDIR" ]; then
39 elif [ "$1" = "$MAINPACKAGE" ]; then
42 echo "debian/$PACKAGE"
46 # Pass it a name of a binary package, it returns the name to prefix to files
47 # in debian for this package.
49 if [ "$1" != "$MAINPACKAGE" ]; then
54 # Automatically add a shell script snippet to a debian script.
55 # Only works if the script has #DEBHELPER# in it.
59 # 2: filename of snippet
60 # 3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
63 autoscript_filename=$2
65 autoscript_debscript=debian/`pkgext $PACKAGE`$autoscript_script.debhelper
67 if [ -e "$DH_AUTOSCRIPTDIR/$autoscript_filename" ]; then
68 autoscript_filename="$DH_AUTOSCRIPTDIR/$autoscript_filename"
70 if [ -e "/usr/lib/debhelper/autoscripts/$autoscript_filename" ]; then
71 autoscript_filename="/usr/lib/debhelper/autoscripts/$autoscript_filename"
73 error "/usr/lib/debhelper/autoscripts/$autoscript_filename does not exist"
77 complex_doit "echo \"# Automatically added by `basename $0` on `822-date`\" >> $autoscript_debscript"
78 complex_doit "sed \"$autoscript_sed\" $autoscript_filename >> $autoscript_debscript"
79 complex_doit "echo '# End automatically added section' >> $autoscript_debscript"
82 # Argument processing and global variable initialization is below.
85 set -- `getopt xvidrnakp:P:u: $*`
103 DH_DOPACKAGES="$DH_DOPACKAGES $2"
144 # Get the package version.
145 # Note that the 2>/dev/null is because a bug in dpkg-parsechangelog makes it
146 # output a bogus error message to stderr.
147 # If it actually has a real error, then the expr will fail, and this whole
148 # script will come crashing to a halt, which is good enough to inform
149 # the user something's wrong. :-)
150 VERSION=`expr "\`dpkg-parsechangelog 2>/dev/null\`" : '.*Version: \(.*\).*Distribution:'`
152 # Get the name of the main binary package.
153 MAINPACKAGE=`grep ^Package: debian/control | cut -d " " -f 2 | head -1`
155 # Is this a native Debian package?
156 if ! expr "$VERSION" : '.*-' >/dev/null; then
160 if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then
161 # Figure out all the binary packages to be produced, by looking at the
162 # control file. Break it into 2 lists, INDEP_PACKAGES and ARCH_PACKAGES.
164 # First, get the list of all binary packages.
165 PACKAGES=`grep ^Package: debian/control | cut -d " " -f 2 | tr "\n" " "`
166 # Remove trailing space.
167 PACKAGES=`expr "$PACKAGES" : '\(.*\) '`
168 # Loop on the list of architectures. Note that we tac the result to reverse
169 # it, becuase we are going through the list of packages in reverse.
170 for ARCH in `grep ^Architecture: debian/control | tac | cut -d " " -f 2` ; do
171 THISPKG=`expr "$PACKAGES" : '.* \(.*\)'` || true
172 if [ ! "$THISPKG" ]; then
175 PACKAGES=`expr "$PACKAGES" : '\(.*\) .*'` || true
176 if [ ! "$THISPKG" ]; then
177 error "debian/control invalid - too many Architecture lines or too few Package lines"
179 if [ "$ARCH" = "all" ]; then
180 INDEP_PACKAGES="$INDEP_PACKAGES $THISPKG"
182 ARCH_PACKAGES="$ARCH_PACKAGES $THISPKG"
186 if [ "$PACKAGES" ]; then
187 error "debian/control invalid - too many Architecure lines or too few Package lines"
189 if [ "$DH_DOINDEP" ]; then
190 DH_DOPACKAGES="$DH_DOPACKAGES $INDEP_PACKAGES"
192 if [ "$DH_DOARCH" ]; then
193 DH_DOPACKAGES="$DH_DOPACKAGES $ARCH_PACKAGES"
197 # Check if packages to build have been specified, if not, fall back to
198 # the default, doing them all. Note that DH_DOPACKAGES may have a leading
199 # space and be empty otherwise.
200 if [ ! "$DH_DOPACKAGES" -o "$DH_DOPACKAGES" = " " ]; then
201 if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then
202 error "I have no package to build."
204 DH_DOPACKAGES=`grep ^Package: debian/control | cut -d " " -f 2`
207 # Check to see if -P was specified. If so, we can only act on a single
209 if [ "$DH_TMPDIR" ] && echo "$DH_DOPACKAGES" | egrep -q '.+ .+' ; then
210 error "-P was specified, but multiple packages would be acted on."