1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.57)
5AC_INIT(libpqtypes, 1.5.1, libpqtypes@esilo.com)
6AC_CANONICAL_TARGET
7AC_PROG_MAKE_SET
8SET_MAKE="MAKE=gmake --no-print-directory"
9AC_CONFIG_AUX_DIR([.])
10AM_INIT_AUTOMAKE(libpqtypes,1.5.1)
11AC_SUBST([LIBPQTYPES_SO_VERSION], [1:5:1])
12AC_DISABLE_STATIC
13AC_PROG_LIBTOOL
14AC_PROG_INSTALL
15AC_CONFIG_SRCDIR([src/param.c])
16AM_CONFIG_HEADER([src/pqt_config.h:src/pqt_config.h.in])
17AC_PROG_CXX
18AC_PROG_CC
19
20CPPFLAGS="$CPPFLAGS -Isrc"
21	# always want reentrant funcs, not just thread-safe mode. -s
22	CFLAGS="$CFLAGS -O3 -Wall -Wpointer-arith -D_GNU_SOURCE -D_REENTRANT -fsigned-char -I/usr/local/include"
23
24	# gcc doesn't indicate an error for unknown options when they are
25	# not warning/feature options, -Wxxx or -fxxx.  We have to test manually.
26	cprog="int main(void){return 0;}"
27	gcctest="$CC -x c -c - -o /dev/null"
28
29	AC_MSG_CHECKING(CFLAGS for $CC -std=gnu99...)
30	result=`echo "$cprog" | $gcctest -std=gnu99 2>&1`
31	if test -z "$result" ; then
32		CFLAGS="$CFLAGS -std=gnu99"
33		AC_MSG_RESULT(-std=gnu99)
34	else
35		AC_MSG_RESULT([no, unknown])
36	fi
37
38	# turn on as many warnings as possible
39	AX_CFLAGS_GCC_OPTION([-Wclobbered])
40	AX_CFLAGS_GCC_OPTION([-Wempty-body])
41	AX_CFLAGS_GCC_OPTION([-Wignored-qualifiers])
42	#AX_CFLAGS_GCC_OPTION([-Wmissing-field-initializers]) # annoying
43	AX_CFLAGS_GCC_OPTION([-Wmissing-parameter-type])
44	AX_CFLAGS_GCC_OPTION([-Wold-style-declaration])
45	AX_CFLAGS_GCC_OPTION([-Woverride-init])
46	AX_CFLAGS_GCC_OPTION([-Wsign-compare])
47	AX_CFLAGS_GCC_OPTION([-Wtype-limits])
48	AX_CFLAGS_GCC_OPTION([-Wuninitialized])
49	AX_CFLAGS_GCC_OPTION([-fomit-frame-pointer])
50	AX_CFLAGS_GCC_OPTION([-fno-strict-aliasing])
51	AX_CFLAGS_GCC_OPTION([-funroll-all-loops])
52	AX_CFLAGS_GCC_OPTION([-funit-at-a-time])
53
54# Each case has an example of what target_os contains
55case ${target_os} in
56	# solaris
57	solaris*)
58		CFLAGS="$CFLAGS -D_STDC_C99"
59	;;
60
61	# SCO UnixWare
62	*UnixWare*|*unixware*)
63		CFLAGS="$CFLAGS -D__UnixWare__"
64	;;
65
66	# SCO OpenServer
67	sco*)
68		CFLAGS="$CFLAGS -D__OpenServer__"
69	;;
70esac
71
72AC_ARG_ENABLE(thread-safety, [  --enable-thread-safety  Enable threads],
73	[have_threads=yes], [have_threads=no])
74
75if test "$have_threads" = "yes" ; then
76	AC_SEARCH_LIBS(pthread_create, [pthread thread],,
77		[AC_MSG_ERROR([Missing libpthread.so or libthread.so, cannot use --enable-thread-safety])])
78	CFLAGS="$CFLAGS -DPQT_THREAD_SAFE -D_THREAD_SAFE"
79
80	# SCO OpenServer 5, possibly other platforms, requires using FSU pthreads.
81	# We detect this by looking at the prototype for pthread_getspecific.
82	# There are a few other prototypes that are different as well but detecting
83	# one is plenty.
84	AC_MSG_CHECKING(whether FSU pthreads is being used)
85	AC_TRY_COMPILE(
86	[#include <pthread.h>],
87	[pthread_getspecific((pthread_key_t)(0), (void *)(0))],
88	[AC_DEFINE(PTHREAD_FSU, 1,
89	  [Define to 1 if using FSU pthreads]) AC_MSG_RESULT(yes)],
90	[AC_MSG_RESULT(no)]
91	)
92fi
93
94# If strict memory alignment is required, this test will produce a
95# Bus error.  Most riscs CPUs (old and modern) are strict.
96save_CFLAGS=$CFLAGS
97CFLAGS=""
98AC_MSG_CHECKING(if strict memory alignment is required)
99AC_RUN_IFELSE([int main(void){char b[[8]];int*i=(int*)(b+1);*i=0;return 0;}],
100[AC_MSG_RESULT(no)], [AC_DEFINE(STRICT_MEMORY_ALIGNMENT, 1,
101  [Define to 1 if architecture requires strict memory alignment]) AC_MSG_RESULT(yes)]
102)
103CFLAGS=$save_CFLAGS
104
105AC_HEADER_STDC
106AC_CHECK_HEADERS([ \
107arpa/inet.h limits.h linux/limits.h netdb.h netinet/in.h stddef.h \
108sys/socket.h time.h math.h sys/time.h strings.h])
109
110AC_STRUCT_TIMEZONE
111AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,, \
112[#ifdef HAVE_TIME_H
113#include <time.h>
114#endif
115#ifdef HAVE_SYS_TIME_H
116#include <sys/time.h>
117#endif])
118
119AC_CHECK_TYPES(socklen_t,,,
120[#include <unistd.h>
121#ifdef HAVE_APRA_INET_H
122#include <arpa/inet.h>
123#endif
124#ifdef HAVE_SYS_SOCKET_H
125#include <sys/socket.h>
126#endif])
127
128AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len],,, \
129[#ifdef HAVE_SYS_SOCKET_H
130#include <sys/socket.h>
131#endif
132#ifdef HAVE_NETINET_IN_H
133#include <netinet/in.h>
134#endif])
135
136AC_C_CONST
137AC_FUNC_MEMCMP
138AC_FUNC_STRTOD
139AC_HEADER_TIME
140AC_TYPE_SIZE_T
141
142AC_SEARCH_LIBS(pow, m)
143AC_SEARCH_LIBS(getaddrinfo, [nsl socket], \
144	[AC_DEFINE([HAVE_GETADDRINFO], [], \
145	[Define if getaddrinfo exists])], [], [])
146
147AC_CHECK_FUNCS([vsnprintf floor ceil rint hstrerror \
148localtime_r strtol strtoll strtoul])
149
150AC_OUTPUT(Makefile)
151
152
153
154