4 MODIFIED_CONF_MSG='Default settings modified by devscripts configuration files:'
8 "Usage: $PROGNAME [options]
9 Clean all debian build trees under current directory.
12 --cleandebs Also remove all .deb, .changes and .build
13 files from the parent of each build tree
15 --nocleandebs Don't remove the .deb etc. files (default)
17 --check-dirname-level N
18 How much to check directory names before cleaning trees:
20 N=1 only if program changes directory (default)
23 --check-dirname-regex REGEX
24 What constitutes a matching directory name; REGEX is
25 a Perl regular expression; the string \`PACKAGE' will
26 be replaced by the package name; see manpage for details
27 (default: 'PACKAGE(-.+)?')
30 Do not read devscripts config files;
31 must be the first option given
33 -d Do not run dpkg-checkbuilddeps to check build dependencies
35 --help Display this help message and exit
37 --version Display version information
44 "This is $PROGNAME, from the Debian devscripts package, version ###VERSION###
45 This code is copyright 1999 by Julian Gilbey, all rights reserved.
46 Original code by Christoph Lameter.
47 This program comes with ABSOLUTELY NO WARRANTY.
48 You are free to redistribute this code under the terms of the
49 GNU General Public License, version 2 or later."
52 # Boilerplate: set config variables
53 DEFAULT_DEBCLEAN_CLEANDEBS=no
54 DEFAULT_DEVSCRIPTS_CHECK_DIRNAME_LEVEL=1
55 DEFAULT_DEVSCRIPTS_CHECK_DIRNAME_REGEX='PACKAGE(-.+)?'
56 VARS="DEBCLEAN_CLEANDEBS DEVSCRIPTS_CHECK_DIRNAME_LEVEL DEVSCRIPTS_CHECK_DIRNAME_REGEX"
59 if [ "$1" = "--no-conf" -o "$1" = "--noconf" ]; then
61 MODIFIED_CONF_MSG="$MODIFIED_CONF_MSG
62 (no configuration files read)"
66 eval "$var=\$DEFAULT_$var"
69 # Run in a subshell for protection against accidental errors
74 eval "$var=\$DEFAULT_$var"
77 for file in /etc/devscripts.conf ~/.devscripts
79 [ -r $file ] && . $file
82 set | egrep '^(DEBCLEAN|DEVSCRIPTS)_')
85 case "$DEBCLEAN_CLEANDEBS" in
87 *) DEBCLEAN_CLEANDEBS=no ;;
89 case "$DEVSCRIPTS_CHECK_DIRNAME_LEVEL" in
91 *) DEVSCRIPTS_CHECK_DIRNAME_LEVEL=1 ;;
97 eval "if [ \"\$$var\" != \"\$DEFAULT_$var\" ]; then
98 MODIFIED_CONF_MSG=\"\$MODIFIED_CONF_MSG
104 if [ -z "$MODIFIED_CONF" ]; then
105 MODIFIED_CONF_MSG="$MODIFIED_CONF_MSG
111 CHECK_DIRNAME_LEVEL="$DEVSCRIPTS_CHECK_DIRNAME_LEVEL"
112 CHECK_DIRNAME_REGEX="$DEVSCRIPTS_CHECK_DIRNAME_REGEX"
114 # Need -o option to getopt or else it doesn't work
115 TEMP=$(getopt -s bash -o "" -o d \
116 --long cleandebs,nocleandebs,no-cleandebs \
117 --long no-conf,noconf \
118 --long check-dirname-level:,check-dirname-regex: \
119 --long help,version -n "$PROGNAME" -- "$@")
120 if [ $? != 0 ] ; then exit 1 ; fi
127 --cleandebs) DEBCLEAN_CLEANDEBS=yes ;;
128 --nocleandebs|--no-cleandebs) DEBCLEAN_CLEANDEBS=no ;;
129 --check-dirname-level)
132 0|1|2) CHECK_DIRNAME_LEVEL=$1 ;;
133 *) echo "$PROGNAME: unrecognised --check-dirname-level value (allowed are 0,1,2)" >&2
138 CHECKBUILDDEP="-d" ;;
139 --check-dirname-regex)
140 shift; CHECK_DIRNAME_REGEX="$1" ;;
142 echo "$PROGNAME: $1 is only acceptable as the first command-line option!" >&2
144 --help) usage; exit 0 ;;
145 --version) version; exit 0 ;;
147 *) echo "$PROGNAME: bug in option parser, sorry!" >&2 ; exit 1 ;;
153 if [ $# -gt 0 ]; then
154 echo "$PROGNAME takes no non-option arguments;" >&2
155 echo "try $PROGNAME --help for usage information" >&2
160 # Script to clean up debian directories
163 for i in `find . -type d -name "debian"`; do
164 ( # subshell to not lose where we are
166 echo "Cleaning in directory $DIR"
169 # Clean up the source package, but only if the directory looks like
170 # a genuine build tree
171 if [ ! -f debian/changelog ]; then
172 echo "Directory $DIR: contains no debian/changelog, skipping" >&2
175 package="`dpkg-parsechangelog | sed -n 's/^Source: //p'`"
176 if [ -z "$package" ]; then
177 echo "Directory $DIR: unable to determine package name, skipping" >&2
181 # let's test the directory name if appropriate
182 if [ $CHECK_DIRNAME_LEVEL -eq 2 -o \
183 \( $CHECK_DIRNAME_LEVEL -eq 1 -a "$OPWD" != "`pwd`" \) ]; then
184 if ! perl -MFile::Basename -w \
185 -e "\$pkg='$package'; \$re='$CHECK_DIRNAME_REGEX';" \
186 -e '$re =~ s/PACKAGE/\\Q$pkg\\E/g; $pwd=`pwd`; chomp $pwd;' \
187 -e 'if ($re =~ m%/%) { eval "exit (\$pwd =~ /^$re\$/ ? 0:1);"; }' \
188 -e 'else { eval "exit (basename(\$pwd) =~ /^$re\$/ ? 0:1);"; }'
190 echo "Full directory path `pwd` does not match package name, skipping." >&2
191 echo "Run $progname --help for more information on directory name matching." >&2
196 # We now know we're OK and debuild won't complain about the dirname
197 debuild $CHECKBUILDDEP clean
199 # Clean up the package related files
200 if [ "$DEBCLEAN_CLEANDEBS" = yes ]; then
202 rm -f *.changes *.deb *.build