weakref fix
[acogc.git] / bootstrap.sh
blobf49025bbbca4bf0067c8b0a1cd0a7382848c982f
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 -DEBUG_ALPHA'
45 #DEF_CFLAGS_RELEASE='-DNDEBUG -O3 -W -Wall -Werror -std=gnu99'
46 DEF_CFLAGS_RELEASE='-O3 -W -Wall -Werror -std=gnu99'
47 DEF_CC="nice $(chk_prg ccache "") $(chk_prg distcc "") $(chk_prg gcc-3.4 gcc cc)"
49 #default programs (probably no need for configuration)
50 AUTOCONFVERSION='2.50'
51 AUTOMAKEVERSION='-1.9'
53 MAKE="$(chk_prg gmake make)"
54 AUTOSCAN="$(chk_prg autoscan$AUTOCONFVERSION autoscan)"
55 ACLOCAL="$(chk_prg aclocal$AUTOMAKEVERSION aclocal)"
56 AUTOCONF="$(chk_prg autoconf$AUTOCONFVERSION autoconf)"
57 AUTOHEADER="$(chk_prg autoheader$AUTOCONFVERSION autoheader)"
58 AUTOMAKE="$(chk_prg automake$AUTOMAKEVERSION)"
61 #commandline parser (needs to be done better / options etc)
62 do_mrproper=false
63 do_release=false
64 do_nobootstrap=false
65 do_stop=false
66 do_configure=false
67 do_chelp=false
68 do_build=false
69 do_check=false
70 do_install=false
71 do_clean=false
72 do_uninstall=false
73 do_dist=false
74 do_dir=true
75 dir_opt="$DEF_BUILDDIR"
76 base_dir=`pwd`
78 for i in "$@"; do
79 case $i in
80 mrproper|distclean)
81 do_mrproper=true
82 do_uninstall=true
83 do_stop=true
85 rebuild)
86 do_mrproper=true
87 do_uninstall=true
88 do_stop=false
90 nobootstrap)
91 do_nobootstrap=true
93 chelp)
94 do_chelp=true
95 do_stop=false
97 configure*)
98 configure_opt=${i#configure}
99 do_configure=true
100 do_stop=false
102 make*)
103 build_opt=${i#make}
104 do_build=true
105 do_configure=true
106 do_stop=false
108 build*)
109 build_opt=${i#build}
110 do_build=true
111 do_configure=true
112 do_stop=false
114 nocd|intree)
115 do_dir=false
117 cd*)
118 dir_opt=${i#cd}
119 dir_opt="${dir_opt:-$DEF_BUILDDIR}"
120 do_dir=true
122 check|test)
123 do_check=true
124 do_configure=true
125 do_stop=false
127 install)
128 do_release=true
129 do_install=true
130 do_check=true
131 do_configure=true
132 do_uninstall=true
133 do_stop=false
135 clean)
136 do_clean=true
137 do_stop=false
139 uninstall)
140 do_uninstall=true
141 do_stop=false
143 dist)
144 do_release=true
145 do_dist=true
146 do_configure=true
147 do_clean=true
148 do_stop=false
150 release)
151 do_release=true
153 help*|-h*)
154 echo "bootstrap a GNU-Autotools Project"
155 echo "usage: bootstrap options..."
156 echo " options can be one or more of:"
157 echo " mrproper - big-clean the project, try's to uninstall previous version"
158 echo " rebuild - mrproper and rebuild from scratch"
159 echo " nobootstrap - don't use autotools, use existing configure"
160 echo " intree - do a build within the sourcetree *BAD!*"
161 echo " cd* - build into a subdir default: ./=build{-release|-debug}"
162 echo " chelp - shows ./configure --help, interactively asks for configure options"
163 echo " configure* - bootstraps the project including ./configure"
164 echo " make* - does a 'make' as well"
165 echo " check - additionally runs tests"
166 echo " install - installs project if checks are passed"
167 echo " clean - cleans up after building"
168 echo " uninstall - try to uninstall allready installed version before proceeding"
169 echo " dist - builds a distribution if all is sane"
170 echo " release - uses 'release' configuration"
171 echo " default: debug for check, release for install"
172 echo " help - this sceen"
173 echo " cd, configure and make can be quoted and appended with options"
174 echo " example:"
175 echo " bootstrap rebuild 'cd build' 'configure --with-x' 'make -j4' dist"
176 exit 0
178 esac
179 done
181 #set some vars to defaults
182 if test ! "$build_opt"; then
183 build_opt="$DEF_BUILDOPT"
186 if test ! "$CFLAGS"; then
187 if test $do_release = true; then
188 CFLAGS="$DEF_CFLAGS_RELEASE $EXTRA_CFLAGS"
189 dir_opt="${dir_opt}.release"
190 else
191 CFLAGS="$DEF_CFLAGS_DEBUG $EXTRA_CFLAGS"
192 dir_opt="${dir_opt}.debug"
194 export CFLAGS
196 if test ! "$CC"; then
197 CC="$DEF_CC"
198 export CC
201 # lets go
203 #first of all we install ourself
204 if test ! -f "$base_dir/bootstrap.sh"; then
205 echo "installing ./bootstrap.sh .."
206 cp -a "$0" "$base_dir/bootstrap.sh"
209 if test $do_nobootstrap = false; then
211 # old compatibilitry check?
212 configure_ac_name='configure.ac'
213 if test -f 'configure.in'; then
214 echo "using obsolete configure.in.."
215 configure_ac_name='configure.in'
218 #we need to go into the build dir for deinstalling and mrproper
219 if test $do_dir = true; then
220 test -d $dir_opt && cd $dir_opt
223 # uninstall old version?
224 if test $do_uninstall = true; then
225 if test -f 'Makefile'; then
226 echo "uninstalling.."
227 $MAKE uninstall
231 # check if we want a really clean mrproper
232 if test $do_mrproper = true; then
233 echo "mrproper.."
234 if test -f 'Makefile'; then
235 $MAKE maintainer-clean
237 cd $base_dir
238 rm -f config.* configure Makefile Makefile.in
239 test -d "$dir_opt" && chmod -R u+w "$dir_opt" && rm -rf $dir_opt
240 test -f $configure_ac_name && touch $configure_ac_name
242 cd $base_dir
244 # enough?
245 if test $do_stop = true; then
246 echo "..stopped"
247 exit 0
250 # do we need to make configure.ac
251 if test ! -f $configure_ac_name; then
252 echo "generating configure.ac.."
253 $AUTOSCAN
254 echo "dnl Note from bootstrap:" >$configure_ac_name
255 echo "dnl this scan is not yet configured for automake" >>$configure_ac_name
256 echo "dnl add at least the following macros" >>$configure_ac_name
257 echo "dnl AM_INIT_AUTOMAKE( name , version )" >>$configure_ac_name
258 echo "dnl AM_CONFIG_HEADER([config.h])" >>$configure_ac_name
259 echo "dnl and don't forget to insert Makefile in AC_CONFIG_FILES()" >>$configure_ac_name
260 echo "dnl end_of_note" >>$configure_ac_name
261 cat configure.scan >>$configure_ac_name
262 rm configure.scan
263 echo "Please edit $configure_ac_name hit Ctrl-D when finished"
265 if test ! -f $configure_ac_name; then
266 echo "can't continue"
267 exit 1
271 # do we need to make Makefile.am
272 if test ! -f 'Makefile.am'; then
273 echo "## Makefile.am" >Makefile.am
274 echo "" >>Makefile.am
275 echo "##end" >>Makefile.am
276 echo "Please edit 'Makefile.am' hit Ctrl-D when finished"
278 if test ! -f 'Makefile.am'; then
279 echo "can't continue"
280 exit 1
284 # generating aclocal.m4
285 if test $configure_ac_name -nt 'aclocal.m4'; then
286 echo "aclocal.."
287 $ACLOCAL
290 #run autoconf?
291 if test $configure_ac_name -nt 'configure'; then
292 echo "autoconf.."
293 $AUTOCONF
296 #run autoheader?
297 if grep '^AM_CONFIG_HEADER' $configure_ac_name >/dev/null && test $configure_ac_name -nt 'config.h.in'; then
298 echo "autoheader.."
299 $AUTOHEADER
300 touch config.h.in
304 #run automake?
305 if test 'Makefile.am' -nt 'Makefile.in'; then
306 echo "automake.."
307 test -f NEWS || echo "write me" >NEWS
308 test -f README || echo "write me" >README
309 test -f AUTHORS || echo "write me" >AUTHORS
310 test -f ChangeLog || echo "write me" >ChangeLog
311 $AUTOMAKE -a -c --gnu
314 #nobootstrap end
317 #cd?
318 if test $do_dir = true; then
319 test -d $dir_opt || mkdir -p "$dir_opt"
320 cd $dir_opt
323 #configure help?
324 if test $do_chelp = true; then
325 echo "configure help.."
326 $base_dir/configure --help
327 echo "Please enter configure options and hit [return]:"
328 read configure_new
329 configure_opt="$configure_opt $configure_new"
330 touch $base_dir/configure
333 #configure?
334 if test $do_configure = true; then
335 if test "$base_dir/configure" -nt 'Makefile'; then
336 echo "configure.."
337 $base_dir/configure $configure_opt
341 #build?
342 if test $do_build = true; then
343 echo "building.."
344 $MAKE $build_opt
347 #check?
348 if test $do_check = true; then
349 echo "testing.."
350 $MAKE $build_opt check || {
351 err=$?
352 echo ".. test failed!"
353 exit $err
357 #install?
358 if test $do_install = true; then
359 echo "installing.."
360 $MAKE install-strip
363 #clean?
364 if test $do_clean = true; then
365 echo "cleaning.."
366 $MAKE clean
369 #dist?
370 if test $do_dist = true; then
371 echo "make distribution.."
372 $MAKE distcheck && $MAKE distclean && $MAKE dist
375 #cd back
376 cd $base_dir
378 echo ".. finished! $(date +%H:%M:%S)"
380 # arch-tag: 0b599c55-a968-4c54-bb41-c0ba6472f0df
381 #end