libtcl.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. dnl libtcl.m4
  2. dnl macros autoconf uses when building configure from configure.in
  3. dnl These are taken from Eggdrop
  4. dnl
  5. dnl EGG_TCL_ARG_WITH()
  6. dnl
  7. AC_DEFUN([EGG_TCL_ARG_WITH],
  8. [
  9. AC_ARG_WITH(tcllib, [ --with-tcllib=PATH full path to Tcl library], [tcllibname="$withval"])
  10. AC_ARG_WITH(tclinc, [ --with-tclinc=PATH full path to Tcl header], [tclincname="$withval"])
  11. WARN=0
  12. # Make sure either both or neither $tcllibname and $tclincname are set
  13. if test "x$tcllibname" != x; then
  14. if test "x$tclincname" = x; then
  15. WARN=1
  16. tcllibname=""
  17. TCLLIB=""
  18. TCLINC=""
  19. fi
  20. else
  21. if test "x$tclincname" != x; then
  22. WARN=1
  23. tclincname=""
  24. TCLLIB=""
  25. TCLINC=""
  26. fi
  27. fi
  28. if test "$WARN" = 1; then
  29. cat << 'EOF' >&2
  30. configure: WARNING:
  31. You must specify both --with-tcllib and --with-tclinc for either to work.
  32. configure will now attempt to autodetect both the Tcl library and header.
  33. EOF
  34. fi
  35. ])
  36. dnl EGG_TCL_ENV()
  37. dnl
  38. AC_DEFUN([EGG_TCL_ENV],
  39. [
  40. WARN=0
  41. # Make sure either both or neither $TCLLIB and $TCLINC are set
  42. if test "x$TCLLIB" != x; then
  43. if test "x$TCLINC" = x; then
  44. WARN=1
  45. WVAR1=TCLLIB
  46. WVAR2=TCLINC
  47. TCLLIB=""
  48. fi
  49. else
  50. if test "x$TCLINC" != x; then
  51. WARN=1
  52. WVAR1=TCLINC
  53. WVAR2=TCLLIB
  54. TCLINC=""
  55. fi
  56. fi
  57. if test "$WARN" = 1; then
  58. cat << EOF >&2
  59. configure: WARNING:
  60. Environment variable $WVAR1 was set, but I did not detect ${WVAR2}.
  61. Please set both TCLLIB and TCLINC correctly if you wish to use them.
  62. configure will now attempt to autodetect both the Tcl library and header.
  63. EOF
  64. fi
  65. ])
  66. dnl EGG_TCL_WITH_TCLLIB()
  67. dnl
  68. AC_DEFUN([EGG_TCL_WITH_TCLLIB],
  69. [
  70. # Look for Tcl library: if $tcllibname is set, check there first
  71. if test "x$tcllibname" != x; then
  72. if test -f "$tcllibname" && test -r "$tcllibname"; then
  73. TCLLIB=`echo $tcllibname | sed 's%/[[^/]][[^/]]*$%%'`
  74. TCLLIBFN=`$BASENAME $tcllibname | cut -c4-`
  75. TCLLIBEXT=".`echo $TCLLIBFN | $AWK '{j=split([$]1, i, "."); print i[[j]]}'`"
  76. TCLLIBFNS=`$BASENAME $tcllibname $TCLLIBEXT | cut -c4-`
  77. else
  78. cat << EOF >&2
  79. configure: WARNING:
  80. The file '$tcllibname' given to option --with-tcllib is not valid.
  81. configure will now attempt to autodetect both the Tcl library and header.
  82. EOF
  83. tcllibname=""
  84. tclincname=""
  85. TCLLIB=""
  86. TCLLIBFN=""
  87. TCLINC=""
  88. TCLINCFN=""
  89. fi
  90. fi
  91. ])
  92. dnl EGG_TCL_WITH_TCLINC()
  93. dnl
  94. AC_DEFUN([EGG_TCL_WITH_TCLINC],
  95. [
  96. # Look for Tcl header: if $tclincname is set, check there first
  97. if test "x$tclincname" != x; then
  98. if test -f "$tclincname" && test -r "$tclincname"; then
  99. TCLINC=`echo $tclincname | sed 's%/[[^/]][[^/]]*$%%'`
  100. TCLINCFN=`$BASENAME $tclincname`
  101. else
  102. cat << EOF >&2
  103. configure: WARNING:
  104. The file '$tclincname' given to option --with-tclinc is not valid.
  105. configure will now attempt to autodetect both the Tcl library and header.
  106. EOF
  107. tcllibname=""
  108. tclincname=""
  109. TCLLIB=""
  110. TCLLIBFN=""
  111. TCLINC=""
  112. TCLINCFN=""
  113. fi
  114. fi
  115. ])
  116. dnl EGG_TCL_FIND_LIBRARY()
  117. dnl
  118. AC_DEFUN([EGG_TCL_FIND_LIBRARY],
  119. [
  120. # Look for Tcl library: if $TCLLIB is set, check there first
  121. if test "x$TCLLIBFN" = x && test "x$TCLLIB" != x; then
  122. if test -d "$TCLLIB"; then
  123. for tcllibfns in $tcllibnames; do
  124. for tcllibext in $tcllibextensions; do
  125. if test -r "${TCLLIB}/lib${tcllibfns}${tcllibext}"; then
  126. TCLLIBFN="${tcllibfns}${tcllibext}"
  127. TCLLIBEXT="$tcllibext"
  128. TCLLIBFNS="$tcllibfns"
  129. break 2
  130. fi
  131. done
  132. done
  133. fi
  134. if test "x$TCLLIBFN" = x; then
  135. cat << 'EOF' >&2
  136. configure: WARNING:
  137. Environment variable TCLLIB was set, but incorrectly.
  138. Please set both TCLLIB and TCLINC correctly if you wish to use them.
  139. configure will now attempt to autodetect both the Tcl library and header.
  140. EOF
  141. TCLLIB=""
  142. TCLLIBFN=""
  143. TCLINC=""
  144. TCLINCFN=""
  145. fi
  146. fi
  147. ])
  148. dnl EGG_TCL_FIND_HEADER()
  149. dnl
  150. AC_DEFUN([EGG_TCL_FIND_HEADER],
  151. [
  152. # Look for Tcl header: if $TCLINC is set, check there first
  153. if test "x$TCLINCFN" = x && test "x$TCLINC" != x; then
  154. if test -d "$TCLINC"; then
  155. for tclheaderfn in $tclheadernames; do
  156. if test -r "${TCLINC}/${tclheaderfn}"; then
  157. TCLINCFN="$tclheaderfn"
  158. break
  159. fi
  160. done
  161. fi
  162. if test "x$TCLINCFN" = x; then
  163. cat << 'EOF' >&2
  164. configure: WARNING:
  165. Environment variable TCLINC was set, but incorrectly.
  166. Please set both TCLLIB and TCLINC correctly if you wish to use them.
  167. configure will now attempt to autodetect both the Tcl library and header.
  168. EOF
  169. TCLLIB=""
  170. TCLLIBFN=""
  171. TCLINC=""
  172. TCLINCFN=""
  173. fi
  174. fi
  175. ])
  176. dnl EGG_TCL_CHECK_LIBRARY()
  177. dnl
  178. AC_DEFUN([EGG_TCL_CHECK_LIBRARY],
  179. [
  180. AC_MSG_CHECKING([for Tcl library])
  181. # Attempt autodetect for $TCLLIBFN if it's not set
  182. if test "x$TCLLIBFN" != x; then
  183. AC_MSG_RESULT([using ${TCLLIB}/lib${TCLLIBFN}])
  184. else
  185. for tcllibfns in $tcllibnames; do
  186. for tcllibext in $tcllibextensions; do
  187. for tcllibpath in $tcllibpaths; do
  188. if test -r "${tcllibpath}/lib${tcllibfns}${tcllibext}"; then
  189. AC_MSG_RESULT([found ${tcllibpath}/lib${tcllibfns}${tcllibext}])
  190. TCLLIB="$tcllibpath"
  191. TCLLIBFN="${tcllibfns}${tcllibext}"
  192. TCLLIBEXT="$tcllibext"
  193. TCLLIBFNS="$tcllibfns"
  194. break 3
  195. fi
  196. done
  197. done
  198. done
  199. fi
  200. # Show if $TCLLIBFN wasn't found
  201. if test "x$TCLLIBFN" = x; then
  202. AC_MSG_RESULT([not found])
  203. fi
  204. AC_SUBST(TCLLIB)
  205. AC_SUBST(TCLLIBFN)
  206. ])
  207. dnl EGG_TCL_CHECK_HEADER()
  208. dnl
  209. AC_DEFUN([EGG_TCL_CHECK_HEADER],
  210. [
  211. AC_MSG_CHECKING([for Tcl header])
  212. # Attempt autodetect for $TCLINCFN if it's not set
  213. if test "x$TCLINCFN" != x; then
  214. AC_MSG_RESULT([using ${TCLINC}/${TCLINCFN}])
  215. else
  216. for tclheaderpath in $tclheaderpaths; do
  217. for tclheaderfn in $tclheadernames; do
  218. if test -r "${tclheaderpath}/${tclheaderfn}"; then
  219. AC_MSG_RESULT([found ${tclheaderpath}/${tclheaderfn}])
  220. TCLINC="$tclheaderpath"
  221. TCLINCFN="$tclheaderfn"
  222. break 2
  223. fi
  224. done
  225. done
  226. # FreeBSD hack ...
  227. if test "x$TCLINCFN" = x; then
  228. for tcllibfns in $tcllibnames; do
  229. for tclheaderpath in $tclheaderpaths; do
  230. for tclheaderfn in $tclheadernames; do
  231. if test -r "${tclheaderpath}/${tcllibfns}/${tclheaderfn}"; then
  232. AC_MSG_RESULT([found ${tclheaderpath}/${tcllibfns}/${tclheaderfn}])
  233. TCLINC="${tclheaderpath}/${tcllibfns}"
  234. TCLINCFN="$tclheaderfn"
  235. break 3
  236. fi
  237. done
  238. done
  239. done
  240. fi
  241. fi
  242. if test "x$TCLINCFN" = x; then
  243. AC_MSG_RESULT([not found])
  244. fi
  245. AC_SUBST(TCLINC)
  246. AC_SUBST(TCLINCFN)
  247. ])
  248. dnl EGG_CACHE_UNSET(CACHE-ID)
  249. dnl
  250. dnl Unsets a certain cache item. Typically called before using the AC_CACHE_*()
  251. dnl macros.
  252. dnl
  253. AC_DEFUN([EGG_CACHE_UNSET], [unset $1])
  254. dnl EGG_TCL_DETECT_CHANGE()
  255. dnl
  256. dnl Detect whether the Tcl system has changed since our last configure run.
  257. dnl Set egg_tcl_changed accordingly.
  258. dnl
  259. dnl Tcl related feature and version checks should re-run their checks as soon
  260. dnl as egg_tcl_changed is set to "yes".
  261. dnl
  262. AC_DEFUN([EGG_TCL_DETECT_CHANGE],
  263. [
  264. dnl NOTE: autoconf 2.50+ disables config.cache by default.
  265. dnl These checks don't do us much good if cache is disabled.
  266. AC_MSG_CHECKING([whether the Tcl system has changed])
  267. egg_tcl_changed="yes"
  268. egg_tcl_id="${TCLLIB}:${TCLLIBFN}:${TCLINC}:${TCLINCFN}"
  269. if test "$egg_tcl_id" != ":::"; then
  270. egg_tcl_cached="yes"
  271. AC_CACHE_VAL(egg_cv_var_tcl_id, [
  272. egg_cv_var_tcl_id="$egg_tcl_id"
  273. egg_tcl_cached="no"
  274. ])
  275. if test "$egg_tcl_cached" = yes; then
  276. if test "x$egg_cv_var_tcl_id" = "x$egg_tcl_id"; then
  277. egg_tcl_changed="no"
  278. else
  279. egg_cv_var_tcl_id="$egg_tcl_id"
  280. fi
  281. fi
  282. fi
  283. if test "$egg_tcl_changed" = yes; then
  284. AC_MSG_RESULT([yes])
  285. else
  286. AC_MSG_RESULT([no])
  287. fi
  288. ])
  289. dnl EGG_TCL_CHECK_VERSION()
  290. dnl
  291. AC_DEFUN([EGG_TCL_CHECK_VERSION],
  292. [
  293. # Both TCLLIBFN & TCLINCFN must be set, or we bail
  294. TCL_FOUND=0
  295. if test "x$TCLLIBFN" != x && test "x$TCLINCFN" != x; then
  296. TCL_FOUND=1
  297. # Check Tcl's version
  298. if test "$egg_tcl_changed" = yes; then
  299. EGG_CACHE_UNSET(egg_cv_var_tcl_version)
  300. fi
  301. AC_MSG_CHECKING([for Tcl version])
  302. AC_CACHE_VAL(egg_cv_var_tcl_version, [
  303. egg_cv_var_tcl_version=`grep TCL_VERSION $TCLINC/$TCLINCFN | $HEAD_1 | $AWK '{gsub(/\"/, "", [$]3); print [$]3}'`
  304. ])
  305. if test "x$egg_cv_var_tcl_version" != x; then
  306. AC_MSG_RESULT([$egg_cv_var_tcl_version])
  307. else
  308. AC_MSG_RESULT([not found])
  309. TCL_FOUND=0
  310. fi
  311. # Check Tcl's patch level (if available)
  312. if test "$egg_tcl_changed" = yes; then
  313. EGG_CACHE_UNSET(egg_cv_var_tcl_patch_level)
  314. fi
  315. AC_MSG_CHECKING([for Tcl patch level])
  316. AC_CACHE_VAL(egg_cv_var_tcl_patch_level, [
  317. eval "egg_cv_var_tcl_patch_level=`grep TCL_PATCH_LEVEL $TCLINC/$TCLINCFN | $HEAD_1 | $AWK '{gsub(/\"/, "", [$]3); print [$]3}'`"
  318. ])
  319. if test "x$egg_cv_var_tcl_patch_level" != x; then
  320. AC_MSG_RESULT([$egg_cv_var_tcl_patch_level])
  321. else
  322. egg_cv_var_tcl_patch_level="unknown"
  323. AC_MSG_RESULT([unknown])
  324. fi
  325. fi
  326. # Check if we found Tcl's version
  327. if test "$TCL_FOUND" = 0; then
  328. cat << 'EOF' >&2
  329. configure: error:
  330. Tcl cannot be found on this system.
  331. Tcl is not required. Wraith will be compiled without TCL support. If you
  332. already have Tcl installed on this system, and I just wasn't looking in
  333. the right place for it, re-run ./configure using the
  334. --with-tcllib='/path/to/libtcl.so' and --with-tclinc='/path/to/tcl.h' options.
  335. EOF
  336. else
  337. AC_DEFINE(HAVE_LIBTCL, 1, [Define if you have support for libtcl])
  338. fi
  339. ])
  340. dnl EGG_TCL_CHECK_PRE70()
  341. dnl
  342. AC_DEFUN([EGG_TCL_CHECK_PRE70],
  343. [
  344. # Is this version of Tcl too old for us to use ?
  345. TCL_VER_PRE70=`echo $egg_cv_var_tcl_version | $AWK '{split([$]1, i, "."); if (i[[1]] < 7) print "yes"; else print "no"}'`
  346. if test "$HAVE_LIBTCL" = 1 -a "$TCL_VER_PRE70" = yes; then
  347. cat << EOF >&2
  348. configure: error:
  349. Your Tcl version is much too old for Eggdrop to use. You should
  350. download and compile a more recent version. The most reliable
  351. current version is $tclrecommendver and can be downloaded from
  352. ${tclrecommendsite}.
  353. See doc/COMPILE-GUIDE's 'Tcl Detection and Installation' section
  354. for more information.
  355. EOF
  356. exit 1
  357. fi
  358. ])
  359. dnl EGG_TCL_TESTLIBS()
  360. dnl
  361. AC_DEFUN([EGG_TCL_TESTLIBS],
  362. [
  363. # Set variables for Tcl library tests
  364. TCL_TEST_LIB="$TCLLIBFNS"
  365. TCL_TEST_OTHERLIBS="-L$TCLLIB $EGG_MATH_LIB"
  366. if test "x$ac_cv_lib_pthread" != x; then
  367. TCL_TEST_OTHERLIBS="$TCL_TEST_OTHERLIBS $ac_cv_lib_pthread"
  368. fi
  369. ])
  370. dnl EGG_TCL_CHECK_FREE()
  371. dnl
  372. AC_DEFUN([EGG_TCL_CHECK_FREE],
  373. [
  374. if test "$egg_tcl_changed" = yes; then
  375. EGG_CACHE_UNSET(egg_cv_var_tcl_free)
  376. fi
  377. # Check for Tcl_Free()
  378. AC_CHECK_LIB($TCL_TEST_LIB, Tcl_Free, [egg_cv_var_tcl_free="yes"], [egg_cv_var_tcl_free="no"], $TCL_TEST_OTHERLIBS)
  379. if test "$egg_cv_var_tcl_free" = yes; then
  380. AC_DEFINE(HAVE_TCL_FREE, 1, [Define for Tcl that has Tcl_Free() (7.5p1 and later).])
  381. fi
  382. ])
  383. dnl EGG_TCL_CHECK_GETCURRENTTHREAD
  384. dnl
  385. AC_DEFUN([EGG_TCL_CHECK_GETCURRENTTHREAD],
  386. [
  387. if test "$egg_tcl_changed" = yes; then
  388. EGG_CACHE_UNSET(egg_cv_var_tcl_getcurrentthread)
  389. fi
  390. # Check for Tcl_GetCurrentThread()
  391. AC_CHECK_LIB($TCL_TEST_LIB, Tcl_GetCurrentThread, [egg_cv_var_tcl_getcurrentthread="yes"], [egg_cv_var_tcl_getcurrentthread="no"], $TCL_TEST_OTHERLIBS)
  392. if test "$egg_cv_var_tcl_getcurrentthread" = yes; then
  393. AC_DEFINE(HAVE_TCL_GETCURRENTTHREAD, 1, [Define for Tcl that has Tcl_GetCurrentThread() (8.1a2 and later).])
  394. # Add pthread library to $LIBS if we need it for threaded Tcl
  395. if test "x$ac_cv_lib_pthread" != x; then
  396. EGG_APPEND_VAR(LIBS, $ac_cv_lib_pthread)
  397. fi
  398. fi
  399. ])
  400. dnl EGG_TCL_CHECK_GETTHREADDATA
  401. dnl
  402. AC_DEFUN([EGG_TCL_CHECK_GETTHREADDATA],
  403. [
  404. if test "$egg_tcl_changed" = yes; then
  405. EGG_CACHE_UNSET(egg_cv_var_tcl_getthreaddata)
  406. fi
  407. # Check for Tcl_GetThreadData()
  408. AC_CHECK_LIB($TCL_TEST_LIB, Tcl_GetThreadData, [egg_cv_var_tcl_getthreaddata="yes"], [egg_cv_var_tcl_getthreaddata="no"], $TCL_TEST_OTHERLIBS)
  409. if test "$egg_cv_var_tcl_getthreaddata" = yes; then
  410. AC_DEFINE(HAVE_TCL_GETTHREADDATA, 1, [Define for Tcl that has Tcl_GetThreadData() (8.1a2 and later).])
  411. fi
  412. ])
  413. dnl EGG_TCL_CHECK_SETNOTIFIER
  414. dnl
  415. AC_DEFUN([EGG_TCL_CHECK_SETNOTIFIER],
  416. [
  417. if test "$egg_tcl_changed" = yes; then
  418. EGG_CACHE_UNSET(egg_cv_var_tcl_setnotifier)
  419. fi
  420. # Check for Tcl_SetNotifier()
  421. AC_CHECK_LIB($TCL_TEST_LIB, Tcl_SetNotifier, [egg_cv_var_tcl_setnotifier="yes"], [egg_cv_var_tcl_setnotifier="no"], $TCL_TEST_OTHERLIBS)
  422. if test "$egg_cv_var_tcl_setnotifier" = yes; then
  423. AC_DEFINE(HAVE_TCL_SETNOTIFIER, 1, [Define for Tcl that has Tcl_SetNotifier() (8.2b1 and later).])
  424. fi
  425. ])
  426. dnl EGG_TCL_LIB_REQS()
  427. dnl
  428. AC_DEFUN([EGG_TCL_LIB_REQS],
  429. [
  430. if test "$EGG_CYGWIN" = yes; then
  431. TCL_REQS="${TCLLIB}/lib${TCLLIBFN}"
  432. TCL_LIBS="-L$TCLLIB -l$TCLLIBFNS $EGG_MATH_LIB"
  433. else
  434. if test "$TCLLIBEXT" != ".a"; then
  435. TCL_REQS="${TCLLIB}/lib${TCLLIBFN}"
  436. TCL_LIBS="-L$TCLLIB -l$TCLLIBFNS $EGG_MATH_LIB"
  437. else
  438. # Set default make as static for unshared Tcl library
  439. if test "$DEFAULT_MAKE" != static; then
  440. cat << 'EOF' >&2
  441. configure: WARNING:
  442. Your Tcl library is not a shared lib.
  443. configure will now set default make type to static.
  444. EOF
  445. DEFAULT_MAKE="static"
  446. AC_SUBST(DEFAULT_MAKE)
  447. fi
  448. # Are we using a pre 7.4 Tcl version ?
  449. TCL_VER_PRE74=`echo $egg_cv_var_tcl_version | $AWK '{split([$]1, i, "."); if (((i[[1]] == 7) && (i[[2]] < 4)) || (i[[1]] < 7)) print "yes"; else print "no"}'`
  450. if test "$TCL_VER_PRE74" = no; then
  451. # Was the --with-tcllib option given ?
  452. if test "x$tcllibname" != x; then
  453. TCL_REQS="${TCLLIB}/lib${TCLLIBFN}"
  454. TCL_LIBS="${TCLLIB}/lib${TCLLIBFN} $EGG_MATH_LIB"
  455. else
  456. TCL_REQS="${TCLLIB}/lib${TCLLIBFN}"
  457. TCL_LIBS="-L$TCLLIB -l$TCLLIBFNS $EGG_MATH_LIB"
  458. fi
  459. else
  460. cat << EOF >&2
  461. configure: WARNING:
  462. Your Tcl version ($egg_cv_var_tcl_version) is older than 7.4.
  463. There are known problems, but we will attempt to work around them.
  464. EOF
  465. TCL_REQS="libtcle.a"
  466. TCL_LIBS="-L`pwd` -ltcle $EGG_MATH_LIB"
  467. fi
  468. fi
  469. fi
  470. AC_SUBST(TCL_REQS)
  471. AC_SUBST(TCL_LIBS)
  472. ])