1
2#################################################################
3# This is the source for the `configure` script, to be compiled #
4# by autoconf (use `make-configure` in "../racket").            #
5#################################################################
6
7AC_INIT([rktio.h])
8AC_CONFIG_HEADERS([rktio_config.h])
9
10AC_CONFIG_AUX_DIR(../lt)
11AC_CANONICAL_SYSTEM
12
13AC_ARG_ENABLE(shared,     [  --enable-shared         create shared libraries (ok, but not recommended)])
14AC_ARG_ENABLE(standalone, [  --enable-standalone     create a standalone shared library])
15AC_ARG_ENABLE(pthread,    [  --enable-pthread        link with pthreads (usually auto-enabled if needed)])
16AC_ARG_ENABLE(iconv,      [  --enable-iconv          use iconv (usually auto-enabled)])
17AC_ARG_ENABLE(bigendian,  [  --enable-bigendian      assume "big" if endianness cannot be determined])
18
19if test "${enable_iconv}" = "" ; then
20  enable_iconv=yes
21fi
22
23skip_iconv_check=no
24use_flag_pthread=yes
25use_flag_posix_pthread=no
26
27# For standalone builds:
28rktio_version=1.0
29HIDE_STANDALONE=hide_standalone_
30HIDE_NOT_STANDALONE=
31
32###### Autoconfigure #######
33
34AC_PROG_CC
35
36# If using gcc, we want all warnings:
37if test "$CC" = "gcc" ; then
38  CFLAGS="$CFLAGS -Wall"
39fi
40
41AC_PROG_RANLIB
42if test "$AR" = '' ; then
43  AR="${ac_tool_prefix}ar"
44  AC_CHECK_PROG(platform_ar_found, $AR, yes, no)
45  if test "$platform_ar_found" = 'no' ; then
46    AR="ar"
47  fi
48fi
49if test "$ARFLAGS" = '' ; then
50  ARFLAGS=rc
51fi
52
53AC_CHECK_LIB(m, fmod)
54AC_CHECK_LIB(dl, dlopen)
55
56############## platform tests ################
57
58case "$host_os" in
59  solaris2*)
60    # Need these libs so that `getaddrinfo` is found:
61    LIBS="$LIBS -lsocket -lnsl -lintl"
62    try_poll_syscall="no" # poll() has performance problems on Solaris?
63    use_flag_pthread="no"
64    use_flag_posix_pthread="yes"
65    ;;
66  aix*)
67    ;;
68  *freebsd*)
69    enable_pthread_by_default=yes
70    try_kqueue_syscall=yes
71    ;;
72  openbsd*)
73    enable_pthread_by_default=yes
74    try_kqueue_syscall=yes
75    ;;
76  bitrig*)
77    enable_pthread_by_default=yes
78    try_kqueue_syscall=yes
79    ;;
80  dragonfly*)
81    enable_pthread_by_default=yes
82    try_kqueue_syscall=yes
83    ;;
84  netbsd*)
85    try_kqueue_syscall=yes
86    ;;
87  irix*)
88    ;;
89  linux*)
90    enable_pthread_by_default=yes
91    try_poll_syscall=yes
92    try_epoll_syscall=yes
93    try_inotify_syscall=yes
94    ;;
95  osf1*)
96    ;;
97  hpux*)
98    ;;
99  *mingw*)
100    skip_iconv_check=yes
101    # force pthread off for Windows:
102    enable_pthread=no
103    ;;
104  cygwin*)
105    ;;
106  darwin*)
107    PREFLAGS="$PREFLAGS -DOS_X -D_DARWIN_UNLIMITED_SELECT"
108    enable_pthread_by_default=yes
109    try_kqueue_syscall=yes
110
111    # select() generally works as well as poll() on OS X,
112    # and it works better for fifos
113    try_poll_syscall=no
114
115    # -pthread is not needed and triggers a warning
116    use_flag_pthread=no
117
118    # Use custom non-libtool build for a shared object
119    if test "${enable_standalone}" = "yes" ; then
120       if test "${enable_shared}" = "" ; then
121         enable_shared=no
122         make_darwin_dylib=yes
123       fi
124    fi
125    ;;
126  nto-qnx*)
127    use_flag_pthread=no
128    ;;
129  *)
130    ;;
131esac
132
133############## C flags ################
134
135AC_LANG_C
136
137AC_TYPE_INTPTR_T
138AC_TYPE_UINTPTR_T
139
140AC_C_BIGENDIAN(endianness=big, endianness=little, endianness=unknown)
141if test "${endianness}" = "unknown" ; then
142  if test "${enable_bigendian}" = "yes" ; then
143    endianness=big
144  else
145    echo configure: warning: cannot determine endianness, assuming little
146  fi
147fi
148
149if test "${endianness}" = "big" ; then
150  AC_DEFINE(RKTIO_BIG_ENDIAN,1,[Big endian])
151fi
152
153# Struct dirent
154AC_CHECK_MEMBER([struct dirent.d_namelen],
155                [AC_DEFINE(HAVE_DIRENT_NAMELEN, 1, [struct dirent has field namelen])],,
156		[#include <dirent.h>])
157AC_CHECK_MEMBER([struct dirent.d_namlen],
158                [AC_DEFINE(HAVE_DIRENT_NAMLEN, 1, [struct dirent has field namlen])],,
159		[#include <dirent.h>])
160
161[ msg="for xlocale.h" ]
162AC_MSG_CHECKING($msg)
163AC_COMPILE_IFELSE([AC_LANG_SOURCE([
164   # include <xlocale.h>
165   int main() {
166      return 0;
167   }])],
168   AC_DEFINE(RKTIO_USE_XLOCALE_HEADER,1,[Use xlocale.h])
169  xlocalehon=yes, xlocalehon=no)
170AC_MSG_RESULT($xlocalehon)
171
172SAVE_CFLAGS="$CFLAGS"
173if test "${xlocalehon}" = "yes" ; then
174  CFLAGS="$CFLAGS -DRKTIO_USE_XLOCALE_HEADER"
175fi
176[ msg="for xlocale functions" ]
177AC_MSG_CHECKING($msg)
178AC_LINK_IFELSE([AC_LANG_SOURCE([
179   #ifdef RKTIO_USE_XLOCALE_HEADER
180   # include <xlocale.h>
181   #endif
182   #include <locale.h>
183   int main() {
184      locale_t l = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, "C", NULL);
185      locale_t old_l = uselocale(l);
186      uselocale(old_l);
187      freelocale(l);
188      return 0;
189   }])],
190   AC_DEFINE(RKTIO_USE_XLOCALE,1,[Use xlocale])
191  xlocaleon=yes, xlocaleon=no)
192AC_MSG_RESULT($xlocaleon)
193CFLAGS="$SAVE_CFLAGS"
194
195AC_MSG_CHECKING([for getaddrinfo])
196AC_TRY_LINK([#include <sys/types.h>
197#include <sys/socket.h>
198#include <netdb.h>],
199	[getaddrinfo(0, 0, 0, 0);],
200   AC_DEFINE(HAVE_GETADDRINFO,1,[Have getaddrinfo])
201   have_getaddrinfo=yes,
202   have_getaddrinfo=no)
203AC_MSG_RESULT($have_getaddrinfo)
204
205iconv_lib_flag=""
206if test "${skip_iconv_check}" = "no" ; then
207 if test "${enable_iconv}" = "yes" ; then
208  AC_CHECK_HEADER(iconv.h, enable_iconv=yes, enable_iconv=no)
209  if test "${enable_iconv}" = "yes" ; then
210    # Does it all work, now?
211    AC_TRY_RUN(
212[   #include <iconv.h>]
213[   #include <langinfo.h>]
214    int main() {
215[     iconv_open("UTF-8", "UTF-8");]
216      return 0;
217    }, enable_iconv=yes, enable_iconv=no, enable_iconv=yes)
218    if test "${enable_iconv}" = "no" ; then
219      # Try adding -liconv ?
220      #  We did not use AC_CHECK_LIB because iconv is sometimes macro-renamed
221      ORIG_LIBS="$LIBS"
222      LIBS="$LIBS -liconv"
223      AC_TRY_RUN(
224[     #include <iconv.h>]
225[     #include <langinfo.h>]
226      int main() {
227[     iconv_open("UTF-8", "UTF-8");]
228      return 0;
229      }, enable_iconv=yes, enable_iconv=no, enable_iconv=yes)
230      if test "${enable_iconv}" = "no" ; then
231        LIBS="$ORIG_LIBS"
232      else
233        iconv_lib_flag=" -liconv"
234      fi
235    fi
236  fi
237 fi
238 [ msg="iconv is usable" ]
239 AC_MSG_CHECKING($msg)
240 iconv_usage_result="$enable_iconv$iconv_lib_flag"
241 AC_MSG_RESULT($iconv_usage_result)
242fi
243if test "${enable_iconv}" = "no" ; then
244  AC_DEFINE(RKTIO_NO_ICONV,1,[Do not use iconv])
245fi
246
247if test "${enable_iconv}" = "yes" ; then
248  AC_MSG_CHECKING([for nl_langinfo (CODESET)])
249  AC_TRY_LINK([#include <langinfo.h>],
250              [char *codeset = nl_langinfo (CODESET);],
251              AC_DEFINE(RKTIO_HAVE_CODESET,1,[Have nl_langinfo (CODESET)])
252               have_codeset=yes,
253              have_codeset=no)
254  AC_MSG_RESULT($have_codeset)
255fi
256
257[ msg="for mbsrtowcs" ]
258AC_MSG_CHECKING($msg)
259AC_LINK_IFELSE([AC_LANG_SOURCE([
260   #include <wchar.h>
261   #include <strings.h>
262   int main() {
263     mbstate_t state;
264     const char *src = "X";
265     bzero(&state, sizeof(mbstate_t));
266     mbsrtowcs(0, &src, 0, &state);
267     return 0;
268   }])], mbsrtowcs=yes, mbsrtowcs=no)
269if test "$mbsrtowcs" = "no" ; then
270  CFLAGS="$CFLAGS -DNO_MBTOWC_FUNCTIONS"
271fi
272AC_MSG_RESULT($mbsrtowcs)
273
274if test "${try_poll_syscall}" = "yes" ; then
275  [ msg="for poll" ]
276  AC_MSG_CHECKING($msg)
277  AC_LINK_IFELSE([AC_LANG_SOURCE([
278     #include <poll.h>
279     int main() {
280      struct pollfd pfd;
281      int r;
282      pfd.fd = 0;
283      pfd.events = POLLIN;
284      r = poll(&pfd, 1, 0);
285      return 0;
286     }])], use_poll=yes, use_poll=no)
287  AC_MSG_RESULT($use_poll)
288  if test "${use_poll}" = "yes" ; then
289     AC_DEFINE(HAVE_POLL_SYSCALL,1,[Have poll])
290  fi
291fi
292
293if test "${try_epoll_syscall}" = "yes" ; then
294  [ msg="for epoll" ]
295  AC_MSG_CHECKING($msg)
296  AC_LINK_IFELSE([AC_LANG_SOURCE([
297    #include <sys/epoll.h>
298    int main() {
299      int fd;
300      struct epoll_event ev;
301      fd = epoll_create(5);
302      ev.events = EPOLLIN | EPOLLONESHOT;
303      epoll_ctl(fd, EPOLL_CTL_ADD, 0, &ev);
304      return 0;
305    }])], use_epoll=yes, use_epoll=no)
306  AC_MSG_RESULT($use_epoll)
307  if test "${use_epoll}" = "yes" ; then
308     AC_DEFINE(HAVE_EPOLL_SYSCALL,1,[Have epoll])
309  fi
310fi
311
312if test "${try_inotify_syscall}" = "yes" ; then
313  [ msg="for inotify" ]
314  AC_MSG_CHECKING($msg)
315  AC_LINK_IFELSE([AC_LANG_SOURCE([
316    #include <sys/inotify.h>
317    int main() {
318      int fd;
319      int wd;
320      fd = inotify_init();
321      wd = inotify_add_watch(fd, "/tmp",
322                             (IN_CREATE | IN_DELETE | IN_DELETE_SELF
323                              | IN_MODIFY | IN_MOVE_SELF | IN_MOVED_TO));
324      return 0;
325    }])], use_inotify=yes, use_inotify=no)
326  AC_MSG_RESULT($use_inotify)
327  if test "${use_inotify}" = "yes" ; then
328     AC_DEFINE(HAVE_INOTIFY_SYSCALL,1,[Have inotify])
329  fi
330fi
331
332if test "${try_kqueue_syscall}" = "yes" ; then
333  [ msg="for kqueue" ]
334  AC_MSG_CHECKING($msg)
335  AC_LINK_IFELSE([AC_LANG_SOURCE([
336     #include <sys/types.h>
337     #include <sys/event.h>
338     #include <sys/time.h>
339     int main() {
340        int kq;
341        struct kevent kev;
342        struct timespec timeout = {0, 0};
343        kq = kqueue();
344        EV_SET(&kev, 0, EVFILT_READ, EV_ADD, 0, 0, NULL);
345        kevent(kq, &kev, 1, NULL, 0, &timeout);
346        return 0;
347     }])], use_kqueue=yes, use_kqueue=no)
348  AC_MSG_RESULT($use_kqueue)
349  if test "${use_kqueue}" = "yes" ; then
350     AC_DEFINE(HAVE_KQUEUE_SYSCALL,1,[Have kqueue])
351  fi
352fi
353
354LFS_CFLAGS=`getconf LFS_CFLAGS 2> /dev/null`
355if test "${LFS_CFLAGS}" != "" && test "${LFS_CFLAGS}" != "undefined"; then
356  echo "Large-file support: ${LFS_CFLAGS}"
357  CFLAGS="${CFLAGS} ${LFS_CFLAGS}"
358fi
359
360############### pthread ###################
361
362if test "${enable_pthread}" = "" ; then
363  if test "${enable_pthread_by_default}" = "yes" ; then
364    enable_pthread=yes
365  fi
366fi
367
368if test "${enable_pthread}" = "yes" ; then
369  if test "${use_flag_pthread}" = "yes" ; then
370    PREFLAGS="$PREFLAGS -pthread"
371    LDFLAGS="$LDFLAGS -pthread"
372  fi
373  if test "${use_flag_posix_pthread}" = "yes" ; then
374    PREFLAGS="$PREFLAGS -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT"
375  fi
376  AC_DEFINE(RKTIO_USE_PTHREADS, 1, [Pthread enabled])
377fi
378
379############## libtool ################
380
381if test "${enable_standalone}" = "yes" ; then
382   HIDE_STANDALONE=""
383   HIDE_NOT_STANDALONE=hide_not_standalone_
384   if test "${enable_shared}" = "" ; then
385     enable_shared=yes
386   fi
387fi
388
389if test "${enable_shared}" = "yes" ; then
390  echo "Configuring libtool"
391
392  # Assuming an absolute "${libdir}":
393  abslibdir="${libdir}"
394
395  if test ! -d "../lt" ; then
396    mkdir "../lt"
397  fi
398  abssrcdir=`(cd ${srcdir}; pwd)`
399
400  if test "${LIBTOOLPROG}" = "" ; then
401    (cd ../lt; sh ${abssrcdir}/../lt/configure --enable-shared --disable-static)
402    LIBTOOLPROG=`pwd`/../lt/libtool
403  fi
404
405  if test "${need_gcc_static_libgcc}" = "yes" ; then
406    need_gcc_static_libgcc=""
407    if test "$CC" = "gcc" ; then
408      gcc_vers_three=`${CC} -v 2>&1 | grep "version 3[.]"`
409      if test "$gcc_vers_three" = "" ; then
410        need_gcc_static_libgcc=""
411      else
412        need_gcc_static_libgcc=" -XCClinker -static-libgcc"
413      fi
414    fi
415  fi
416
417  # Use only for standalone builds:
418  AR="${LIBTOOLPROG} --mode=link --tag=CC $CC${need_gcc_static_libgcc}${ar_libtool_no_undefined} -release ${rktio_version} -rpath ${abslibdir} \$(ARLIBFLAGS) -o"
419  # Used for a librktio convenience library:
420  STATIC_AR="${LIBTOOLPROG} --mode=link --tag=CC $CC -o"
421  ARFLAGS=""
422  RANLIB=":"
423
424  RKTLINKER="${LIBTOOLPROG} --mode=link --tag=CC $CC${need_gcc_static_libgcc}"
425  CC="${LIBTOOLPROG} --mode=compile --tag=CC $CC"
426  LTO="lo"
427  LTA="la"
428  STRIP_LIB_DEBUG=":"
429  LIBSFX=la
430  ICP_LIB="${LIBTOOLPROG} --mode=install install -s"
431else
432  ICP=cp
433  LTO="o"
434  LTA="a"
435  RKTLINKER='$(CC)'
436  STATIC_AR="$AR"
437  LIBSFX=so
438  ICP_LIB=cp
439  if test "${make_darwin_dylib}" = "yes" ; then
440     LIBSFX="dylib"
441     AR='$(RKTLINKER) --shared -o'
442     ARFLAGS=""
443     LIBS="${LIBS} -framework CoreFoundation"
444     ICP_LIB=cp
445  fi
446fi
447
448############## final output ################
449
450CPPFLAGS="$CPPFLAGS $PREFLAGS"
451
452AC_SUBST(CC)
453AC_SUBST(CPPFLAGS)
454AC_SUBST(CFLAGS)
455AC_SUBST(LDFLAGS)
456AC_SUBST(LIBS)
457AC_SUBST(RKTLINKER)
458AC_SUBST(AR)
459AC_SUBST(ARFLAGS)
460AC_SUBST(RANLIB)
461AC_SUBST(STATIC_AR)
462AC_SUBST(ICP_LIB)
463
464AC_SUBST(LIBSFX)
465AC_SUBST(LTO)
466AC_SUBST(LTA)
467
468AC_SUBST(HIDE_NOT_STANDALONE)
469AC_SUBST(HIDE_STANDALONE)
470
471AC_SUBST(RKTIO_NO_ICONV)
472
473AC_SUBST(HAVE_DIRENT_NAMLEN)
474AC_SUBST(HAVE_DIRENT_NAMELEN)
475
476makefiles="Makefile"
477
478AC_OUTPUT($makefiles)
479