Blame


1 f4ade537 2001-12-11 alex #!/bin/sh
2 f4ade537 2001-12-11 alex #
3 507a9e9c 2004-03-11 alex # ngIRCd -- The Next Generation IRC Daemon
4 804c2403 2016-10-21 alex # Copyright (c)2001-2015 Alexander Barton (alex@barton.de) and Contributors
5 f4ade537 2001-12-11 alex #
6 507a9e9c 2004-03-11 alex # This program is free software; you can redistribute it and/or modify
7 507a9e9c 2004-03-11 alex # it under the terms of the GNU General Public License as published by
8 507a9e9c 2004-03-11 alex # the Free Software Foundation; either version 2 of the License, or
9 507a9e9c 2004-03-11 alex # (at your option) any later version.
10 507a9e9c 2004-03-11 alex # Please read the file COPYING, README and AUTHORS for more information.
11 507a9e9c 2004-03-11 alex #
12 b945726a 2008-06-27 alex # Usage:
13 b945726a 2008-06-27 alex # [VAR=<value>] ./autogen.sh [<configure-args>]
14 507a9e9c 2004-03-11 alex #
15 8212662d 2004-03-15 alex # This script generates the ./configure script using GNU automake and
16 8212662d 2004-03-15 alex # GNU autoconf. It tries to be smart in finding the correct/usable/available
17 8212662d 2004-03-15 alex # installed versions of these tools on your system.
18 8212662d 2004-03-15 alex #
19 8cfb9104 2012-09-24 alex # In addition, it enables or disables the "de-ANSI-fication" support of GNU
20 8cfb9104 2012-09-24 alex # automake, which is supported up to autoconf 1.11.x an has been removed
21 8cfb9104 2012-09-24 alex # in automake 1.12 -- make sure to use a version of automake supporting it
22 8cfb9104 2012-09-24 alex # when generating distribution archives!
23 8cfb9104 2012-09-24 alex #
24 8212662d 2004-03-15 alex # The following strategy is used for each of aclocal, autoheader, automake,
25 8212662d 2004-03-15 alex # and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
26 8212662d 2004-03-15 alex # or "automake") is checked. If this fails, "tool<major><minor>" (for example
27 8212662d 2004-03-15 alex # "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
28 8212662d 2004-03-15 alex # with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
29 8212662d 2004-03-15 alex # <minor> is tried from 99 to 0. The first occurrence will be used.
30 8212662d 2004-03-15 alex #
31 8212662d 2004-03-15 alex # When you pass <configure-args> to autogen.sh it will call the generated
32 8212662d 2004-03-15 alex # ./configure script on success and pass these parameters to it.
33 8212662d 2004-03-15 alex #
34 8212662d 2004-03-15 alex # You can tweak the behaviour using these environment variables:
35 8212662d 2004-03-15 alex #
36 f68e92eb 2004-04-05 alex # - ACLOCAL=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
37 8212662d 2004-03-15 alex # Name and optionally path to the particular tool.
38 8212662d 2004-03-15 alex # - PREFIX=<path>
39 8212662d 2004-03-15 alex # Search the GNU autoconf and GNU automake tools in <path> first. If the
40 8212662d 2004-03-15 alex # generated ./configure script will be called, pass "--prefix=<path>" to it.
41 f68e92eb 2004-04-05 alex # - EXIST=<tool>
42 f68e92eb 2004-04-05 alex # Use <tool> to test for aclocal, autoheader etc. pp. ...
43 f68e92eb 2004-04-05 alex # When not specified, either "type" or "which" is used.
44 8212662d 2004-03-15 alex # - VERBOSE=1
45 8212662d 2004-03-15 alex # Output the detected names of the GNU automake and GNU autoconf tools.
46 8212662d 2004-03-15 alex # - GO=1
47 8212662d 2004-03-15 alex # Call ./configure even if no arguments have been passed to autogen.sh.
48 8212662d 2004-03-15 alex #
49 8212662d 2004-03-15 alex # Examples:
50 8212662d 2004-03-15 alex #
51 8212662d 2004-03-15 alex # - ./autogen.sh
52 8212662d 2004-03-15 alex # Generates the ./configure script.
53 8212662d 2004-03-15 alex # - GO=1 ./autogen.sh
54 8212662d 2004-03-15 alex # Generates the ./configure script and runs it as "./configure".
55 8212662d 2004-03-15 alex # - VERBOSE=1 ./autogen.sh --with-ident
56 8212662d 2004-03-15 alex # Show tool names, generates the ./configure script, and runs it with
57 8212662d 2004-03-15 alex # these arguments: "./configure --with-ident".
58 8212662d 2004-03-15 alex # - ACLOCAL=aclocal-1.6 GO=1 PREFIX=$HOME ./autogen.sh
59 8212662d 2004-03-15 alex # Uses "aclocal-1.6" as aclocal tool, generates the ./configure script,
60 8212662d 2004-03-15 alex # and runs it with these arguments: "./configure --prefix=$HOME".
61 8212662d 2004-03-15 alex #
62 8212662d 2004-03-15 alex
63 507a9e9c 2004-03-11 alex Search()
64 507a9e9c 2004-03-11 alex {
65 507a9e9c 2004-03-11 alex [ $# -eq 2 ] || exit 1
66 507a9e9c 2004-03-11 alex
67 8212662d 2004-03-15 alex searchlist="$1"
68 507a9e9c 2004-03-11 alex major="$2"
69 507a9e9c 2004-03-11 alex minor=99
70 507a9e9c 2004-03-11 alex
71 0b1202cd 2004-03-19 alex [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
72 0b1202cd 2004-03-19 alex
73 8212662d 2004-03-15 alex for name in $searchlist; do
74 f68e92eb 2004-04-05 alex $EXIST "${name}" >/dev/null 2>&1
75 8212662d 2004-03-15 alex if [ $? -eq 0 ]; then
76 c891b5f2 2013-01-27 alex "${name}" --version 2>&1 \
77 c891b5f2 2013-01-27 alex | grep -v "environment variable" >/dev/null 2>&1
78 c891b5f2 2013-01-27 alex if [ $? -eq 0 ]; then
79 c891b5f2 2013-01-27 alex echo "${name}"
80 c891b5f2 2013-01-27 alex return 0
81 c891b5f2 2013-01-27 alex fi
82 8212662d 2004-03-15 alex fi
83 8212662d 2004-03-15 alex done
84 8212662d 2004-03-15 alex
85 507a9e9c 2004-03-11 alex while [ $minor -ge 0 ]; do
86 8212662d 2004-03-15 alex for name in $searchlist; do
87 f68e92eb 2004-04-05 alex $EXIST "${name}${major}${minor}" >/dev/null 2>&1
88 8212662d 2004-03-15 alex if [ $? -eq 0 ]; then
89 8212662d 2004-03-15 alex echo "${name}${major}${minor}"
90 8212662d 2004-03-15 alex return 0
91 8212662d 2004-03-15 alex fi
92 f68e92eb 2004-04-05 alex $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
93 8212662d 2004-03-15 alex if [ $? -eq 0 ]; then
94 972b07ff 2005-02-21 alex echo "${name}-${major}.${minor}"
95 8212662d 2004-03-15 alex return 0
96 8212662d 2004-03-15 alex fi
97 8212662d 2004-03-15 alex done
98 804c2403 2016-10-21 alex minor=$(expr $minor - 1)
99 507a9e9c 2004-03-11 alex done
100 507a9e9c 2004-03-11 alex return 1
101 507a9e9c 2004-03-11 alex }
102 507a9e9c 2004-03-11 alex
103 507a9e9c 2004-03-11 alex Notfound()
104 507a9e9c 2004-03-11 alex {
105 507a9e9c 2004-03-11 alex echo "Error: $* not found!"
106 507a9e9c 2004-03-11 alex echo "Please install recent versions of GNU autoconf and GNU automake."
107 507a9e9c 2004-03-11 alex exit 1
108 507a9e9c 2004-03-11 alex }
109 507a9e9c 2004-03-11 alex
110 107bfdc8 2012-09-16 alex Run()
111 107bfdc8 2012-09-16 alex {
112 c56138c2 2015-08-26 alex [ "$VERBOSE" = "1" ] && echo " - running \"$*\" ..."
113 c56138c2 2015-08-26 alex "$@"
114 107bfdc8 2012-09-16 alex }
115 107bfdc8 2012-09-16 alex
116 507a9e9c 2004-03-11 alex # Reset locale settings to suppress warning messages of Perl
117 507a9e9c 2004-03-11 alex unset LC_ALL
118 507a9e9c 2004-03-11 alex unset LANG
119 507a9e9c 2004-03-11 alex
120 f68e92eb 2004-04-05 alex # Which command should be used to detect the automake/autoconf tools?
121 f68e92eb 2004-04-05 alex [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
122 f68e92eb 2004-04-05 alex EXIST=""
123 f68e92eb 2004-04-05 alex for t in $existlist; do
124 f68e92eb 2004-04-05 alex $t /bin/ls >/dev/null 2>&1
125 f68e92eb 2004-04-05 alex if [ $? -eq 0 ]; then
126 f68e92eb 2004-04-05 alex rm -f /tmp/test.$$
127 f68e92eb 2004-04-05 alex $t /tmp/test.$$ >/dev/null 2>&1
128 f68e92eb 2004-04-05 alex [ $? -ne 0 ] && EXIST="$t"
129 f68e92eb 2004-04-05 alex fi
130 f68e92eb 2004-04-05 alex [ -n "$EXIST" ] && break
131 f68e92eb 2004-04-05 alex done
132 f68e92eb 2004-04-05 alex if [ -z "$EXIST" ]; then
133 f68e92eb 2004-04-05 alex echo "Didn't detect a working command to test for the autoconf/automake tools!"
134 f68e92eb 2004-04-05 alex echo "Searchlist: $existlist"
135 f68e92eb 2004-04-05 alex exit 1
136 f68e92eb 2004-04-05 alex fi
137 f68e92eb 2004-04-05 alex [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
138 f68e92eb 2004-04-05 alex
139 507a9e9c 2004-03-11 alex # Try to detect the needed tools when no environment variable already
140 77939c38 2007-10-07 alex # specifies one:
141 8cfb9104 2012-09-24 alex echo "Searching for required tools ..."
142 804c2403 2016-10-21 alex [ -z "$ACLOCAL" ] && ACLOCAL=$(Search aclocal 1)
143 107bfdc8 2012-09-16 alex [ "$VERBOSE" = "1" ] && echo " - ACLOCAL=$ACLOCAL"
144 804c2403 2016-10-21 alex [ -z "$AUTOHEADER" ] && AUTOHEADER=$(Search autoheader 2)
145 107bfdc8 2012-09-16 alex [ "$VERBOSE" = "1" ] && echo " - AUTOHEADER=$AUTOHEADER"
146 804c2403 2016-10-21 alex [ -z "$AUTOMAKE" ] && AUTOMAKE=$(Search automake 1)
147 107bfdc8 2012-09-16 alex [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE=$AUTOMAKE"
148 804c2403 2016-10-21 alex [ -z "$AUTOCONF" ] && AUTOCONF=$(Search autoconf 2)
149 107bfdc8 2012-09-16 alex [ "$VERBOSE" = "1" ] && echo " - AUTOCONF=$AUTOCONF"
150 f4ade537 2001-12-11 alex
151 804c2403 2016-10-21 alex AUTOCONF_VERSION=$(echo "$AUTOCONF" | cut -d'-' -f2-)
152 804c2403 2016-10-21 alex [ -n "$AUTOCONF_VERSION" ] && [ "$AUTOCONF_VERSION" != "autoconf" ] \
153 c891b5f2 2013-01-27 alex && export AUTOCONF_VERSION || unset AUTOCONF_VERSION
154 c891b5f2 2013-01-27 alex [ "$VERBOSE" = "1" ] && echo " - AUTOCONF_VERSION=$AUTOCONF_VERSION"
155 804c2403 2016-10-21 alex AUTOMAKE_VERSION=$(echo $AUTOMAKE | cut -d'-' -f2-)
156 804c2403 2016-10-21 alex [ -n "$AUTOMAKE_VERSION" ] && [ "$AUTOMAKE_VERSION" != "automake" ] \
157 c891b5f2 2013-01-27 alex && export AUTOMAKE_VERSION || unset AUTOMAKE_VERSION
158 c891b5f2 2013-01-27 alex [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE_VERSION=$AUTOMAKE_VERSION"
159 c891b5f2 2013-01-27 alex
160 c56138c2 2015-08-26 alex [ $# -gt 0 ] && CONFIGURE_ARGS=" $*" || CONFIGURE_ARGS=""
161 804c2403 2016-10-21 alex [ -z "$GO" ] && [ -n "$CONFIGURE_ARGS" ] && GO=1
162 507a9e9c 2004-03-11 alex
163 507a9e9c 2004-03-11 alex # Verify that all tools have been found
164 b945726a 2008-06-27 alex [ -z "$ACLOCAL" ] && Notfound aclocal
165 507a9e9c 2004-03-11 alex [ -z "$AUTOHEADER" ] && Notfound autoheader
166 507a9e9c 2004-03-11 alex [ -z "$AUTOMAKE" ] && Notfound automake
167 507a9e9c 2004-03-11 alex [ -z "$AUTOCONF" ] && Notfound autoconf
168 507a9e9c 2004-03-11 alex
169 804c2403 2016-10-21 alex AM_VERSION=$($AUTOMAKE --version | head -n 1 | sed -e 's/.* //g')
170 8cfb9104 2012-09-24 alex ifs=$IFS; IFS="."; set $AM_VERSION; IFS=$ifs
171 dd6d75d3 2016-12-05 alex AM_MAJOR="$1"; AM_MINOR="$2"
172 4594583f 2013-01-05 alex echo "Detected automake $AM_VERSION ..."
173 8cfb9104 2012-09-24 alex
174 8cfb9104 2012-09-24 alex AM_MAKEFILES="src/ipaddr/Makefile.ng src/ngircd/Makefile.ng src/testsuite/Makefile.ng src/tool/Makefile.ng"
175 8cfb9104 2012-09-24 alex
176 4594583f 2013-01-05 alex # De-ANSI-fication?
177 804c2403 2016-10-21 alex if [ "$AM_MAJOR" -eq "1" ] && [ "$AM_MINOR" -lt "12" ]; then
178 8cfb9104 2012-09-24 alex # automake < 1.12 => automatic de-ANSI-fication support available
179 4594583f 2013-01-05 alex echo " - Enabling de-ANSI-fication support."
180 e65a35e9 2012-09-24 alex sed -e "s|^__ng_PROTOTYPES__|AM_C_PROTOTYPES|g" configure.ng >configure.ac
181 8cfb9104 2012-09-24 alex DEANSI_START=""
182 8cfb9104 2012-09-24 alex DEANSI_END=""
183 8cfb9104 2012-09-24 alex else
184 8cfb9104 2012-09-24 alex # automake >= 1.12 => no de-ANSI-fication support available
185 4594583f 2013-01-05 alex echo " - Disabling de-ANSI-fication support."
186 e65a35e9 2012-09-24 alex sed -e "s|^__ng_PROTOTYPES__|AC_C_PROTOTYPES|g" configure.ng >configure.ac
187 8cfb9104 2012-09-24 alex DEANSI_START="#"
188 4594583f 2013-01-05 alex DEANSI_END=" (disabled by ./autogen.sh script)"
189 8cfb9104 2012-09-24 alex fi
190 0703fcd7 2013-01-05 alex # Serial test harness?
191 804c2403 2016-10-21 alex if [ "$AM_MAJOR" -eq "1" ] && [ "$AM_MINOR" -ge "13" ]; then
192 0703fcd7 2013-01-05 alex # automake >= 1.13 => enforce "serial test harness"
193 0703fcd7 2013-01-05 alex echo " - Enforcing serial test harness."
194 0703fcd7 2013-01-05 alex SERIAL_TESTS="serial-tests"
195 0703fcd7 2013-01-05 alex else
196 0703fcd7 2013-01-05 alex # automake < 1.13 => no new test harness, nothing to do
197 dd6d75d3 2016-12-05 alex # shellcheck disable=SC2034
198 0703fcd7 2013-01-05 alex SERIAL_TEST=""
199 0703fcd7 2013-01-05 alex fi
200 0703fcd7 2013-01-05 alex
201 0703fcd7 2013-01-05 alex sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}ansi2knr${DEANSI_END}|g" \
202 8cfb9104 2012-09-24 alex src/portab/Makefile.ng >src/portab/Makefile.am
203 8cfb9104 2012-09-24 alex for makefile_ng in $AM_MAKEFILES; do
204 804c2403 2016-10-21 alex makefile_am=$(echo "$makefile_ng" | sed -e "s|\.ng\$|\.am|g")
205 0703fcd7 2013-01-05 alex sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}../portab/ansi2knr${DEANSI_END}|g" \
206 8cfb9104 2012-09-24 alex $makefile_ng >$makefile_am
207 8cfb9104 2012-09-24 alex done
208 8cfb9104 2012-09-24 alex
209 b945726a 2008-06-27 alex export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
210 507a9e9c 2004-03-11 alex
211 507a9e9c 2004-03-11 alex # Generate files
212 c891b5f2 2013-01-27 alex echo "Generating files using \"$AUTOCONF\" and \"$AUTOMAKE\" ..."
213 107bfdc8 2012-09-16 alex Run $ACLOCAL && \
214 107bfdc8 2012-09-16 alex Run $AUTOCONF && \
215 107bfdc8 2012-09-16 alex Run $AUTOHEADER && \
216 107bfdc8 2012-09-16 alex Run $AUTOMAKE --add-missing --no-force
217 507a9e9c 2004-03-11 alex
218 804c2403 2016-10-21 alex if [ $? -eq 0 ] && [ -x ./configure ]; then
219 507a9e9c 2004-03-11 alex # Success: if we got some parameters we call ./configure and pass
220 507a9e9c 2004-03-11 alex # all of them to it.
221 804c2403 2016-10-21 alex NAME=$(grep PACKAGE_STRING= configure | cut -d"'" -f2)
222 0b1202cd 2004-03-19 alex if [ "$GO" = "1" ]; then
223 8212662d 2004-03-15 alex [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
224 8cfb9104 2012-09-24 alex c="./configure${p}${CONFIGURE_ARGS}"
225 82888781 2010-10-24 alex echo "Okay, autogen.sh for $NAME done."
226 8212662d 2004-03-15 alex echo "Calling \"$c\" ..."
227 8212662d 2004-03-15 alex $c
228 507a9e9c 2004-03-11 alex exit $?
229 507a9e9c 2004-03-11 alex else
230 82888781 2010-10-24 alex echo "Okay, autogen.sh for $NAME done."
231 82888781 2010-10-24 alex echo "Now run the \"./configure\" script."
232 507a9e9c 2004-03-11 alex exit 0
233 507a9e9c 2004-03-11 alex fi
234 507a9e9c 2004-03-11 alex else
235 507a9e9c 2004-03-11 alex # Failure!?
236 507a9e9c 2004-03-11 alex echo "Error! Check your installation of GNU automake and autoconf!"
237 507a9e9c 2004-03-11 alex exit 1
238 507a9e9c 2004-03-11 alex fi
239 507a9e9c 2004-03-11 alex
240 f4ade537 2001-12-11 alex # -eof-