Autotools portability fixes and cleanups.
[cboard.git] / configure.ac
blobff3412bd9a4c1608f0a4bc4baff84380944e7c43
1 dnl Process this file with autoconf to produce a configure script.
2 AC_PREREQ(2.60)
3 AC_INIT(cboard, 0.6-dev, [Ben Kibbey bjk@luxsci.net])
4 AC_CONFIG_AUX_DIR(build)
5 AC_CANONICAL_TARGET
6 AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip])
7 AC_USE_SYSTEM_EXTENSIONS()
8 AC_CONFIG_SRCDIR([src/cboard.c])
9 AM_CONFIG_HEADER([config.h])
11 case "$target_os" in
12     darwin*)
13         LDFLAGS="$LDFLAGS -flat_namespace -L/sw/lib"
14         CPPFLAGS="$CPPFLAGS -I/sw/include -L/sw/lib"
15         ;;
16     *)
17         ;;
18 esac
20 dnl Checks for programs.
21 AC_PROG_CXX
22 AC_PROG_AWK
23 AC_PROG_CC
24 AC_PROG_CPP
25 AC_PROG_INSTALL
26 AC_PROG_LN_S
27 AC_PROG_MAKE_SET
28 AC_PROG_RANLIB
30 dnl Checks for library functions.
31 AC_CHECK_LIB(curses, initscr, ,
32             [AC_CHECK_LIB(ncurses, initscr, ,
33             [AC_MSG_ERROR([Missing or incomplete curses installation.])])])
34 AC_CHECK_LIB(panel, new_panel, ,
35             [AC_MSG_ERROR([Missing or incomplete curses installation.])])
36 AC_CHECK_LIB(form, new_form, ,
37             [AC_MSG_ERROR([Missing or incomplete curses installation.])])
39 AC_ARG_WITH(libperl, AC_HELP_STRING([--with-libperl], [PERL support.]),
40     want_libperl=yes, want_libperl=no)
42 AC_MSG_CHECKING([if PERL support is wanted])
43 AC_MSG_RESULT($want_libperl)
45 if test "$want_libperl" = "yes"; then
46     AC_CHECK_LIB(perl, perl_run, have_libperl=yes, have_libperl=no)
48     if test "$have_libperl" = "yes"; then
49         LIBPERL_CFLAGS=`perl -MExtUtils::Embed -e ccopts`
51         if test $? -ne 0; then
52             AC_MSG_ERROR([Missing or incomplete PERL installation.])
53         fi
55         AC_SUBST(LIBPERL_CFLAGS)
56         LIBPERL_LDFLAGS=`perl -MExtUtils::Embed -e ldopts`
57         AC_SUBST(LIBPERL_LDFLAGS)
58         AC_DEFINE([WITH_LIBPERL], 1, [Define if you want PERL support.])
59     else
60         AC_MSG_ERROR([Missing or incomplete PERL installation.])
61     fi
64 AM_CONDITIONAL([WITH_LIBPERL], [test "$have_libperl" = "yes"])
65 dnl Checks for header files.
66 AC_HEADER_DIRENT
67 AC_HEADER_SYS_WAIT
68 AC_HEADER_STDC
69 AC_CHECK_HEADERS([fcntl.h paths.h sys/socket.h limits.h sys/time.h unistd.h \
70                   stdlib.h string.h strings.h curses.h panel.h form.h wchar.h \
71                   getopt.h sys/param.h regex.h glob.h stdarg.h paths.h])
72 AC_CHECK_HEADERS([err.h],, [AC_CHECK_FUNCS([fputs_unlocked putwc_unlocked \
73                  putw_unlocked])])
75 AM_CONDITIONAL([NO_ERR_H], [test "x$ac_cv_header_err_h" = "xno"])
77 AC_TRY_COMPILE([#include <curses.h>], [attr_t n = 0;],
78                AC_DEFINE([HAVE_ATTR_T], 1, \
79                          [Define if your curses installation contains attr_t.]))
81 AC_TRY_LINK([#include <err.h>], [extern char *__progname;],
82                AC_DEFINE([HAVE_PROGNAME], 1, \
83                          [Define if your system has __progname.]))
85 AC_TRY_COMPILE([#include <glob.h>], [int n = GLOB_NOMATCH;],
86                AC_DEFINE([HAVE_GLOB_NOMATCH], 1, \
87                          [Define if glob.h defines GLOB_NOMATCH.]))
89 AC_TRY_COMPILE([#include <form.h>], [FIELDTYPE *t = TYPE_IPV4;],
90                AC_DEFINE([HAVE_TYPE_IPV4], 1, \
91                          [Define if form.h defines TYPE_IPV4.]))
93 dnl Checks for typedefs, structures, and compiler characteristics.
94 AC_HEADER_STDBOOL
95 AC_C_CONST
96 AC_TYPE_PID_T
97 AC_TYPE_SIZE_T
98 AC_HEADER_TIME
99 AC_STRUCT_TM
101 dnl Checks for library functions.
102 AC_FUNC_ALLOCA
103 AC_FUNC_MEMCMP
104 AC_FUNC_VPRINTF
105 AC_FUNC_FORK
106 AC_FUNC_MALLOC
107 AC_FUNC_REALLOC
108 AC_FUNC_SELECT_ARGTYPES
109 AC_TYPE_SIGNAL
110 AC_FUNC_STAT
111 AC_FUNC_STRFTIME
112 AC_CHECK_FUNCS([bzero dup2 getcwd gethostbyname memset mkdir mkfifo regcomp \
113                 select socket strcasecmp strdup strerror strrchr strstr \
114                 vasprintf strsep strchr strncasecmp strpbrk putenv])
115 AC_FUNC_ALLOCA
116 AC_FUNC_FORK
117 AC_FUNC_MALLOC
118 AC_FUNC_REALLOC
120 AM_CONDITIONAL([NO_STRSEP], [test "x$ac_cv_func_strsep" = "xno"])
122 AC_TRY_LINK([#include <curses.h>], [WINDOW *w; wresize(w, 0, 0);],
123            AC_DEFINE([HAVE_WRESIZE], 1, \
124                      [Define if your curses installation contains wresize().]))
126 AC_DEFUN([AC_DEBUG],
128     if test "$1"; then
129         ac_cv_sys_debug=$1
130     fi
132     AC_CACHE_CHECK([if debugging is wanted], [ac_cv_sys_debug],
133         [ac_cv_sys_debug=no])
134     AM_CONDITIONAL([WITH_DEBUG], [test "$ac_cv_sys_debug" = "yes"])
137 AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [Enable debugging.]),
138     AC_DEBUG([$enableval]), AC_DEBUG)
140 AC_MSG_CHECKING([for Unix98 pty support])
141 if test -c "/dev/ptmx"; then
142     have_ptmx=yes
143 else
144     have_ptmx=no
147 ptmx_works=no
149 if test "x$have_ptmx" = "xyes"; then
150     AC_LANG([C])
151     AC_RUN_IFELSE([AC_LANG_SOURCE([[\
152                    #include <stdio.h>
153                    #include <sys/types.h>
154                    #include <sys/stat.h>
155                    #include <fcntl.h>
157                    int main()
158                    {
159                        int fd;
161                        if ((fd = open("/dev/ptmx", O_RDWR)) == -1)
162                            exit(1);
164                        if (ptsname(fd) == NULL)
165                            exit(1);
167                        exit(0);
168                    }
169                    ]])], [ptmx_works=yes], [ptmx_works=no])
171     if test "x$ptmx_works" = "xyes"; then
172         AC_MSG_RESULT([yes])
173         AC_DEFINE([UNIX98], 1, [Define if your system has Unix98 pty support.])
174     else
175         AC_MSG_RESULT([no])
176     fi
179 if test "x$have_ptmx" = "xno" -o "x$ptmx_works" = "xno"; then
180 # From the GNU Screen package.
181     AC_MSG_CHECKING([pty ranges])
182     if test -d /dev/ptym; then
183     pdir='/dev/ptym'
184     else
185     pdir='/dev'
186     fi
188     ptys=`echo $pdir/pty??`
190     if test "$ptys" != "$pdir/pty??" ; then
191     p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
192     p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g'  | sort -u | tr -d '\012'`
194     AC_DEFINE_UNQUOTED([PTY_MAJOR], "$p0", [Pseudo tty ranges.])
195     AC_DEFINE_UNQUOTED([PTY_MINOR], "$p1", [Pseudo tty ranges.])
196     AC_MSG_RESULT($p0 $p1)
197     fi
200 AM_WITH_DMALLOC
202 AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile data/Makefile \
203                  libchess/Makefile])
204 AC_OUTPUT