1dnl ---------------------------------------------------------------------------
2dnl This file offers the following common macros...
3dnl ---------------------------------------------------------------------------
4dnl CHECK_REXX
5dnl MH_IPC
6dnl MH_CHECK_X_INC
7dnl MH_CHECK_X_LIB
8dnl MH_HAVE_PROTO
9dnl MH_HAVE_BROKEN_CXX_WITH_STRING_H
10dnl MH_PROG_CC
11dnl MH_PROG_CXX
12dnl MH_CHECK_X_HEADERS
13dnl MH_CHECK_X_KEYDEFS
14dnl MH_CHECK_X_TYPEDEF
15dnl MH_TRY_LINK
16dnl MH_CHECK_LIB
17dnl MH_HOWTO_SHARED_LIBRARY
18dnl MH_SHARED_LIBRARY
19dnl MH_HOWTO_DYN_LINK
20dnl MH_CHECK_CC_O
21dnl MH_CHECK_LEADING_USCORE
22dnl MH_SHLPST
23dnl MH_CHECK_POSIX_THREADS
24dnl MH_CHECK_RPM
25dnl MH_C_LONG_LONG
26dnl MH_SHOW_STATUS
27dnl MH_CHECK_OSX_ARCH
28dnl MH_GET_KERNEL_NAME
29dnl MH_GET_DISTRO_NAME
30dnl MH_CHECK_CURSES
31dnl MH_CHECK_FUNCS
32dnl MH_CHECK_TYPES
33
34dnl
35dnl include the stdint.h wrapper
36sinclude(common/ax_create_stdint_h.m4)
37dnl include the compare_version test
38sinclude(common/ax_compare_version.m4)
39dnl
40dnl add our expansion macro for directories
41dnl
42sinclude(common/ac_define_dir.m4)
43dnl ---------------------------------------------------------------------------
44dnl Check REXX library and header files
45dnl ---------------------------------------------------------------------------
46AC_DEFUN([CHECK_REXX],
47[
48AC_REQUIRE([AC_CANONICAL_SYSTEM])
49dnl
50dnl Setup various things for different interpreters
51dnl
52extra_rexx_libs=""
53extra_rexx_defines=""
54extra_incdirs=""
55extra_libdirs=""
56REXX_USING_CONFIG=no
57REXX_LIBS=""
58REXX_INCLUDES=""
59REXX_VER="unknown"
60REXX_ADDONS=""
61REXX_VER=""
62case "$with_rexx" in
63   regina)               dnl -------- Regina
64      AC_DEFINE(USE_REGINA)
65      AC_CHECK_PROG(regina_config, [regina-config], yes, no)
66      rexx_h="rexxsaa.h"
67      rexx_l="regina"
68      REXX_INT="Regina"
69      REXX_TARGET="Regina"
70      if test "$ac_cv_prog_regina_config" = yes; then
71         REXX_INCLUDES=`regina-config --cflags`
72         numlines=`regina-config --libs$bitflag | wc -l`
73         if test $numlines -eq 1; then
74            REXX_LIBS=`regina-config --libs$bitflag`
75         else
76            REXX_LIBS=`regina-config --libs`
77         fi
78         REXX_INT="Regina (using regina-config)"
79         REXX_VER=`regina-config --version`
80         REXX_USING_CONFIG=yes
81         AX_COMPARE_VERSION([$REXX_VER],[gt],[3.6],[REXX_ADDONS=`regina-config --addons`],[REXXADDONS=$libdir])
82         REXX_VER=`regina-config --version`
83      else
84         case "$target" in
85            *nto-qnx*)
86               AC_SEARCH_LIBS(dlopen,dl)
87            ;;
88            *qnx*)
89            ;;
90            *hp-hpux*)
91               AC_SEARCH_LIBS(shl_load,dld)
92            ;;
93            *)
94               AC_SEARCH_LIBS(dlopen,dl)
95            ;;
96         esac
97         AC_SEARCH_LIBS(crypt,crypt)
98         AC_CHECK_PROG(flex,[flex],yes,no)
99         if test "$ac_cv_prog_flex" = yes; then
100            LEXLIB="-fl"
101            AC_SUBST(LEXLIB)
102         fi
103      fi
104      dnl for FreeBSD, the use of -pthread with ld doesn't work,
105      dnl so remove it.
106      case "$target" in
107         *freebsd*)
108            REXX_LIBS="`echo ${REXX_LIBS} | sed -e s/-pthread//`"
109         ;;
110         *)
111         ;;
112      esac
113   ;;
114   rexxtrans)            dnl -------- Rexx/Trans
115      AC_DEFINE(USE_REXXTRANS)
116      AC_CHECK_PROG(rexxtrans_config, [rexxtrans-config], yes, no)
117      rexx_h="rexxtrans.h"
118      rexx_l="rexxtrans"
119      REXX_INT="Rexx/Trans"
120      REXX_TARGET="RexxTrans"
121      if test "$ac_cv_prog_rexxtrans_config" = yes; then
122         REXX_INCLUDES=`rexxtrans-config --cflags`
123dnl
124dnl We now link with the static rexxtrans library
125dnl
126#         numlines=`rexxtrans-config --libs$bitflag | wc -l`
127#         if test $numlines -eq 1; then
128#            REXX_LIBS=`rexxtrans-config --libs$bitflag`
129#         else
130#            REXX_LIBS=`rexxtrans-config --libs`
131#         fi
132         REXX_LIBS=`rexxtrans-config --libs-static`
133         REXX_INT="Rexx/Trans - static (using rexxtrans-config)"
134         REXX_VER=`rexxtrans-config --version`
135         REXX_USING_CONFIG=yes
136      else
137         AC_SEARCH_LIBS(dlopen,dl)
138      fi
139   ;;
140   objrexx | orexx | objectrexx)              dnl -------- Object Rexx
141   with_rexx="objrexx"
142      AC_DEFINE(USE_OREXX)
143      rexx_h="rexx.h"
144      rexx_l="rexxapi"
145      REXX_INT="Object Rexx"
146      REXX_TARGET="ObjectRexx"
147      extra_rexx_libs="-lrexx"
148      extra_incdirs="/opt/orexx /usr/local/orexx /usr/lpp/orexx/include"
149      extra_libdirs="/opt/orexx/lib /usr/local/orexx/lib /usr/lpp/orexx/lib"
150      case "$target" in
151         *linux*)
152            extra_rexx_defines="-DLINUX"
153         ;;
154         *)
155         ;;
156      esac
157   AC_SEARCH_LIBS(pthread_create,pthread pthreads thread)
158   ;;
159   oorexx)              dnl -------- Open Object Rexx
160   with_rexx="oorexx"
161      AC_DEFINE(USE_OOREXX) dnl ---- Open Object Rexx
162      AC_CHECK_PROG(oorexx_config, [oorexx-config], yes, no)
163      rexx_h="rexx.h"
164      rexx_l="rexxapi"
165      REXX_INT="Open Object Rexx"
166      REXX_TARGET="ooRexx"
167      if test "$ac_cv_prog_oorexx_config" = yes; then
168         REXX_INCLUDES="-DLINUX `oorexx-config --cflags`"
169         REXX_LIBS="`oorexx-config --libs` -ldl"
170         REXX_INT="ooRexx (using oorexx-config)"
171         REXX_VER=`oorexx-config --version`
172         dnl if we are using ooRexx 4.x and greater treat it as another interpreter :-(
173         REXX_MAJOR=`echo $REXX_VER | cut -d. -f1`
174         if test "x$REXX_MAJOR" = "x4"; then
175            AC_DEFINE(OOREXX_40)
176         fi
177         if test "x$REXX_MAJOR" = "x5"; then
178            AC_DEFINE(OOREXX_40)
179         fi
180         REXX_USING_CONFIG=yes
181      else
182         extra_rexx_libs="-lrexx"
183         extra_incdirs="/usr/local/include/ooRexx /usr/include/ooRexx /opt/ooRexx/include"
184         extra_libdirs="/usr/local/lib/ooRexx /usr/lib/ooRexx /opt/ooRexx/lib/ooRexx"
185         extra_rexx_defines="-DLINUX"
186      fi
187   AC_SEARCH_LIBS(pthread_create,pthread pthreads thread)
188   ;;
189   rexximc)              dnl -------- Rexx/imc
190      AC_DEFINE(USE_REXXIMC)
191      rexx_h="rexxsaa.h"
192      rexx_l="rexx"
193      REXX_INT="REXX/imc"
194      REXX_TARGET="REXXimc"
195      AC_SEARCH_LIBS(dlopen,dl)
196   ;;
197   rexx6000)             dnl -------- REXX6000
198dnl
199dnl Check that the OS supports REXX/6000
200dnl Only supported it on AIX
201dnl
202      if test "$with_rexx6000" = yes ; then
203      case "$target" in
204         *aix*)
205         ;;
206         *)
207            AC_MSG_ERROR(REXX/6000 support only available on AIX; cannot configure)
208            ;;
209      esac
210   fi
211      AC_DEFINE(USE_REXX6000)
212      rexx_h="rexxtype.h"
213      rexx_l="rexx"
214      REXX_INT="REXX/6000"
215      REXX_TARGET="REXX6000"
216   ;;
217   unirexx)              dnl -------- uni-REXX
218      AC_DEFINE(USE_UNIREXX)
219      rexx_h="rexxsaa.h"
220      rexx_l="rx"
221      REXX_INT="uni-REXX"
222      REXX_TARGET="uni-REXX"
223      AC_SEARCH_LIBS(dlopen,dl)
224   ;;
225   none)                 dnl -------- No Rexx interpreter
226      AC_DEFINE(NOREXX)
227      rexx_h=""
228      rexx_l=""
229      REXX_INT="No Rexx Support"
230      REXX_TARGET=""
231   ;;
232   *)
233      AC_MSG_ERROR(No Rexx interpreter specified with --with-rexx=int : must be one of: regina rexximc oorexx objrexx unirexx rexx6000 rexxtrans none)
234   ;;
235esac
236AC_SUBST(REXX_TARGET)
237AC_SUBST(REXX_ADDONS)
238REXX_BUILD=$with_rexx
239AC_SUBST(REXX_BUILD)
240AC_SUBST(REXX_VER)
241
242dnl look for REXX header and library, exit if not found
243
244if test "xx$rexx_h" != "xx" -a "x$REXX_INCLUDES" = "x"; then
245dnl look for REXX header and library, exit if not found
246   AC_MSG_CHECKING(for location of Rexx header file: $rexx_h)
247   mh_rexx_inc_dir=""
248   mh_inc_dirs="\
249       ${REXXINCDIR}             \
250       ${extra_incdirs}          \
251       ${HOME}/include           \
252       ${HOME}/${MACHTYPE}/include     \
253       /usr/local/include        \
254       /usr/contrib/include      \
255       /opt/include              \
256       /opt/sfw/include          \
257       /sw/include               \
258       /usr/include              \
259       /usr/unsupported/include"
260dnl
261dnl Provide for user supplying directory
262dnl
263   if test "$with_rexxincdir" != no ; then
264      mh_inc_dirs="$with_rexxincdir $mh_inc_dirs"
265   fi
266dnl
267dnl Try to determine the directory containing Rexx header
268dnl
269   for ac_dir in $mh_inc_dirs ; do
270     if test -r $ac_dir/$rexx_h; then
271       mh_rexx_inc_dir=$ac_dir
272       break
273     fi
274   done
275   if test "x$mh_rexx_inc_dir" != "x" ; then
276      REXX_INCLUDES="-I$mh_rexx_inc_dir $extra_rexx_defines"
277      AC_MSG_RESULT(found in $mh_rexx_inc_dir)
278   else
279      AC_MSG_ERROR(Cannot find Rexx header file: $rexx_h; cannot configure)
280   fi
281fi
282AC_SUBST(REXX_INCLUDES)
283
284if test "xx$rexx_h" != "xx" -a "x$REXX_LIBS" = "x"; then
285   AC_MSG_CHECKING(for location of Rexx library file: $rexx_l)
286   mh_rexx_lib_dir=""
287   mh_lib_dirs="\
288       ${REXXLIBDIR}             \
289       ${extra_libdirs}          \
290       ${HOME}/lib64             \
291       ${HOME}/lib32             \
292       ${HOME}/lib               \
293       ${HOME}/${MACHTYPE}/lib64 \
294       ${HOME}/${MACHTYPE}/lib32 \
295       ${HOME}/${MACHTYPE}/lib   \
296       /usr/local/lib64          \
297       /usr/local/lib32          \
298       /usr/local/lib            \
299       /usr/contrib/lib          \
300       /opt/lib64                \
301       /opt/lib32                \
302       /opt/lib                  \
303       /opt/sfw/lib              \
304       /sw/lib                   \
305       /usr/lib64                \
306       /usr/lib32                \
307       /usr/lib                  \
308       /usr/unsupported/lib"
309dnl
310dnl Provide for user supplying directory
311dnl
312   if test "$with_rexxlibdir" != no ; then
313      mh_lib_dirs="$with_rexxlibdir $mh_lib_dirs"
314   fi
315dnl
316dnl Try to determine the directory containing Rexx library
317dnl
318   for ac_dir in $mh_lib_dirs ; do
319      for mh_ext in lib${rexx_l}.a lib${rexx_l}.so lib${rexx_l}.sl ${rexx_l}.lib lib${rexx_l}.dylib; do
320        if test -r $ac_dir/$mh_ext; then
321           mh_rexx_lib_dir=$ac_dir
322         break 2
323        fi
324      done
325   done
326   if test "x$mh_rexx_lib_dir" != "x" ; then
327      REXX_LIBS="-L$mh_rexx_lib_dir -l$rexx_l $extra_rexx_libs"
328      AC_MSG_RESULT(found in $mh_rexx_lib_dir)
329      AC_SUBST(rexxtrans_lib_name)
330   else
331      AC_MSG_ERROR(Cannot find Rexx library file: $rexx_l; cannot configure)
332   fi
333fi
334AC_SUBST(REXX_LIBS)
335])dnl
336
337dnl ---------------------------------------------------------------------------
338dnl Determine if the system has System V IPC. ie sys/ipc.h and sys/shm.h
339dnl headers.
340dnl ---------------------------------------------------------------------------
341AC_DEFUN([MH_IPC],
342[
343AC_MSG_CHECKING(for System V IPC support)
344AC_CHECK_HEADER(sys/ipc.h)
345if test $ac_cv_header_sys_ipc_h = no; then
346   AC_MSG_ERROR(Cannot find required header file sys/ipc.h; XCurses cannot be configured)
347fi
348])dnl
349
350dnl ---------------------------------------------------------------------------
351dnl Set up the correct X header file location
352dnl ---------------------------------------------------------------------------
353AC_DEFUN([MH_CHECK_X_INC],
354[
355AC_MSG_CHECKING(for location of X headers)
356mh_x11_dir=""
357mh_x11_xaw_dir=""
358dnl
359dnl specify latest release of X directories first
360dnl
361mh_inc_dirs="\
362    $HOME/include/X11         \
363    $HOME/include             \
364    /tmp/include/X11          \
365    /tmp/include              \
366    /usr/X11R6/include        \
367    /usr/include/X11R6        \
368    /usr/local/X11R6/include  \
369    /usr/local/include/X11R6  \
370
371    /usr/X11R5/include        \
372    /usr/include/X11R5        \
373    /usr/local/X11R5/include  \
374    /usr/local/include/X11R5  \
375    /usr/local/x11r5/include  \
376
377    /usr/X11R4/include        \
378    /usr/include/X11R4        \
379    /usr/local/X11R4/include  \
380    /usr/local/include/X11R4  \
381                              \
382    /usr/X11/include          \
383    /usr/include/X11          \
384    /usr/local/X11/include    \
385    /usr/local/include/X11    \
386                              \
387    /usr/X386/include         \
388    /usr/x386/include         \
389    /usr/XFree86/include/X11  \
390                              \
391    /usr/include              \
392    /usr/local/include        \
393    /usr/unsupported/include  \
394    /usr/athena/include       \
395    /usr/lpp/Xamples/include  \
396                              \
397    /usr/openwin/include      \
398    /usr/openwin/share/include"
399dnl
400dnl Provide for user supplying directory
401dnl
402if test "x$x_includes" != xNONE ; then
403   mh_inc_dirs="$x_includes $mh_inc_dirs"
404fi
405
406dnl
407dnl Try to determine the directory containing X headers
408dnl We will append X11 to all the paths above as an extra check
409dnl
410for ac_dir in $mh_inc_dirs ; do
411  if test -r $ac_dir/Intrinsic.h; then
412    mh_x11_dir=$ac_dir
413    break
414  fi
415  if test -r $ac_dir/X11/Intrinsic.h; then
416    mh_x11_dir="$ac_dir/X11"
417    break
418  fi
419done
420
421dnl
422dnl Try to determine the directory containing Xaw headers
423dnl We will append X11 to all the paths above as an extra check
424dnl
425if test "$with_xaw3d" = yes; then
426   mh_xaw_dir="Xaw3d"
427else
428   if test "$with_nextaw" = yes; then
429      mh_xaw_dir="neXtaw"
430   else
431      mh_xaw_dir="Xaw"
432   fi
433fi
434for ac_dir in $mh_inc_dirs ; do
435  if test -r $ac_dir/$mh_xaw_dir/Box.h; then
436    mh_x11_xaw_dir=$ac_dir
437    break
438  fi
439  if test -r $ac_dir/X11/$mh_xaw_dir/Box.h; then
440    mh_x11_xaw_dir="$ac_dir/X11"
441    break
442  fi
443done
444
445if test "x$mh_x11_dir" != "x" ; then
446   mh_x11_dir_no_x11=`echo $mh_x11_dir | sed 's/\/X11$//'`
447dnl
448dnl Test to see if $mh_x11_dir_no_x11 is /usr/include and we are using gcc
449dnl under Solaris. If so, ignore it.
450   AC_REQUIRE([AC_CANONICAL_SYSTEM])
451   mh_solaris_gcc_usr_include="no"
452   case "$target" in
453      *solaris*)
454         if test "$ac_cv_prog_CC" = "gcc" -a "$mh_x11_dir_no_x11" = "/usr/include" ; then
455            mh_solaris_gcc_usr_include="yes"
456         fi
457         ;;
458   esac
459   if test "$mh_x11_dir_no_x11" != "$mh_x11_dir" -a "$mh_solaris_gcc_usr_include" = "no" ; then
460      MH_XINC_DIR="-I$mh_x11_dir -I$mh_x11_dir_no_x11"
461   else
462      MH_XINC_DIR="-I$mh_x11_dir"
463   fi
464else
465   AC_MSG_ERROR(Cannot find required header file Intrinsic.h; XCurses cannot be configured)
466fi
467
468if test "x$mh_x11_xaw_dir" != "x" ; then
469   MH_XINC_DIR="-I$mh_x11_xaw_dir $MH_XINC_DIR"
470else
471   AC_MSG_ERROR(Cannot find required Xaw header file Box.h; XCurses cannot be configured)
472fi
473
474   AC_MSG_RESULT(found in $mh_x11_dir $mh_x11_xaw_dir)
475   AC_SUBST(MH_XINC_DIR)
476
477])dnl
478
479dnl ---------------------------------------------------------------------------
480dnl Set up the correct X library file location
481dnl ---------------------------------------------------------------------------
482AC_DEFUN([MH_CHECK_X_LIB],
483[
484dnl
485dnl Some systems require extra libraries...
486dnl
487mh_solaris_flag=no
488mh_hpux9_flag=no
489AC_REQUIRE([AC_CANONICAL_SYSTEM])
490case "$target" in
491   *solaris*)
492      mh_solaris_flag=yes
493      ;;
494   *pc-sco*)
495      extra_x_libs="Xext"
496      ;;
497   sparc*sunos*)
498      extra_x_libs="Xext"
499      if test "$ac_cv_prog_CC" = "gcc" ; then
500         extra_ld_flags="-Wl,-Bstatic"
501         extra_ld_flags2="-Wl,-Bdynamic"
502      else
503         extra_ld_flags="-Bstatic"
504         extra_ld_flags2="-Bdynamic"
505      fi
506      ;;
507   *hpux9*)
508      mh_hpux9_flag=yes
509      ;;
510esac
511
512AC_MSG_CHECKING(for location of X libraries)
513if test "$with_xaw3d" = yes; then
514   MH_X11_LIBS="Xaw3d Xmu Xt X11"
515else
516   if test "$with_nextaw" = yes; then
517      MH_X11_LIBS="neXtaw Xmu Xt X11"
518   else
519      MH_X11_LIBS="Xaw Xmu Xt X11"
520   fi
521fi
522MH_X11R6_LIBS="SM ICE Xext"
523mh_x11r6=no
524dnl
525dnl specify latest release of X directories first
526dnl
527mh_lib_dirs="\
528    $HOME/lib64           \
529    $HOME/lib32           \
530    $HOME/lib             \
531    /tmp/lib              \
532    /usr/X11R6/lib64      \
533    /usr/X11R6/lib32      \
534    /usr/X11R6/lib        \
535    /usr/lib64/X11R6      \
536    /usr/lib32/X11R6      \
537    /usr/lib/X11R6        \
538    /usr/local/X11R6/lib64  \
539    /usr/local/X11R6/lib32  \
540    /usr/local/X11R6/lib  \
541    /usr/local/lib64/X11R6  \
542    /usr/local/lib32/X11R6  \
543    /usr/local/lib/X11R6  \
544
545    /usr/X11R5/lib        \
546    /usr/lib/X11R5        \
547    /usr/local/X11R5/lib  \
548    /usr/local/lib/X11R5  \
549    /usr/local/x11r5/lib  \
550
551    /usr/X11R4/lib        \
552    /usr/lib/X11R4        \
553    /usr/local/X11R4/lib  \
554    /usr/local/lib/X11R4  \
555                          \
556    /usr/X11/lib          \
557    /usr/lib/X11          \
558    /usr/local/X11/lib    \
559    /usr/local/lib/X11    \
560                          \
561    /usr/X386/lib         \
562    /usr/x386/lib         \
563    /usr/XFree86/lib/X11  \
564                          \
565    /usr/lib64            \
566    /usr/lib32            \
567    /usr/lib              \
568    /usr/local/lib64      \
569    /usr/local/lib32      \
570    /usr/local/lib        \
571    /usr/unsupported/lib  \
572    /usr/athena/lib       \
573    /usr/lpp/Xamples/lib  \
574                          \
575    /usr/openwin/lib      \
576    /usr/openwin/share/lib"
577dnl
578dnl Provide for user supplying directory
579dnl
580if test "x$x_libraries" != xNONE ; then
581   mh_lib_dirs="$x_libraries $mh_lib_dirs"
582fi
583
584dnl
585dnl try to find libSM.[a,sl,so,dylib]. If we find it we are using X11R6
586dnl
587for ac_dir in $mh_lib_dirs ; do
588   for mh_xsm in libSM.a libSM.so libSM.sl libSM.dylib; do
589     if test -r $ac_dir/$mh_xsm; then
590       mh_x11r6=yes
591       break 2
592     fi
593   done
594done
595
596if test "$mh_x11r6" = yes ; then
597   mh_libs="$MH_X11_LIBS $MH_X11R6_LIBS"
598else
599   mh_libs="$MH_X11_LIBS $extra_x_libs"
600fi
601
602dnl
603dnl Ensure that all required X libraries are found
604dnl
605mh_prev_dir=""
606mh_where_found=""
607mh_where_found_dirs=""
608mh_solaris_path=""
609for mh_lib in $mh_libs; do
610  mh_lib_found=no
611  for ac_dir in $mh_lib_dirs ; do
612    for mh_ext in a so sl dll.a; do
613      if test -r $ac_dir/lib$mh_lib.$mh_ext; then
614        if test "x$mh_prev_dir" != "x$ac_dir" ; then
615          if test "x$mh_prev_dir" = "x" ; then
616             mh_where_found="$mh_where_found found in $ac_dir"
617          else
618             mh_where_found="$mh_where_found and in $ac_dir"
619          fi
620          mh_prev_dir=$ac_dir
621          mh_where_found_dirs="$mh_where_found_dirs $ac_dir"
622          MH_XLIBS="$MH_XLIBS -L$ac_dir"
623          mh_solaris_path="${mh_solaris_path}:$ac_dir"
624        fi
625        MH_XLIBS="$MH_XLIBS -l$mh_lib"
626        mh_lib_found=yes
627        break 2
628      fi
629    done
630  done
631  if test "$mh_lib_found" = no; then
632    AC_MSG_ERROR(Cannot find required X library; lib$mh_lib. XCurses cannot be configured)
633  fi
634done
635AC_MSG_RESULT($mh_where_found)
636mh_solaris_path=`echo $mh_solaris_path | sed 's/^://'`
637if test "$mh_solaris_flag" = yes ; then
638   MH_XLIBS="-R$mh_solaris_path $extra_ld_flags $MH_XLIBS $extra_libs $extra_ld_flags2"
639else
640   MH_XLIBS="$extra_ld_flags $MH_XLIBS $extra_libs $extra_ld_flags2"
641fi
642if test "$mh_hpux9_flag" = yes ; then
643  grep -q XtSetLanguageProc $mh_x11_dir/Intrinsic.h
644  if test $? -eq 0 ; then
645    mh_found_xtshellstrings=no
646    for mh_acdir in $mh_where_found_dirs ; do
647      for mh_xaw in `ls $mh_acdir/libXaw.*` ; do
648        nm $mh_xaw | grep XtShellStrings | grep -qv extern
649        if test $? -eq 0 ; then
650          mh_found_xtshellstrings=yes
651        fi
652      done
653    done
654    if test "$mh_found_xtshellstrings" = no ; then
655      AC_MSG_WARN(The X11 development environment has not been installed correctly.)
656      AC_MSG_WARN(The header file; Intrinsic.h, is for X11R5 while the Athena Widget)
657      AC_MSG_WARN(Set library; libXaw is for X11R4.  This is a common problem with)
658      AC_MSG_WARN(HP-UX 9.x.)
659      AC_MSG_WARN(A set of required X11R5 library files can be obtained from the)
660      AC_MSG_WARN(anonymous ftp sites listed on the PDCurses WWW home page:)
661      AC_MSG_WARN(http://www.lightlink.com/hessling/)
662      AC_MSG_WARN(The file is called HPUX-9.x-libXaw-libXmu.tar.Z)
663      AC_MSG_ERROR(X11 installation incomplete; cannot continue)
664    fi
665  fi
666fi
667   AC_SUBST(MH_XLIBS)
668])dnl
669
670dnl ---------------------------------------------------------------------------
671dnl Determine if C compiler handles ANSI prototypes
672dnl ---------------------------------------------------------------------------
673AC_DEFUN([MH_HAVE_PROTO],
674[
675AC_MSG_CHECKING(if compiler supports ANSI prototypes)
676dnl
677dnl override existing value of $ac_compile so we use the correct compiler
678dnl SHOULD NOT NEED THIS
679dnl
680ac_compile='$ac_cv_prog_CC conftest.$ac_ext $CFLAGS $CPPFLAGS -c 1>&5 2>&5'
681AC_TRY_COMPILE([#include <stdio.h>],
682[extern int xxx(int, char *);],
683  mh_have_proto=yes; AC_DEFINE(HAVE_PROTO), mh_have_proto=no )
684AC_MSG_RESULT($mh_have_proto)
685])dnl
686
687dnl -----------------------------------------------------
688dnl Determine if compiling <string.h> breaks g++ compiler
689dnl -----------------------------------------------------
690AC_DEFUN([MH_HAVE_BROKEN_CXX_WITH_STRING_H],
691[
692AC_MSG_CHECKING(if g++ compiler cannot compile <string.h>)
693dnl
694dnl override existing value of $ac_compile so we use the correct compiler
695dnl SHOULD NOT NEED THIS
696dnl
697ac_compile='$ac_cv_prog_CC conftest.$ac_ext $CFLAGS $CPPFLAGS -c 1>&5 2>&5'
698AC_TRY_COMPILE([#include <string.h>],
699[extern int xxx(int, char *);],
700  mh_have_broken_cxx_with_string_h=yes; AC_DEFINE(HAVE_BROKEN_CXX_WITH_STRING_H), mh_have_broken_cxx_with_string_h=no )
701AC_MSG_RESULT($mh_have_broken_cxx_with_string_h)
702])dnl
703
704dnl ---------------------------------------------------------------------------
705dnl Determine the best C compiler to use given a list
706dnl ---------------------------------------------------------------------------
707AC_DEFUN([MH_PROG_CC],
708[
709mh_sysv_incdir=""
710mh_sysv_libdir=""
711all_words="clang gcc xlc acc cc"
712ac_dir=""
713AC_MSG_CHECKING(for one of the following C compilers: $all_words)
714AC_CACHE_VAL(ac_cv_prog_CC,[
715if test -n "$CC"; then
716  ac_cv_prog_CC="$CC" # Let the user override the test.
717else
718  IFS="${IFS=  }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
719  for mh_cc in $all_words; do
720    for ac_dir in $PATH; do
721      test -z "$ac_dir" && ac_dir=.
722      if test -f $ac_dir/$mh_cc; then
723        ac_cv_prog_CC="$mh_cc"
724        if test "$ac_dir" = "/usr/5bin"; then
725          mh_sysv_incdir="/usr/5include"
726          mh_sysv_libdir="/usr/5lib"
727        fi
728        break 2
729      fi
730    done
731  done
732  IFS="$ac_save_ifs"
733  test -z "$ac_cv_prog_CC" && ac_cv_prog_CC="cc"
734fi
735CC="$ac_cv_prog_CC"
736])
737AC_SUBST(CC)
738if test "$ac_dir" = ""; then
739   AC_MSG_RESULT(using $ac_cv_prog_CC specified in CC env variable)
740else
741   AC_MSG_RESULT(using $ac_dir/$ac_cv_prog_CC)
742fi
743])dnl
744
745dnl ---------------------------------------------------------------------------
746dnl Determine the best C++ compiler to use given a list
747dnl ---------------------------------------------------------------------------
748AC_DEFUN([MH_PROG_CXX],
749[
750mh_sysv_incdir=""
751mh_sysv_libdir=""
752all_words="$CC_LIST"
753ac_dir=""
754AC_MSG_CHECKING(for one of the following C++ compilers: $all_words)
755AC_CACHE_VAL(ac_cv_prog_CXX,[
756if test -n "$CXX"; then
757  ac_cv_prog_CXX="$CC" # Let the user override the test.
758else
759  IFS="${IFS=  }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
760  for mh_cc in $all_words; do
761    for ac_dir in $PATH; do
762      test -z "$ac_dir" && ac_dir=.
763      if test -f $ac_dir/$mh_cc; then
764        ac_cv_prog_CXX="$mh_cc"
765        break 2
766      fi
767    done
768  done
769  IFS="$ac_save_ifs"
770  test -z "$ac_cv_prog_CXX" && ac_cv_prog_CXX="c++"
771fi
772CXX="$ac_cv_prog_CXX"
773])
774AC_SUBST(CXX)
775if test "$ac_dir" = ""; then
776   AC_MSG_RESULT(using $ac_cv_prog_CXX specified in CXX env variable)
777else
778   AC_MSG_RESULT(using $ac_dir/$ac_cv_prog_CXX)
779fi
780])dnl
781
782dnl ---------------------------------------------------------------------------
783dnl Determine if the supplied X headers exist.
784dnl ---------------------------------------------------------------------------
785AC_DEFUN([MH_CHECK_X_HEADERS],
786[
787save_CPPFLAGS="$CPPFLAGS"
788CPPFLAGS="$CPPFLAGS $MH_XINC_DIR"
789for mh_header in $1; do
790   AC_CHECK_HEADERS($mh_header)
791done
792CPPFLAGS="$save_CPPFLAGS"
793])dnl
794
795dnl ---------------------------------------------------------------------------
796dnl Determine if various key definitions exist in keysym.h
797dnl ---------------------------------------------------------------------------
798AC_DEFUN([MH_CHECK_X_KEYDEFS],
799[
800save_CPPFLAGS="$CPPFLAGS"
801CPPFLAGS="$CPPFLAGS $MH_XINC_DIR"
802for mh_keydef in $1; do
803   AC_MSG_CHECKING(for $mh_keydef in keysym.h)
804   mh_upper_name="HAVE_`echo $mh_keydef | tr '[a-z]' '[A-Z]'`"
805   AC_TRY_COMPILE([#include <keysym.h>],
806[int i = $mh_keydef;],
807  mh_have_key=yes; AC_DEFINE_UNQUOTED($mh_upper_name,1), mh_have_key=no )
808   AC_MSG_RESULT($mh_have_key)
809done
810CPPFLAGS="$save_CPPFLAGS"
811])dnl
812
813dnl ---------------------------------------------------------------------------
814dnl Determine if supplied types have been typedefed
815dnl ---------------------------------------------------------------------------
816AC_DEFUN([MH_CHECK_X_TYPEDEF],
817[
818save_CPPFLAGS="$CPPFLAGS"
819CPPFLAGS="$CPPFLAGS $SYS_DEFS $MH_XINC_DIR"
820for td in $1 ; do
821AC_MSG_CHECKING(if $td is typedefed:)
822AC_TRY_COMPILE(
823[#include "X11/Xlib.h"],
824[$td fred],
825   [mh_td=yes],
826   [mh_td=no]
827)
828if test "$mh_td" = yes ; then
829   TD_upper=`echo $td | tr a-z A-Z`
830   AC_DEFINE_UNQUOTED(${TD_upper}_TYPEDEFED, 1)
831fi
832AC_MSG_RESULT($mh_td)
833done
834CPPFLAGS="$save_CPPFLAGS"
835])dnl
836
837dnl ---------------------------------------------------------------------------
838dnl Provide our own AC_TRY_LINK
839dnl ---------------------------------------------------------------------------
840AC_DEFUN([MH_TRY_LINK],
841[
842mh_link='${LD-ld} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&AC_FD_CC'
843save_CPPFLAGS="$CPPFLAGS"
844CPPFLAGS="$CPPFLAGS $MH_XINC_DIR"
845for mh_keydef in $1; do
846   AC_MSG_CHECKING(for $mh_keydef in keysym.h)
847   mh_upper_name="HAVE_`echo $mh_keydef | tr '[a-z]' '[A-Z]'`"
848   AC_TRY_COMPILE([#include <keysym.h>],
849[int i = $mh_keydef;],
850  mh_have_key=yes; AC_DEFINE_UNQUOTED($mh_upper_name,1), mh_have_key=no )
851   AC_MSG_RESULT($mh_have_key)
852done
853CPPFLAGS="$save_CPPFLAGS"
854])dnl
855
856dnl ---------------------------------------------------------------------------
857dnl Check for presense of various libraries
858dnl ---------------------------------------------------------------------------
859AC_DEFUN([MH_CHECK_LIB],
860[
861MH_EXTRA_LIBS=''
862for mh_lib in $1; do
863   if test "$on_qnx4" = yes; then
864      AC_MSG_CHECKING(for library -l${mh_lib})
865      if test -r /usr/lib/${mh_lib}3r.lib; then
866         AC_MSG_RESULT(found)
867         MH_EXTRA_LIBS="${MH_EXTRA_LIBS} -l${mh_lib}"
868      else
869      AC_MSG_RESULT(not found)
870      fi
871   else
872      AC_CHECK_LIB($mh_lib,main,mh_lib_found=yes,mh_lib_found=no)
873      if test "$mh_lib_found" = yes; then
874         MH_EXTRA_LIBS="${MH_EXTRA_LIBS} -l${mh_lib}"
875      fi
876   fi
877done
878])dnl
879
880dnl ---------------------------------------------------------------------------
881dnl Work out how to create a shared library
882dnl ---------------------------------------------------------------------------
883AC_DEFUN([MH_HOWTO_SHARED_LIBRARY],
884[
885AC_MSG_CHECKING(how to create a shared library)
886mh_compile='${CC-cc} -c $DYN_COMP conftest.$ac_ext 1>&AC_FD_CC'
887cat > conftest.$ac_ext <<EOF
888dnl [#]line __oline__ "[$]0"
889[#]line __oline__ "configure"
890int foo()
891{
892return(0);
893}
894EOF
895if AC_TRY_EVAL(mh_compile) && test -s conftest.o; then
896   mh_dyn_link='ld -shared -o conftest.so.1.0 conftest.o -lc 1>&AC_FD_CC'
897#  mh_dyn_link='${CC} -Wl,-shared -o conftest.so.1.0 conftest.o -lc 1>&AC_FD_CC'
898   if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.so.1.0; then
899      SHL_LD="ld -shared -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'" -lc"
900#     SHL_LD="${CC} -Wl,-shared -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'" -lc"
901   else
902      mh_dyn_link='ld -G -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
903#     mh_dyn_link='${CC} -Wl,-G -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
904      if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.so.1.0; then
905         SHL_LD="ld -G -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'
906#        SHL_LD="${CC} -Wl,-G -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'
907      else
908         mh_dyn_link='ld -o conftest.so.1.0 -shared -no_archive conftest.o  -lc 1>&AC_FD_CC'
909#        mh_dyn_link='${CC} -o conftest.so.1.0 -Wl,-shared,-no_archive conftest.o  -lc 1>&AC_FD_CC'
910         if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.so.1.0; then
911            SHL_LD="ld -o ${SHLPRE}${SHLFILE}${SHLPST} -shared -no_archive "'$('SHOFILES')'" -lc"
912#           SHL_LD="${CC} -o ${SHLPRE}${SHLFILE}${SHLPST} -Wl,-shared,-no_archive "'$('SHOFILES')'" -lc"
913         else
914            mh_dyn_link='ld -b -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
915#           mh_dyn_link='${CC} -Wl,-b -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
916            if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.so.1.0; then
917               SHL_LD="ld -b -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'
918#              SHL_LD="${CC} -Wl,-b -o ${SHLPRE}${SHLFILE}.${SHLPST} "'$('SHOFILES')'
919            else
920               mh_dyn_link='ld -Bshareable -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
921#              mh_dyn_link='${CC} -Wl,-Bshareable -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
922               if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.so.1.0; then
923                  SHL_LD="ld -Bshareable -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'
924#                 SHL_LD="${CC} -Wl,-Bshareable -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'
925               else
926                  mh_dyn_link='ld -assert pure-text -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
927#                 mh_dyn_link='${CC} -Wl,-assert pure-text -o conftest.so.1.0 conftest.o 1>&AC_FD_CC'
928                  if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.so.1.0; then
929                     SHL_LD="ld -assert pure-text -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'
930#                    SHL_LD="${CC} -Wl,-assert pure-text -o ${SHLPRE}${SHLFILE}${SHLPST} "'$('SHOFILES')'
931                  else
932                     SHL_LD=""
933                  fi
934               fi
935            fi
936         fi
937      fi
938   fi
939fi
940if test "$SHL_LD" = ""; then
941   AC_MSG_RESULT(unknown)
942else
943   AC_MSG_RESULT(found)
944fi
945rm -f conftest*
946])
947
948dnl ---------------------------------------------------------------------------
949dnl Work out how to create a dynamically loaded module
950dnl ---------------------------------------------------------------------------
951AC_DEFUN([MH_HOWTO_DYN_LINK],
952[
953mh_compile='${CC-cc} -c $DYN_COMP conftest.$ac_ext 1>&AC_FD_CC'
954cat > conftest.$ac_ext <<EOF
955dnl [#]line __oline__ "[$]0"
956[#]line __oline__ "configure"
957int foo()
958{
959return(0);
960}
961EOF
962if AC_TRY_EVAL(mh_compile) && test -s conftest.o; then
963   mh_dyn_link='ld -shared -o conftest.rxlib conftest.o -lc 1>&AC_FD_CC'
964#  mh_dyn_link='${CC} -Wl,-shared -o conftest.rxlib conftest.o -lc 1>&AC_FD_CC'
965   if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.rxlib; then
966      LD_RXLIB1="ld -shared"
967      LD_RXTRANSLIB1="$LD_RXLIB1"
968#     LD_RXLIB1="${CC} -Wl,-shared"
969      LD_RXLIB2="${REXX_LIBS}"
970      SHLPRE="lib"
971      SHLPST=".so"
972      RXLIBLEN="6"
973   else
974      mh_dyn_link='ld -G -o conftest.rxlib conftest.o 1>&AC_FD_CC'
975#     mh_dyn_link='${CC} -Wl,-G -o conftest.rxlib conftest.o 1>&AC_FD_CC'
976      if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.rxlib; then
977         LD_RXLIB1="ld -G"
978         LD_RXTRANSLIB1="$LD_RXLIB1"
979#        LD_RXLIB1="${CC} -Wl,-G"
980         LD_RXLIB2="${REXX_LIBS}"
981         SHLPRE="lib"
982         SHLPST=".so"
983         RXLIBLEN="6"
984      else
985         LD_RXLIB1=""
986         LD_RXTRANSLIB1="$LD_RXLIB1"
987         LD_RXLIB2=""
988         SHLPRE=""
989         SHLPST=""
990         RXLIBLEN="0"
991      fi
992   fi
993fi
994rm -f conftest*
995])dnl
996
997dnl ---------------------------------------------------------------------------
998dnl Determine how to build shared libraries etc..
999dnl ---------------------------------------------------------------------------
1000AC_DEFUN([MH_SHARED_LIBRARY],
1001[
1002AC_REQUIRE([MH_SHLPST])
1003dnl
1004dnl If compiler is gcc, then flags should be the same for all platforms
1005dnl (just guessing on this)
1006dnl
1007OSAVE=".o.save"
1008OBJ="o"
1009EXE=""
1010GETOPT=""
1011STATIC_LDFLAGS=""
1012DYNAMIC_LDFLAGS=""
1013AIX_DYN="no"
1014BEOS_DYN="no"
1015SHLFILE="$1"
1016SHLFILES="$*"
1017RXPACKEXPORTS=""
1018BASE_INSTALL="installbase"
1019BASE_BINARY="binarybase"
1020SHLPRE="lib"
1021LD_RXLIB1=""
1022LD_RXTRANSLIB1="$LD_RXLIB1"
1023CAN_USE_ABI="no"
1024LIBEXE="ar"
1025LIBFLAGS="cr"
1026LIBPRE="lib"
1027LIBPST=".a"
1028RXDEFEXP1=""
1029# OTHER_INSTALLS is set to install a non-version numbered shared library
1030# by default; ie. no .\$(ABI) suffix. If the regina executable is not built,
1031# then there is no shared library. Set OTHER_INSTALLS="installabilib" if you
1032# are building a version numbered shared library.
1033OTHER_INSTALLS="installlib"
1034EXTRATARGET=""
1035
1036AC_REQUIRE([AC_CANONICAL_SYSTEM])
1037case "$target" in
1038   *hp-hpux*)
1039      SYS_DEFS="-D_HPUX_SOURCE"
1040      EEXTRA="-Wl,-E"
1041      LD_RXLIB1="ld -b -q -n  ${LDFLAGS}"
1042      LD_RXTRANSLIB1="$LD_RXLIB1"
1043      DYNAMIC_LDFLAGS="-Wl,+s"
1044      ;;
1045   *ibm-aix*)
1046      if test "$with_rexx6000" = yes; then
1047         mh_entry="-eInitFunc"
1048      else
1049         mh_entry="-bnoentry"
1050      fi
1051      SYS_DEFS="-D_ALL_SOURCE -DAIX"
1052      AIX_DYN="yes"
1053      DYN_COMP="-DDYNAMIC"
1054      STATIC_LDFLAGS="-bnso -bI:/lib/syscalls.exp"
1055      if test "$ac_cv_prog_CC" = "gcc"; then
1056         LD_RXLIB1="${CC} -Wl,$mh_entry -Wl,-bM:SRE  ${LDFLAGS}"
1057      else
1058         LD_RXLIB1="${CC} $mh_entry -bM:SRE  ${LDFLAGS}"
1059      fi
1060      LD_RXTRANSLIB1="$LD_RXLIB1"
1061      RXPACKEXPORTS="-bE:$SHLFILE.exp"
1062      RXPACKEXP="$SHLFILE.exp"
1063      ;;
1064   *dec-osf*)
1065      if test "$ac_cv_prog_CC" = "gcc"; then
1066         SYS_DEFS="-D_POSIX_SOURCE -D_XOPEN_SOURCE"
1067      else
1068         SYS_DEFS="-D_POSIX_SOURCE -D_XOPEN_SOURCE -Olimit 800"
1069      fi
1070      LD_RXLIB1="ld -shared  ${LDFLAGS}"
1071      LD_RXTRANSLIB1="$LD_RXLIB1"
1072      ;;
1073   *sequent-dynix*)
1074      LD_RXLIB1="ld -G  ${LDFLAGS}"
1075      LD_RXTRANSLIB1="$LD_RXLIB1"
1076      ;;
1077   *solaris*)
1078      if test "$ac_cv_prog_CC" = "gcc"; then
1079         LD_RXLIB1="gcc -shared  ${LDFLAGS}"
1080         LD_RXTRANSLIB1="$LD_RXLIB1"
1081      else
1082         LD_RXLIB1="ld -G  ${LDFLAGS}"
1083         LD_RXTRANSLIB1="$LD_RXLIB1"
1084      fi
1085      ;;
1086   *esix*)
1087      LD_RXLIB1="ld -G  ${LDFLAGS}"
1088      LD_RXTRANSLIB1="$LD_RXLIB1"
1089      ;;
1090   *dgux*)
1091      LD_RXLIB1="ld -G  ${LDFLAGS}"
1092      LD_RXTRANSLIB1="$LD_RXLIB1"
1093      ;;
1094   sparc*sunos*)
1095      SYS_DEFS="-DSUNOS -DSUNOS_STRTOD_BUG"
1096      LD_RXLIB1="ld  ${LDFLAGS}"
1097      LD_RXTRANSLIB1="$LD_RXLIB1"
1098      ;;
1099   *linux*|*kfreebsd*-gnu*)
1100      LD_RXLIB1="${CC} -shared  ${LDFLAGS} -Wl,-soname,\$(@)"
1101      LD_RXTRANSLIB1="$LD_RXLIB1"
1102      CAN_USE_ABI="yes"
1103      if test "$USE_ABI" = "yes"; then
1104         OTHER_INSTALLS="installabilib"
1105      fi
1106      ;;
1107   *atheos*)
1108      LD_RXLIB1="${CC} -shared  ${LDFLAGS}"
1109      LD_RXTRANSLIB1="$LD_RXLIB1"
1110      ;;
1111   *-freebsd* | *openbsd*)
1112      if test "$ac_cv_prog_CC" = "gcc"; then
1113         LD_RXLIB1="gcc -shared  ${LDFLAGS}"
1114         LD_RXTRANSLIB1="$LD_RXLIB1"
1115      else
1116         LD_RXLIB1="ld -Bdynamic -Bshareable  ${LDFLAGS}"
1117         LD_RXTRANSLIB1="$LD_RXLIB1"
1118      fi
1119      STATIC_LDFLAGS="-static"
1120      ;;
1121   *pc-sco*)
1122      LD_RXLIB1="ld -dy -G  ${LDFLAGS}"
1123      LD_RXTRANSLIB1="$LD_RXLIB1"
1124      ;;
1125   *beos* | *haiku*)
1126      LD_RXLIB1="${CC}  ${LDFLAGS} -Wl,-shared -nostart -Xlinker -soname=\$(@)"
1127      LD_RXTRANSLIB1="$LD_RXLIB1"
1128      BEOS_DYN="yes"
1129      BASE_INSTALL="beosinstall"
1130      BASE_BINARY="beosbinary"
1131      OTHER_INSTALLS=""
1132      ;;
1133   *nto-qnx*)
1134      LD_RXLIB1="${CC} -shared  ${LDFLAGS}"
1135      LD_RXTRANSLIB1="$LD_RXLIB1"
1136      ;;
1137   *qnx*)
1138      LIBPRE=""
1139      LIBPST=".lib"
1140      SHLPRE=""
1141      DYN_COMP="-Q"
1142      SHLFILE=""
1143      EEXTRA="-mf -N0x20000 -Q"
1144      ;;
1145   *cygwin)
1146      LIBPRE="lib"
1147      SHLPRE=""
1148      DYN_COMP="-DDYNAMIC"
1149      LIBPST=".a"
1150      EXE=".exe"
1151      RXDEFEXP1="./cygwin.def"
1152# Only for Rexx/Trans do we produce an import library for the DLL we are
1153# building
1154      LD_RXLIB1="dllwrap --def \$(RXDEFEXP1) --target i386-cygwin32 --dllname \$(@)"
1155      LD_RXTRANSLIB1="dllwrap --def \$(srcdir)/\$(basename \$(@))w32.def --output-lib ${LIBPRE}\$(basename \$(@))${LIBPST} --target i386-cygwin32 --dllname \$(@)"
1156      BASE_INSTALL="cygwininstall"
1157      BASE_BINARY="cygwinbinary"
1158# cygwininstall target MUST install the shared library itself because
1159# it puts it into $(bindir) not $(libdir) as all other platforms
1160      OTHER_INSTALLS=""
1161      ;;
1162   *darwin*)
1163      DYN_COMP="-fno-common -DDYNAMIC"
1164# ensure we use two-name namespace on Mac so that when a function in a common source file is called the one
1165# in the shared library the call came from is executed, not one with the same name from another shared library
1166# otherwise you will get memory corruption.
1167      LD_RXLIB1="${CC}  ${LDFLAGS} ${EEXTRA} -dynamiclib -install_name=\$(@) -headerpad_max_install_names"
1168      LD_RXTRANSLIB1="$LD_RXLIB1"
1169      ;;
1170   *)
1171      ;;
1172esac
1173
1174dnl
1175dnl determine what switches our compiler uses for building objects
1176dnl suitable for inclusion in shared libraries
1177dnl Only call this if DYN_COMP is not set. If we have set DYN_COMP
1178dnl above, then we know how to compile AND link for dynamic libraries
1179dnl
1180if test "$DYN_COMP" = ""; then
1181AC_MSG_CHECKING(compiler flags for a dynamic object)
1182
1183cat > conftest.$ac_ext <<EOF
1184dnl [#]line __oline__ "[$]0"
1185[#]line __oline__ "configure"
1186int a=0
1187EOF
1188
1189   DYN_COMP=""
1190   mh_cv_stop=no
1191   save_cflags="$CFLAGS"
1192   mh_cv_flags="-fPIC -KPIC +Z"
1193   for a in $mh_cv_flags; do
1194      CFLAGS="-c $a"
1195
1196      mh_compile='${CC-cc} -c $CFLAGS conftest.$ac_ext > conftest.tmp 2>&1'
1197      if AC_TRY_EVAL(mh_compile); then
1198         DYN_COMP=""
1199      else
1200         slash="\\"
1201         mh_dyncomp="`egrep -c $slash$a conftest.tmp`"
1202         if test "$mh_dyncomp" = "0"; then
1203            DYN_COMP="$a -DDYNAMIC"
1204            AC_MSG_RESULT($a)
1205            break
1206         else
1207            DYN_COMP=""
1208         fi
1209      fi
1210   done
1211   if test "$DYN_COMP" = ""; then
1212      AC_MSG_RESULT(none of $mh_cv_flags supported)
1213   fi
1214   if test "$LD_RXLIB1" = ""; then
1215      MH_HOWTO_DYN_LINK()
1216   fi
1217   CFLAGS=$save_cflags
1218   rm -f conftest.*
1219fi
1220
1221
1222aix_exports="config.exports.aix"
1223echo "" > $aix_exports
1224if test "$ac_cv_header_dl_h" = "yes" -o "$ac_cv_header_dlfcn_h" = "yes" -o "$AIX_DYN" = "yes" -o "$BEOS_DYN" = "yes" -o "$DLFCNINCDIR" != "" -o "$DLFCNLIBDIR" != ""; then
1225   if test "$with_rexx" = "rexxtrans" -o "$with_rexx" = "regina" -o  "$with_rexx" = "objrexx" -o "$with_rexx" = "oorexx" -o "$with_rexx" = "rexx6000"; then
1226      EXPS="1,2,3,4,5,6,7,8,9"
1227      SHL_TARGETS=""
1228      for a in $SHLFILES
1229      do
1230         if test "$USE_ABI" = "yes" -a "$CAN_USE_ABI" = "yes"; then
1231            SHL_TARGETS="${SHL_TARGETS} ${SHLPRE}${a}${SHLPST}.\$(ABI)"
1232         else
1233            SHL_TARGETS="${SHL_TARGETS} ${SHLPRE}${a}${SHLPST}"
1234         fi
1235         this=`echo $EXPS | cut -d, -f1`
1236         EXPS=`echo $EXPS | cut -d, -f2-`
1237         if test "$AIX_DYN" = "yes"; then
1238            echo "RXPACKEXP$this=$a.exp" >> $aix_exports
1239            echo "RXPACKEXPORTS$this=-bE:$a.exp" >> $aix_exports
1240            if test "$ac_cv_prog_CC" = "gcc"; then
1241               echo "RXPACKEXPORTS$this=-Wl,-bE:$a.exp" >> $aix_exports
1242            else
1243               echo "RXPACKEXPORTS$this=-bE:$a.exp" >> $aix_exports
1244            fi
1245         else
1246            echo "RXPACKEXP$this=" >> $aix_exports
1247            echo "RXPACKEXPORTS$this=" >> $aix_exports
1248         fi
1249      done
1250   else
1251      SHL_TARGETS=""
1252   fi
1253else
1254   SHL_TARGETS=""
1255fi
1256
1257if test "$AIX_DYN" = "yes"; then
1258   STATICLIB=""
1259   LIBPST=".junk"
1260else
1261   STATICLIB="${LIBPRE}${SHLFILE}${LIBPST}"
1262fi
1263
1264LD_RXLIB1="$LD_RXLIB1 ${LDFLAGS}"
1265
1266AC_SUBST_FILE(aix_exports)
1267AC_SUBST(EEXTRA)
1268AC_SUBST(CEXTRA)
1269AC_SUBST(OSAVE)
1270AC_SUBST(OBJ)
1271AC_SUBST(EXE)
1272AC_SUBST(GETOPT)
1273AC_SUBST(DYN_COMP)
1274AC_SUBST(LIBS)
1275AC_SUBST(SHLIBS)
1276AC_SUBST(LD_RXLIB1)
1277AC_SUBST(LD_RXTRANSLIB1)
1278AC_SUBST(SHLPRE)
1279AC_SUBST(SHLPST)
1280AC_SUBST(LIBPST)
1281AC_SUBST(LIBPRE)
1282AC_SUBST(LIBEXE)
1283AC_SUBST(LIBFLAGS)
1284AC_SUBST(DYNAMIC_LDFLAGS)
1285AC_SUBST(STATIC_LDFLAGS)
1286AC_SUBST(STATICLIB)
1287AC_SUBST(SHL_TARGETS)
1288AC_SUBST(O2SAVE)
1289AC_SUBST(O2SHO)
1290AC_SUBST(CC2O)
1291AC_SUBST(BASE_INSTALL)
1292AC_SUBST(OTHER_INSTALLS)
1293AC_SUBST(BASE_BINARY)
1294AC_SUBST(SAVE2O)
1295AC_SUBST(RXPACKEXPORTS)
1296AC_SUBST(RXPACKEXP)
1297AC_SUBST(RXDEFEXP1)
1298AC_SUBST(CAN_USE_ABI)
1299])dnl
1300
1301dnl ---------------------------------------------------------------------------
1302dnl Check if C compiler supports -c -o file.ooo
1303dnl ---------------------------------------------------------------------------
1304AC_DEFUN([MH_CHECK_CC_O],
1305[
1306AC_MSG_CHECKING(whether $CC understand -c and -o together)
1307set dummy $CC; ac_cc="`echo [$]2 |
1308changequote(, )dnl
1309             sed -e 's/[^a-zA-Z0-9_]/_/g' -e 's/^[0-9]/_/'`"
1310changequote([, ])dnl
1311AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
1312[echo 'foo(){}' > conftest.c
1313# We do the test twice because some compilers refuse to overwrite an
1314# existing .o file with -o, though they will create one.
1315eval ac_cv_prog_cc_${ac_cc}_c_o=no
1316ac_try='${CC-cc} -c conftest.c -o conftest.ooo 1>&AC_FD_CC'
1317if AC_TRY_EVAL(ac_try) && test -f conftest.ooo && AC_TRY_EVAL(ac_try);
1318then
1319  ac_try='${CC-cc} -c conftest.c -o conftest.ooo 1>&AC_FD_CC'
1320  if AC_TRY_EVAL(ac_try) && test -f conftest.ooo && AC_TRY_EVAL(ac_try);
1321  then
1322    eval ac_cv_prog_cc_${ac_cc}_c_o=yes
1323  fi
1324fi
1325rm -f conftest*
1326])dnl
1327if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = yes"; then
1328   O2SHO=""
1329   O2SAVE=""
1330   SAVE2O=""
1331   CC2O="-o $"'@'
1332   AC_MSG_RESULT(yes)
1333else
1334   O2SHO="-mv \`basename "$'@'" .sho\`.o "$'@'
1335   O2SAVE="-mv \`basename "$'@'" .sho\`.o \`basename "$'@'" .sho\`.o.save"
1336   SAVE2O="-mv \`basename "$'@'" .sho\`.o.save \`basename "$'@'" .sho\`.o"
1337   CC2O=""
1338   AC_MSG_RESULT(no)
1339fi
1340])
1341
1342dnl ---------------------------------------------------------------------------
1343dnl Work out if functions in dynamically loadable libraries need leading _
1344dnl Tests based on glib code and only valid for dlopen() mechanism
1345dnl ---------------------------------------------------------------------------
1346AC_DEFUN([MH_CHECK_LEADING_USCORE],
1347[
1348if test "$ac_cv_header_dlfcn_h" = "yes" -o "$HAVE_DLFCN_H" = "1"; then
1349   AC_MSG_CHECKING(if symbols need underscore prepended in loadable modules)
1350   tmpLIBS="$LIBS"
1351   save_cflags="$CFLAGS"
1352   LIBS="$LIBS $DLFCNLIBDIR"
1353   CFLAGS="$CFLAGS $DLFCNINCDIR"
1354   AC_CACHE_VAL(mh_cv_uscore,[
1355   AC_RUN_IFELSE(
1356     [AC_LANG_SOURCE([
1357       #include <dlfcn.h>
1358       int mh_underscore_test (void) { return 42; }
1359       int main() {
1360         void *f1 = (void*)0, *f2 = (void*)0, *handle;
1361         handle = dlopen ((void*)0, 0);
1362         if (handle) {
1363           f1 = dlsym (handle, "mh_underscore_test");
1364           f2 = dlsym (handle, "_mh_underscore_test");
1365         } return (!f2 || f1);
1366       ])],
1367     mh_cv_uscore=yes,
1368     mh_cv_uscore=no
1369   )
1370   ])
1371   AC_MSG_RESULT($mh_cv_uscore)
1372   if test "x$mh_cv_uscore" = "xyes"; then
1373     AC_DEFINE(MODULES_NEED_USCORE)
1374   fi
1375   LIBS="$tmpLIBS"
1376   CFLAGS="$save_cflags"
1377fi
1378])
1379
1380dnl ---------------------------------------------------------------------------
1381dnl Determines the file extension for shared libraries
1382dnl ---------------------------------------------------------------------------
1383AC_DEFUN([MH_SHLPST],
1384[
1385AC_MSG_CHECKING(shared library/external function extensions)
1386SHLPST=".so"
1387MODPST=".so"
1388AC_REQUIRE([AC_CANONICAL_SYSTEM])
1389case "$target" in
1390        *hp-hpux*)
1391                SHLPST=".sl"
1392                MODPST=".sl"
1393                ;;
1394        *ibm-aix5*)
1395                SHLPST=".a"
1396                MODPST=".a"
1397                ;;
1398        *ibm-aix*)
1399                SHLPST=".a"
1400                MODPST=".a"
1401                ;;
1402        *qnx*)
1403                SHLPST=".junk"
1404                MODPST=""
1405                ;;
1406        *cygwin*)
1407                SHLPST=".dll"
1408                MODPST=".dll"
1409                ;;
1410        *darwin*)
1411                SHLPST=".dylib"
1412                MODPST=".dylib"
1413                ;;
1414esac
1415AC_SUBST(SHLPST)
1416AC_SUBST(MODPST)
1417AC_MSG_RESULT($SHLPST/$MODPST)
1418])
1419
1420dnl ---------------------------------------------------------------------------
1421dnl Work out if POSIX Threads are supported
1422dnl ---------------------------------------------------------------------------
1423AC_DEFUN([MH_CHECK_POSIX_THREADS],
1424[
1425MH_MT_LIBS=""
1426THREADING_COMPILE=""
1427THREADING_LINK=""
1428THREADSAFE_TARGET=""
1429MT_FILE="rxmt_notmt"
1430if test "$enable_posix_threads" = yes; then
1431   dnl
1432   dnl -lrt is needed by posix threads on Solaris
1433   dnl
1434   AC_CHECK_LIB("rt",main,mh_rt_lib_found=yes,mh_rt_lib_found=no)
1435   AC_MSG_CHECKING(whether Posix Threads are supported)
1436   tmpLIBS=$LIBS
1437   save_cflags="$CFLAGS"
1438   pthread_libs="pthreads pthread c_r c"
1439   case "$target" in
1440      *freebsd*)
1441         CFLAGS="$CFLAGS -pthread"
1442         ;;
1443   esac
1444   for mh_lib in $pthread_libs; do
1445      LIBS="$tmpLIBS -l${mh_lib}"
1446      AC_TRY_LINK(
1447      [#include <pthread.h>],
1448      [pthread_create(NULL,NULL,NULL,NULL)],
1449      [mh_has_pthreads=yes],
1450      [mh_has_pthreads=no]
1451      )
1452      if test "$mh_has_pthreads" = yes; then
1453         MH_MT_LIBS="-l${mh_lib}"
1454         AC_REQUIRE([AC_CANONICAL_SYSTEM])
1455         THREADING_COMPILE="-D_REENTRANT -DPOSIX"
1456         THREADING_LINK=""
1457         MT_FILE="rxmt_posix"
1458         case "$target" in
1459            *solaris*)
1460               if test "$ac_cv_prog_CC" = "gcc" -o "$ac_cv_prog_CC" = "g++" -o "$ac_cv_prog_CC" = "clang"; then
1461                  THREADING_COMPILE="-D_REENTRANT -DPOSIX"
1462                  if test "$mh_rt_lib_found" = "yes"; then
1463                     THREADING_LINK="-lrt"
1464                  fi
1465               else
1466                  THREADING_COMPILE="-mt -D_REENTRANT -DREENTRANT -D_PTHREAD_SEMANTICS"
1467                  THREADING_LINK="-mt"
1468               fi
1469               ;;
1470            *hp-hpux1*)
1471               if test "$ac_cv_prog_CC" = "gcc" -o "$ac_cv_prog_CC" = "g++" -o "$ac_cv_prog_CC" = "clang"; then
1472                  THREADING_COMPILE="-D_REENTRANT -DPOSIX"
1473               fi
1474               if test "$mh_rt_lib_found" = "yes"; then
1475                  THREADING_LINK="-lrt"
1476               fi
1477               ;;
1478            *linux*)
1479               if test "$ac_cv_prog_CC" = "gcc" -o "$ac_cv_prog_CC" = "g++" -o "$ac_cv_prog_CC" = "clang"; then
1480                  THREADING_LINK="-lpthread"
1481               else
1482                  THREADING_LINK="-lpthread"
1483               fi
1484               ;;
1485            *freebsd*)
1486               THREADING_COMPILE="-pthread -D_REENTRANT -DPOSIX"
1487               THREADING_LINK="-pthread"
1488               ;;
1489            *cygwin*)
1490               THREADING_COMPILE="-D_REENTRANT -DPOSIX"
1491               THREADING_LINK=""
1492               ;;
1493            *)
1494               if test "$ac_cv_prog_CC" = "gcc" -o "$ac_cv_prog_CC" = "g++" -o "$ac_cv_prog_CC" = "clang"; then
1495                  THREADING_COMPILE="-D_REENTRANT -DPOSIX"
1496               fi
1497               ;;
1498         esac
1499         break
1500      fi
1501   done
1502   LIBS="$tmpLIBS"
1503   CFLAGS="$save_cflags"
1504   AC_MSG_RESULT($mh_has_pthreads)
1505fi
1506AC_SUBST(THREADING_COMPILE)
1507AC_SUBST(THREADING_LINK)
1508AC_SUBST(MH_MT_LIBS)
1509AC_SUBST(MT_FILE)
1510])
1511
1512dnl ---------------------------------------------------------------------------
1513dnl Determines where rpm build files are located
1514dnl ---------------------------------------------------------------------------
1515AC_DEFUN([MH_CHECK_RPM],
1516[
1517AC_CHECK_PROG(mh_rpm_exists, rpm, yes, no )
1518if test "$mh_rpm_exists" = yes; then
1519   AC_MSG_CHECKING(where rpms are built)
1520   RPMTOPDIR=`rpm --eval "%{_topdir}"`
1521   AC_MSG_RESULT($RPMTOPDIR)
1522   AC_SUBST(RPMTOPDIR)
1523fi
1524])
1525
1526dnl ---------------------------------------------------------------------------
1527dnl Determines whether compiler supports long long
1528dnl ---------------------------------------------------------------------------
1529AC_DEFUN([MH_C_LONG_LONG],
1530[AC_CACHE_CHECK(for long long int, mh_cv_c_long_long,
1531[if test "$ac_cv_prog_CC" = "gcc"; then
1532  mh_cv_c_long_long=yes
1533  else
1534        AC_TRY_COMPILE(,[long long int i;],
1535   mh_cv_c_long_long=yes,
1536   mh_cv_c_long_long=no)
1537   fi])
1538   if test $mh_cv_c_long_long = yes; then
1539     AC_DEFINE(HAVE_LONG_LONG, 1, [compiler understands long long])
1540   fi
1541])
1542
1543dnl ---------------------------------------------------------------------------
1544dnl Shows the status of the configure options
1545dnl ---------------------------------------------------------------------------
1546AC_DEFUN([MH_SHOW_STATUS],
1547[
1548echo
1549echo "$MH_PACKAGE has now been configured with the following options:"
1550echo
1551echo "                 Rexx Interpreter: $REXX_INT"
1552
1553if test "$with_rexxincdir" != no ; then
1554   echo "                  rexx headers in: $with_rexxincdir"
1555fi
1556
1557if test "$with_rexxlibdir" != no ; then
1558   echo "                rexx libraries in: $with_rexxlibdir"
1559fi
1560
1561if test "$with_dlfcnincdir" != no ; then
1562   echo "                 dlfcn headers in: $with_dlfcnincdir"
1563fi
1564if test "$with_dlfcnlibdir" != no ; then
1565   echo "               dlfcn libraries in: $with_dlfcnlibdir"
1566fi
1567
1568dnl
1569dnl Run the package_specific status shower
1570dnl
1571$1
1572
1573myopts="$myopts ${bitflag}BIT"
1574
1575if test "$with_debug" = yes ; then
1576   myopts="$myopts DEBUG"
1577fi
1578
1579if test "$with_purify" = yes ; then
1580   myopts="$myopts PURIFY"
1581fi
1582
1583if test "$with_efence" = yes; then
1584   myopts="$myopts EFENCE"
1585fi
1586
1587if test "$with_hpux_portable" = yes ; then
1588   myopts="$myopts HPUX-PORTABLE"
1589fi
1590
1591if test "x$found_arch_flags" != "x" ; then
1592   myopts="$myopts UNIVERSAL: $found_arch_flags"
1593fi
1594
1595if test "$on_beos" = yes; then
1596   bindir="/boot/home/config/bin"
1597   libdir="/boot/home/config/lib"
1598fi
1599
1600echo "                    Build options: $myopts"
1601echo "    binaries will be installed in: $bindir"
1602if test "x$binarybitprefix" = "x32"; then
1603   echo "   32bit binaries will have '32' appended to them."
1604fi
1605echo "   libraries will be installed in: $libdir"
1606echo "                         {prefix}: $prefix"
1607echo "                    {exec_prefix}: $exec_prefix"
1608echo
1609if test "x$2" != "xnotrailer"; then
1610   echo "To build the $MH_PACKAGE binaries, and dynamically loadable libraries, type 'make'"
1611   echo "To install $MH_PACKAGE in the above directories, type 'make install'"
1612   echo
1613fi
1614])
1615
1616dnl ---------------------------------------------------------------------------
1617dnl Determines which -arch flags valid on Mac OSX with gcc
1618dnl ---------------------------------------------------------------------------
1619AC_DEFUN([MH_CHECK_OSX_ARCH],
1620[
1621valid_arch_flags=""
1622found_arch_flags=""
1623AC_ARG_WITH(arch,
1624   [  --with-arch=option      build universal binaries on OS X, option: one of "all 32bit 64bit intel ppc ppc64 x86_64 i386"],
1625   [with_arch=$withval],
1626   [with_arch=none],
1627)
1628case "$with_arch" in
1629   none)
1630      arch_flags=""
1631      ;;
1632   all)
1633      arch_flags="-arch ppc -arch ppc64 -arch x86_64 -arch i386"
1634      ;;
1635   32bit)
1636      arch_flags="-arch ppc -arch i386"
1637      ;;
1638   64bit)
1639      arch_flags="-arch ppc64 -arch x86_64"
1640      ;;
1641   intel)
1642      arch_flags="-arch i386 -arch x86_64"
1643      ;;
1644   *)
1645      arch_flags="-arch $with_arch"
1646      ;;
1647esac
1648
1649valid_arch_flags=""
1650found_arch_flags=""
1651if test $on_osx = "yes"; then
1652  AC_MSG_CHECKING(for which Mac OSX -arch flags are supported for universal binaries)
1653  for a in $arch_flags; do
1654    save_ldflags="$LDFLAGS"
1655    LDFLAGS="$LDFLAGS -arch $a"
1656    AC_LINK_IFELSE(
1657    [AC_LANG_PROGRAM([#include <stdio.h>],
1658    [exit(0)])],
1659    [valid_arch_flags="$valid_arch_flags -arch $a";found_arch_flags="$found_arch_flags $a"],
1660    [a="$a"]
1661    )
1662    LDFLAGS="$save_ldflags"
1663  done
1664  AC_MSG_RESULT($found_arch_flags)
1665  AC_SUBST(valid_arch_flags)
1666fi
1667])
1668
1669dnl ---------------------------------------------------------------------------
1670dnl Determines the kernel name from uname
1671dnl ---------------------------------------------------------------------------
1672AC_DEFUN([MH_GET_KERNEL_NAME],
1673[
1674AC_CHECK_PROG(uname, [uname], yes, no)
1675AC_MSG_CHECKING(kernel name)
1676if test "$ac_cv_prog_uname" = yes; then
1677   kn=`uname -s`
1678else
1679   kn="unknown"
1680fi
1681AC_DEFINE_UNQUOTED(MH_KERNEL_NAME, "$kn", [kernel name])
1682AC_MSG_RESULT($kn)
1683])
1684
1685dnl ---------------------------------------------------------------------------
1686dnl Determines the Linux distribution name
1687dnl ---------------------------------------------------------------------------
1688AC_DEFUN([MH_GET_DISTRO_NAME],
1689[
1690AC_CHECK_PROG(lsb_release, [lsb_release], yes, no)
1691if test "$ac_cv_prog_lsb_release" = yes; then
1692   AC_MSG_CHECKING(OS distribution name)
1693   MYDISTRO="`lsb_release -i | cut -f 2`-`lsb_release -r | cut -f 2`"
1694   MYDISTRO="`echo $MYDISTRO | sed \"s/ /_/g\"`"
1695   AC_MSG_RESULT($MYDISTRO)
1696else
1697   case "$target" in
1698      *freebsd* | *openbsd*)
1699         MYDISTRO="`echo $target | cut -f3 -d-`"
1700      ;;
1701      *darwin*)
1702         MYDISTRO="`echo $target | cut -f2-3 -d-`"
1703      ;;
1704      *pc-solaris2*)
1705         MYDISTRO="`echo $target | cut -f2- -d-`"
1706      ;;
1707      *cygwin*)
1708         MYDISTRO="`echo $target | cut -f2- -d-`"
1709      ;;
1710      *nto-qnx*)
1711         MYDISTRO="`uname -s`-`uname -r`"
1712      ;;
1713      *qnx*)
1714         MYDISTRO="`uname -s`-`uname -v`"
1715      ;;
1716      *)
1717         MYDISTRO="$target"
1718      ;;
1719   esac
1720fi
1721AC_SUBST(MYDISTRO)
1722])
1723
1724dnl ---------------------------------------------------------------------------
1725dnl Check curses library and header files
1726dnl ---------------------------------------------------------------------------
1727AC_DEFUN([MH_CHECK_CURSES],
1728[
1729case "$target" in
1730   *hpux1*)
1731         mh_curses_colr=yes
1732         mh_pre_curses_h_include="stdarg"
1733      ;;
1734   *aix*4.2*)
1735         mh_curses_colr=no
1736         mh_pre_curses_h_include="stdarg"
1737      ;;
1738   *)
1739         mh_curses_colr=no
1740         mh_pre_curses_h_include=""
1741esac
1742
1743if test "$with_xcurses" = yes; then
1744   CURSES_TARGET="XCurses"
1745   AC_DEFINE(USE_XCURSES)
1746   AC_CHECK_PROG(xcurses_config, [xcurses-config], yes, no)
1747   curses_h="xcurses.h"
1748   curses_l="XCurses"
1749else
1750   if test "$with_pdcurses" = yes; then
1751      CURSES_TARGET="pdcurses"
1752      AC_DEFINE(USE_PDCURSES)
1753      curses_h="curses.h"
1754      curses_l="pdcurses"
1755   else
1756      if test "$with_ncurses" = yes; then
1757         CURSES_TARGET="ncurses"
1758         AC_DEFINE(USE_NCURSES)
1759         AC_CHECK_PROG(ncurses5_config, [ncurses5-config], yes, no)
1760         if test "$ac_cv_prog_ncurses5_config" = yes; then
1761            ncurses_config_bin="ncurses5-config"
1762         else
1763            AC_CHECK_PROG(ncursesw5_config, [ncursesw5-config], yes, no)
1764            if test "$ac_cv_prog_ncursesw5_config" = yes; then
1765               ncurses_config_bin="ncurses5.4-config"
1766            else
1767               ncurses_config_bin=""
1768            fi
1769         fi
1770         curses_h="ncurses.h"
1771         curses_l="ncurses"
1772      else
1773         if test "$with_extcurses" = yes; then
1774            CURSES_TARGET="extcurses"
1775            AC_DEFINE(USE_EXTCURSES)
1776            curses_h="cur00.h"
1777            curses_l="cur"
1778         else
1779            if test "$with_dwindows" = yes; then
1780               CURSES_TARGET="dwindows"
1781               AC_DEFINE(USE_DWINDOWS)
1782               AC_CHECK_PROG(dw_config, [dw-config], yes, no)
1783               curses_h="dw.h"
1784               curses_l="dwindows"
1785            else
1786               CURSES_TARGET="curses"
1787               if test "$mh_curses_colr" = yes; then
1788                  curses_h="curses.h"
1789                  curses_l="cur_colr"
1790               else
1791                  curses_h="curses.h"
1792                  curses_l="curses"
1793               fi
1794            fi
1795         fi
1796      fi
1797   fi
1798fi
1799AC_SUBST(CURSES_TARGET)
1800
1801dnl look for curses header and library, exit if not found
1802if test "$ac_cv_prog_xcurses_config" = yes -a "$with_cursesincdir" = no; then
1803   AC_MSG_CHECKING(for location of $curses_h header file)
1804   AC_MSG_RESULT(obtained from xcurses-config)
1805   MH_CURSES_INC=`xcurses-config --cflags`
1806   AC_SUBST(MH_CURSES_INC)
1807else
1808   if test "$ac_cv_prog_ncurses5_config" = yes -a "$with_cursesincdir" = no; then
1809      AC_MSG_CHECKING(for location of $curses_h header file)
1810      AC_MSG_RESULT(obtained from ncurses5-config)
1811      MH_CURSES_INC=`ncurses5-config --cflags`
1812      AC_SUBST(MH_CURSES_INC)
1813   else
1814      if test "$ac_cv_prog_ncursesw5_config" = yes -a "$with_cursesincdir" = no; then
1815         AC_MSG_CHECKING(for location of $curses_h header file)
1816         AC_MSG_RESULT(obtained from ncursesw5-config)
1817         MH_CURSES_INC=`ncursesw5-config --cflags`
1818         AC_SUBST(MH_CURSES_INC)
1819      else
1820         if test "$ac_cv_prog_dw_config" = yes -a "$with_cursesincdir" = no; then
1821            AC_MSG_CHECKING(for location of $curses_h header file)
1822            AC_MSG_RESULT(obtained from dw-config)
1823            MH_CURSES_INC=`dw-config --cflags`
1824            AC_SUBST(MH_CURSES_INC)
1825         else
1826            AC_MSG_CHECKING(for location of $curses_h header file)
1827            mh_curses_inc_dir=""
1828            mh_inc_dirs="\
1829                ${CURSESINCDIR}           \
1830                ${mh_sysv_incdir}         \
1831                ${exec_prefix}/include    \
1832                ${HOME}/include           \
1833                /usr/local/include        \
1834                /usr/contrib/include      \
1835                /usr/include/curses_colr  \
1836                /opt/include              \
1837                /usr/include              \
1838                /usr/ucbinclude           \
1839                /usr/ucbinc               \
1840                /opt/sfw/include          \
1841                /sw/include               \
1842                /usr/unsupported/include  \
1843                /boot/home/config/include \
1844                /boot/home/config/include/ncurses"
1845dnl
1846dnl Provide for user supplying directory
1847dnl
1848            if test "$with_cursesincdir" != no ; then
1849               mh_inc_dirs="$with_cursesincdir $mh_inc_dirs"
1850            fi
1851dnl
1852dnl Try to determine the directory containing curses header
1853dnl
1854            for ac_dir in $mh_inc_dirs ; do
1855              if test -r $ac_dir/$curses_h; then
1856                mh_curses_inc_dir=$ac_dir
1857                break
1858              fi
1859            done
1860            if test "x$mh_curses_inc_dir" != "x" ; then
1861               AC_MSG_RESULT(found in $mh_curses_inc_dir)
1862               MH_CURSES_INC="-I$mh_curses_inc_dir"
1863dnl
1864dnl If the curses header file contains NCURSES_VERSION then we can assume it is
1865dnl ncurses, so AC_DEFINE(USE_NCURSES)
1866      AC_TRY_COMPILE(
1867      [#include <$curses_h>],
1868      [int xxx=NCURSES_VERSION_MAJOR],
1869      [mh_is_ncurses=yes],
1870      [mh_is_ncurses=no]
1871      )
1872      if test "$mh_is_ncurses" = yes ; then
1873         AC_DEFINE(USE_NCURSES)
1874      fi
1875dnl
1876dnl If using gcc under Solaris 2, don't use -I/usr/include
1877dnl
1878            case "$target" in
1879               *solaris*)
1880                  if test "$ac_cv_prog_gcc" = yes ; then
1881                     if test "x$mh_curses_inc_dir" = "x/usr/include" ; then
1882                     MH_CURSES_INC=""
1883                     fi
1884                  fi
1885                  ;;
1886            esac
1887               AC_SUBST(MH_CURSES_INC)
1888            else
1889               AC_MSG_ERROR(Cannot find curses header file: $curses_h; cannot configure)
1890            fi
1891         fi
1892      fi
1893   fi
1894fi
1895
1896if test "$ac_cv_prog_xcurses_config" = yes -a "$with_curseslibdir" = no; then
1897AC_MSG_CHECKING(for location of $curses_l library file)
1898   AC_MSG_RESULT(obtained from xcurses-config)
1899   MH_CURSES_LIB=`xcurses-config --libs`
1900   AC_SUBST(MH_CURSES_LIB)
1901else
1902   if test "$ac_cv_prog_ncurses5_config" = yes -a "$with_curseslibdir" = no; then
1903   AC_MSG_CHECKING(for location of $curses_l library file)
1904      AC_MSG_RESULT(obtained from ncurses5-config)
1905      MH_CURSES_LIB=`ncurses5-config --libs`
1906      AC_SUBST(MH_CURSES_LIB)
1907   else
1908      if test "$ac_cv_prog_dw_config" = yes -a "$with_curseslibdir" = no; then
1909      AC_MSG_CHECKING(for location of $curses_l library file)
1910         AC_MSG_RESULT(obtained from dw-config)
1911         MH_CURSES_LIB=`dw-config --libs`
1912         AC_SUBST(MH_CURSES_LIB)
1913      else
1914         AC_MSG_CHECKING(for location of $curses_l library file)
1915         mh_curses_lib_dir=""
1916         mh_lib_dirs="\
1917             ${CURSESLIBDIR}           \
1918             ${mh_sysv_libdir}         \
1919             ${exec_prefix}/lib64      \
1920             ${exec_prefix}/lib        \
1921             ${HOME}/lib64             \
1922             ${HOME}/lib               \
1923             /usr/local/lib64          \
1924             /usr/local/lib            \
1925             /usr/contrib/lib          \
1926             /opt/lib                  \
1927             /usr/lib64                \
1928             /usr/lib                  \
1929             /usr/ccs/lib              \
1930             /usr/ucblib               \
1931             /opt/sfw/lib              \
1932             /sw/lib                   \
1933             /usr/unsupported/lib      \
1934             /boot/home/config/lib"
1935dnl
1936dnl Provide for user supplying directory
1937dnl
1938         if test "$with_curseslibdir" != no ; then
1939            mh_lib_dirs="$with_curseslibdir $mh_lib_dirs"
1940         fi
1941dnl
1942dnl Try to determine the directory containing curses library
1943dnl
1944         for ac_dir in $mh_lib_dirs ; do
1945            for mh_ext in lib${curses_l}.a lib${curses_l}.so lib${curses_l}.sl ${curses_l}.lib ${curses_l}3r.lib lib${curses_l}.dylib; do
1946              if test -r $ac_dir/$mh_ext; then
1947                 mh_curses_lib_dir=$ac_dir
1948                 break 2
1949              fi
1950            done
1951         done
1952         if test "x$mh_curses_lib_dir" != "x" ; then
1953            MH_CURSES_LIB="-L$mh_curses_lib_dir -l$curses_l"
1954            AC_MSG_RESULT(found in $mh_curses_lib_dir)
1955            AC_SUBST(MH_CURSES_LIB)
1956         else
1957            AC_MSG_ERROR(Cannot find curses library file: $curses_l; cannot configure)
1958         fi
1959      fi
1960   fi
1961fi
1962])dnl
1963
1964dnl ---------------------------------------------------------------------------
1965dnl Wrapper for AC_CHECK_FUNCS.
1966dnl ---------------------------------------------------------------------------
1967AC_DEFUN([MH_CHECK_FUNCS],
1968[
1969dnl check a standard list of functions, then those passed in as args
1970AC_CHECK_FUNCS(memcpy memmove strerror getopt strtof $*)
1971])dnl
1972
1973dnl ---------------------------------------------------------------------------
1974dnl Check if various types have been typedefed by supplied header files
1975dnl ---------------------------------------------------------------------------
1976AC_DEFUN([MH_CHECK_TYPES],
1977[
1978header=$1
1979inc=$2
1980types="LONG CHAR SHORT ULONG UCHAR USHORT $3"
1981if test "x$inc" != "x"; then
1982   save_CFLAGS="$CFLAGS"
1983   CFLAGS="$CFLAGS $inc"
1984fi
1985CFLAGS="$CFLAGS $DB_INCLUDES"
1986for mh_type in $types; do
1987   AC_MSG_CHECKING(if $mh_type already defined)
1988   if test "x$header" = "x"; then
1989      AC_TRY_COMPILE([],
1990         [${mh_type} var1;],
1991         mh_type_found=yes, mh_type_found=no )
1992   else
1993      AC_TRY_COMPILE([#include <$header>],
1994         [${mh_type} var1;],
1995         mh_type_found=yes, mh_type_found=no )
1996   fi
1997   AC_MSG_RESULT($mh_type_found)
1998   if test "$mh_type_found" = yes; then
1999      AC_DEFINE_UNQUOTED(${mh_type}_TYPEDEFED)
2000   fi
2001done
2002if test "x$inc" != "x"; then
2003   CFLAGS=$save_CFLAGS
2004fi
2005])dnl
2006