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
11 # Echo something if the verbose flag is on.
13 if [ "$DH_VERBOSE" ]; then
18 # Echo an error message and exit.
20 echo `basename $0`": $1" >&2
24 # Pass it a name of a binary package, it returns the name of the tmp dir to
25 # use, for that package.
26 # This is for back-compatability with the debian/tmp tradition.
28 if [ "$DH_TMPDIR" ]; then
30 elif [ "$1" = "$MAINPACKAGE" ]; then
33 echo "debian/$PACKAGE"
37 # Pass it a name of a binary package, it returns the name to prefix to files
38 # in debian for this package.
40 if [ "$1" != "$MAINPACKAGE" ]; then
45 # Automatically add a shell script snippet to a debian script.
46 # Only works if the script has #DEBHELPER# in it.
50 # 2: filename of snippet
51 # 3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
54 autoscript_filename=$2
56 autoscript_debscript=debian/`pkgext $PACKAGE`$autoscript_script.debhelper
58 if [ -e "$DH_AUTOSCRIPTDIR/$autoscript_filename" ]; then
59 autoscript_filename="$DH_AUTOSCRIPTDIR/$autoscript_filename"
61 if [ -e "/usr/lib/debhelper/autoscripts/$autoscript_filename" ]; then
62 autoscript_filename="/usr/lib/debhelper/autoscripts/$autoscript_filename"
64 error "/usr/lib/debhelper/autoscripts/$autoscript_filename does not exist"
68 # Running doit doesn't cut it here.
69 doit "echo \"# Automatically added by `basename $0` on `822-date`\" >> $autoscript_debscript"
70 doit "sed \"$autoscript_sed\" $autoscript_filename >> $autoscript_debscript"
71 doit "echo '# End automatically added section' >> $autoscript_debscript"
74 # Argument processing and global variable initialization is below.
77 set -- `getopt xvianp:P: $*`
95 DH_DOPACKAGES="$DH_DOPACKAGES $2"
119 # Get the package version from the changelog.
120 LINE=`head -1 debian/changelog`
121 VERSION=`expr "$LINE" : '.* (\(.*\))'`
123 # Get the name of the main binary package.
124 MAINPACKAGE=`grep ^Package: debian/control | cut -d " " -f 2 | head -1`
126 # Is this a native Debian package?
127 if ! expr "$VERSION" : '.*-' >/dev/null; then
131 if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then
132 # Figure out all the binary packages to be produced, by looking at the
133 # control file. Break it into 2 lists, INDEP_PACKAGES and ARCH_PACKAGES.
135 # First, get the list of all binary packages.
136 PACKAGES=`grep ^Package: debian/control | cut -d " " -f 2 | tr "\n" " "`
137 # Remove trailing space.
138 PACKAGES=`expr "$PACKAGES" : '\(.*\) '`
139 # Loop on the list of architectures. Note that we tac the result to reverse
140 # it, becuase we are going through the list of packages in reverse.
141 for ARCH in `grep ^Architecture: debian/control | tac | cut -d " " -f 2` ; do
142 THISPKG=`expr "$PACKAGES" : '.* \(.*\)'` || true
143 if [ ! "$THISPKG" ]; then
146 PACKAGES=`expr "$PACKAGES" : '\(.*\) .*'` || true
147 if [ ! "$THISPKG" ]; then
148 error "debian/control invalid - too many Architecture lines or too few Package lines"
150 if [ "$ARCH" = "all" ]; then
151 INDEP_PACKAGES="$INDEP_PACKAGES $THISPKG"
153 ARCH_PACKAGES="$ARCH_PACKAGES $THISPKG"
157 if [ "$PACKAGES" ]; then
158 error "debian/control invalid - too many Architecure lines or too few Package lines"
160 if [ "$DH_DOINDEP" ]; then
161 DH_DOPACKAGES="$DH_DOPACKAGES $INDEP_PACKAGES"
163 if [ "$DH_DOARCH" ]; then
164 DH_DOPACKAGES="$DH_DOPACKAGES $ARCH_PACKAGES"
168 # Check if packages to build have been specified, if not, fall back to
169 # the default, doing them all. Note that DH_DOPACKAGES may have a leading
170 # space and be empty otherwise.
171 if [ ! "$DH_DOPACKAGES" -o "$DH_DOPACKAGES" = " " ]; then
172 if [ "$DH_DOINDEP" -o "$DH_DOARCH" ]; then
173 error "I have no package to build."
175 DH_DOPACKAGES=`grep ^Package: debian/control | cut -d " " -f 2`
178 # Check to see if -P was specified. If so, we can only act on a single
180 if [ "$DH_TMPDIR" ] && echo "$DH_DOPACKAGES" | egrep -q '.+ .+' ; then
181 error "-P was specified, but multiple packages would be acted on."