update for compatibility with recent nobug
[acogc.git] / bootstrap.sh
blobf9e86a556ae18d4090815822bf5075c263a399c7
1 #!/bin/sh
3 # GNU autotools driver
5 # Copyright (C) 2001, 2004, Christian Thaeter <chth@gmx.net>
7 # hint: install this somewhere in your PATH as 'autobootstrap'
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2 as
11 # published by the Free Software Foundation.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, contact me.
22 function chk_prg()
24 test ! "$chk_prg_org" && chk_prg_org="$*"
25 test $# -eq 0 && { echo "lacking on of $chk_prg_org"; exit 1;}
26 if test ! "$1"; then
27 echo "";
28 else
29 local prg
30 prg=$(which "$1")
31 if test "$prg" = ""; then
32 shift;
33 chk_prg "$@"
34 else
35 chk_prg_org="";
36 echo "$prg"
41 #default options (configure this for your package)
42 DEF_BUILDDIR='=build'
43 DEF_BUILDOPT='-j 9'
44 DEF_CFLAGS_DEBUG='-O0 -g -W -Wall -Werror -std=gnu99'
45 DEF_CFLAGS_RELEASE='-O3 -W -Wall -Werror -std=gnu99'
46 DEF_CONFIGUREFLAGS_DEBUG=''
47 DEF_CONFIGUREFLAGS_RELEASE='--enable-nobug=RELEASE'
48 DEF_CC="nice $(chk_prg ccache "") $(chk_prg distcc "") $(chk_prg gcc-3.4 gcc cc)"
50 #default programs (probably no need for configuration)
51 AUTOCONFVERSION='2.50'
52 AUTOMAKEVERSION='-1.9'
54 MAKE="$(chk_prg gmake make)"
55 AUTOSCAN="$(chk_prg autoscan$AUTOCONFVERSION autoscan)"
56 ACLOCAL="$(chk_prg aclocal$AUTOMAKEVERSION aclocal)"
57 AUTOCONF="$(chk_prg autoconf$AUTOCONFVERSION autoconf)"
58 AUTOHEADER="$(chk_prg autoheader$AUTOCONFVERSION autoheader)"
59 AUTOMAKE="$(chk_prg automake$AUTOMAKEVERSION)"
62 #commandline parser (needs to be done better / options etc)
63 do_mrproper=false
64 do_release=false
65 do_nobootstrap=false
66 do_stop=false
67 do_configure=false
68 do_chelp=false
69 do_build=false
70 do_check=false
71 do_install=false
72 do_clean=false
73 do_uninstall=false
74 do_dist=false
75 do_dir=true
76 dir_opt="$DEF_BUILDDIR"
77 base_dir=`pwd`
79 for i in "$@"; do
80 case $i in
81 mrproper|distclean)
82 do_mrproper=true
83 do_uninstall=true
84 do_stop=true
86 rebuild)
87 do_mrproper=true
88 do_uninstall=true
89 do_stop=false
91 nobootstrap)
92 do_nobootstrap=true
94 chelp)
95 do_chelp=true
96 do_stop=false
98 configure*)
99 configure_opt=${i#configure}
100 do_configure=true
101 do_stop=false
103 make*)
104 build_opt=${i#make}
105 do_build=true
106 do_configure=true
107 do_stop=false
109 build*)
110 build_opt=${i#build}
111 do_build=true
112 do_configure=true
113 do_stop=false
115 nocd|intree)
116 do_dir=false
118 cd*)
119 dir_opt=${i#cd}
120 dir_opt="${dir_opt:-$DEF_BUILDDIR}"
121 do_dir=true
123 check|test)
124 do_check=true
125 do_configure=true
126 do_stop=false
128 install)
129 do_release=true
130 do_install=true
131 do_check=true
132 do_configure=true
133 do_uninstall=true
134 do_stop=false
136 clean)
137 do_clean=true
138 do_stop=false
140 uninstall)
141 do_uninstall=true
142 do_stop=false
144 dist)
145 do_release=true
146 do_dist=true
147 do_configure=true
148 do_clean=true
149 do_stop=false
151 release)
152 do_release=true
154 help*|-h*)
155 echo "bootstrap a GNU-Autotools Project"
156 echo "usage: bootstrap options..."
157 echo " options can be one or more of:"
158 echo " mrproper - big-clean the project, try's to uninstall previous version"
159 echo " rebuild - mrproper and rebuild from scratch"
160 echo " nobootstrap - don't use autotools, use existing configure"
161 echo " intree - do a build within the sourcetree *BAD!*"
162 echo " cd* - build into a subdir default: ./=build{-release|-debug}"
163 echo " chelp - shows ./configure --help, interactively asks for configure options"
164 echo " configure* - bootstraps the project including ./configure"
165 echo " make* - does a 'make' as well"
166 echo " check - additionally runs tests"
167 echo " install - installs project if checks are passed"
168 echo " clean - cleans up after building"
169 echo " uninstall - try to uninstall allready installed version before proceeding"
170 echo " dist - builds a distribution if all is sane"
171 echo " release - uses 'release' configuration"
172 echo " default: debug for check, release for install"
173 echo " help - this sceen"
174 echo " cd, configure and make can be quoted and appended with options"
175 echo " example:"
176 echo " bootstrap rebuild 'cd build' 'configure --with-x' 'make -j4' dist"
177 exit 0
179 esac
180 done
182 #set some vars to defaults
183 if test ! "$build_opt"; then
184 build_opt="$DEF_BUILDOPT"
187 if test ! "$CONFIGUREFLAGS"; then
188 if test $do_release = true; then
189 CONFIGUREFLAGS="$DEF_CONFIGUREFLAGS_RELEASE $EXTRA_CONFIGUREFLAGS"
190 else
191 CONFIGUREFLAGS="$DEF_CONFIGUREFLAGS_DEBUG $EXTRA_CONFIGUREFLAGS"
193 export CONFIGUREFLAGS
196 if test ! "$CFLAGS"; then
197 if test $do_release = true; then
198 CFLAGS="$DEF_CFLAGS_RELEASE $EXTRA_CFLAGS"
199 dir_opt="${dir_opt}.release"
200 else
201 CFLAGS="$DEF_CFLAGS_DEBUG $EXTRA_CFLAGS"
202 dir_opt="${dir_opt}.debug"
204 export CFLAGS
206 if test ! "$CC"; then
207 CC="$DEF_CC"
208 export CC
211 # lets go
213 #first of all we install ourself
214 if test ! -f "$base_dir/bootstrap.sh"; then
215 echo "installing ./bootstrap.sh .."
216 cp -a "$0" "$base_dir/bootstrap.sh"
219 if test $do_nobootstrap = false; then
221 # old compatibilitry check?
222 configure_ac_name='configure.ac'
223 if test -f 'configure.in'; then
224 echo "using obsolete configure.in.."
225 configure_ac_name='configure.in'
228 #we need to go into the build dir for deinstalling and mrproper
229 if test $do_dir = true; then
230 test -d $dir_opt && cd $dir_opt
233 # uninstall old version?
234 if test $do_uninstall = true; then
235 if test -f 'Makefile'; then
236 echo "uninstalling.."
237 $MAKE uninstall
241 # check if we want a really clean mrproper
242 if test $do_mrproper = true; then
243 echo "mrproper.."
244 if test -f 'Makefile'; then
245 $MAKE maintainer-clean
247 cd $base_dir
248 rm -f config.* configure Makefile Makefile.in
249 test -d "$dir_opt" && chmod -R u+w "$dir_opt" && rm -rf $dir_opt
250 test -f $configure_ac_name && touch $configure_ac_name
252 cd $base_dir
254 # enough?
255 if test $do_stop = true; then
256 echo "..stopped"
257 exit 0
260 # do we need to make configure.ac
261 if test ! -f $configure_ac_name; then
262 echo "generating configure.ac.."
263 $AUTOSCAN
264 echo "dnl Note from bootstrap:" >$configure_ac_name
265 echo "dnl this scan is not yet configured for automake" >>$configure_ac_name
266 echo "dnl add at least the following macros" >>$configure_ac_name
267 echo "dnl AM_INIT_AUTOMAKE( name , version )" >>$configure_ac_name
268 echo "dnl AM_CONFIG_HEADER([config.h])" >>$configure_ac_name
269 echo "dnl and don't forget to insert Makefile in AC_CONFIG_FILES()" >>$configure_ac_name
270 echo "dnl end_of_note" >>$configure_ac_name
271 cat configure.scan >>$configure_ac_name
272 rm configure.scan
273 echo "Please edit $configure_ac_name hit Ctrl-D when finished"
275 if test ! -f $configure_ac_name; then
276 echo "can't continue"
277 exit 1
281 # do we need to make Makefile.am
282 if test ! -f 'Makefile.am'; then
283 echo "## Makefile.am" >Makefile.am
284 echo "" >>Makefile.am
285 echo "##end" >>Makefile.am
286 echo "Please edit 'Makefile.am' hit Ctrl-D when finished"
288 if test ! -f 'Makefile.am'; then
289 echo "can't continue"
290 exit 1
294 # generating aclocal.m4
295 if test $configure_ac_name -nt 'aclocal.m4'; then
296 echo "aclocal.."
297 $ACLOCAL
300 #run autoconf?
301 if test $configure_ac_name -nt 'configure'; then
302 echo "autoconf.."
303 $AUTOCONF
306 #run autoheader?
307 if grep '^AM_CONFIG_HEADER' $configure_ac_name >/dev/null && test $configure_ac_name -nt 'config.h.in'; then
308 echo "autoheader.."
309 $AUTOHEADER
310 touch config.h.in
314 #run automake?
315 if test 'Makefile.am' -nt 'Makefile.in'; then
316 echo "automake.."
317 test -f NEWS || echo "write me" >NEWS
318 test -f README || echo "write me" >README
319 test -f AUTHORS || echo "write me" >AUTHORS
320 test -f ChangeLog || echo "write me" >ChangeLog
321 $AUTOMAKE -a -c --gnu
324 #nobootstrap end
327 #cd?
328 if test $do_dir = true; then
329 test -d $dir_opt || mkdir -p "$dir_opt"
330 cd $dir_opt
333 #configure help?
334 if test $do_chelp = true; then
335 echo "configure help.."
336 $base_dir/configure --help
337 echo "Please enter configure options and hit [return]:"
338 read configure_new
339 configure_opt="$configure_opt $configure_new"
340 touch $base_dir/configure
343 #configure?
344 if test $do_configure = true; then
345 if test "$base_dir/configure" -nt 'Makefile'; then
346 echo "configure.."
347 $base_dir/configure $CONFIGUREFLAGS $configure_opt
351 #build?
352 if test $do_build = true; then
353 echo "building.."
354 $MAKE $build_opt
357 #check?
358 if test $do_check = true; then
359 echo "testing.."
360 $MAKE $build_opt check || {
361 err=$?
362 echo ".. test failed!"
363 exit $err
367 #install?
368 if test $do_install = true; then
369 echo "installing.."
370 $MAKE install-strip
373 #clean?
374 if test $do_clean = true; then
375 echo "cleaning.."
376 $MAKE clean
379 #dist?
380 if test $do_dist = true; then
381 echo "make distribution.."
382 $MAKE distcheck && $MAKE distclean && $MAKE dist
385 #cd back
386 cd $base_dir
388 echo ".. finished! $(date +%H:%M:%S)"
390 # arch-tag: 0b599c55-a968-4c54-bb41-c0ba6472f0df
391 #end