]> arthur.barton.de Git - ngircd-alex.git/blob - autogen.sh
Use "which" when available; understand "GO=0"; made "VERBOSE=1" more verbose.
[ngircd-alex.git] / autogen.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2004 Alexander Barton <alex@barton.de>
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 # $Id: autogen.sh,v 1.11 2004/03/19 11:47:51 alex Exp $
13 #
14
15 #
16 # Usage: [VAR=<value>] ./autogen.sh [<configure-args>]
17 #
18 # This script generates the ./configure script using GNU automake and
19 # GNU autoconf. It tries to be smart in finding the correct/usable/available
20 # installed versions of these tools on your system.
21 #
22 # The following strategy is used for each of aclocal, autoheader, automake,
23 # and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
24 # or "automake") is checked. If this fails, "tool<major><minor>" (for example
25 # "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
26 # with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
27 # <minor> is tried from 99 to 0. The first occurrence will be used.
28 #
29 # When you pass <configure-args> to autogen.sh it will call the generated
30 # ./configure script on success and pass these parameters to it.
31 #
32 # You can tweak the behaviour using these environment variables:
33 #
34 # - ALICA=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
35 #   Name and optionally path to the particular tool.
36 # - PREFIX=<path>
37 #   Search the GNU autoconf and GNU automake tools in <path> first. If the
38 #   generated ./configure script will be called, pass "--prefix=<path>" to it.
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         which /bin/ls >/dev/null 2>&1
67         [ $? -eq 0 ] && exists="which" || exists="type"
68
69         [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
70
71         for name in $searchlist; do
72                 $exists "${name}" >/dev/null 2>&1
73                 if [ $? -eq 0 ]; then
74                         echo "${name}"
75                         return 0
76                 fi
77         done
78
79         while [ $minor -ge 0 ]; do
80                 for name in $searchlist; do
81                         $exists "${name}${major}${minor}" >/dev/null 2>&1
82                         if [ $? -eq 0 ]; then
83                                 echo "${name}${major}${minor}"
84                                 return 0
85                         fi
86                         $exists "${name}-${major}.${minor}" >/dev/null 2>&1
87                         if [ $? -eq 0 ]; then
88                                 echo "${name}-${major}.${minor}" >/dev/null 2>&1
89                                 return 0
90                         fi
91                 done
92                 minor=`expr $minor - 1`
93         done
94         return 1
95 }
96
97 Notfound()
98 {
99         echo "Error: $* not found!"
100         echo "Please install recent versions of GNU autoconf and GNU automake."
101         exit 1
102 }
103
104 # Reset locale settings to suppress warning messages of Perl
105 unset LC_ALL
106 unset LANG
107
108 # We want to use GNU automake 1.7, if available (WANT_AUTOMAKE is used by
109 # the wrapper scripts of Gentoo Linux):
110 WANT_AUTOMAKE=1.7
111 export WANT_AUTOMAKE
112
113 # Try to detect the needed tools when no environment variable already
114 # spezifies one:
115 echo "Searching tools ..."
116 [ -z "$ACLOCAL" ] && ACLOCAL=`Search aclocal 1`
117 [ "$VERBOSE" = "1" ] && echo "ACLOCAL=$ACLOCAL"
118 [ -z "$AUTOHEADER" ] && AUTOHEADER=`Search autoheader 2`
119 [ "$VERBOSE" = "1" ] && echo "AUTOHEADER=$AUTOHEADER"
120 [ -z "$AUTOMAKE" ] && AUTOMAKE=`Search automake 1`
121 [ "$VERBOSE" = "1" ] && echo "AUTOMAKE=$AUTOMAKE"
122 [ -z "$AUTOCONF" ] && AUTOCONF=`Search autoconf 2`
123 [ "$VERBOSE" = "1" ] && echo "AUTOCONF=$AUTOCONF"
124
125 # Call ./configure when parameters have been passed to this script and
126 # GO isn't already defined.
127 [ -z "$GO" -a $# -gt 0 ] && GO=1
128
129 # Verify that all tools have been found
130 [ -z "$AUTOCONF" ] && Notfounf autoconf
131 [ -z "$AUTOHEADER" ] && Notfound autoheader
132 [ -z "$AUTOMAKE" ] && Notfound automake
133 [ -z "$AUTOCONF" ] && Notfound autoconf
134
135 export AUTOCONF AUTOHEADER AUTOMAKE AUTOCONF
136
137 # Generate files
138 echo "Generating files ..."
139 $ACLOCAL && \
140         $AUTOHEADER && \
141         $AUTOMAKE --add-missing && \
142         $AUTOCONF
143
144 if [ $? -eq 0 -a -x ./configure ]; then
145         # Success: if we got some parameters we call ./configure and pass
146         # all of them to it.
147         if [ "$GO" = "1" ]; then
148                 [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
149                 [ -n "$*" ] && a=" $*" || a=""
150                 c="./configure${p}${a}"
151                 echo "Calling \"$c\" ..."
152                 $c
153                 exit $?
154         else
155                 echo "Okay, autogen.sh done; now run the \"configure\" script."
156                 exit 0
157         fi
158 else
159         # Failure!?
160         echo "Error! Check your installation of GNU automake and autoconf!"
161         exit 1
162 fi
163
164 # -eof-