1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(../include/mk4.h)
3AC_PREREQ(2.5)
4AC_CONFIG_AUX_DIR(scripts)
5AC_CONFIG_HEADER(config.h)
6AC_LANG_CPLUSPLUS
7
8MK_TARGETS="core"
9MK_INSTALL="install-mk"
10
11AC_ARG_WITH(python,
12[  --with-python=PATH      build the Mk4py extension for Python with headers in
13                          `PATH/include/python2.5'; install the Mk4py modules in
14                          `PATH/lib/python2.5/site-packages'.  If PATH is of the
15                          form `HEADER,LIB', search for header files in HEADER,
16                          and install Mk4py in LIB.  If you omit the `=PATH'
17                          part, use the standard includedir and libdir.],
18                          [with_python=${withval}], [with_python=no])
19
20AC_MSG_CHECKING([for Python configuration])
21case "$with_python" in
22  "yes" )
23	PY_INCLUDE_DIR="${prefix}/include/python2.5"
24	PY_LIB_DIR="${prefix}/lib/python2.5/site-packages"
25  ;;
26  "no" )
27	PY_INCLUDE_DIR="# no Python headers"
28  ;;
29  *","* )
30	PY_INCLUDE_DIR="`echo $with_python | sed -e 's/,.*$//'`"
31	PY_LIB_DIR="`echo $with_python | sed -e 's/^.*,//'`"
32  ;;
33  * )
34    PY_INCLUDE_DIR="$with_python/include/python2.5"
35    PY_LIB_DIR="$with_python/lib/python2.5/site-packages"
36  ;;
37esac
38
39if test x"$with_python" = xno; then
40  AC_MSG_RESULT(not enabled)
41else
42  MK_TARGETS="$MK_TARGETS python"
43  MK_INSTALL="$MK_INSTALL install-python"
44  if test -f "${PY_INCLUDE_DIR}/Python.h" ; then
45    MK_TARGETS="$MK_TARGETS python"
46    MK_INSTALL="$MK_INSTALL install-python"
47    AC_MSG_RESULT($PY_INCLUDE_DIR and $PY_LIB_DIR)
48  else
49    AC_MSG_RESULT(can't find ${PY_INCLUDE_DIR}/Python.h)
50  fi
51fi
52
53AC_ARG_WITH(tcl, 
54[  --with-tcl=PATH         build the Mk4tcl extension for Tcl with tcl.h in
55                          `PATH/tcl.h'; install the Mk4tcl package in
56			  `PATH/../lib'.  If PATH is of the form `HEADER,LIB',
57                          search for tcl.h in HEADER, and install Mk4tcl in
58                          LIB.  If you omit the `=PATH' part, use the standard
59			  includedir and libdir.],
60			  [with_tcl=${withval}], [with_tcl=no])
61
62AC_MSG_CHECKING([for Tcl headers])
63case "$with_tcl" in
64  "yes" )
65	TCL_INCLUDE_DIR="${prefix}/include"
66	TCL_LIB_DIR="${prefix}/lib/tcl8.4"
67  ;;
68  "no" )
69	TCL_INCLUDE_DIR="# no Tcl headers"
70  ;;
71  *","* )
72	TCL_INCLUDE_DIR="`echo $with_tcl | sed -e 's/,.*$//'`"
73	TCL_LIB_DIR="`echo $with_tcl | sed -e 's/^.*,//'`"
74  ;;
75  * )
76    TCL_INCLUDE_DIR="$with_tcl"
77    TCL_LIB_DIR="$with_tcl/../lib"
78  ;;
79esac
80
81if test x"$with_tcl" = xno ; then
82  AC_MSG_RESULT(not enabled)
83else
84  MK_TARGETS="$MK_TARGETS tcl"
85  MK_INSTALL="$MK_INSTALL install-tcl"
86  if test -f "${TCL_INCLUDE_DIR}/tcl.h" ; then
87    AC_MSG_RESULT(found ${TCL_INCLUDE_DIR}/tcl.h)
88    MK_TARGETS="$MK_TARGETS tcl"
89    MK_INSTALL="$MK_INSTALL install-tcl"
90    AC_MSG_CHECKING(for Tcl package installation location)
91    AC_MSG_RESULT(${TCL_LIB_DIR})
92  else
93    AC_MSG_ERROR([${TCL_INCLUDE_DIR} directory doesn't contain tcl.h])
94  fi
95fi
96
97AC_MSG_CHECKING([for building with threads])
98AC_ARG_ENABLE(threads, [  --enable-threads        build with threads], [ok=$enableval], [ok=no])
99if test "$ok" = yes; then
100  MK_THREADS="-Dq4_MULTI -DTCL_THREADS"
101  AC_MSG_RESULT(yes)
102else
103  MK_THREADS=""
104  AC_MSG_RESULT([no (default)])
105fi
106
107AC_MSG_CHECKING([for building as shared lib])
108AC_ARG_ENABLE(shared, [  --enable-shared         build as shared lib (default=yes)], [ok=$enableval], [ok=yes])
109if test "$ok" = yes; then
110  SHARED_BUILD=1
111  AC_MSG_RESULT([yes (default)])
112else
113  SHARED_BUILD=0
114  AC_MSG_RESULT([no, static])
115fi
116
117if test $SHARED_BUILD = 1; then
118  SHLIB_FLAGS="-shared"
119  SHLIB_CFLAGS="-fPIC -DUSE_TCL_STUBS"
120  SHLIB_LD="g++ -shared"
121else
122  SHLIB_FLAGS=""
123  SHLIB_CFLAGS=""
124  SHLIB_LD=""
125fi
126
127# Checks for programs.
128AC_PROG_CXX
129AC_PROG_INSTALL
130
131# Checks for libraries.
132
133# Checks for header files.
134AC_HEADER_STDC
135
136# Checks for typedefs, structures, and compiler characteristics.
137AC_C_CONST
138AC_C_INLINE
139AC_CHECK_SIZEOF(long,4)
140AC_CHECK_TYPES(long long)
141
142# Checks for library functions.
143AC_CHECK_FUNCS(mmap memmove bcopy)
144
145# Deal with static & shared lib differences
146LIB_SUFFIX=".a"
147SHLIB_SUFFIX=".so"
148STRIP_FLAGS=
149
150build_os=`uname -s`
151build_cpu=`uname -p`
152
153case $build_os in
154  Darwin*)
155    SHLIB_SUFFIX=".dylib"
156    SHLIB_LD="g++ -dynamiclib -flat_namespace -undefined suppress"
157    STRIP_FLAGS=-S
158    ;;
159  HP-UX*)
160    case "`uname -r`" in
161      B.11.00|B.10*)
162	CXXFLAGS="$CXXFLAGS -DNO_MMAP"
163	;;
164    esac
165    SHLIB_SUFFIX=".sl"
166    ;;
167  cyg*)
168    LIB_SUFFIX=".lib"
169    SHLIB_SUFFIX=".dll"
170    ;;
171esac
172
173if test $SHARED_BUILD = 1; then
174  LIBEXT=$SHLIB_SUFFIX
175else
176  LIBEXT=$LIB_SUFFIX
177fi
178
179AC_CHECK_LIB(pthread, pthread_mutex_init, [LIBS="$LIBS -lpthread"])
180
181# ---------------------------------------------------------
182# Special hackery for hpux machines to allow usage of the
183# metakit C++ library from within Tcl (C application).
184#
185# The special configurations are:
186#
187# (1)  CXX=aCC, CC=cc, build_os=hpux*, build_cpu=hppa
188# (1a) CXX=aCC, CC=cc, build_os=hpux*, build_cpu=hppa2.0w (true 64 bit)
189# (2)  CXX=aCC, CC=cc, build_os=hpux*, build_cpu=ia64
190#
191# [Ad 1]  Link against -lCsup and insert cpprt0_stub.o
192# [Ad 1a] Link against -lCsup
193# [Ad 2]  Link against -lCsup
194#
195# Variables to substitute
196# = LINK_SPECIAL_FLAGS
197# = LINK_SPECIAL_FILES
198
199LINK_SPECIAL_FLAGS=""
200LINK_SPECIAL_FILES=""
201
202case $build_os in
203  HP-UX*)
204    if test "X$build_cpu" != "Xia64" -a "$threads_ok" = yes; then
205       # Handle special link requirements of hpux-parisc in threaded case.
206       LINK_SPECIAL_FLAGS="$LINK_SPECIAL_FLAGS -lpthread"
207    fi
208
209    if test \
210	"`basename $CXX`x" = "aCCx" -a	\
211	"Z`basename $CC`" = "Zcc"
212    then
213	# Native HP compilers
214
215    	if test "X$build_cpu" = "Xia64" ; then
216	    # Itanium: No -lstdc++
217	    LINK_SPECIAL_FLAGS="$LINK_SPECIAL_FLAGS -lCsup"
218	    LINK_SPECIAL_FILES=""
219    	else
220	    # pa-risc: The exact architecture of the cpu is now important.
221	    # Actually: The exact nature of the code we generate is important.
222
223	    case $CXXFLAGS in
224	      *DA2.0W*)
225	        # True 64 bit, no stdc++, no stubs
226	    	LINK_SPECIAL_FLAGS="$LINK_SPECIAL_FLAGS -lCsup"
227	      ;;
228	      *)
229	        # Everything else
230		LINK_SPECIAL_FLAGS="$LINK_SPECIAL_FLAGS -lCsup -Wl,cpprt0_stubs.o"
231	    	LINK_SPECIAL_FILES="cpprt0_stubs.o"
232    	    	LDFLAGS="${LDFLAGS} -lstdc++"
233	      ;;
234	    esac
235	fi
236    fi
237    ;;
238  SunOS-*)
239    # Tested for solaris-2.8.
240
241    if test "x`basename $CXX`" = "xCC"
242    then
243	# Native SUN C++ compiler
244	# Depending on 32/64 mode choose between runtime libraries
245
246	# Stupid which can insert warnings into the output
247	# instad of using stderr. Bah.
248
249	base=`which $CXX 2>/dev/null`    ; # Full path of compiler.
250	basea=`echo "$base" | sed -e 's/^Warning: ridiculously long PATH truncated//'`
251	baseb=`dirname $basea` ; # Strip name of compiler
252	basec=`dirname $baseb` ; # Strip bin directory
253	CCRUNDIR="$basec/lib"
254
255	case $CXXFLAGS in
256	    *xarch=v9*) CCRUNDIR="$CCRUNDIR/v9" ;;
257	    *)          :                       ;;
258	esac
259
260	LDFLAGS="${LDFLAGS} -L${CCRUNDIR} -lCrun"
261    else
262	# Setup not using CC, use -lstdc++, like for case '*' below.
263
264	LDFLAGS="${LDFLAGS} -lstdc++"
265    fi
266    ;;
267  *)
268    LDFLAGS="${LDFLAGS} -lstdc++"
269    ;;
270esac
271
272AC_SUBST(LINK_SPECIAL_FLAGS)
273AC_SUBST(LINK_SPECIAL_FILES)
274
275# ---------------------------------------------------------
276
277
278AC_SUBST(MK_TARGETS)
279AC_SUBST(MK_INSTALL)
280AC_SUBST(MK_THREADS)
281AC_SUBST(PY_INCLUDE_DIR)
282AC_SUBST(PY_LIB_DIR)
283AC_SUBST(TCL_INCLUDE_DIR)
284AC_SUBST(TCL_LIB_DIR)
285AC_SUBST(EXEEXT)
286AC_SUBST(CPPFLAGS)
287AC_SUBST(LDFLAGS)
288AC_SUBST(LIBEXT)
289AC_SUBST(LIB_SUFFIX)
290AC_SUBST(SHLIB_SUFFIX)
291AC_SUBST(SHLIB_CFLAGS)
292AC_SUBST(SHLIB_LD)
293AC_SUBST(SHLIB_FLAGS)
294AC_SUBST(STRIP_FLAGS)
295
296AC_OUTPUT(Makefile)
297