omit args/newline printing if there are none
[mala.git] / bootstrap.sh
blobd8baf745e7cf400f3b9c43df8241047706d9580d
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 AUTOCONFVERSION='2.50'
50 AUTOMAKEVERSION='-1.9'
52 MAKE="$(chk_prg gmake make)"
53 AUTOSCAN="$(chk_prg autoscan$AUTOCONFVERSION autoscan)"
54 ACLOCAL="$(chk_prg aclocal$AUTOMAKEVERSION aclocal)"
55 AUTOCONF="$(chk_prg autoconf$AUTOCONFVERSION autoconf)"
56 AUTOHEADER="$(chk_prg autoheader$AUTOCONFVERSION autoheader)"
57 AUTOMAKE="$(chk_prg automake$AUTOMAKEVERSION)"
60 #commandline parser (needs to be done better / options etc)
61 do_mrproper=false
62 do_release=false
63 do_nobootstrap=false
64 do_stop=false
65 do_configure=false
66 do_chelp=false
67 do_build=false
68 do_check=false
69 do_install=false
70 do_clean=false
71 do_uninstall=false
72 do_dist=false
73 do_dir=true
74 dir_opt="$DEF_BUILDDIR"
75 base_dir=`pwd`
77 for i in "$@"; do
78 case $i in
79 mrproper|distclean)
80 do_mrproper=true
81 do_uninstall=true
82 do_stop=true
84 rebuild)
85 do_mrproper=true
86 do_uninstall=true
87 do_stop=false
89 nobootstrap)
90 do_nobootstrap=true
92 chelp)
93 do_chelp=true
94 do_stop=false
96 configure*)
97 configure_opt=${i#configure}
98 do_configure=true
99 do_stop=false
101 make*)
102 build_opt=${i#make}
103 do_build=true
104 do_configure=true
105 do_stop=false
107 nocd|intree)
108 do_dir=false
110 cd*)
111 dir_opt=${i#cd}
112 dir_opt="${dir_opt:-$DEF_BUILDDIR}"
113 do_dir=true
115 check|test)
116 do_check=true
117 do_configure=true
118 do_stop=false
120 install)
121 do_release=true
122 do_install=true
123 do_check=true
124 do_configure=true
125 do_uninstall=true
126 do_stop=false
128 clean)
129 do_clean=true
130 do_stop=false
132 uninstall)
133 do_uninstall=true
134 do_stop=false
136 dist)
137 do_release=true
138 do_dist=true
139 do_configure=true
140 do_clean=true
141 do_stop=false
143 release)
144 do_release=true
146 help*|-h*)
147 echo "bootstrap a GNU-Autotools Project"
148 echo "usage: bootstrap options..."
149 echo " options can be one or more of:"
150 echo " mrproper - big-clean the project, try's to uninstall previous version"
151 echo " rebuild - mrproper and rebuild from scratch"
152 echo " nobootstrap - don't use autotools, use existing configure"
153 echo " intree - do a build within the sourcetree *BAD!*"
154 echo " cd* - build into a subdir default: ./=build{-release|-debug}"
155 echo " chelp - shows ./configure --help, interactively asks for configure options"
156 echo " configure* - bootstraps the project including ./configure"
157 echo " make* - does a 'make' as well"
158 echo " check - additionally runs tests"
159 echo " install - installs project if checks are passed"
160 echo " clean - cleans up after building"
161 echo " uninstall - try to uninstall allready installed version before proceeding"
162 echo " dist - builds a distribution if all is sane"
163 echo " release - uses 'release' configuration"
164 echo " default: debug for check, release for install"
165 echo " help - this sceen"
166 echo " cd, configure and make can be quoted and appended with options"
167 echo " example:"
168 echo " bootstrap rebuild 'cd build' 'configure --with-x' 'make -j4' dist"
169 exit 0
171 esac
172 done
174 #set some vars to defaults
175 if test ! "$build_opt"; then
176 build_opt="$DEF_BUILDOPT"
179 if test ! "$CFLAGS"; then
180 if test $do_release = true; then
181 CFLAGS="$DEF_CFLAGS_RELEASE $EXTRA_CFLAGS"
182 dir_opt="${dir_opt}.release"
183 else
184 CFLAGS="$DEF_CFLAGS_DEBUG $EXTRA_CFLAGS"
185 dir_opt="${dir_opt}.debug"
187 export CFLAGS
189 if test ! "$CC"; then
190 CC="$DEF_CC"
191 export CC
194 # lets go
196 #first of all we install ourself
197 if test ! -f "$base_dir/bootstrap.sh"; then
198 echo "installing ./bootstrap.sh .."
199 cp -a "$0" "$base_dir/bootstrap.sh"
202 if test $do_nobootstrap = false; then
204 # old compatibilitry check?
205 configure_ac_name='configure.ac'
206 if test -f 'configure.in'; then
207 echo "using obsolete configure.in.."
208 configure_ac_name='configure.in'
211 #we need to go into the build dir for deinstalling and mrproper
212 if test $do_dir = true; then
213 test -d $dir_opt && cd $dir_opt
216 # uninstall old version?
217 if test $do_uninstall = true; then
218 if test -f 'Makefile'; then
219 echo "uninstalling.."
220 $MAKE uninstall
224 # check if we want a really clean mrproper
225 if test $do_mrproper = true; then
226 echo "mrproper.."
227 if test -f 'Makefile'; then
228 $MAKE maintainer-clean
230 cd $base_dir
231 rm -f config.* configure Makefile Makefile.in
232 test -d "$dir_opt" && chmod -R u+w "$dir_opt" && rm -rf $dir_opt
233 test -f $configure_ac_name && touch $configure_ac_name
235 cd $base_dir
237 # enough?
238 if test $do_stop = true; then
239 echo "..stopped"
240 exit 0
243 # do we need to make configure.ac
244 if test ! -f $configure_ac_name; then
245 echo "generating configure.ac.."
246 $AUTOSCAN
247 echo "dnl Note from bootstrap:" >$configure_ac_name
248 echo "dnl this scan is not yet configured for automake" >>$configure_ac_name
249 echo "dnl add at least the following macros" >>$configure_ac_name
250 echo "dnl AM_INIT_AUTOMAKE( name , version )" >>$configure_ac_name
251 echo "dnl AM_CONFIG_HEADER([config.h])" >>$configure_ac_name
252 echo "dnl and don't forget to insert Makefile in AC_CONFIG_FILES()" >>$configure_ac_name
253 echo "dnl end_of_note" >>$configure_ac_name
254 cat configure.scan >>$configure_ac_name
255 rm configure.scan
256 echo "Please edit $configure_ac_name hit Ctrl-D when finished"
258 if test ! -f $configure_ac_name; then
259 echo "can't continue"
260 exit 1
264 # do we need to make Makefile.am
265 if test ! -f 'Makefile.am'; then
266 echo "## Makefile.am" >Makefile.am
267 echo "" >>Makefile.am
268 echo "##end" >>Makefile.am
269 echo "Please edit 'Makefile.am' hit Ctrl-D when finished"
271 if test ! -f 'Makefile.am'; then
272 echo "can't continue"
273 exit 1
277 # generating aclocal.m4
278 if test $configure_ac_name -nt 'aclocal.m4'; then
279 echo "aclocal.."
280 $ACLOCAL
283 #run autoconf?
284 if test $configure_ac_name -nt 'configure'; then
285 echo "autoconf.."
286 $AUTOCONF
289 #run autoheader?
290 if grep '^AM_CONFIG_HEADER' $configure_ac_name >/dev/null && test $configure_ac_name -nt 'config.h.in'; then
291 echo "autoheader.."
292 $AUTOHEADER
293 touch config.h.in
297 #run automake?
298 if test 'Makefile.am' -nt 'Makefile.in'; then
299 echo "automake.."
300 test -f NEWS || echo "write me" >NEWS
301 test -f README || echo "write me" >README
302 test -f AUTHORS || echo "write me" >AUTHORS
303 test -f ChangeLog || echo "write me" >ChangeLog
304 $AUTOMAKE -a -c --gnu
307 #nobootstrap end
310 #cd?
311 if test $do_dir = true; then
312 test -d $dir_opt || mkdir -p "$dir_opt"
313 cd $dir_opt
316 #configure help?
317 if test $do_chelp = true; then
318 echo "configure help.."
319 $base_dir/configure --help
320 echo "Please enter configure options and hit [return]:"
321 read configure_new
322 configure_opt="$configure_opt $configure_new"
323 touch $base_dir/configure
326 #configure?
327 if test $do_configure = true; then
328 if test "$base_dir/configure" -nt 'Makefile'; then
329 echo "configure.."
330 $base_dir/configure $configure_opt
334 #build?
335 if test $do_build = true; then
336 echo "building.."
337 $MAKE $build_opt
340 #check?
341 if test $do_check = true; then
342 echo "testing.."
343 $MAKE $build_opt check || {
344 err=$?
345 echo ".. test failed!"
346 exit $err
350 #install?
351 if test $do_install = true; then
352 echo "installing.."
353 $MAKE install-strip
356 #clean?
357 if test $do_clean = true; then
358 echo "cleaning.."
359 $MAKE clean
362 #dist?
363 if test $do_dist = true; then
364 echo "make distribution.."
365 $MAKE distcheck && $MAKE distclean && $MAKE dist
368 #cd back
369 cd $base_dir
371 echo ".. finished!"
373 # arch-tag: 0b599c55-a968-4c54-bb41-c0ba6472f0df
374 #end