1AC_INIT(Spread_Util, 4.2.0)
2
3AC_CONFIG_AUX_DIR(buildtools)
4AC_CONFIG_HEADERS(src/config.h)
5
6AC_CANONICAL_HOST
7
8case "$host" in
9mips-sgi-irix* )
10	CC=cc
11	CFLAGS="-n32 -signed"
12	;;
13esac
14
15AC_PROG_CC
16AC_C_BIGENDIAN
17
18# Checks for programs.
19AC_PROG_CPP
20AC_PROG_RANLIB
21AC_PROG_INSTALL
22AC_PROG_LN_S
23AC_PATH_PROG(AR, ar)
24AC_PATH_PROGS(PERL, perl5 perl)
25AC_SUBST(PERL)
26
27if test -z "$AR" ; then
28	AC_MSG_ERROR([*** 'ar' missing, please install or fix your \$PATH ***])
29fi
30
31if test -z "$LD" ; then
32	LD=$CC
33fi
34AC_SUBST(LD)
35
36# C Compiler features
37AC_C_INLINE
38if test "$GCC" = "yes"; then
39	CFLAGS="$CFLAGS -Wall"
40fi
41
42# Allow user to specify flags
43AC_ARG_WITH(cflags,
44	[  --with-cflags           Specify additional flags to pass to compiler],
45	[
46		if test "x$withval" != "xno" ; then
47			CFLAGS="$CFLAGS $withval"
48		fi
49	]
50)
51AC_ARG_WITH(cppflags,
52	[  --with-cppflags         Specify additional flags to pass to preprocessor] ,
53	[
54		if test "x$withval" != "xno"; then
55			CPPFLAGS="$CPPFLAGS $withval"
56		fi
57	]
58)
59AC_ARG_WITH(ldflags,
60	[  --with-ldflags          Specify additional flags to pass to linker],
61	[
62		if test "x$withval" != "xno" ; then
63			LDFLAGS="$LDFLAGS $withval"
64		fi
65	]
66)
67AC_ARG_WITH(libs,
68	[  --with-libs             Specify additional libraries to link with],
69	[
70		if test "x$withval" != "xno" ; then
71			LIBS="$LIBS $withval"
72		fi
73	]
74)
75
76# Checks for libraries.
77 OLDLDFLAGS=$LDFLAGS
78 LDFLAGS=
79AC_PTHREAD_FREEBSD
80 THLDFLAGS=$LDFLAGS
81AC_SUBST(THLDFLAGS)
82 LDFLAGS=$OLDLDFLAGS
83
84 OLDLIBS=$LIBS
85 LIBS=
86AC_CHECK_LIB(pthread, pthread_create, , )
87AC_CHECK_LIB(thread, thr_create, , )
88AC_CHECK_LIB(posix4, sem_wait, , )
89 THLIBS=$LIBS
90AC_SUBST(THLIBS)
91dnl    Check for pthread functions
92AC_CHECK_FUNCS(pthread_atfork)
93 LIBS=$OLDLIBS
94
95AC_CHECK_LIB(nsl, gethostbyaddr, , )
96AC_CHECK_LIB(socket, socket, , )
97AC_SEARCH_LIBS(shm_open, rt posix4, [], [])
98AC_SEARCH_LIBS(nanosleep, rt posix4, [], [])
99AC_CHECK_LIB(m, sqrt)
100
101AC_FUNC_STRFTIME
102
103# Checks for header files.
104AC_CHECK_HEADERS(arpa/inet.h assert.h errno.h grp.h limits.h netdb.h netinet/in.h netinet/tcp.h process.h pthread.h pwd.h signal.h stdarg.h stdint.h stdio.h stdlib.h string.h sys/inttypes.h sys/ioctl.h sys/param.h sys/socket.h sys/stat.h sys/time.h sys/timeb.h sys/types.h sys/uio.h sys/un.h sys/filio.h time.h unistd.h windows.h winsock.h)
105
106dnl    Checks for library functions.
107AC_CHECK_FUNCS(bcopy inet_aton inet_ntoa inet_ntop memmove setsid snprintf strerror lrand48)
108dnl    Checks for time functions
109AC_CHECK_FUNCS(gettimeofday time)
110
111# Check for clock_gettime(CLOCK_MONOTONIC, ...)
112AC_CACHE_CHECK([for clock_gettime(CLOCK_MONOTONIC)], ac_cv_clock_gettime_monotonic, [
113	AC_TRY_COMPILE(
114		[ #include <time.h> ],
115		[ struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); ],
116		[ ac_cv_clock_gettime_monotonic="yes" ],
117		[ ac_cv_clock_gettime_monotonic="no" ]
118	)
119])
120if test "x$ac_cv_clock_gettime_monotonic" = "xyes" ; then
121	AC_DEFINE(HAVE_CLOCK_GETTIME_CLOCK_MONOTONIC, 1, [Have clock_gettime(CLOCK_MONOTONIC, ...)!])
122fi
123
124
125dnl    Check for dladdr function in different libraries
126AC_SEARCH_LIBS([dladdr], [dl dld], [], [
127  AC_MSG_ERROR([unable to find the dladdr() function])
128 ])
129
130dnl	Check for dladdr so code can be condititionally defined if not present
131AC_CACHE_CHECK([for dladdr], ac_cv_have_dladdr, [
132	AC_TRY_COMPILE(
133	[ #ifndef _GNU_SOURCE
134	  #define _GNU_SOURCE 1
135	  #endif
136	  #include <dlfcn.h>  ],
137	[ Dl_info* info = 0;
138	  dladdr(0, info); ],
139	[ ac_cv_have_dladdr="yes" ],
140	[ ac_cv_have_dladdr="no" ]
141	)
142])
143
144if test "x$ac_cv_have_dladdr" = "xyes" ; then
145	AC_DEFINE(HAVE_DLADDR, 1, dladdr function)
146fi
147
148# Check for broken snprintf
149if test "x$ac_cv_func_snprintf" = "xyes" ; then
150	AC_MSG_CHECKING([whether snprintf correctly terminates long strings])
151	AC_TRY_RUN(
152		[
153#include <stdio.h>
154int main(void){char b[5];snprintf(b,5,"123456789");return(b[4]!='\0');}
155		],
156		[AC_MSG_RESULT(yes)],
157		[
158			AC_MSG_RESULT(no)
159			AC_DEFINE(BROKEN_SNPRINTF, 1, Define if your snprintf is busted)
160			AC_MSG_WARN([****** Your snprintf() function is broken, complain to your vendor])
161		]
162	)
163fi
164
165# Cheap hack to ensure NEWS-OS libraries are arranged right.
166if test ! -z "$SONY" ; then
167  LIBS="$LIBS -liberty";
168fi
169
170# Checks for data types
171AC_CHECK_SIZEOF(char, 1)
172AC_CHECK_SIZEOF(short int, 2)
173AC_CHECK_SIZEOF(int, 4)
174AC_CHECK_SIZEOF(long int, 4)
175AC_CHECK_SIZEOF(long long int, 8)
176
177# More checks for data types
178AC_CACHE_CHECK([for windows arch], ac_cv_arch_win, [
179	AC_TRY_COMPILE(
180		[ #include <process.h> ],
181		[ CRITICAL_SECTION mutex; InitializeCriticalSection(mutex); ],
182		[ ac_cv_arch_win="yes" ],
183		[ ac_cv_arch_win="no" ]
184	)
185])
186if test "x$ac_cv_arch_win" = "xyes" ; then
187	AC_DEFINE(ARCH_PC_WIN95, 1, Building on a Windows OS Platform)
188fi
189
190AC_CACHE_CHECK([for struct timezone type], ac_cv_have_struct_timezone, [
191	AC_TRY_COMPILE(
192		[ #include <time.h>
193		  #include <sys/time.h>
194		  #include <sys/types.h> ],
195		[ struct timezone opt; ],
196		[ ac_cv_have_struct_timezone="yes" ],
197		[ ac_cv_have_struct_timezone="no" ]
198	)
199])
200if test "x$ac_cv_have_struct_timezone" = "xyes" ; then
201	AC_DEFINE(HAVE_STRUCT_TIMEZONE, 1, struct timezone)
202fi
203
204AC_CACHE_CHECK([for struct sockopt_len_t type], ac_cv_have_sockopt_len_t, [
205	AC_TRY_COMPILE(
206		[ #include <sys/types.h>
207		  #include <sys/socket.h> ],
208		[ static sockopt_len_t opt; opt=0; ],
209		[ ac_cv_have_sockopt_len_t="yes" ],
210		[ ac_cv_have_sockopt_len_t="no" ]
211	)
212])
213if test "x$ac_cv_have_sockopt_len_t" = "xyes" ; then
214	AC_DEFINE(HAVE_SOCKOPT_LEN_T, 1, struct sockopt_len_t)
215fi
216
217AC_CACHE_CHECK([for struct msghdr type], ac_cv_have_struct_msghdr, [
218	AC_TRY_COMPILE(
219		[ #include <sys/types.h>
220		  #include <sys/socket.h> ],
221		[ static  struct  msghdr msg; msg.msg_namelen = 1; ],
222		[ ac_cv_have_struct_msghdr="yes" ],
223		[ ac_cv_have_struct_msghdr="no" ]
224	)
225])
226if test "x$ac_cv_have_struct_msghdr" = "xno" ; then
227	AC_DEFINE(ARCH_SCATTER_NONE, 1, Platform does not support scatter/gather sendmsg)
228else
229  have_scatter="no"
230  AC_CACHE_CHECK([for struct msghdr accrights], ac_cv_have_struct_msghdr_acc, [
231        AC_TRY_COMPILE(
232                [ #include <sys/types.h>
233		  #include <sys/socket.h> ],
234                [ static  struct  msghdr msg; msg.msg_accrightslen = 0; ],
235                [ ac_cv_have_struct_msghdr_acc="yes" ],
236                [ ac_cv_have_struct_msghdr_acc="no" ]
237        )
238  ])
239  if test "x$ac_cv_have_struct_msghdr_acc" = "xyes" ; then
240	AC_DEFINE(ARCH_SCATTER_ACCRIGHTS, 1, Platform supports sendmsg scatter/gather using accrights structure)
241	have_scatter="yes"
242  fi
243  if test "x$have_scatter" = "xno" ; then
244	AC_CACHE_CHECK([for struct msghdr control], ac_cv_have_struct_msghdr_ctl, [
245	    AC_TRY_COMPILE(
246            [ #include <sys/types.h>
247	      #include <sys/socket.h> ],
248            [ static  struct  msghdr msg; msg.msg_controllen = 0; ],
249            [ ac_cv_have_struct_msghdr_ctl="yes" ],
250            [ ac_cv_have_struct_msghdr_ctl="no" ]
251            )
252     	])
253	if test "x$ac_cv_have_struct_msghdr_ctl" = "xyes" ; then
254	    AC_DEFINE(ARCH_SCATTER_CONTROL, 1, Platform supports sendmsg scatter/gather using control structure)
255            have_scatter="yes"
256	fi
257  fi
258  if test "x$have_scatter" = "xno" ; then
259        AC_MSG_ERROR([*** cannot determine which scatter type to use ***])
260  fi
261fi
262
263AC_CACHE_CHECK([for u_int type], ac_cv_have_u_int, [
264	AC_TRY_COMPILE(
265		[ #include <sys/types.h> ],
266		[ u_int a; a = 1;],
267		[ ac_cv_have_u_int="yes" ],
268		[ ac_cv_have_u_int="no" ]
269	)
270])
271if test "x$ac_cv_have_u_int" = "xyes" ; then
272	AC_DEFINE(HAVE_U_INT, 1, unsigned int type u_int)
273	have_u_int=1
274fi
275
276AC_CACHE_CHECK([for intXX_t types], ac_cv_have_intxx_t, [
277	AC_TRY_COMPILE(
278		[ #include <sys/types.h> ],
279		[ int8_t a; int16_t b; int32_t c; a = b = c = 1;],
280		[ ac_cv_have_intxx_t="yes" ],
281		[ ac_cv_have_intxx_t="no" ]
282	)
283])
284if test "x$ac_cv_have_intxx_t" = "xyes" ; then
285	AC_DEFINE(HAVE_INTXX_T, 1, various intxx_t types)
286	have_intxx_t=1
287fi
288
289AC_CACHE_CHECK([for int64_t type], ac_cv_have_int64_t, [
290	AC_TRY_COMPILE(
291		[ #include <sys/types.h> ],
292		[ int64_t a; a = 1;],
293		[ ac_cv_have_int64_t="yes" ],
294		[ ac_cv_have_int64_t="no" ]
295	)
296])
297if test "x$ac_cv_have_int64_t" = "xyes" ; then
298	AC_DEFINE(HAVE_INT64_T, 1, int64_t type)
299	have_int64_t=1
300fi
301
302AC_CACHE_CHECK([for u_intXX_t types], ac_cv_have_u_intxx_t, [
303	AC_TRY_COMPILE(
304		[ #include <sys/types.h> ],
305		[ u_int8_t a; u_int16_t b; u_int32_t c; a = b = c = 1;],
306		[ ac_cv_have_u_intxx_t="yes" ],
307		[ ac_cv_have_u_intxx_t="no" ]
308	)
309])
310if test "x$ac_cv_have_u_intxx_t" = "xyes" ; then
311	AC_DEFINE(HAVE_U_INTXX_T, 1, various unsigned intxx_t types)
312	have_u_intxx_t=1
313fi
314
315AC_CACHE_CHECK([for u_int64_t types], ac_cv_have_u_int64_t, [
316	AC_TRY_COMPILE(
317		[ #include <sys/types.h> ],
318		[ u_int64_t a; a = 1;],
319		[ ac_cv_have_u_int64_t="yes" ],
320		[ ac_cv_have_u_int64_t="no" ]
321	)
322])
323if test "x$ac_cv_have_u_int64_t" = "xyes" ; then
324	AC_DEFINE(HAVE_U_INT64_T, 1, unsigned int64_t)
325	have_u_int64_t=1
326fi
327
328if (test -z "$have_u_intxx_t" || test -z "$have_intxx_t" && \
329           test "x$ac_cv_header_sys_bitypes_h" = "xyes")
330then
331	AC_MSG_CHECKING([for intXX_t and u_intXX_t types in sys/bitypes.h])
332	AC_TRY_COMPILE(
333		[
334#include <sys/bitypes.h>
335		],
336		[
337			int8_t a; int16_t b; int32_t c;
338			u_int8_t e; u_int16_t f; u_int32_t g;
339			a = b = c = e = f = g = 1;
340		],
341		[
342			AC_DEFINE(HAVE_U_INTXX_T, 1)
343			AC_DEFINE(HAVE_INTXX_T, 1)
344			AC_MSG_RESULT(yes)
345		],
346		[AC_MSG_RESULT(no)]
347	)
348fi
349
350if test -z "$have_u_intxx_t" ; then
351	AC_CACHE_CHECK([for uintXX_t types], ac_cv_have_uintxx_t, [
352		AC_TRY_COMPILE(
353			[
354#include <sys/types.h>
355			],
356			[ uint8_t a; uint16_t b; uint32_t c; a = b = c = 1; ],
357			[ ac_cv_have_uintxx_t="yes" ],
358			[ ac_cv_have_uintxx_t="no" ]
359		)
360	])
361	if test "x$ac_cv_have_uintxx_t" = "xyes" ; then
362		AC_DEFINE(HAVE_UINTXX_T, 1, various unsigned intxx_t types)
363	fi
364fi
365
366AC_CACHE_CHECK([for socklen_t], ac_cv_have_socklen_t, [
367	AC_TRY_COMPILE(
368		[
369#include <sys/types.h>
370#include <sys/socket.h>
371		],
372		[socklen_t foo; foo = 1235;],
373		[ ac_cv_have_socklen_t="yes" ],
374		[ ac_cv_have_socklen_t="no" ]
375	)
376])
377if test "x$ac_cv_have_socklen_t" = "xyes" ; then
378	AC_DEFINE(HAVE_SOCKLEN_T, 1, socklen_t type)
379fi
380
381AC_CACHE_CHECK([for size_t], ac_cv_have_size_t, [
382	AC_TRY_COMPILE(
383		[
384#include <sys/types.h>
385		],
386		[ size_t foo; foo = 1235; ],
387		[ ac_cv_have_size_t="yes" ],
388		[ ac_cv_have_size_t="no" ]
389	)
390])
391if test "x$ac_cv_have_size_t" = "xyes" ; then
392	AC_DEFINE(HAVE_SIZE_T, 1, size_t type)
393fi
394
395AC_CACHE_CHECK([for ssize_t], ac_cv_have_ssize_t, [
396	AC_TRY_COMPILE(
397		[
398#include <sys/types.h>
399		],
400		[ ssize_t foo; foo = 1235; ],
401		[ ac_cv_have_ssize_t="yes" ],
402		[ ac_cv_have_ssize_t="no" ]
403	)
404])
405if test "x$ac_cv_have_ssize_t" = "xyes" ; then
406	AC_DEFINE(HAVE_SSIZE_T, 1, signed size_t type)
407fi
408
409AC_CACHE_CHECK([for clock_t], ac_cv_have_clock_t, [
410	AC_TRY_COMPILE(
411		[
412#include <time.h>
413		],
414		[ clock_t foo; foo = 1235; ],
415		[ ac_cv_have_clock_t="yes" ],
416		[ ac_cv_have_clock_t="no" ]
417	)
418])
419if test "x$ac_cv_have_clock_t" = "xyes" ; then
420	AC_DEFINE(HAVE_CLOCK_T, 1, clock_t type)
421fi
422
423AC_CACHE_CHECK([for sa_family_t], ac_cv_have_sa_family_t, [
424	AC_TRY_COMPILE(
425		[
426#include <sys/types.h>
427#include <sys/socket.h>
428		],
429		[ sa_family_t foo; foo = 1235; ],
430		[ ac_cv_have_sa_family_t="yes" ],
431		[ AC_TRY_COMPILE(
432		  [
433#include <sys/types.h>
434#include <sys/socket.h>
435#include <netinet/in.h>
436		],
437		[ sa_family_t foo; foo = 1235; ],
438		[ ac_cv_have_sa_family_t="yes" ],
439
440		[ ac_cv_have_sa_family_t="no" ]
441	)]
442	)
443])
444if test "x$ac_cv_have_sa_family_t" = "xyes" ; then
445	AC_DEFINE(HAVE_SA_FAMILY_T, 1, sa_family_t type)
446fi
447
448
449AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_have_struct_sockaddr_storage, [
450	AC_TRY_COMPILE(
451		[
452#include <sys/types.h>
453#include <sys/socket.h>
454		],
455		[ struct sockaddr_storage s; ],
456		[ ac_cv_have_struct_sockaddr_storage="yes" ],
457		[ ac_cv_have_struct_sockaddr_storage="no" ]
458	)
459])
460if test "x$ac_cv_have_struct_sockaddr_storage" = "xyes" ; then
461	AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, struct sockaddr_storage type)
462fi
463
464AC_CACHE_CHECK([for struct sockaddr_in6], ac_cv_have_struct_sockaddr_in6, [
465	AC_TRY_COMPILE(
466		[
467#include <sys/types.h>
468#include <netinet/in.h>
469		],
470		[ struct sockaddr_in6 s; s.sin6_family = 0; ],
471		[ ac_cv_have_struct_sockaddr_in6="yes" ],
472		[ ac_cv_have_struct_sockaddr_in6="no" ]
473	)
474])
475if test "x$ac_cv_have_struct_sockaddr_in6" = "xyes" ; then
476	AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, struct sockaddr_in6 type)
477fi
478
479AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
480	AC_TRY_COMPILE(
481		[
482#include <sys/types.h>
483#include <netinet/in.h>
484		],
485		[ struct in6_addr s; s.s6_addr[0] = 0; ],
486		[ ac_cv_have_struct_in6_addr="yes" ],
487		[ ac_cv_have_struct_in6_addr="no" ]
488	)
489])
490if test "x$ac_cv_have_struct_in6_addr" = "xyes" ; then
491	AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, struct in6_addr type)
492fi
493
494AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
495	AC_TRY_COMPILE(
496		[
497#include <sys/types.h>
498#include <sys/socket.h>
499#include <netdb.h>
500		],
501		[ struct addrinfo s; s.ai_flags = AI_PASSIVE; ],
502		[ ac_cv_have_struct_addrinfo="yes" ],
503		[ ac_cv_have_struct_addrinfo="no" ]
504	)
505])
506if test "x$ac_cv_have_struct_addrinfo" = "xyes" ; then
507	AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, struct sockaddr type)
508fi
509
510AC_CACHE_CHECK([for struct timeval], ac_cv_have_struct_timeval, [
511	AC_TRY_COMPILE(
512		[ #include <sys/time.h> ],
513		[ struct timeval tv; tv.tv_sec = 1;],
514		[ ac_cv_have_struct_timeval="yes" ],
515		[ ac_cv_have_struct_timeval="no" ]
516	)
517])
518if test "x$ac_cv_have_struct_timeval" = "xyes" ; then
519	AC_DEFINE(HAVE_STRUCT_TIMEVAL, 1, struct timeval)
520	have_struct_timeval=1
521fi
522
523AC_CACHE_CHECK([for sun_len field in struct sockaddr_un],
524		ac_cv_have_sun_len_in_struct_sockaddr_un, [
525	AC_TRY_COMPILE(
526		[
527#include <sys/types.h>
528#include <sys/socket.h>
529		],
530		[ struct sockaddr_un s; s.sun_len = 1; ],
531		[ ac_cv_have_sun_len_in_struct_sockaddr_un="yes" ],
532		[ ac_cv_have_sun_len_in_struct_sockaddr_un="no" ],
533	)
534])
535if test "x$ac_cv_have_sun_len_in_struct_sockaddr_un" = "xyes" ; then
536	AC_DEFINE(HAVE_SUN_LEN_IN_SOCKADDR_UN, 1, sockaddr_un type has sun_len field)
537fi
538
539AC_CACHE_CHECK([for sin_len field in sockaddr_in],
540		ac_cv_have_sin_len_in_struct_sockaddr_in, [
541	AC_TRY_COMPILE(
542  		[
543#include <sys/types.h>
544#include <sys/socket.h>
545#include <netinet/in.h>
546		],
547		[ struct sockaddr_in s; s.sin_len = sizeof(s); ],
548		[ ac_cv_have_sin_len_in_struct_sockaddr_in="yes" ],
549		[ ac_cv_have_sin_len_in_struct_sockaddr_in="no"],
550	)
551])
552if test x"$ac_cv_have_sin_len_in_struct_sockaddr_in" = "xyes"; then
553   	AC_DEFINE(HAVE_SIN_LEN_IN_SOCKADDR_IN, 1 ,[sockaddr_in type has sin_len field])
554fi
555
556AC_CACHE_CHECK([for ss_family field in struct sockaddr_storage],
557		ac_cv_have_ss_family_in_struct_ss, [
558	AC_TRY_COMPILE(
559		[
560#include <sys/types.h>
561#include <sys/socket.h>
562		],
563		[ struct sockaddr_storage s; s.ss_family = 1; ],
564		[ ac_cv_have_ss_family_in_struct_ss="yes" ],
565		[ ac_cv_have_ss_family_in_struct_ss="no" ],
566	)
567])
568if test "x$ac_cv_have_ss_family_in_struct_ss" = "xyes" ; then
569	AC_DEFINE(HAVE_SS_FAMILY_IN_SS, 1, struct sockaddr_storage has ss_family)
570fi
571
572AC_CACHE_CHECK([for __ss_family field in struct sockaddr_storage],
573		ac_cv_have___ss_family_in_struct_ss, [
574	AC_TRY_COMPILE(
575		[
576#include <sys/types.h>
577#include <sys/socket.h>
578		],
579		[ struct sockaddr_storage s; s.__ss_family = 1; ],
580		[ ac_cv_have___ss_family_in_struct_ss="yes" ],
581		[ ac_cv_have___ss_family_in_struct_ss="no" ]
582	)
583])
584if test "x$ac_cv_have___ss_family_in_struct_ss" = "xyes" ; then
585	AC_DEFINE(HAVE___SS_FAMILY_IN_SS, 1, struct sockaddr_storage has __ss_family field)
586fi
587
588AC_CACHE_CHECK([for pid_t], ac_cv_have_pid_t, [
589        AC_TRY_COMPILE(
590                [
591#include <sys/types.h>
592                ],
593                [ pid_t foo; foo = 1235; ],
594                [ ac_cv_have_pid_t="yes" ],
595                [ ac_cv_have_pid_t="no" ]
596        )
597])
598if test "x$ac_cv_have_pid_t" = "xyes" ; then
599        AC_DEFINE(HAVE_PID_T, 1, pid_t type)
600fi
601
602AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [
603	AC_TRY_LINK([],
604		[ extern char *__progname; printf("%s", __progname); ],
605		[ ac_cv_libc_defines___progname="yes" ],
606		[ ac_cv_libc_defines___progname="no" ]
607	)
608])
609if test "x$ac_cv_libc_defines___progname" = "xyes" ; then
610	AC_DEFINE(HAVE___PROGNAME, 1, Define if libc defines __progname)
611fi
612
613
614AC_CACHE_CHECK([if libc defines sys_errlist], ac_cv_libc_defines_sys_errlist, [
615	AC_TRY_LINK([],
616		[ extern const char *const sys_errlist[]; printf("%s", sys_errlist[0]);],
617		[ ac_cv_libc_defines_sys_errlist="yes" ],
618		[ ac_cv_libc_defines_sys_errlist="no" ]
619	)
620])
621if test "x$ac_cv_libc_defines_sys_errlist" = "xyes" ; then
622	AC_DEFINE(HAVE_SYS_ERRLIST, 1, sys_errlist structure)
623fi
624
625
626AC_CACHE_CHECK([if libc defines sys_nerr], ac_cv_libc_defines_sys_nerr, [
627	AC_TRY_LINK([],
628		[ extern int sys_nerr; printf("%i", sys_nerr);],
629		[ ac_cv_libc_defines_sys_nerr="yes" ],
630		[ ac_cv_libc_defines_sys_nerr="no" ]
631	)
632])
633if test "x$ac_cv_libc_defines_sys_nerr" = "xyes" ; then
634	AC_DEFINE(HAVE_SYS_NERR, 1, sys_nerr function)
635fi
636
637# Options from here on. Some of these are preset by platform above
638
639AC_ARG_WITH(catman,
640	[  --with-mantype=man|cat|doc  Set man page type],
641	[
642		case "$withval" in
643		man|cat|doc)
644			MANTYPE=$withval
645			;;
646		*)
647			AC_MSG_ERROR(invalid man type: $withval)
648			;;
649		esac
650	]
651)
652if test -z "$MANTYPE"; then
653	AC_PATH_PROGS(NROFF, nroff awf, /bin/false, /usr/bin:/usr/ucb)
654	if ${NROFF} -mdoc ${srcdir}/docs/libspread-util.3 >/dev/null 2>&1; then
655		MANTYPE=doc
656	elif ${NROFF} -man ${srcdir}/docs/libspread-util.3 >/dev/null 2>&1; then
657		MANTYPE=man
658	else
659		MANTYPE=cat
660	fi
661fi
662AC_SUBST(MANTYPE)
663if test "$MANTYPE" = "doc"; then
664	mansubdir=man;
665else
666	mansubdir=$MANTYPE;
667fi
668AC_SUBST(mansubdir)
669
670# autoconf does not have docdir option, so add one
671AC_ARG_WITH(docdir,
672	[  --with-docdir=DIR       Where to put the documentation],
673	[
674		if test "x$withval" = xyes || test "x$withval" = xno; then
675		   docdir='${datadir}/doc/libspread-util'
676		else
677		   docdir="$withval"
678		fi
679	],
680	[
681	  docdir='${datadir}/doc/libspread-util'
682	]
683)
684AC_SUBST(docdir)
685
686# feature enable to turn on threaded alarm processing
687AC_ARG_ENABLE([threaded-alarm],
688	[AS_HELP_STRING([--enable-threaded-alarm], [Turn on threaded Alarm call processing to move IO to separate thread]) ],
689)
690
691if test "x$enable_threaded_alarm" = "xyes" ; then
692	AC_DEFINE(USE_THREADED_ALARM, 1, [Enable Threaded Alarm code to move IO to separate thread])
693fi
694
695# control whether dladdr is used to lookup function names. Default is to use it.
696AC_ARG_ENABLE([function-name-lookup],
697	[AS_HELP_STRING([--disable-function-name-lookup], [Disable the dladdr based function name lookups]) ],
698)
699
700if test "x$enable_function_name_lookup" = "xno" ; then
701     AC_DEFINE(DISABLE_FUNCTION_NAME_LOOKUP, 1, [Disable lookups of function names using dladdr])
702fi
703
704
705AH_TOP(
706#ifndef _CONFIG_H
707#define _CONFIG_H
708)
709
710AH_BOTTOM(
711#include "defines.h"
712
713#endif /* _CONFIG_H */
714)
715
716AC_EXEEXT
717
718LIBSPSO=none
719case "$host" in
720*-*-darwin*)
721	SHCC=$CC
722	SHCFLAGS="$CFLAGS -fPIC -fno-common"
723	SHCPPFLAGS="$CPPFLAGS"
724	SHLD="$CC -dynamiclib"
725	SHLDFLAGS="$SHLDFLAGS $LDFLAGS"
726	SHLIBS=$LIBS
727	SHLDOPTION="-Wl,"
728	SHLDNAME="-headerpad_max_install_names -install_name "
729	SHLDCONVERTSTATIC=
730	SHLDCONVERTSTATICEND=
731	LIBSPSO="libspread-util.dylib"
732        ;;
733mips-sgi-irix*)
734	LIBSPSO=none
735	;;
736*-*-solaris*)
737	SHCC=$CC
738	SHCFLAGS="$CFLAGS -fPIC"
739	SHCPPFLAGS="$CPPFLAGS"
740	SHLD="$CC -shared"
741	SHLDFLAGS="$SHLDFLAGS $LDFLAGS"
742	SHLIBS=$LIBS
743	SHLDOPTION="-Wl,"
744	SHLDNAME="-h,"
745	SHLDCONVERTSTATIC="-Wl,-whole-archive"
746	SHLDCONVERTSTATICEND="-Wl,-no-whole-archive"
747	LIBSPSO="libspread-util.so"
748	;;
749*-*-*)
750	SHCC=$CC
751	SHCFLAGS="$CFLAGS -fPIC"
752	SHCPPFLAGS="$CPPFLAGS"
753	SHLD="$CC -shared"
754	SHLDFLAGS="$SHLDFLAGS $LDFLAGS"
755	SHLIBS=$LIBS
756	SHLDOPTION="-Wl,"
757	SHLDNAME="-soname,"
758	SHLDCONVERTSTATIC="-Wl,-whole-archive"
759	SHLDCONVERTSTATICEND="-Wl,-no-whole-archive"
760	LIBSPSO="libspread-util.so"
761	;;
762esac
763
764AC_SUBST(SHCC)
765AC_SUBST(SHCFLAGS)
766AC_SUBST(SHCPPFLAGS)
767AC_SUBST(SHLD)
768AC_SUBST(SHLDFLAGS)
769AC_SUBST(SHLIBS)
770AC_SUBST(LIBSPSO)
771AC_SUBST(SHLDOPTION)
772AC_SUBST(SHLDNAME)
773AC_SUBST(SHLDCONVERTSTATIC)
774AC_SUBST(SHLDCONVERTSTATICEND)
775
776AC_OUTPUT(Makefile src/Makefile docs/Makefile include/Makefile)
777
778# Print summary of options
779
780echo ""
781echo "Spread Util has been configured with the following options:"
782echo ""
783echo "              Host: ${host}"
784echo "          Compiler: ${CC}"
785echo "    Compiler flags: ${CFLAGS}"
786echo "Preprocessor flags: ${CPPFLAGS}"
787echo "      Linker flags: ${LDFLAGS}"
788echo "         Libraries: ${LIBS}"
789
790echo ""
791