configure.in 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. dnl Process this file with autoconf to produce a configure script.
  2. dnl
  3. dnl
  4. define(S48_PICK_GC, [dnl
  5. AC_ARG_ENABLE([gc],
  6. [AC_HELP_STRING([--enable-gc=GC],
  7. [choose garbage collector (twospace, bibop), default is twospace])],
  8. [dnl
  9. case $enableval in
  10. twospace )
  11. AC_DEFINE([S48_GC_TWOSPACE], 1, [Define if building with two-space GC.])
  12. GC_OBJS='${GC_TWOSPACE_OBJS}' ;;
  13. bibop )
  14. AC_DEFINE([S48_GC_BIBOP], 1, [Define if building with BIBOP GC.])
  15. GC_OBJS='${GC_BIBOP_OBJS}' ;;
  16. * ) AC_MSG_ERROR([Invalid argument to --enable-gc]) ;;
  17. esac
  18. ],
  19. [AC_DEFINE([S48_GC_TWOSPACE], 1, [Define if building with two-space GC.])
  20. GC_OBJS='$(GC_TWOSPACE_OBJS)'])dnl
  21. ])dnl
  22. dnl
  23. dnl
  24. define(S48_MISALIGNED_DOUBLES, [dnl
  25. if test "$GCC" = "yes"; then
  26. AC_MSG_CHECKING([-munaligned-doubles])
  27. oldCFLAGS="$CFLAGS"
  28. CFLAGS="$CFLAGS -munaligned-doubles"
  29. AC_TRY_RUN([int main() { return 0;}],
  30. [AC_MSG_RESULT(yes)],
  31. [AC_MSG_RESULT(no)
  32. CFLAGS="$oldCFLAGS"],
  33. [AC_MSG_RESULT(no)
  34. CFLAGS="$oldCFLAGS"])
  35. fi
  36. ])dnl
  37. dnl
  38. dnl
  39. dnl
  40. define(S48_ENABLE_UNIVERSAL_BINARY, [dnl
  41. AC_MSG_CHECKING([whether we are building a Universal Binary])
  42. dnl
  43. AC_ARG_ENABLE([universal-binary],
  44. [AC_HELP_STRING([--enable-universal-binary],
  45. [Build MacOS X Universal Binary])],
  46. [dnl
  47. CFLAGS="${CFLAGS} -arch i386 -arch ppc";
  48. option_enable_universal_binary="yes";
  49. AC_DEFINE([BUILD_UNIVERSAL_BINARY], 1,
  50. [Define if we are building an OS X Universal Binary.])
  51. AC_MSG_RESULT(yes)],
  52. [dnl
  53. option_enable_universal_binary="no";
  54. AC_MSG_RESULT(no)])])
  55. dnl
  56. dnl
  57. dnl
  58. dnl We might want AC_WORDS_BIGENDIAN in the future.
  59. dnl We might want AC_CHAR_UNSIGNED in the future.
  60. dnl
  61. define(S48_POSIX_LIBC, [dnl
  62. echo checking for RISC/OS POSIX library lossage
  63. if test -f /usr/posix/usr/lib/libc.a; then
  64. LIBS="${LIBS} /usr/posix/usr/lib/libc.a"
  65. fi
  66. ])dnl
  67. dnl
  68. dnl Run AC_PROG_CC, but don't accept it's changes to CFLAGS.
  69. dnl For some insane reason, it sets CFLAGS to either `-O' or `-g -O' for gcc.
  70. dnl I don't want the silly -g (because if you are using nlist, you can't strip
  71. dnl the binary), I want -O2 for gcc and -O for other C compilers.
  72. define(S48_PROG_CC, [dnl
  73. oldCFLAGS="$CFLAGS"
  74. AC_PROG_CC
  75. if test "z$oldCFLAGS" = z; then
  76. if test "z$GCC" = z; then
  77. CFLAGS='-O'
  78. else
  79. CFLAGS='-O2'
  80. fi
  81. fi
  82. ])dnl
  83. dnl
  84. dnl Linux/ELF systems need the -rdynamic flag when linking so that
  85. dnl dlsym() can find symbols in the executable.
  86. dnl Note, on some Sun's, you can link with -rdynamic but the resulting
  87. dnl a.out always core dumps.
  88. define(S48_RDYNAMIC, [dnl
  89. AC_MSG_CHECKING([link with -rdynamic])
  90. AC_TRY_COMPILE([],
  91. [#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__)
  92. this must not compile
  93. #endif],
  94. [AC_MSG_RESULT(no)],
  95. [AC_MSG_RESULT(yes)
  96. LDFLAGS="$LDFLAGS -rdynamic"])
  97. ])dnl
  98. dnl
  99. define(S48_INLINE, [dnl
  100. AC_MSG_CHECKING([for inline keyword])
  101. AC_COMPILE_IFELSE([#include <stdio.h>
  102. inline void f(void)
  103. {
  104. printf("inlined");
  105. }], [AC_MSG_RESULT([yes])
  106. AC_DEFINE([HAVE_INLINE], [1], [Define if the C compiler supports the inline keyword])],
  107. [AC_MSG_RESULT([no])])
  108. ])
  109. dnl
  110. define(S48_IEEE_ENDIANNESS, [dnl
  111. AC_MSG_CHECKING([IEEE floating-point endianness])
  112. if test "$option_enable_universal_binary" = "yes"
  113. then
  114. AC_MSG_RESULT([building Universal Binary; using compiler defined macros instead])
  115. else
  116. AC_TRY_RUN([#include <stdio.h>
  117. typedef unsigned long word32_t;
  118. typedef union { double d; word32_t word[2]; } double_overlay;
  119. #define DOUBLE_WORD0(x) ((double_overlay*)&(x))->word[0]
  120. #define DOUBLE_WORD1(x) ((double_overlay*)&(x))->word[1]
  121. int
  122. main(void)
  123. {
  124. double n = 0.3;
  125. /* least significant byte first */
  126. if ((DOUBLE_WORD0(n) == 0x33333333) && (DOUBLE_WORD1(n) == 0x3fd33333))
  127. return 0;
  128. /* most significant byte first */
  129. else if ((DOUBLE_WORD1(n) == 0x33333333) && (DOUBLE_WORD0(n) == 0x3fd33333))
  130. return 1;
  131. else {
  132. fprintf(stderr, "WARNING: unknown IEEE format; assuming IEEE with least significant byte first\n");
  133. return 0;
  134. }
  135. }], ieee_endianness="least first", ieee_endianness="most first", ieee_endianness="least first")
  136. AC_MSG_RESULT([$ieee_endianness])
  137. if test "$ieee_endianness" = "most first"; then
  138. AC_DEFINE([IEEE_MOST_FIRST], 1, [Define if IEEE doubles are stored with most-significant byte first.])
  139. fi
  140. fi
  141. ])dnl
  142. dnl
  143. define(S48_USCORE, [dnl
  144. AC_MSG_CHECKING([underscore before symbols])
  145. echo 'main() { return 0; } fnord() {}' >conftest.c
  146. if ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} conftest.c ${LIBS} &&
  147. nm a.out | grep _fnord >/dev/null; then
  148. AC_MSG_RESULT([yes])
  149. AC_DEFINE(USCORE)
  150. else
  151. AC_MSG_RESULT([no])
  152. fi
  153. rm -f conftest.c a.out
  154. ])dnl
  155. dnl
  156. define(S48_CREATE_BUILD_DIRS, [dnl
  157. mkdir -p c/bibop
  158. mkdir -p c/unix
  159. mkdir -p c/posix
  160. mkdir -p c/fake
  161. ])dnl
  162. dnl
  163. AC_INIT(c/prescheme.h)
  164. AC_CONFIG_HEADER(c/sysdep.h)
  165. AC_CONFIG_HEADER(c/scheme48write-barrier.h)
  166. dnl set the cross-compile flag before we try anything.
  167. AC_TRY_RUN([int main() { return 0;}], [], [], [true])
  168. S48_PICK_GC
  169. S48_ENABLE_UNIVERSAL_BINARY
  170. S48_CREATE_BUILD_DIRS
  171. S48_PROG_CC
  172. AC_ISC_POSIX
  173. S48_INLINE
  174. AC_PROG_INSTALL
  175. AC_CHECK_LIB(m, main)
  176. AC_CHECK_LIB(dl, main)
  177. AC_CHECK_LIB(mld, main)
  178. AC_CHECK_LIB(nsl, main)
  179. AC_CHECK_LIB(gen, main)
  180. AC_CHECK_LIB(socket, main)
  181. AC_CHECK_LIB(sun, getpwnam)
  182. dnl Solaris 2.3 seems to need -lelf for nlist(). (tnx Bryan O'Sullivan)
  183. AC_CHECK_LIB(elf, main)
  184. S48_POSIX_LIBC
  185. AC_CONST
  186. AC_MSG_CHECKING(for socklen_t)
  187. AC_TRY_COMPILE([#include <sys/types.h>
  188. #include <sys/socket.h>
  189. socklen_t x;
  190. ],[],
  191. [AC_MSG_RESULT(yes)],
  192. [AC_TRY_COMPILE([#include <sys/types.h>
  193. #include <sys/socket.h>
  194. int accept (int,
  195. struct sockaddr *,
  196. size_t *);
  197. ],[],
  198. [AC_MSG_RESULT(size_t)
  199. AC_DEFINE(socklen_t,size_t)],
  200. [AC_MSG_RESULT(int)
  201. AC_DEFINE(socklen_t,int)])])
  202. AC_RETSIGTYPE
  203. AC_CHECK_HEADERS(libgen.h sys/timeb.h posix/time.h)
  204. AC_CHECK_HEADERS(sys/select.h)
  205. AC_CHECK_HEADERS(sysexits.h)
  206. AC_CHECK_HEADERS(langinfo.h)
  207. AC_CHECK_FUNC(nl_langinfo, [], [AC_LIBOBJ([c/fake/langinfo])])
  208. AC_CHECK_FUNCS(gettimeofday ftime nlist select setitimer sigaction)
  209. AC_CHECK_FUNC(dlopen, [AC_DEFINE(HAVE_DLOPEN,
  210. 1, [Define to 1 if the interface to the dynamic linker exists])],
  211. [AC_CHECK_FUNC(nlist, [AC_LIBOBJ([c/fake/libdl1])],
  212. [AC_LIBOBJ([c/fake/libdl2])])])
  213. AC_CHECK_FUNCS(socket chroot)
  214. AC_CHECK_FUNC(strerror, AC_DEFINE(HAVE_STRERROR),
  215. [AC_LIBOBJ([c/fake/strerror.o])])
  216. dnl Some idiot renamed `environ' as `__environ' in some versions of Linux.
  217. dnl POSIX says it's `environ'.
  218. AC_MSG_CHECKING([environ])
  219. AC_TRY_LINK([],
  220. [extern char **environ;
  221. if (environ)
  222. return 0;
  223. else
  224. return 1;],
  225. dnl Have `environ'
  226. [AC_DEFINE(ENVIRON_NAME,environ)
  227. AC_MSG_RESULT([using environ])],
  228. dnl Do not have `environ'
  229. [AC_TRY_LINK([],
  230. [extern char **__environ;
  231. if (__environ)
  232. return 0;
  233. else
  234. return 1;],
  235. dnl Have `__environ'
  236. [AC_DEFINE(ENVIRON_NAME,__environ)
  237. AC_MSG_RESULT([using __environ])],
  238. dnl Do not have `__environ'
  239. [AC_MSG_WARN([no environ variable found])
  240. AC_LIBOBJ([c/fake/environ.o])])])
  241. AC_MSG_CHECKING([n_name])
  242. AC_TRY_LINK([#include <nlist.h>],
  243. [struct nlist name_list;
  244. name_list.n_name = "foo";],
  245. AC_DEFINE(NLIST_HAS_N_NAME)
  246. AC_MSG_RESULT([yes]),
  247. AC_MSG_RESULT([no]))
  248. AC_MSG_CHECKING([__NEXT__])
  249. AC_TRY_LINK(,[
  250. #ifdef __NeXT__
  251. return 0;
  252. #else
  253. fail
  254. #endif
  255. ],
  256. CC="$CC -posix"
  257. AC_DEFINE(HAVE_SIGACTION)
  258. AC_MSG_RESULT([yes]),
  259. AC_MSG_RESULT([no]))
  260. S48_USCORE
  261. S48_RDYNAMIC
  262. S48_MISALIGNED_DOUBLES
  263. S48_IEEE_ENDIANNESS
  264. AC_SUBST(CFLAGS)
  265. AC_SUBST(LDFLAGS)
  266. AC_SUBST(GC_OBJS)
  267. AC_SUBST(S48_GC_TWOSPACE)
  268. AC_SUBST(S48_GC_BIBOP)
  269. AC_OUTPUT(Makefile)