xref: /openbsd-src/gnu/usr.bin/binutils/gdb/testsuite/aclocal.m4 (revision e93f7393d476ad1c5192174ea92f14ecc97182e7)
1*e93f7393Sniklasdnl This file is duplicated in four places:
2*e93f7393Sniklasdnl * gdb/aclocal.m4
3*e93f7393Sniklasdnl * gdb/testsuite/aclocal.m4
4*e93f7393Sniklasdnl * expect/aclocal.m4
5*e93f7393Sniklasdnl * dejagnu/aclocal.m4
6*e93f7393Sniklasdnl Consider modifying all copies in parallel.
7*e93f7393Sniklasdnl written by Rob Savoye <rob@cygnus.com> for Cygnus Support
8*e93f7393Sniklasdnl CYGNUS LOCAL: This gets the right posix flag for gcc
9*e93f7393SniklasAC_DEFUN(CY_AC_TCL_LYNX_POSIX,
10*e93f7393Sniklas[AC_REQUIRE([AC_PROG_CC])AC_REQUIRE([AC_PROG_CPP])
11*e93f7393SniklasAC_MSG_CHECKING([to see if this is LynxOS])
12*e93f7393SniklasAC_CACHE_VAL(ac_cv_os_lynx,
13*e93f7393Sniklas[AC_EGREP_CPP(yes,
14*e93f7393Sniklas[/*
15*e93f7393Sniklas * The old Lynx "cc" only defines "Lynx", but the newer one uses "__Lynx__"
16*e93f7393Sniklas */
17*e93f7393Sniklas#if defined(__Lynx__) || defined(Lynx)
18*e93f7393Sniklasyes
19*e93f7393Sniklas#endif
20*e93f7393Sniklas], ac_cv_os_lynx=yes, ac_cv_os_lynx=no)])
21*e93f7393Sniklas#
22*e93f7393Sniklasif test "$ac_cv_os_lynx" = "yes" ; then
23*e93f7393Sniklas  AC_MSG_RESULT(yes)
24*e93f7393Sniklas  AC_DEFINE(LYNX)
25*e93f7393Sniklas  AC_MSG_CHECKING([whether -mposix or -X is available])
26*e93f7393Sniklas  AC_CACHE_VAL(ac_cv_c_posix_flag,
27*e93f7393Sniklas  [AC_TRY_COMPILE(,[
28*e93f7393Sniklas  /*
29*e93f7393Sniklas   * This flag varies depending on how old the compiler is.
30*e93f7393Sniklas   * -X is for the old "cc" and "gcc" (based on 1.42).
31*e93f7393Sniklas   * -mposix is for the new gcc (at least 2.5.8).
32*e93f7393Sniklas   */
33*e93f7393Sniklas  #if defined(__GNUC__) && __GNUC__ >= 2
34*e93f7393Sniklas  choke me
35*e93f7393Sniklas  #endif
36*e93f7393Sniklas  ], ac_cv_c_posix_flag=" -mposix", ac_cv_c_posix_flag=" -X")])
37*e93f7393Sniklas  CC="$CC $ac_cv_c_posix_flag"
38*e93f7393Sniklas  AC_MSG_RESULT($ac_cv_c_posix_flag)
39*e93f7393Sniklas  else
40*e93f7393Sniklas  AC_MSG_RESULT(no)
41*e93f7393Sniklasfi
42*e93f7393Sniklas])
43*e93f7393Sniklas
44*e93f7393SniklasAC_DEFUN(CY_AC_PATH_TCLH, [
45*e93f7393Sniklas#
46*e93f7393Sniklas# Ok, lets find the tcl source trees so we can use the headers
47*e93f7393Sniklas# Warning: transition of version 9 to 10 will break this algorithm
48*e93f7393Sniklas# because 10 sorts before 9. We also look for just tcl. We have to
49*e93f7393Sniklas# be careful that we don't match stuff like tclX by accident.
50*e93f7393Sniklas# the alternative search directory is involked by --with-tclinclude
51*e93f7393Sniklas#
52*e93f7393Sniklasno_tcl=true
53*e93f7393SniklasAC_MSG_CHECKING(for Tcl private headers)
54*e93f7393SniklasAC_ARG_WITH(tclinclude, [  --with-tclinclude       directory where tcl private headers are], with_tclinclude=${withval})
55*e93f7393SniklasAC_CACHE_VAL(ac_cv_c_tclh,[
56*e93f7393Sniklas# first check to see if --with-tclinclude was specified
57*e93f7393Sniklasif test x"${with_tclinclude}" != x ; then
58*e93f7393Sniklas  if test -f ${with_tclinclude}/tclInt.h ; then
59*e93f7393Sniklas    ac_cv_c_tclh=`(cd ${with_tclinclude}; pwd)`
60*e93f7393Sniklas  else
61*e93f7393Sniklas    AC_MSG_ERROR([${with_tclinclude} directory doesn't contain private headers])
62*e93f7393Sniklas  fi
63*e93f7393Sniklasfi
64*e93f7393Sniklas# next check in private source directory
65*e93f7393Sniklas#
66*e93f7393Sniklas# since ls returns lowest version numbers first, reverse its output
67*e93f7393Sniklasif test x"${ac_cv_c_tclh}" = x ; then
68*e93f7393Sniklas  for i in \
69*e93f7393Sniklas		${srcdir}/../tcl \
70*e93f7393Sniklas		`ls -dr ${srcdir}/../tcl[[0-9]]* 2>/dev/null` \
71*e93f7393Sniklas		${srcdir}/../../tcl \
72*e93f7393Sniklas		`ls -dr ${srcdir}/../../tcl[[0-9]]* 2>/dev/null` \
73*e93f7393Sniklas		${srcdir}/../../../tcl \
74*e93f7393Sniklas		`ls -dr ${srcdir}/../../../tcl[[0-9]]* 2>/dev/null ` ; do
75*e93f7393Sniklas    if test -f $i/tclInt.h ; then
76*e93f7393Sniklas      ac_cv_c_tclh=`(cd $i; pwd)`
77*e93f7393Sniklas      break
78*e93f7393Sniklas    fi
79*e93f7393Sniklas    # Tcl 7.5 and greater puts headers in subdirectory.
80*e93f7393Sniklas    if test -f $i/generic/tclInt.h ; then
81*e93f7393Sniklas      ac_cv_c_tclh=`(cd $i; pwd)`/generic
82*e93f7393Sniklas      break
83*e93f7393Sniklas    fi
84*e93f7393Sniklas  done
85*e93f7393Sniklasfi
86*e93f7393Sniklas# finally check in a few common install locations
87*e93f7393Sniklas#
88*e93f7393Sniklas# since ls returns lowest version numbers first, reverse its output
89*e93f7393Sniklasif test x"${ac_cv_c_tclh}" = x ; then
90*e93f7393Sniklas  for i in \
91*e93f7393Sniklas		`ls -dr /usr/local/src/tcl[[0-9]]* 2>/dev/null` \
92*e93f7393Sniklas		`ls -dr /usr/local/lib/tcl[[0-9]]* 2>/dev/null` \
93*e93f7393Sniklas		/usr/local/src/tcl \
94*e93f7393Sniklas		/usr/local/lib/tcl \
95*e93f7393Sniklas		${prefix}/include ; do
96*e93f7393Sniklas    if test -f $i/tclInt.h ; then
97*e93f7393Sniklas      ac_cv_c_tclh=`(cd $i; pwd)`
98*e93f7393Sniklas      break
99*e93f7393Sniklas    fi
100*e93f7393Sniklas  done
101*e93f7393Sniklasfi
102*e93f7393Sniklas# see if one is installed
103*e93f7393Sniklasif test x"${ac_cv_c_tclh}" = x ; then
104*e93f7393Sniklas   AC_HEADER_CHECK(tclInt.h, ac_cv_c_tclh=installed, ac_cv_c_tclh="")
105*e93f7393Sniklasfi
106*e93f7393Sniklas])
107*e93f7393Sniklasif test x"${ac_cv_c_tclh}" = x ; then
108*e93f7393Sniklas  TCLHDIR="# no Tcl private headers found"
109*e93f7393Sniklas  AC_MSG_ERROR([Can't find Tcl private headers])
110*e93f7393Sniklasfi
111*e93f7393Sniklasif test x"${ac_cv_c_tclh}" != x ; then
112*e93f7393Sniklas  no_tcl=""
113*e93f7393Sniklas  if test x"${ac_cv_c_tclh}" = x"installed" ; then
114*e93f7393Sniklas    AC_MSG_RESULT([is installed])
115*e93f7393Sniklas    TCLHDIR=""
116*e93f7393Sniklas  else
117*e93f7393Sniklas    AC_MSG_RESULT([found in ${ac_cv_c_tclh}])
118*e93f7393Sniklas    # this hack is cause the TCLHDIR won't print if there is a "-I" in it.
119*e93f7393Sniklas    TCLHDIR="-I${ac_cv_c_tclh}"
120*e93f7393Sniklas  fi
121*e93f7393Sniklasfi
122*e93f7393Sniklas
123*e93f7393SniklasAC_MSG_CHECKING([Tcl version])
124*e93f7393Sniklasorig_includes="$CPPFLAGS"
125*e93f7393Sniklas
126*e93f7393Sniklasif test x"${TCLHDIR}" != x ; then
127*e93f7393Sniklas  CPPFLAGS="$CPPFLAGS $TCLHDIR"
128*e93f7393Sniklasfi
129*e93f7393Sniklas
130*e93f7393Sniklas# Get major and minor versions of Tcl.  Use funny names to avoid
131*e93f7393Sniklas# clashes with eg SunOS.
132*e93f7393Sniklascat > conftest.c <<'EOF'
133*e93f7393Sniklas#include "tcl.h"
134*e93f7393SniklasMaJor = TCL_MAJOR_VERSION
135*e93f7393SniklasMiNor = TCL_MINOR_VERSION
136*e93f7393SniklasEOF
137*e93f7393Sniklas
138*e93f7393Sniklastclmajor=
139*e93f7393Sniklastclminor=
140*e93f7393Sniklasif (eval "$CPP $CPPFLAGS conftest.c") 2>/dev/null >conftest.out; then
141*e93f7393Sniklas   # Success.
142*e93f7393Sniklas   tclmajor=`egrep '^MaJor = ' conftest.out | sed -e 's/^MaJor = *//' -e 's/ *$//'`
143*e93f7393Sniklas   tclminor=`egrep '^MiNor = ' conftest.out | sed -e 's/^MiNor = *//' -e 's/ *$//'`
144*e93f7393Sniklasfi
145*e93f7393Sniklasrm -f conftest.c conftest.out
146*e93f7393Sniklas
147*e93f7393Sniklasif test -z "$tclmajor" || test -z "$tclminor"; then
148*e93f7393Sniklas   AC_MSG_RESULT([fatal error: could not find major or minor version number of Tcl])
149*e93f7393Sniklas   exit 1
150*e93f7393Sniklasfi
151*e93f7393SniklasAC_MSG_RESULT(${tclmajor}.${tclminor})
152*e93f7393Sniklas
153*e93f7393SniklasCPPFLAGS="${orig_includes}"
154*e93f7393Sniklas
155*e93f7393SniklasAC_PROVIDE([$0])
156*e93f7393SniklasAC_SUBST(TCLHDIR)
157*e93f7393Sniklas])
158*e93f7393SniklasAC_DEFUN(CY_AC_PATH_TCLLIB, [
159*e93f7393Sniklas#
160*e93f7393Sniklas# Ok, lets find the tcl library
161*e93f7393Sniklas# First, look for one uninstalled.
162*e93f7393Sniklas# the alternative search directory is invoked by --with-tcllib
163*e93f7393Sniklas#
164*e93f7393Sniklas
165*e93f7393Sniklasif test $tclmajor -ge 7 -a $tclminor -ge 4 ; then
166*e93f7393Sniklas  installedtcllibroot=tcl$tclversion
167*e93f7393Sniklaselse
168*e93f7393Sniklas  installedtcllibroot=tcl
169*e93f7393Sniklasfi
170*e93f7393Sniklas
171*e93f7393Sniklasif test x"${no_tcl}" = x ; then
172*e93f7393Sniklas  # we reset no_tcl incase something fails here
173*e93f7393Sniklas  no_tcl=true
174*e93f7393Sniklas  AC_ARG_WITH(tcllib, [  --with-tcllib           directory where the tcl library is],
175*e93f7393Sniklas         with_tcllib=${withval})
176*e93f7393Sniklas  AC_MSG_CHECKING([for Tcl library])
177*e93f7393Sniklas  AC_CACHE_VAL(ac_cv_c_tcllib,[
178*e93f7393Sniklas  # First check to see if --with-tcllib was specified.
179*e93f7393Sniklas  # This requires checking for both the installed and uninstalled name-styles
180*e93f7393Sniklas  # since we have no idea if it's installed or not.
181*e93f7393Sniklas  if test x"${with_tcllib}" != x ; then
182*e93f7393Sniklas    if test -f "${with_tcllib}/lib$installedtcllibroot.so" ; then
183*e93f7393Sniklas      ac_cv_c_tcllib=`(cd ${with_tcllib}; pwd)`/lib$installedtcllibroot.so
184*e93f7393Sniklas    elif test -f "${with_tcllib}/libtcl.so" ; then
185*e93f7393Sniklas      ac_cv_c_tcllib=`(cd ${with_tcllib}; pwd)`/libtcl.so
186*e93f7393Sniklas    # then look for a freshly built statically linked library
187*e93f7393Sniklas    # if Makefile exists we assume its configured and libtcl will be built first.
188*e93f7393Sniklas    elif test -f "${with_tcllib}/lib$installedtcllibroot.a" ; then
189*e93f7393Sniklas      ac_cv_c_tcllib=`(cd ${with_tcllib}; pwd)`/lib$installedtcllibroot.a
190*e93f7393Sniklas    elif test -f "${with_tcllib}/libtcl.a" ; then
191*e93f7393Sniklas      ac_cv_c_tcllib=`(cd ${with_tcllib}; pwd)`/libtcl.a
192*e93f7393Sniklas    else
193*e93f7393Sniklas      AC_MSG_ERROR([${with_tcllib} directory doesn't contain libraries])
194*e93f7393Sniklas    fi
195*e93f7393Sniklas  fi
196*e93f7393Sniklas  # then check for a private Tcl library
197*e93f7393Sniklas  # Since these are uninstalled, use the simple lib name root.
198*e93f7393Sniklas  if test x"${ac_cv_c_tcllib}" = x ; then
199*e93f7393Sniklas    for i in \
200*e93f7393Sniklas		../tcl \
201*e93f7393Sniklas		`ls -dr ../tcl[[0-9]]* 2>/dev/null` \
202*e93f7393Sniklas		../../tcl \
203*e93f7393Sniklas		`ls -dr ../../tcl[[0-9]]* 2>/dev/null` \
204*e93f7393Sniklas		../../../tcl \
205*e93f7393Sniklas		`ls -dr ../../../tcl[[0-9]]* 2>/dev/null` ; do
206*e93f7393Sniklas      # Tcl 7.5 and greater puts library in subdir.  Look there first.
207*e93f7393Sniklas      if test -f "$i/unix/libtcl.so" ; then
208*e93f7393Sniklas	 ac_cv_c_tcllib=`(cd $i; pwd)`/unix/libtcl.so
209*e93f7393Sniklas	 break
210*e93f7393Sniklas      elif test -f "$i/unix/libtcl.a" -o -f "$i/unix/Makefile"; then
211*e93f7393Sniklas	 ac_cv_c_tcllib=`(cd $i; pwd)`/unix/libtcl.a
212*e93f7393Sniklas	 break
213*e93f7393Sniklas      # look for a freshly built dynamically linked library
214*e93f7393Sniklas      elif test -f "$i/libtcl.so" ; then
215*e93f7393Sniklas        ac_cv_c_tcllib=`(cd $i; pwd)`/libtcl.so
216*e93f7393Sniklas	break
217*e93f7393Sniklas
218*e93f7393Sniklas      # then look for a freshly built statically linked library
219*e93f7393Sniklas      # if Makefile exists we assume its configured and libtcl will be
220*e93f7393Sniklas      # built first.
221*e93f7393Sniklas      elif test -f "$i/libtcl.a" -o -f "$i/Makefile" ; then
222*e93f7393Sniklas        ac_cv_c_tcllib=`(cd $i; pwd)`/libtcl.a
223*e93f7393Sniklas	break
224*e93f7393Sniklas      fi
225*e93f7393Sniklas    done
226*e93f7393Sniklas  fi
227*e93f7393Sniklas  # check in a few common install locations
228*e93f7393Sniklas  if test x"${ac_cv_c_tcllib}" = x ; then
229*e93f7393Sniklas    for i in `ls -d ${prefix}/lib /usr/local/lib 2>/dev/null` ; do
230*e93f7393Sniklas      # first look for a freshly built dynamically linked library
231*e93f7393Sniklas      if test -f "$i/lib$installedtcllibroot.so" ; then
232*e93f7393Sniklas        ac_cv_c_tcllib=`(cd $i; pwd)`/lib$installedtcllibroot.so
233*e93f7393Sniklas	break
234*e93f7393Sniklas      # then look for a freshly built statically linked library
235*e93f7393Sniklas      # if Makefile exists we assume its configured and libtcl will be built first.
236*e93f7393Sniklas      elif test -f "$i/lib$installedtcllibroot.a" -o -f "$i/Makefile" ; then
237*e93f7393Sniklas        ac_cv_c_tcllib=`(cd $i; pwd)`/lib$installedtcllibroot.a
238*e93f7393Sniklas	break
239*e93f7393Sniklas      fi
240*e93f7393Sniklas    done
241*e93f7393Sniklas  fi
242*e93f7393Sniklas  # check in a few other private locations
243*e93f7393Sniklas  if test x"${ac_cv_c_tcllib}" = x ; then
244*e93f7393Sniklas    for i in \
245*e93f7393Sniklas		${srcdir}/../tcl \
246*e93f7393Sniklas		`ls -dr ${srcdir}/../tcl[[0-9]]* 2>/dev/null` ; do
247*e93f7393Sniklas      # Tcl 7.5 and greater puts library in subdir.  Look there first.
248*e93f7393Sniklas      if test -f "$i/unix/libtcl.so" ; then
249*e93f7393Sniklas	 ac_cv_c_tcllib=`(cd $i; pwd)`/unix/libtcl.so
250*e93f7393Sniklas	 break
251*e93f7393Sniklas      elif test -f "$i/unix/libtcl.a" -o -f "$i/unix/Makefile"; then
252*e93f7393Sniklas	 ac_cv_c_tcllib=`(cd $i; pwd)`/unix/libtcl.a
253*e93f7393Sniklas	 break
254*e93f7393Sniklas      # look for a freshly built dynamically linked library
255*e93f7393Sniklas      elif test -f "$i/libtcl.so" ; then
256*e93f7393Sniklas        ac_cv_c_tcllib=`(cd $i; pwd)`/libtcl.so
257*e93f7393Sniklas	break
258*e93f7393Sniklas
259*e93f7393Sniklas      # then look for a freshly built statically linked library
260*e93f7393Sniklas      # if Makefile exists we assume its configured and libtcl will be
261*e93f7393Sniklas      # built first.
262*e93f7393Sniklas      elif test -f "$i/libtcl.a" -o -f "$i/Makefile" ; then
263*e93f7393Sniklas        ac_cv_c_tcllib=`(cd $i; pwd)`/libtcl.a
264*e93f7393Sniklas	break
265*e93f7393Sniklas      fi
266*e93f7393Sniklas    done
267*e93f7393Sniklas  fi
268*e93f7393Sniklas
269*e93f7393Sniklas  # see if one is conveniently installed with the compiler
270*e93f7393Sniklas  if test x"${ac_cv_c_tcllib}" = x ; then
271*e93f7393Sniklas    orig_libs="$LIBS"
272*e93f7393Sniklas    LIBS="$LIBS -l$installedtcllibroot -lm"
273*e93f7393Sniklas    AC_TRY_RUN([
274*e93f7393Sniklas    Tcl_AppInit()
275*e93f7393Sniklas    { exit(0); }], ac_cv_c_tcllib="-l$installedtcllibroot", ac_cv_c_tcllib=""
276*e93f7393Sniklas    , ac_cv_c_tclib="-l$installedtcllibroot")
277*e93f7393Sniklas    LIBS="${orig_libs}"
278*e93f7393Sniklas   fi
279*e93f7393Sniklas  ])
280*e93f7393Sniklas  if test x"${ac_cv_c_tcllib}" = x ; then
281*e93f7393Sniklas    TCLLIB="# no Tcl library found"
282*e93f7393Sniklas    AC_MSG_WARN(Can't find Tcl library)
283*e93f7393Sniklas  else
284*e93f7393Sniklas    TCLLIB=${ac_cv_c_tcllib}
285*e93f7393Sniklas    AC_MSG_RESULT(found $TCLLIB)
286*e93f7393Sniklas    no_tcl=
287*e93f7393Sniklas  fi
288*e93f7393Sniklasfi
289*e93f7393Sniklas
290*e93f7393SniklasAC_PROVIDE([$0])
291*e93f7393SniklasAC_SUBST(TCLLIB)
292*e93f7393Sniklas])
293*e93f7393SniklasAC_DEFUN(CY_AC_PATH_TKH, [
294*e93f7393Sniklas#
295*e93f7393Sniklas# Ok, lets find the tk source trees so we can use the headers
296*e93f7393Sniklas# If the directory (presumably symlink) named "tk" exists, use that one
297*e93f7393Sniklas# in preference to any others.  Same logic is used when choosing library
298*e93f7393Sniklas# and again with Tcl. The search order is the best place to look first, then in
299*e93f7393Sniklas# decreasing significance. The loop breaks if the trigger file is found.
300*e93f7393Sniklas# Note the gross little conversion here of srcdir by cd'ing to the found
301*e93f7393Sniklas# directory. This converts the path from a relative to an absolute, so
302*e93f7393Sniklas# recursive cache variables for the path will work right. We check all
303*e93f7393Sniklas# the possible paths in one loop rather than many seperate loops to speed
304*e93f7393Sniklas# things up.
305*e93f7393Sniklas# the alternative search directory is invoked by --with-tkinclude
306*e93f7393Sniklas#
307*e93f7393SniklasAC_MSG_CHECKING(for Tk private headers)
308*e93f7393SniklasAC_ARG_WITH(tkinclude, [  --with-tkinclude        directory where the tk private headers are],
309*e93f7393Sniklas            with_tkinclude=${withval})
310*e93f7393Sniklasno_tk=true
311*e93f7393SniklasAC_CACHE_VAL(ac_cv_c_tkh,[
312*e93f7393Sniklas# first check to see if --with-tkinclude was specified
313*e93f7393Sniklasif test x"${with_tkinclude}" != x ; then
314*e93f7393Sniklas  if test -f ${with_tkinclude}/tk.h ; then
315*e93f7393Sniklas    ac_cv_c_tkh=`(cd ${with_tkinclude}; pwd)`
316*e93f7393Sniklas  else
317*e93f7393Sniklas    AC_MSG_ERROR([${with_tkinclude} directory doesn't contain private headers])
318*e93f7393Sniklas  fi
319*e93f7393Sniklasfi
320*e93f7393Sniklas# next check in private source directory
321*e93f7393Sniklas#
322*e93f7393Sniklas# since ls returns lowest version numbers first, reverse the entire list
323*e93f7393Sniklas# and search for the worst fit, overwriting it with better fits as we find them
324*e93f7393Sniklasif test x"${ac_cv_c_tkh}" = x ; then
325*e93f7393Sniklas  for i in \
326*e93f7393Sniklas		${srcdir}/../tk \
327*e93f7393Sniklas		`ls -dr ${srcdir}/../tk[[0-9]]* 2>/dev/null` \
328*e93f7393Sniklas		${srcdir}/../../tk \
329*e93f7393Sniklas		`ls -dr ${srcdir}/../../tk[[0-9]]* 2>/dev/null` \
330*e93f7393Sniklas		${srcdir}/../../../tk \
331*e93f7393Sniklas		`ls -dr ${srcdir}/../../../tk[[0-9]]* 2>/dev/null ` ; do
332*e93f7393Sniklas    if test -f $i/tk.h ; then
333*e93f7393Sniklas      ac_cv_c_tkh=`(cd $i; pwd)`
334*e93f7393Sniklas      break
335*e93f7393Sniklas    fi
336*e93f7393Sniklas    # Tk 4.1 and greater puts this in a subdir.
337*e93f7393Sniklas    if test -f $i/generic/tk.h; then
338*e93f7393Sniklas       ac_cv_c_tkh=`(cd $i; pwd)`/generic
339*e93f7393Sniklas    fi
340*e93f7393Sniklas  done
341*e93f7393Sniklasfi
342*e93f7393Sniklas# finally check in a few common install locations
343*e93f7393Sniklas#
344*e93f7393Sniklas# since ls returns lowest version numbers first, reverse the entire list
345*e93f7393Sniklas# and search for the worst fit, overwriting it with better fits as we find them
346*e93f7393Sniklasif test x"${ac_cv_c_tkh}" = x ; then
347*e93f7393Sniklas  for i in \
348*e93f7393Sniklas		`ls -dr /usr/local/src/tk[[0-9]]* 2>/dev/null` \
349*e93f7393Sniklas		`ls -dr /usr/local/lib/tk[[0-9]]* 2>/dev/null` \
350*e93f7393Sniklas		/usr/local/src/tk \
351*e93f7393Sniklas		/usr/local/lib/tk \
352*e93f7393Sniklas		${prefix}/include ; do
353*e93f7393Sniklas    if test -f $i/tk.h ; then
354*e93f7393Sniklas      ac_cv_c_tkh=`(cd $i; pwd)`
355*e93f7393Sniklas      break
356*e93f7393Sniklas    fi
357*e93f7393Sniklas  done
358*e93f7393Sniklasfi
359*e93f7393Sniklas# see if one is installed
360*e93f7393Sniklasif test x"${ac_cv_c_tkh}" = x ; then
361*e93f7393Sniklas  AC_HEADER_CHECK(tk.h, ac_cv_c_tkh=installed)
362*e93f7393Sniklasfi
363*e93f7393Sniklas])
364*e93f7393Sniklasif test x"${ac_cv_c_tkh}" != x ; then
365*e93f7393Sniklas  no_tk=""
366*e93f7393Sniklas  if test x"${ac_cv_c_tkh}" = x"installed" ; then
367*e93f7393Sniklas    AC_MSG_RESULT([is installed])
368*e93f7393Sniklas    TKHDIR=""
369*e93f7393Sniklas  else
370*e93f7393Sniklas    AC_MSG_RESULT([found in $ac_cv_c_tkh])
371*e93f7393Sniklas    # this hack is cause the TKHDIR won't print if there is a "-I" in it.
372*e93f7393Sniklas    TKHDIR="-I${ac_cv_c_tkh}"
373*e93f7393Sniklas  fi
374*e93f7393Sniklaselse
375*e93f7393Sniklas  TKHDIR="# no Tk directory found"
376*e93f7393Sniklas  AC_MSG_WARN([Can't find Tk private headers])
377*e93f7393Sniklas  no_tk=true
378*e93f7393Sniklasfi
379*e93f7393Sniklas
380*e93f7393Sniklas# if Tk is installed, extract the major/minor version
381*e93f7393Sniklasif test x"${no_tk}" = x ; then
382*e93f7393SniklasAC_MSG_CHECKING([Tk version])
383*e93f7393Sniklasorig_includes="$CPPFLAGS"
384*e93f7393Sniklas
385*e93f7393Sniklasif test x"${TCLHDIR}" != x ; then
386*e93f7393Sniklas  CPPFLAGS="$CPPFLAGS $TCLHDIR"
387*e93f7393Sniklasfi
388*e93f7393Sniklasif test x"${TKHDIR}" != x ; then
389*e93f7393Sniklas  CPPFLAGS="$CPPFLAGS $TKHDIR"
390*e93f7393Sniklasfi
391*e93f7393Sniklasif test x"${x_includes}" != x -a x"${x_includes}" != xNONE ; then
392*e93f7393Sniklas  CPPFLAGS="$CPPFLAGS -I$x_includes"
393*e93f7393Sniklasfi
394*e93f7393Sniklas
395*e93f7393Sniklas# Get major and minor versions of Tk.  Use funny names to avoid
396*e93f7393Sniklas# clashes with eg SunOS.
397*e93f7393Sniklascat > conftest.c <<'EOF'
398*e93f7393Sniklas#include "tk.h"
399*e93f7393SniklasMaJor = TK_MAJOR_VERSION
400*e93f7393SniklasMiNor = TK_MINOR_VERSION
401*e93f7393SniklasEOF
402*e93f7393Sniklas
403*e93f7393Sniklastkmajor=
404*e93f7393Sniklastkminor=
405*e93f7393Sniklasif (eval "$CPP $CPPFLAGS conftest.c") 2>/dev/null >conftest.out; then
406*e93f7393Sniklas   # Success.
407*e93f7393Sniklas   tkmajor=`egrep '^MaJor = ' conftest.out | sed -e 's/^MaJor = *//' -e 's/ *$//'`
408*e93f7393Sniklas   tkminor=`egrep '^MiNor = ' conftest.out | sed -e 's/^MiNor = *//' -e 's/ *$//'`
409*e93f7393Sniklasfi
410*e93f7393Sniklasrm -f conftest.c conftest.out
411*e93f7393Sniklas
412*e93f7393Sniklasif test -z "$tkmajor" || test -z "$tkminor"; then
413*e93f7393Sniklas   AC_MSG_RESULT([fatal error: could not find major or minor version number of Tk])
414*e93f7393Sniklas   exit 1
415*e93f7393Sniklasfi
416*e93f7393SniklasAC_MSG_RESULT(${tkmajor}.${tkminor})
417*e93f7393Sniklas
418*e93f7393SniklasCPPFLAGS="${orig_includes}"
419*e93f7393Sniklasfi
420*e93f7393Sniklas
421*e93f7393SniklasAC_PROVIDE([$0])
422*e93f7393SniklasAC_SUBST(TKHDIR)
423*e93f7393Sniklas])
424*e93f7393SniklasAC_DEFUN(CY_AC_PATH_TKLIB, [
425*e93f7393SniklasAC_REQUIRE([CY_AC_PATH_TCL])
426*e93f7393Sniklas#
427*e93f7393Sniklas# Ok, lets find the tk library
428*e93f7393Sniklas# First, look for the latest private (uninstalled) copy
429*e93f7393Sniklas# Notice that the destinations in backwards priority since the tests have
430*e93f7393Sniklas# no break.
431*e93f7393Sniklas# Then we look for either .a, .so, or Makefile.  A Makefile is acceptable
432*e93f7393Sniklas# is it indicates the target has been configured and will (probably)
433*e93f7393Sniklas# soon be built.  This allows an entire tree of Tcl software to be
434*e93f7393Sniklas# configured at once and then built.
435*e93f7393Sniklas# the alternative search directory is invoked by --with-tklib
436*e93f7393Sniklas#
437*e93f7393Sniklas
438*e93f7393Sniklasif test x"${no_tk}" = x ; then
439*e93f7393Sniklas  # reset no_tk incase something fails here
440*e93f7393Sniklas  no_tk="true"
441*e93f7393Sniklas
442*e93f7393Sniklas  if test $tkmajor -ge 4 ; then
443*e93f7393Sniklas    installedtklibroot=tk$tkversion
444*e93f7393Sniklas  else
445*e93f7393Sniklas    installedtkllibroot=tk
446*e93f7393Sniklas  fi
447*e93f7393Sniklas
448*e93f7393Sniklas  AC_ARG_WITH(tklib, [  --with-tklib            directory where the tk library is],
449*e93f7393Sniklas              with_tklib=${withval})
450*e93f7393Sniklas  AC_MSG_CHECKING([for Tk library])
451*e93f7393Sniklas  AC_CACHE_VAL(ac_cv_c_tklib,[
452*e93f7393Sniklas  # first check to see if --with-tklib was specified
453*e93f7393Sniklas  # This requires checking for both the installed and uninstalled name-styles
454*e93f7393Sniklas  # since we have no idea if it's installed or not.
455*e93f7393Sniklas  if test x"${with_tklib}" != x ; then
456*e93f7393Sniklas    if test -f "${with_tklib}/lib$installedtklibroot.so" ; then
457*e93f7393Sniklas      ac_cv_c_tklib=`(cd ${with_tklib}; pwd)`/lib$installedtklibroot.so
458*e93f7393Sniklas      no_tk=""
459*e93f7393Sniklas    elif test -f "${with_tklib}/libtk.so" ; then
460*e93f7393Sniklas      ac_cv_c_tklib=`(cd ${with_tklib}; pwd)`/libtk.so
461*e93f7393Sniklas      no_tk=""
462*e93f7393Sniklas    # then look for a freshly built statically linked library
463*e93f7393Sniklas    # if Makefile exists we assume its configured and libtk will be built
464*e93f7393Sniklas    elif test -f "${with_tklib}/lib$installedtklibroot.a" ; then
465*e93f7393Sniklas      ac_cv_c_tklib=`(cd ${with_tklib}; pwd)`/lib$installedtklibroot.a
466*e93f7393Sniklas      no_tk=""
467*e93f7393Sniklas    elif test -f "${with_tklib}/libtk.a" ; then
468*e93f7393Sniklas      ac_cv_c_tklib=`(cd ${with_tklib}; pwd)`/libtk.a
469*e93f7393Sniklas      no_tk=""
470*e93f7393Sniklas    else
471*e93f7393Sniklas      AC_MSG_ERROR([${with_tklib} directory doesn't contain libraries])
472*e93f7393Sniklas    fi
473*e93f7393Sniklas  fi
474*e93f7393Sniklas  # then check for a private Tk library
475*e93f7393Sniklas  # Since these are uninstalled, use the simple lib name root.
476*e93f7393Sniklas  if test x"${ac_cv_c_tklib}" = x ; then
477*e93f7393Sniklas    for i in \
478*e93f7393Sniklas		../tk \
479*e93f7393Sniklas		`ls -dr ../tk[[0-9]]* 2>/dev/null` \
480*e93f7393Sniklas		../../tk \
481*e93f7393Sniklas		`ls -dr ../../tk[[0-9]]* 2>/dev/null` \
482*e93f7393Sniklas		../../../tk \
483*e93f7393Sniklas		`ls -dr ../../../tk[[0-9]]* 2>/dev/null` ; do
484*e93f7393Sniklas      # Tk 4.1 and greater puts things in subdirs.  Check these first.
485*e93f7393Sniklas      if test -f "$i/unix/libtk.so" ; then
486*e93f7393Sniklas	 ac_cv_c_tklib=`(cd $i; pwd)`/unix/libtk.so
487*e93f7393Sniklas	 no_tk=
488*e93f7393Sniklas	 break
489*e93f7393Sniklas      elif test -f "$i/unix/libtk.a" -o -f "$i/unix/Makefile"; then
490*e93f7393Sniklas	 ac_cv_c_tklib=`(cd $i; pwd)`/unix/libtk.a
491*e93f7393Sniklas	 no_tk=
492*e93f7393Sniklas	 break
493*e93f7393Sniklas      # look for a freshly built dynamically linked library
494*e93f7393Sniklas      elif test -f "$i/libtk.so" ; then
495*e93f7393Sniklas        ac_cv_c_tklib=`(cd $i; pwd)`/libtk.so
496*e93f7393Sniklas        no_tk=
497*e93f7393Sniklas	break
498*e93f7393Sniklas      # then look for a freshly built statically linked library
499*e93f7393Sniklas      # if Makefile exists we assume its configured and libtk will be built
500*e93f7393Sniklas      elif test -f "$i/libtk.a" -o -f "$i/Makefile" ; then
501*e93f7393Sniklas        ac_cv_c_tklib=`(cd $i; pwd)`/libtk.a
502*e93f7393Sniklas        no_tk=""
503*e93f7393Sniklas 	break
504*e93f7393Sniklas      fi
505*e93f7393Sniklas    done
506*e93f7393Sniklas  fi
507*e93f7393Sniklas  # finally check in a few common install locations
508*e93f7393Sniklas  if test x"${ac_cv_c_tklib}" = x ; then
509*e93f7393Sniklas    for i in `ls -d ${prefix}/lib /usr/local/lib 2>/dev/null` ; do
510*e93f7393Sniklas      # first look for a freshly built dynamically linked library
511*e93f7393Sniklas      if test -f "$i/lib$installedtklibroot.so" ; then
512*e93f7393Sniklas        ac_cv_c_tklib=`(cd $i; pwd)`/lib$installedtklibroot.so
513*e93f7393Sniklas        no_tk=""
514*e93f7393Sniklas	break
515*e93f7393Sniklas      # then look for a freshly built statically linked library
516*e93f7393Sniklas      # if Makefile exists, we assume it's configured and libtcl will be built
517*e93f7393Sniklas      elif test -f "$i/lib$installedtklibroot.a" -o -f "$i/Makefile" ; then
518*e93f7393Sniklas        ac_cv_c_tklib=`(cd $i; pwd)`/lib$installedtklibroot.a
519*e93f7393Sniklas        no_tk=""
520*e93f7393Sniklas 	break
521*e93f7393Sniklas      fi
522*e93f7393Sniklas    done
523*e93f7393Sniklas  fi
524*e93f7393Sniklas  # check in a few other private locations
525*e93f7393Sniklas  if test x"${ac_cv_c_tklib}" = x ; then
526*e93f7393Sniklas    for i in \
527*e93f7393Sniklas		${srcdir}/../tk \
528*e93f7393Sniklas		`ls -dr ${srcdir}/../tk[[0-9]]* 2>/dev/null` ; do
529*e93f7393Sniklas      # Tk 4.1 and greater puts things in subdirs.  Check these first.
530*e93f7393Sniklas      if test -f "$i/unix/libtk.so" ; then
531*e93f7393Sniklas	 ac_cv_c_tklib=`(cd $i; pwd)`/unix/libtk.so
532*e93f7393Sniklas	 no_tk=
533*e93f7393Sniklas	 break
534*e93f7393Sniklas      elif test -f "$i/unix/libtk.a" -o -f "$i/unix/Makefile"; then
535*e93f7393Sniklas	 ac_cv_c_tcllib=`(cd $i; pwd)`/unix/libtk.a
536*e93f7393Sniklas	 no_tk=
537*e93f7393Sniklas	 break
538*e93f7393Sniklas      # look for a freshly built dynamically linked library
539*e93f7393Sniklas      elif test -f "$i/libtk.so" ; then
540*e93f7393Sniklas        ac_cv_c_tklib=`(cd $i; pwd)`/libtk.so
541*e93f7393Sniklas        no_tk=""
542*e93f7393Sniklas	break
543*e93f7393Sniklas      # then look for a freshly built statically linked library
544*e93f7393Sniklas      # if Makefile exists, we assume it's configured and libtcl will be built
545*e93f7393Sniklas      elif test -f "$i/libtk.a" -o -f "$i/Makefile" ; then
546*e93f7393Sniklas        ac_cv_c_tklib=`(cd $i; pwd)`/libtk.a
547*e93f7393Sniklas        no_tk=""
548*e93f7393Sniklas 	break
549*e93f7393Sniklas      fi
550*e93f7393Sniklas    done
551*e93f7393Sniklas  fi
552*e93f7393Sniklas  # see if one is conveniently installed with the compiler
553*e93f7393Sniklas  if test x"${ac_cv_c_tklib}" = x ; then
554*e93f7393Sniklas       AC_REQUIRE([AC_PATH_X])
555*e93f7393Sniklas       orig_libs="$LIBS"
556*e93f7393Sniklas       LIBS="$LIBS -l$installedtklibroot $x_libraries $ac_cv_c_tcllib -lm"
557*e93f7393Sniklas       AC_TRY_RUN([
558*e93f7393Sniklas       Tcl_AppInit()
559*e93f7393Sniklas       { exit(0); }], ac_cv_c_tklib="-l$installedtklibroot", ac_cv_c_tklib=""
560*e93f7393Sniklas       , ac_cv_c_tklib="-l$installedtklibroot")
561*e93f7393Sniklas       LIBS="${orig_libs}"
562*e93f7393Sniklas   fi
563*e93f7393Sniklas  ])
564*e93f7393Sniklas  if test x"${ac_cv_c_tklib}" = x ; then
565*e93f7393Sniklas    TKLIB="# no Tk library found"
566*e93f7393Sniklas    AC_MSG_WARN(Can't find Tk library)
567*e93f7393Sniklas  else
568*e93f7393Sniklas    TKLIB=$ac_cv_c_tklib
569*e93f7393Sniklas    AC_MSG_RESULT(found $TKLIB)
570*e93f7393Sniklas    no_tk=
571*e93f7393Sniklas  fi
572*e93f7393Sniklasfi
573*e93f7393SniklasAC_PROVIDE([$0])
574*e93f7393SniklasAC_SUBST(TKLIB)
575*e93f7393Sniklas])
576*e93f7393SniklasAC_DEFUN(CY_AC_PATH_TK, [
577*e93f7393Sniklas  CY_AC_PATH_TKH
578*e93f7393Sniklas  CY_AC_PATH_TKLIB
579*e93f7393Sniklas])
580*e93f7393SniklasAC_DEFUN(CY_AC_PATH_TCL, [
581*e93f7393Sniklas  CY_AC_PATH_TCLH
582*e93f7393Sniklas  CY_AC_PATH_TCLLIB
583*e93f7393Sniklas])
584