autogen.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #!/bin/sh
  2. #
  3. # ngIRCd -- The Next Generation IRC Daemon
  4. # Copyright (c)2001-2024 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. Check_Tool()
  63. {
  64. searchlist="$1"
  65. major="$2"
  66. minor="$3"
  67. for name in $searchlist; do
  68. $EXIST "${name}${major}${minor}" >/dev/null 2>&1
  69. if [ $? -eq 0 ]; then
  70. echo "${name}${major}${minor}"
  71. return 0
  72. fi
  73. $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
  74. if [ $? -eq 0 ]; then
  75. echo "${name}-${major}.${minor}"
  76. return 0
  77. fi
  78. done
  79. return 1
  80. }
  81. Search()
  82. {
  83. [ $# -lt 2 ] && return 1
  84. [ $# -gt 3 ] && return 1
  85. searchlist="$1"
  86. major="$2"
  87. minor_pref="$3"
  88. minor=99
  89. [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
  90. if [ -n "$minor_pref" ]; then
  91. Check_Tool "$searchlist" "$major" "$minor_pref" && return 0
  92. fi
  93. for name in $searchlist; do
  94. $EXIST "${name}" >/dev/null 2>&1
  95. if [ $? -eq 0 ]; then
  96. "${name}" --version 2>&1 \
  97. | grep -v "environment variable" >/dev/null 2>&1
  98. if [ $? -eq 0 ]; then
  99. echo "${name}"
  100. return 0
  101. fi
  102. fi
  103. done
  104. while [ $minor -ge 0 ]; do
  105. Check_Tool "$searchlist" "$major" "$minor" && return 0
  106. minor=$(expr $minor - 1)
  107. done
  108. return 1
  109. }
  110. Notfound()
  111. {
  112. echo "Error: $* not found!"
  113. echo 'Please install supported versions of GNU autoconf, GNU automake'
  114. echo 'and pkg-config: see the INSTALL file for details.'
  115. exit 1
  116. }
  117. Run()
  118. {
  119. [ "$VERBOSE" = "1" ] && echo " - running \"$*\" ..."
  120. "$@"
  121. }
  122. # Reset locale settings to suppress warning messages of Perl
  123. unset LC_ALL
  124. unset LANG
  125. # Which command should be used to detect the automake/autoconf tools?
  126. [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
  127. EXIST=""
  128. for t in $existlist; do
  129. $t /bin/ls >/dev/null 2>&1
  130. if [ $? -eq 0 ]; then
  131. rm -f /tmp/test.$$
  132. $t /tmp/test.$$ >/dev/null 2>&1
  133. [ $? -ne 0 ] && EXIST="$t"
  134. fi
  135. [ -n "$EXIST" ] && break
  136. done
  137. if [ -z "$EXIST" ]; then
  138. echo "Didn't detect a working command to test for the autoconf/automake tools!"
  139. echo "Searchlist: $existlist"
  140. exit 1
  141. fi
  142. [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
  143. # Try to detect the needed tools when no environment variable already
  144. # specifies one:
  145. echo "Searching for required tools ..."
  146. [ -z "$ACLOCAL" ] && ACLOCAL=$(Search aclocal 1 11)
  147. [ "$VERBOSE" = "1" ] && echo " - ACLOCAL=$ACLOCAL"
  148. [ -z "$AUTOHEADER" ] && AUTOHEADER=$(Search autoheader 2)
  149. [ "$VERBOSE" = "1" ] && echo " - AUTOHEADER=$AUTOHEADER"
  150. [ -z "$AUTOMAKE" ] && AUTOMAKE=$(Search automake 1 11)
  151. [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE=$AUTOMAKE"
  152. [ -z "$AUTOCONF" ] && AUTOCONF=$(Search autoconf 2)
  153. [ "$VERBOSE" = "1" ] && echo " - AUTOCONF=$AUTOCONF"
  154. AUTOCONF_VERSION=$(echo "$AUTOCONF" | cut -d'-' -f2-)
  155. [ -n "$AUTOCONF_VERSION" ] && [ "$AUTOCONF_VERSION" != "autoconf" ] \
  156. && export AUTOCONF_VERSION || unset AUTOCONF_VERSION
  157. [ "$VERBOSE" = "1" ] && echo " - AUTOCONF_VERSION=$AUTOCONF_VERSION"
  158. AUTOMAKE_VERSION=$(echo $AUTOMAKE | cut -d'-' -f2-)
  159. [ -n "$AUTOMAKE_VERSION" ] && [ "$AUTOMAKE_VERSION" != "automake" ] \
  160. && export AUTOMAKE_VERSION || unset AUTOMAKE_VERSION
  161. [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE_VERSION=$AUTOMAKE_VERSION"
  162. [ $# -gt 0 ] && CONFIGURE_ARGS=" $*" || CONFIGURE_ARGS=""
  163. [ -z "$GO" ] && [ -n "$CONFIGURE_ARGS" ] && GO=1
  164. # Verify that all tools have been found
  165. command -v pkg-config >/dev/null || Notfound pkg-config
  166. [ -z "$ACLOCAL" ] && Notfound aclocal
  167. [ -z "$AUTOHEADER" ] && Notfound autoheader
  168. [ -z "$AUTOMAKE" ] && Notfound automake
  169. [ -z "$AUTOCONF" ] && Notfound autoconf
  170. AM_VERSION=$($AUTOMAKE --version | head -n 1 | sed -e 's/.* //g')
  171. ifs=$IFS; IFS="."; set $AM_VERSION; IFS=$ifs
  172. AM_MAJOR="$1"; AM_MINOR="$2"
  173. echo "Detected automake $AM_VERSION ..."
  174. AM_MAKEFILES="src/ipaddr/Makefile.ng src/ngircd/Makefile.ng src/testsuite/Makefile.ng src/tool/Makefile.ng"
  175. # De-ANSI-fication?
  176. if [ "$AM_MAJOR" -eq "1" ] && [ "$AM_MINOR" -lt "12" ]; then
  177. # automake < 1.12 => automatic de-ANSI-fication support available
  178. echo " - Enabling de-ANSI-fication support."
  179. sed -e "s|^__ng_PROTOTYPES__|AM_C_PROTOTYPES|g" configure.ng >configure.ac
  180. DEANSI_START=""
  181. DEANSI_END=""
  182. else
  183. # automake >= 1.12 => no de-ANSI-fication support available
  184. echo " - Disabling de-ANSI-fication support."
  185. sed -e "s|^__ng_PROTOTYPES__|AC_C_PROTOTYPES|g" configure.ng >configure.ac
  186. DEANSI_START="#"
  187. DEANSI_END=" (disabled by ./autogen.sh script)"
  188. fi
  189. # Serial test harness?
  190. if [ "$AM_MAJOR" -eq "1" ] && [ "$AM_MINOR" -ge "13" ]; then
  191. # automake >= 1.13 => enforce "serial test harness"
  192. echo " - Enforcing serial test harness."
  193. SERIAL_TESTS="serial-tests"
  194. else
  195. # automake < 1.13 => no new test harness, nothing to do
  196. # shellcheck disable=SC2034
  197. SERIAL_TEST=""
  198. fi
  199. sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}ansi2knr${DEANSI_END}|g" \
  200. src/portab/Makefile.ng >src/portab/Makefile.am
  201. for makefile_ng in $AM_MAKEFILES; do
  202. makefile_am=$(echo "$makefile_ng" | sed -e "s|\.ng\$|\.am|g")
  203. sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}../portab/ansi2knr${DEANSI_END}|g" \
  204. $makefile_ng >$makefile_am
  205. done
  206. export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
  207. # Generate files
  208. echo "Generating files using \"$AUTOCONF\" and \"$AUTOMAKE\" ..."
  209. Run $ACLOCAL && \
  210. Run $AUTOCONF && \
  211. Run $AUTOHEADER && \
  212. Run $AUTOMAKE --add-missing --no-force
  213. if [ $? -eq 0 ] && [ -x ./configure ]; then
  214. # Success: if we got some parameters we call ./configure and pass
  215. # all of them to it.
  216. NAME=$(grep PACKAGE_STRING= configure | cut -d"'" -f2)
  217. if [ "$GO" = "1" ]; then
  218. [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
  219. c="./configure${p}${CONFIGURE_ARGS}"
  220. echo "Okay, autogen.sh for $NAME done."
  221. echo "Calling \"$c\" ..."
  222. $c
  223. exit $?
  224. else
  225. echo "Okay, autogen.sh for $NAME done."
  226. echo "Now run the \"./configure\" script."
  227. exit 0
  228. fi
  229. else
  230. # Failure!?
  231. echo "Error! Check your installation of GNU automake and autoconf!"
  232. exit 1
  233. fi
  234. # -eof-