exception fix
[mala.git] / bootstrap.sh
blobfad67a6e2b1ea534fe37932cd00348d4e10eefb6
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='-DNDEBUG -O3 -W -Wall -Werror -std=gnu99'
46 DEF_CC="nice $(chk_prg ccache "") $(chk_prg distcc "") $(chk_prg gcc-3.4 gcc cc)"
48 #default programs (probably no need for configuration)
49 MAKE="$(chk_prg gmake make)"
50 AUTOSCAN="$(chk_prg autoscan)"
51 ACLOCAL="$(chk_prg aclocal)"
52 AUTOCONF="$(chk_prg autoconf)"
53 AUTOHEADER="$(chk_prg autoheader)"
54 AUTOMAKE="$(chk_prg automake)"
57 #commandline parser (needs to be done better / options etc)
58 do_mrproper=false
59 do_release=false
60 do_nobootstrap=false
61 do_stop=false
62 do_configure=false
63 do_chelp=false
64 do_build=false
65 do_check=false
66 do_install=false
67 do_clean=false
68 do_uninstall=false
69 do_dist=false
70 do_dir=true
71 dir_opt="$DEF_BUILDDIR"
72 base_dir=`pwd`
74 for i in "$@"; do
75 case $i in
76 mrproper|distclean)
77 do_mrproper=true
78 do_uninstall=true
79 do_stop=true
81 rebuild)
82 do_mrproper=true
83 do_uninstall=true
84 do_stop=false
86 nobootstrap)
87 do_nobootstrap=true
89 chelp)
90 do_chelp=true
91 do_stop=false
93 configure*)
94 configure_opt=${i#configure}
95 do_configure=true
96 do_stop=false
98 make*)
99 build_opt=${i#make}
100 do_build=true
101 do_configure=true
102 do_stop=false
104 nocd|intree)
105 do_dir=false
107 cd*)
108 dir_opt=${i#cd}
109 dir_opt="${dir_opt:-$DEF_BUILDDIR}"
110 do_dir=true
112 check|test)
113 do_check=true
114 do_configure=true
115 do_stop=false
117 install)
118 do_release=true
119 do_install=true
120 do_check=true
121 do_configure=true
122 do_uninstall=true
123 do_stop=false
125 clean)
126 do_clean=true
127 do_stop=false
129 uninstall)
130 do_uninstall=true
131 do_stop=false
133 dist)
134 do_release=true
135 do_dist=true
136 do_configure=true
137 do_clean=true
138 do_stop=false
140 release)
141 do_release=true
143 help*|-h*)
144 echo "bootstrap a GNU-Autotools Project"
145 echo "usage: bootstrap options..."
146 echo " options can be one or more of:"
147 echo " mrproper - big-clean the project, try's to uninstall previous version"
148 echo " rebuild - mrproper and rebuild from scratch"
149 echo " nobootstrap - don't use autotools, use existing configure"
150 echo " intree - do a build within the sourcetree *BAD!*"
151 echo " cd* - build into a subdir default: ./=build{-release|-debug}"
152 echo " chelp - shows ./configure --help, interactively asks for configure options"
153 echo " configure* - bootstraps the project including ./configure"
154 echo " make* - does a 'make' as well"
155 echo " check - additionally runs tests"
156 echo " install - installs project if checks are passed"
157 echo " clean - cleans up after building"
158 echo " uninstall - try to uninstall allready installed version before proceeding"
159 echo " dist - builds a distribution if all is sane"
160 echo " release - uses 'release' configuration"
161 echo " default: debug for check, release for install"
162 echo " help - this sceen"
163 echo " cd, configure and make can be quoted and appended with options"
164 echo " example:"
165 echo " bootstrap rebuild 'cd build' 'configure --with-x' 'make -j4' dist"
166 exit 0
168 esac
169 done
171 #set some vars to defaults
172 if test ! "$build_opt"; then
173 build_opt="$DEF_BUILDOPT"
176 if test ! "$CFLAGS"; then
177 if test $do_release = true; then
178 CFLAGS="$DEF_CFLAGS_RELEASE $EXTRA_CFLAGS"
179 dir_opt="${dir_opt}.release"
180 else
181 CFLAGS="$DEF_CFLAGS_DEBUG $EXTRA_CFLAGS"
182 dir_opt="${dir_opt}.debug"
184 export CFLAGS
186 if test ! "$CC"; then
187 CC="$DEF_CC"
188 export CC
191 # lets go
193 #first of all we install ourself
194 if test ! -f "$base_dir/bootstrap.sh"; then
195 echo "installing ./bootstrap.sh .."
196 cp -a "$0" "$base_dir/bootstrap.sh"
199 if test $do_nobootstrap = false; then
201 # old compatibilitry check?
202 configure_ac_name='configure.ac'
203 if test -f 'configure.in'; then
204 echo "using obsolete configure.in.."
205 configure_ac_name='configure.in'
208 #we need to go into the build dir for deinstalling and mrproper
209 if test $do_dir = true; then
210 test -d $dir_opt && cd $dir_opt
213 # uninstall old version?
214 if test $do_uninstall = true; then
215 if test -f 'Makefile'; then
216 echo "uninstalling.."
217 $MAKE uninstall
221 # check if we want a really clean mrproper
222 if test $do_mrproper = true; then
223 echo "mrproper.."
224 if test -f 'Makefile'; then
225 $MAKE maintainer-clean
227 cd $base_dir
228 rm -f config.* configure Makefile Makefile.in
229 test -d "$dir_opt" && chmod -R u+w "$dir_opt" && rm -rf $dir_opt
230 test -f $configure_ac_name && touch $configure_ac_name
232 cd $base_dir
234 # enough?
235 if test $do_stop = true; then
236 echo "..stopped"
237 exit 0
240 # do we need to make configure.ac
241 if test ! -f $configure_ac_name; then
242 echo "generating configure.ac.."
243 $AUTOSCAN
244 echo "dnl Note from bootstrap:" >$configure_ac_name
245 echo "dnl this scan is not yet configured for automake" >>$configure_ac_name
246 echo "dnl add at least the following macros" >>$configure_ac_name
247 echo "dnl AM_INIT_AUTOMAKE( name , version )" >>$configure_ac_name
248 echo "dnl AM_CONFIG_HEADER([config.h])" >>$configure_ac_name
249 echo "dnl and don't forget to insert Makefile in AC_CONFIG_FILES()" >>$configure_ac_name
250 echo "dnl end_of_note" >>$configure_ac_name
251 cat configure.scan >>$configure_ac_name
252 rm configure.scan
253 echo "Please edit $configure_ac_name hit Ctrl-D when finished"
255 if test ! -f $configure_ac_name; then
256 echo "can't continue"
257 exit 1
261 # do we need to make Makefile.am
262 if test ! -f 'Makefile.am'; then
263 echo "## Makefile.am" >Makefile.am
264 echo "" >>Makefile.am
265 echo "##end" >>Makefile.am
266 echo "Please edit 'Makefile.am' hit Ctrl-D when finished"
268 if test ! -f 'Makefile.am'; then
269 echo "can't continue"
270 exit 1
274 # generating aclocal.m4
275 if test $configure_ac_name -nt 'aclocal.m4'; then
276 echo "aclocal.."
277 $ACLOCAL
280 #run autoconf?
281 if test $configure_ac_name -nt 'configure'; then
282 echo "autoconf.."
283 $AUTOCONF
286 #run autoheader?
287 if grep '^AM_CONFIG_HEADER' $configure_ac_name >/dev/null && test $configure_ac_name -nt 'config.h.in'; then
288 echo "autoheader.."
289 $AUTOHEADER
290 touch config.h.in
294 #run automake?
295 if test 'Makefile.am' -nt 'Makefile.in'; then
296 echo "automake.."
297 test -f NEWS || echo "write me" >NEWS
298 test -f README || echo "write me" >README
299 test -f AUTHORS || echo "write me" >AUTHORS
300 test -f ChangeLog || echo "write me" >ChangeLog
301 $AUTOMAKE -a -c --gnu
304 #nobootstrap end
307 #cd?
308 if test $do_dir = true; then
309 test -d $dir_opt || mkdir -p "$dir_opt"
310 cd $dir_opt
313 #configure help?
314 if test $do_chelp = true; then
315 echo "configure help.."
316 $base_dir/configure --help
317 echo "Please enter configure options and hit [return]:"
318 read configure_new
319 configure_opt="$configure_opt $configure_new"
320 touch $base_dir/configure
323 #configure?
324 if test $do_configure = true; then
325 if test "$base_dir/configure" -nt 'Makefile'; then
326 echo "configure.."
327 $base_dir/configure $configure_opt
331 #build?
332 if test $do_build = true; then
333 echo "building.."
334 $MAKE $build_opt
337 #check?
338 if test $do_check = true; then
339 echo "testing.."
340 $MAKE $build_opt check
343 #install?
344 if test $do_install = true; then
345 echo "installing.."
346 $MAKE install-strip
349 #clean?
350 if test $do_clean = true; then
351 echo "cleaning.."
352 $MAKE clean
355 #dist?
356 if test $do_dist = true; then
357 echo "make distribution.."
358 $MAKE distcheck && $MAKE distclean && $MAKE dist
361 #cd back
362 cd $base_dir
364 echo ".. finished!"
366 # arch-tag: 0b599c55-a968-4c54-bb41-c0ba6472f0df
367 #end