]> arthur.barton.de Git - ngircd-alex.git/blob - autogen.sh
Merge branch 'autoconf-update'
[ngircd-alex.git] / autogen.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
11 #
12 # Usage:
13 #   [VAR=<value>] ./autogen.sh [<configure-args>]
14 #
15 # This script generates the ./configure script using GNU automake and
16 # GNU autoconf. It tries to be smart in finding the correct/usable/available
17 # installed versions of these tools on your system.
18 #
19 # The following strategy is used for each of aclocal, autoheader, automake,
20 # and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
21 # or "automake") is checked. If this fails, "tool<major><minor>" (for example
22 # "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
23 # with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
24 # <minor> is tried from 99 to 0. The first occurrence will be used.
25 #
26 # When you pass <configure-args> to autogen.sh it will call the generated
27 # ./configure script on success and pass these parameters to it.
28 #
29 # You can tweak the behaviour using these environment variables:
30 #
31 # - ACLOCAL=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
32 #   Name and optionally path to the particular tool.
33 # - PREFIX=<path>
34 #   Search the GNU autoconf and GNU automake tools in <path> first. If the
35 #   generated ./configure script will be called, pass "--prefix=<path>" to it.
36 # - EXIST=<tool>
37 #   Use <tool> to test for aclocal, autoheader etc. pp. ...
38 #   When not specified, either "type" or "which" is used.
39 # - VERBOSE=1
40 #   Output the detected names of the GNU automake and GNU autoconf tools.
41 # - GO=1
42 #   Call ./configure even if no arguments have been passed to autogen.sh.
43 #
44 # Examples:
45 #
46 # - ./autogen.sh
47 #   Generates the ./configure script.
48 # - GO=1 ./autogen.sh
49 #   Generates the ./configure script and runs it as "./configure".
50 # - VERBOSE=1 ./autogen.sh --with-ident
51 #   Show tool names, generates the ./configure script, and runs it with
52 #   these arguments: "./configure --with-ident".
53 # - ACLOCAL=aclocal-1.6 GO=1 PREFIX=$HOME ./autogen.sh
54 #   Uses "aclocal-1.6" as aclocal tool, generates the ./configure script,
55 #   and runs it with these arguments: "./configure --prefix=$HOME".
56 #
57
58 Search()
59 {
60         [ $# -eq 2 ] || exit 1
61
62         searchlist="$1"
63         major="$2"
64         minor=99
65
66         [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
67
68         for name in $searchlist; do
69                 $EXIST "${name}" >/dev/null 2>&1
70                 if [ $? -eq 0 ]; then
71                         echo "${name}"
72                         return 0
73                 fi
74         done
75
76         while [ $minor -ge 0 ]; do
77                 for name in $searchlist; do
78                         $EXIST "${name}${major}${minor}" >/dev/null 2>&1
79                         if [ $? -eq 0 ]; then
80                                 echo "${name}${major}${minor}"
81                                 return 0
82                         fi
83                         $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
84                         if [ $? -eq 0 ]; then
85                                 echo "${name}-${major}.${minor}"
86                                 return 0
87                         fi
88                 done
89                 minor=`expr $minor - 1`
90         done
91         return 1
92 }
93
94 Notfound()
95 {
96         echo "Error: $* not found!"
97         echo "Please install recent versions of GNU autoconf and GNU automake."
98         exit 1
99 }
100
101 Run()
102 {
103         [ "$VERBOSE" = "1" ] && echo " - running \"$@\" ..."
104         $@
105 }
106
107 # Reset locale settings to suppress warning messages of Perl
108 unset LC_ALL
109 unset LANG
110
111 # Which command should be used to detect the automake/autoconf tools?
112 [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
113 EXIST=""
114 for t in $existlist; do
115         $t /bin/ls >/dev/null 2>&1
116         if [ $? -eq 0 ]; then
117                 rm -f /tmp/test.$$
118                 $t /tmp/test.$$ >/dev/null 2>&1
119                 [ $? -ne 0 ] && EXIST="$t"
120         fi
121         [ -n "$EXIST" ] && break
122 done
123 if [ -z "$EXIST" ]; then
124         echo "Didn't detect a working command to test for the autoconf/automake tools!"
125         echo "Searchlist: $existlist"
126         exit 1
127 fi
128 [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
129
130 # Try to detect the needed tools when no environment variable already
131 # specifies one:
132 echo "Searching tools ..."
133 [ -z "$ACLOCAL" ] && ACLOCAL=`Search aclocal 1`
134 [ "$VERBOSE" = "1" ] && echo " - ACLOCAL=$ACLOCAL"
135 [ -z "$AUTOHEADER" ] && AUTOHEADER=`Search autoheader 2`
136 [ "$VERBOSE" = "1" ] && echo " - AUTOHEADER=$AUTOHEADER"
137 [ -z "$AUTOMAKE" ] && AUTOMAKE=`Search automake 1`
138 [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE=$AUTOMAKE"
139 [ -z "$AUTOCONF" ] && AUTOCONF=`Search autoconf 2`
140 [ "$VERBOSE" = "1" ] && echo " - AUTOCONF=$AUTOCONF"
141
142 # Call ./configure when parameters have been passed to this script and
143 # GO isn't already defined.
144 [ -z "$GO" -a $# -gt 0 ] && GO=1
145
146 # Verify that all tools have been found
147 [ -z "$ACLOCAL" ] && Notfound aclocal
148 [ -z "$AUTOHEADER" ] && Notfound autoheader
149 [ -z "$AUTOMAKE" ] && Notfound automake
150 [ -z "$AUTOCONF" ] && Notfound autoconf
151
152 export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
153
154 # Generate files
155 echo "Generating files ..."
156 Run $ACLOCAL && \
157         Run $AUTOCONF && \
158         Run $AUTOHEADER && \
159         Run $AUTOMAKE --add-missing --no-force
160
161 if [ $? -eq 0 -a -x ./configure ]; then
162         # Success: if we got some parameters we call ./configure and pass
163         # all of them to it.
164         NAME=`grep PACKAGE_STRING= configure | cut -d"'" -f2`
165         if [ "$GO" = "1" ]; then
166                 [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
167                 [ -n "$*" ] && a=" $*" || a=""
168                 c="./configure${p}${a}"
169                 echo "Okay, autogen.sh for $NAME done."
170                 echo "Calling \"$c\" ..."
171                 $c
172                 exit $?
173         else
174                 echo "Okay, autogen.sh for $NAME done."
175                 echo "Now run the \"./configure\" script."
176                 exit 0
177         fi
178 else
179         # Failure!?
180         echo "Error! Check your installation of GNU automake and autoconf!"
181         exit 1
182 fi
183
184 # -eof-