autogen.sh clean: handle both m4 and m4m
[platform/upstream/libexif.git] / autogen.sh
1 #!/bin/sh
2 # autogen.sh - initialize and clean automake&co based build trees
3 #
4 # For more detailed info, run "autogen.sh --help" or scroll down to the
5 # print_help() function.
6
7
8 if test "$(pwd)" != "`pwd`"
9 then
10         echo "Urgh. Dinosaur shell, eh?"
11         exit 1
12 fi
13
14
15 ########################################################################
16 # Constant and initial values
17
18 debug=false
19 self="$(basename "$0")"
20 autogen_version="0.3.2"
21
22
23 ########################################################################
24 # Print help message
25
26 print_help() {
27     cat<<EOF
28 $self - initialize automake/autoconf/gettext/libtool based build system
29
30 Usage:
31     $self [<command>...] [<directory>...]
32
33 Runs given command sequence on all given directories, in sequence.
34 If there is no command given, --init is assumed.
35 If there is no directory given, the location of $self is assumed.
36
37 Commands:
38     --help
39         Print this help text
40     --version
41         Print the tool versions
42     --verbose
43         Verbose output
44
45     --clean
46         Clean all files and directories generated by "$self --init"
47     --init
48         Converts untouched CVS checkout into a build tree which
49         can be processed further by running the classic
50           ./configure && make && make install
51
52 $self depends on automake, autoconf, libtool and gettext.
53
54 You may want to set AUTOCONF, AUTOHEADER, AUTOMAKE, ACLOCAL,
55 AUTOPOINT, LIBTOOLIZE to use specific version of these tools, and
56 AUTORECONF_OPTS to add options to the call to autoreconf.
57 EOF
58 }
59
60
61 ########################################################################
62 # Print software versions
63
64 print_versions() {
65     echo "${self} (ndim's autogen) ${autogen_version}"
66     for tool in \
67         "${AUTOCONF-autoconf}" \
68         "${AUTOMAKE-automake}" \
69         "${AUTOPOINT-autopoint}" \
70         "${LIBTOOLIZE-libtoolize}"
71     do
72         "$tool" --version 2>&1 | sed '1q'
73     done
74 }
75
76
77 ########################################################################
78 # Initialize variables for configure.{in,ac} in $1
79
80 init_vars() {
81     dir="$1"
82     echo -n "Looking for \`${dir}/configure.{ac,in}'..."
83     # There are shells which don't understand {,} wildcards
84     CONFIGURE_AC=""
85     for tmp in "${dir}/configure.ac" "${dir}/configure.in"; do
86         if test -f "$tmp"; then
87             CONFIGURE_AC="$tmp"
88             echo " $tmp"
89             break
90         fi
91     done
92     if test "x$CONFIGURE_AC" = "x"; then
93         echo " no."
94         exit 1
95     fi
96
97     if "$debug"; then
98         if test "$(uname -o)" = "Cygwin"; then
99             # Cygwin autoreconf doesn't understand -Wall
100             AUTORECONF_OPTS="$AUTORECONF_OPTS --verbose"
101         else
102             AUTORECONF_OPTS="$AUTORECONF_OPTS --verbose -Wall"
103         fi
104     fi
105
106     echo -n "Initializing variables for \`${dir}'..."
107     # FIXME: Just getting those directories and cleaning them isn't enough.
108     #        OK, the "init" part is done recursively by autopoint, so that is easy.
109     #        But the cleaning should also work recursively, but that is difficult
110     #        with the current structure of the script.
111     AG_SUBDIRS="$(for k in $(sed -n 's/^[[:space:]]*AC_CONFIG_SUBDIRS(\[\{0,1\}\([^])]*\).*/\1/p' "$CONFIGURE_AC"); do echo "${dir}/${k}"; done)"
112     AG_AUX="$(sed -n 's/^AC_CONFIG_AUX_DIR(\[\{0,1\}\([^])]*\).*/\1/p' < "$CONFIGURE_AC")"
113     if test "x$AG_AUX" = "x"; then
114         AG_AUX="."
115     fi
116     AG_CONFIG_H="$(sed -n 's/^\(A[CM]_CONFIG_HEADERS\?\)(\[\{0,1\}\([^]),]*\).*/\2/p' < "$CONFIGURE_AC")"
117     AG_CONFIG_K="$(sed -n 's/^\(A[CM]_CONFIG_HEADERS\?\)(\[\{0,1\}\([^]),]*\).*/\1/p' < "$CONFIGURE_AC")"
118     if echo "x$AG_CONFIG_H" | grep -q ':'; then
119         echo "$AG_CONFIG_K contains unsupported \`:' character: \`$AG_CONFIG_H'"
120         exit 13
121     fi
122     if test "x$AG_CONFIG_H" != "x"; then
123         AG_CONFIG_DIR="$(dirname "${AG_CONFIG_H}")"
124         AG_GEN_CONFIG_H="${AG_CONFIG_H} ${AG_CONFIG_H}.in ${AG_CONFIG_DIR}/stamp-h1 ${AG_CONFIG_DIR}/stamp-h2"
125     else
126         AG_CONFIG_DIR=""
127         AG_GEN_CONFIG_H=""
128     fi
129     for d in "$AG_AUX" "$AG_CONFIG_DIR"; do
130         if test -n "$d" && test ! -d "$d"; then
131             mkdir "$d"
132         fi
133     done
134     AG_GEN_ACAM="aclocal.m4 configure $AG_AUX/config.guess $AG_AUX/config.sub $AG_AUX/compile"
135     AG_GEN_RECONF="$AG_AUX/install-sh $AG_AUX/missing $AG_AUX/depcomp"
136     AG_GEN_GETTEXT="$AG_AUX/mkinstalldirs $AG_AUX/config.rpath ABOUT-NLS"
137     while read file; do
138         AG_GEN_GETTEXT="${AG_GEN_GETTEXT} ${file}"
139     done <<EOF
140 m4/codeset.m4
141 m4/gettext.m4
142 m4/glibc21.m4
143 m4/iconv.m4
144 m4/intdiv0.m4
145 m4/intmax.m4
146 m4/inttypes-pri.m4
147 m4/inttypes.m4
148 m4/inttypes_h.m4
149 m4/isc-posix.m4
150 m4/lcmessage.m4
151 m4/lib-ld.m4
152 m4/lib-link.m4
153 m4/lib-prefix.m4
154 m4/longdouble.m4
155 m4/longlong.m4
156 m4/nls.m4
157 m4/po.m4
158 m4/printf-posix.m4
159 m4/progtest.m4
160 m4/signed.m4
161 m4/size_max.m4
162 m4/stdint_h.m4
163 m4/uintmax_t.m4
164 m4/ulonglong.m4
165 m4/wchar_t.m4
166 m4/wint_t.m4
167 m4/xsize.m4
168 m4m/codeset.m4
169 m4m/gettext.m4
170 m4m/glibc21.m4
171 m4m/iconv.m4
172 m4m/intdiv0.m4
173 m4m/intmax.m4
174 m4m/inttypes-pri.m4
175 m4m/inttypes.m4
176 m4m/inttypes_h.m4
177 m4m/isc-posix.m4
178 m4m/lcmessage.m4
179 m4m/lib-ld.m4
180 m4m/lib-link.m4
181 m4m/lib-prefix.m4
182 m4m/longdouble.m4
183 m4m/longlong.m4
184 m4m/nls.m4
185 m4m/po.m4
186 m4m/printf-posix.m4
187 m4m/progtest.m4
188 m4m/signed.m4
189 m4m/size_max.m4
190 m4m/stdint_h.m4
191 m4m/uintmax_t.m4
192 m4m/ulonglong.m4
193 m4m/wchar_t.m4
194 m4m/wint_t.m4
195 m4m/xsize.m4
196 po/Makefile.in.in
197 po/Makevars.template
198 po/Rules-quot
199 po/boldquot.sed
200 po/en@boldquot.header
201 po/en@quot.header
202 po/insert-header.sin
203 po/quot.sed
204 po/remove-potcdate.sin
205 po/stamp-po
206 EOF
207     AG_GEN_CONF="config.status config.log"
208     AG_GEN_LIBTOOL="$AG_AUX/ltmain.sh libtool"
209     AG_GEN_FILES="$AG_GEN_ACAM $AG_GEN_RECONF $AG_GEN_GETTEXT"
210     AG_GEN_FILES="$AG_GEN_FILES $AG_GEN_CONFIG_H $AG_GEN_CONF $AG_GEN_LIBTOOL"
211     AG_GEN_DIRS="autom4te.cache"
212     echo " done."
213
214     if "$debug"; then set | grep '^AG_'; fi
215 }
216
217
218 ########################################################################
219 # Clean generated files from $* directories
220
221 clean() {
222     if test "x$AG_GEN_FILES" = "x"; then echo "Internal error"; exit 2; fi
223     dir="$1"
224     while test "$dir"; do
225         echo "$self:clean: Entering directory \`${dir}'"
226         (
227             if cd "$dir"; then
228                 echo -n "Cleaning autogen generated files..."
229                 rm -rf ${AG_GEN_DIRS}
230                 rm -f ${AG_GEN_FILES}
231                 echo " done."
232                 if test -h INSTALL; then rm -f INSTALL; fi
233                 echo -n "Cleaning generated Makefile, Makefile.in files..."
234                 if "$debug"; then echo; fi
235                 find . -type f -name 'Makefile.am' -print | \
236                     while read file; do
237                     echo "$file" | grep -q '/{arch}' && continue
238                     echo "$file" | grep -q '/\.svn'  && continue
239                     echo "$file" | grep -q '/CVS'    && continue
240                     base="$(dirname "$file")/$(basename "$file" .am)"
241                     if "$debug"; then
242                         echo -e "  Removing files created from ${file}"
243                     fi
244                     rm -f "${base}" "${base}.in"
245                 done
246                 if "$debug"; then :; else echo " done."; fi
247                 echo -n "Removing *~ backup files..."
248                 find . -type f -name '*~' -exec rm -f {} \;
249                 echo " done."
250             fi
251         )
252         echo "$self:clean: Left directory \`${dir}'"
253         shift
254         dir="$1"
255     done
256 }
257
258
259 ########################################################################
260 # Initialize build system in $1 directory
261
262 init() {
263     dir="$1"
264     if test "x$AG_GEN_FILES" = "x"; then echo "Internal error"; exit 2; fi
265     echo "$self:init: Entering directory \`${dir}'"
266 (
267 if cd "${dir}"; then
268     echo "Running <<" autoreconf --install --symlink ${AUTORECONF_OPTS} ">>"
269     if autoreconf --install --symlink ${AUTORECONF_OPTS}; then
270         :; else
271         status="$?"
272         echo "autoreconf quit with exit code $status, aborting."
273         exit "$status"
274     fi    
275     echo "You may run ./configure now in \`${dir}'."
276     echo "Run as \"./configure --help\" to find out about config options."
277 else
278     exit "$?"
279 fi
280 )
281     # Just error propagation
282     status="$?"
283     echo "$self:init: Left directory \`${dir}'"
284     if test "$status" -ne "0"; then
285         exit "$status"
286     fi
287 }
288
289
290 ########################################################################
291 # Parse command line.
292 # This still accepts more than the help text says it does, but that
293 # isn't supported.
294
295 commands="init" # default command in case none is given
296 pcommands=""
297 check_versions=false
298 dirs="$(dirname "$0")"
299 #dirs="$(cd "$dirs" && pwd)"
300 pdirs=""
301 # Yes, unquoted $@ isn't space safe, but it works with simple shells.
302 for param in $@; do
303     case "$param" in
304         --clean)
305             pcommands="$pcommands clean"
306             ;;
307         --init)
308             pcommands="$pcommands init"
309             check_versions=:
310             ;;
311         --verbose)
312             debug="true"
313             ;;
314         --version)
315             print_versions
316             exit 0
317             ;;
318         -h|--help)
319             print_help
320             exit 0
321             ;;
322         -*)
323             echo "Unhandled $self option: $param"
324             exit 1
325             ;;
326         *)
327             pdirs="${pdirs} ${param}"
328             ;;
329     esac
330 done
331 if test "x$pcommands" != "x"; then
332     # commands given on command line? use them!
333     commands="$pcommands"
334 else
335     check_versions=:
336 fi
337 if test "x$pdirs" != "x"; then
338     # dirs given on command line? use them!
339     dirs="$pdirs"
340 fi
341
342 if "$check_versions"; then
343         # check tool versions
344         errors=false
345         lf="
346 "
347         while read tool minversion; do
348                 version="$("$tool" --version | sed 's/^.*(.*) *\(.*\)$/\1/g;1q')"
349                 first="$(echo "$version$lf$minversion" | sort -n | sed '1q')"
350                 if test "x$minversion" != "x$first" && test "x$version" = "x$first"; then
351                         echo "Version \`$version' of \`$tool' not sufficient. At least \`$minversion' required."
352                         errors=:
353                 fi
354         done <<EOF
355 ${ACLOCAL-"aclocal"}    1.8
356 ${AUTOMAKE-"automake"}  1.8
357 ${AUTOCONF-"autoconf"}  2.59
358 ${AUTOHEADER-"autoheader"}      2.59
359 ${AUTOPOINT-"autopoint"}        0.14.1
360 ${LIBTOOLIZE-"libtoolize"}      1.4
361 EOF
362         if "$errors"; then
363                 echo "Please update your toolset."
364                 echo "If you want to continue regardless of your old toolset, press ENTER."
365                 read
366         fi
367 fi
368
369
370 ########################################################################
371 # Actually run the commands
372
373 for dir in ${dirs}; do
374     echo "Running commands on directory \`${dir}'"
375     if test ! -d "$dir"; then
376         echo "Could not find directory \`${dir}'"       
377     fi
378     init_vars "$dir"
379     for command in ${commands}; do
380         "$command" "$dir" ${AG_SUBDIRS}
381     done
382 done
383
384 exit 0
385
386 # Please do not remove this:
387 # filetype: 89b1e88e-4cf2-44f1-980d-730067367775
388 # I use this to find all the different instances of this file which 
389 # are supposed to be synchronized.