autogen.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. # In addition, it enables or disables the "de-ANSI-fication" support of GNU
  20. # automake, which is supported up to autoconf 1.11.x an has been removed
  21. # in automake 1.12 -- make sure to use a version of automake supporting it
  22. # when generating distribution archives!
  23. #
  24. # The following strategy is used for each of aclocal, autoheader, automake,
  25. # and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
  26. # or "automake") is checked. If this fails, "tool<major><minor>" (for example
  27. # "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
  28. # with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
  29. # <minor> is tried from 99 to 0. The first occurrence will be used.
  30. #
  31. # When you pass <configure-args> to autogen.sh it will call the generated
  32. # ./configure script on success and pass these parameters to it.
  33. #
  34. # You can tweak the behaviour using these environment variables:
  35. #
  36. # - ACLOCAL=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
  37. # Name and optionally path to the particular tool.
  38. # - PREFIX=<path>
  39. # Search the GNU autoconf and GNU automake tools in <path> first. If the
  40. # generated ./configure script will be called, pass "--prefix=<path>" to it.
  41. # - EXIST=<tool>
  42. # Use <tool> to test for aclocal, autoheader etc. pp. ...
  43. # When not specified, either "type" or "which" is used.
  44. # - VERBOSE=1
  45. # Output the detected names of the GNU automake and GNU autoconf tools.
  46. # - GO=1
  47. # Call ./configure even if no arguments have been passed to autogen.sh.
  48. #
  49. # Examples:
  50. #
  51. # - ./autogen.sh
  52. # Generates the ./configure script.
  53. # - GO=1 ./autogen.sh
  54. # Generates the ./configure script and runs it as "./configure".
  55. # - VERBOSE=1 ./autogen.sh --with-ident
  56. # Show tool names, generates the ./configure script, and runs it with
  57. # these arguments: "./configure --with-ident".
  58. # - ACLOCAL=aclocal-1.6 GO=1 PREFIX=$HOME ./autogen.sh
  59. # Uses "aclocal-1.6" as aclocal tool, generates the ./configure script,
  60. # and runs it with these arguments: "./configure --prefix=$HOME".
  61. #
  62. Search()
  63. {
  64. [ $# -eq 2 ] || exit 1
  65. searchlist="$1"
  66. major="$2"
  67. minor=99
  68. [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
  69. for name in $searchlist; do
  70. $EXIST "${name}" >/dev/null 2>&1
  71. if [ $? -eq 0 ]; then
  72. echo "${name}"
  73. return 0
  74. fi
  75. done
  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. Notfound()
  94. {
  95. echo "Error: $* not found!"
  96. echo "Please install recent versions of GNU autoconf and GNU automake."
  97. exit 1
  98. }
  99. Run()
  100. {
  101. [ "$VERBOSE" = "1" ] && echo " - running \"$@\" ..."
  102. $@
  103. }
  104. # Reset locale settings to suppress warning messages of Perl
  105. unset LC_ALL
  106. unset LANG
  107. # Which command should be used to detect the automake/autoconf tools?
  108. [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
  109. EXIST=""
  110. for t in $existlist; do
  111. $t /bin/ls >/dev/null 2>&1
  112. if [ $? -eq 0 ]; then
  113. rm -f /tmp/test.$$
  114. $t /tmp/test.$$ >/dev/null 2>&1
  115. [ $? -ne 0 ] && EXIST="$t"
  116. fi
  117. [ -n "$EXIST" ] && break
  118. done
  119. if [ -z "$EXIST" ]; then
  120. echo "Didn't detect a working command to test for the autoconf/automake tools!"
  121. echo "Searchlist: $existlist"
  122. exit 1
  123. fi
  124. [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
  125. # Try to detect the needed tools when no environment variable already
  126. # specifies one:
  127. echo "Searching for required tools ..."
  128. [ -z "$ACLOCAL" ] && ACLOCAL=`Search aclocal 1`
  129. [ "$VERBOSE" = "1" ] && echo " - ACLOCAL=$ACLOCAL"
  130. [ -z "$AUTOHEADER" ] && AUTOHEADER=`Search autoheader 2`
  131. [ "$VERBOSE" = "1" ] && echo " - AUTOHEADER=$AUTOHEADER"
  132. [ -z "$AUTOMAKE" ] && AUTOMAKE=`Search automake 1`
  133. [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE=$AUTOMAKE"
  134. [ -z "$AUTOCONF" ] && AUTOCONF=`Search autoconf 2`
  135. [ "$VERBOSE" = "1" ] && echo " - AUTOCONF=$AUTOCONF"
  136. [ $# -gt 0 ] && CONFIGURE_ARGS=" $@" || CONFIGURE_ARGS=""
  137. [ -z "$GO" -a -n "$CONFIGURE_ARGS" ] && GO=1
  138. # Verify that all tools have been found
  139. [ -z "$ACLOCAL" ] && Notfound aclocal
  140. [ -z "$AUTOHEADER" ] && Notfound autoheader
  141. [ -z "$AUTOMAKE" ] && Notfound automake
  142. [ -z "$AUTOCONF" ] && Notfound autoconf
  143. AM_VERSION=`$AUTOMAKE --version|head -n 1|egrep -o "([1-9]\.[0-9]+(\.[0-9]+)*)"`
  144. ifs=$IFS; IFS="."; set $AM_VERSION; IFS=$ifs
  145. AM_MAJOR="$1"; AM_MINOR="$2"; AM_PATCHLEVEL="$3"
  146. AM_MAKEFILES="src/ipaddr/Makefile.ng src/ngircd/Makefile.ng src/testsuite/Makefile.ng src/tool/Makefile.ng"
  147. if [ "$AM_MAJOR" -eq "1" -a "$AM_MINOR" -lt "12" ]; then
  148. # automake < 1.12 => automatic de-ANSI-fication support available
  149. echo "Enabling de-ANSI-fication support (automake $AM_VERSION) ..."
  150. sed -e "s|^__ng_PROTOTYPES__|AM_C_PROTOTYPES|g" configure.ng >configure.ac
  151. DEANSI_START=""
  152. DEANSI_END=""
  153. else
  154. # automake >= 1.12 => no de-ANSI-fication support available
  155. echo "Disabling de-ANSI-fication support (automake $AM_VERSION) ..."
  156. sed -e "s|^__ng_PROTOTYPES__|AC_C_PROTOTYPES|g" configure.ng >configure.ac
  157. DEANSI_START="#"
  158. DEANSI_END=" # disabled by ./autogen.sh script"
  159. fi
  160. sed -e "s|^__ng_Makefile_am_template__|${DEANSI_START}AUTOMAKE_OPTIONS = ansi2knr${DEANSI_END}|g" \
  161. src/portab/Makefile.ng >src/portab/Makefile.am
  162. for makefile_ng in $AM_MAKEFILES; do
  163. makefile_am=`echo "$makefile_ng" | sed -e "s|\.ng\$|\.am|g"`
  164. sed -e "s|^__ng_Makefile_am_template__|${DEANSI_START}AUTOMAKE_OPTIONS = ../portab/ansi2knr${DEANSI_END}|g" \
  165. $makefile_ng >$makefile_am
  166. done
  167. export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
  168. # Generate files
  169. echo "Generating files using GNU $AUTOCONF and $AUTOMAKE ..."
  170. Run $ACLOCAL && \
  171. Run $AUTOCONF && \
  172. Run $AUTOHEADER && \
  173. Run $AUTOMAKE --add-missing --no-force
  174. if [ $? -eq 0 -a -x ./configure ]; then
  175. # Success: if we got some parameters we call ./configure and pass
  176. # all of them to it.
  177. NAME=`grep PACKAGE_STRING= configure | cut -d"'" -f2`
  178. if [ "$GO" = "1" ]; then
  179. [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
  180. c="./configure${p}${CONFIGURE_ARGS}"
  181. echo "Okay, autogen.sh for $NAME done."
  182. echo "Calling \"$c\" ..."
  183. $c
  184. exit $?
  185. else
  186. echo "Okay, autogen.sh for $NAME done."
  187. echo "Now run the \"./configure\" script."
  188. exit 0
  189. fi
  190. else
  191. # Failure!?
  192. echo "Error! Check your installation of GNU automake and autoconf!"
  193. exit 1
  194. fi
  195. # -eof-