1#! /bin/sh
2
3# bootstrap: generic bootstrap/autogen.sh script for autotools projects
4#
5# Copyright (c) 2002-2011 Sam Hocevar <sam@hocevar.net>
6#
7#    This program is free software. It comes without any warranty, to
8#    the extent permitted by applicable law. You can redistribute it
9#    and/or modify it under the terms of the Do What the Fuck You Want
10#    to Public License, Version 2, as published by Sam Hocevar. See
11#    http://www.wtfpl.net/ for more details.
12#
13# The latest version of this script can be found at the following place:
14#    http://caca.zoy.org/wiki/build
15
16# Die if an error occurs
17set -e
18
19# Guess whether we are using configure.ac or configure.in
20if test -f configure.ac; then
21  conffile="configure.ac"
22elif test -f configure.in; then
23  conffile="configure.in"
24else
25  echo "$0: could not find configure.ac or configure.in"
26  exit 1
27fi
28
29# Check for needed features
30auxdir="`sed -ne 's/^[ \t]*A._CONFIG_AUX_DIR *([[ ]*\([^] )]*\).*/\1/p' $conffile`"
31pkgconfig="`grep '^[ \t]*PKG_PROG_PKG_CONFIG' $conffile >/dev/null 2>&1 && echo yes || echo no`"
32libtool="`grep '^[ \t]*A._PROG_LIBTOOL' $conffile >/dev/null 2>&1 && echo yes || echo no`"
33header="`grep '^[ \t]*A._CONFIG_HEADER' $conffile >/dev/null 2>&1 && echo yes || echo no`"
34makefile="`[ -f Makefile.am ] && echo yes || echo no`"
35aclocalflags="`sed -ne 's/^[ \t]*ACLOCAL_AMFLAGS[ \t]*=//p' Makefile.am 2>/dev/null || :`"
36
37# Check for automake
38amvers="no"
39v=5
40tries=0
41while : ; do
42  if automake-1.${v} --version >/dev/null 2>&1; then
43    amvers="-1.${v}"
44    tries=0
45  elif automake1.${v} --version >/dev/null 2>&1; then
46    amvers="1.${v}"
47    tries=0
48  fi
49  if [ "$tries" = 20 ]; then
50    break
51  fi
52  v="$((v + 1))"
53  tries="$((tries + 1))"
54done
55
56if test "${amvers}" = "no" && automake --version > /dev/null 2>&1; then
57  amvers="`automake --version | sed -e '1s/[^0-9]*//' -e q`"
58  if expr "$amvers" "<" "1.5" > /dev/null 2>&1; then
59    amvers="no"
60  else
61    amvers=""
62  fi
63fi
64
65if test "$amvers" = "no"; then
66  echo "$0: you need automake version 1.5 or later"
67  exit 1
68fi
69
70# Check for autoconf
71acvers="no"
72for v in "" "259" "253"; do
73  if autoconf${v} --version >/dev/null 2>&1; then
74    acvers="${v}"
75    break
76  fi
77done
78
79if test "$acvers" = "no"; then
80  echo "$0: you need autoconf"
81  exit 1
82fi
83
84# Check for libtool
85if test "$libtool" = "yes"; then
86  libtoolize="no"
87  if glibtoolize --version >/dev/null 2>&1; then
88    libtoolize="glibtoolize"
89  else
90    for v in "16" "15" "" "14"; do
91      if libtoolize${v} --version >/dev/null 2>&1; then
92        libtoolize="libtoolize${v}"
93        break
94      fi
95    done
96  fi
97
98  if test "$libtoolize" = "no"; then
99    echo "$0: you need libtool"
100    exit 1
101  fi
102fi
103
104# Check for pkg-config
105if test "$pkgconfig" = "yes"; then
106  if ! pkg-config --version >/dev/null 2>&1; then
107    echo "$0: you need pkg-config"
108    exit 1
109  fi
110fi
111
112# Remove old cruft
113for x in aclocal.m4 configure config.guess config.log config.sub config.cache config.h.in config.h compile libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 ltmain.sh libtool ltconfig missing mkinstalldirs depcomp install-sh; do rm -f $x autotools/$x; if test -n "$auxdir"; then rm -f "$auxdir/$x"; fi; done
114rm -Rf autom4te.cache
115if test -n "$auxdir"; then
116  if test ! -d "$auxdir"; then
117    mkdir "$auxdir"
118  fi
119  aclocalflags="${aclocalflags} -I $auxdir -I ."
120fi
121
122# Honour M4PATH because sometimes M4 doesn't
123save_IFS=$IFS
124IFS=:
125tmp="$M4PATH"
126for x in $tmp; do
127  if test -n "$x"; then
128    aclocalflags="${aclocalflags} -I $x"
129  fi
130done
131IFS=$save_IFS
132
133# Explain what we are doing from now
134set -x
135
136# Bootstrap package
137if test "$libtool" = "yes"; then
138  ${libtoolize} --copy --force
139  if test -n "$auxdir" -a ! "$auxdir" = "." -a -f "ltmain.sh"; then
140    echo "$0: working around a minor libtool issue"
141    mv ltmain.sh "$auxdir/"
142  fi
143fi
144
145aclocal${amvers} ${aclocalflags}
146autoconf${acvers}
147if test "$header" = "yes"; then
148  autoheader${acvers}
149fi
150if test "$makefile" = "yes"; then
151  #add --include-deps if you want to bootstrap with any other compiler than gcc
152  #automake${amvers} --add-missing --copy --include-deps
153  automake${amvers} --foreign --add-missing --copy
154fi
155
156# Remove cruft that we no longer want
157rm -Rf autom4te.cache
158
159