1dnl $Id$
2dnl
3dnl some code to get roken working
4dnl
5dnl rk_ROKEN(subdir)
6dnl
7AC_DEFUN([rk_ROKEN], [
8
9AC_REQUIRE([rk_CONFIG_HEADER])
10
11DIR_roken=roken
12LIB_roken='$(top_builddir)/$1/libroken.la'
13INCLUDES_roken='-I$(top_builddir)/$1 -I$(top_srcdir)/$1'
14
15dnl Checks for programs
16AC_REQUIRE([AC_PROG_CC])
17AC_REQUIRE([AC_PROG_AWK])
18AC_REQUIRE([AC_OBJEXT])
19AC_REQUIRE([AC_EXEEXT])
20AC_REQUIRE([AC_PROG_LIBTOOL])
21
22AC_REQUIRE([AC_MIPS_ABI])
23
24AC_DEFINE(rk_PATH_DELIM, '/', [Path name delimiter])
25
26dnl C characteristics
27
28AC_REQUIRE([AC_C___ATTRIBUTE__])
29AC_REQUIRE([AC_C_INLINE])
30AC_REQUIRE([AC_C_CONST])
31rk_WFLAGS(-Wall -Wmissing-prototypes -Wpointer-arith -Wbad-function-cast -Wmissing-declarations -Wnested-externs)
32
33AC_REQUIRE([rk_DB])
34
35dnl C types
36
37AC_REQUIRE([AC_TYPE_SIZE_T])
38AC_HAVE_TYPE([ssize_t],[#include <unistd.h>])
39AC_REQUIRE([AC_TYPE_PID_T])
40AC_REQUIRE([AC_TYPE_UID_T])
41AC_HAVE_TYPE([long long])
42
43AC_REQUIRE([rk_RETSIGTYPE])
44
45dnl Checks for header files.
46AC_REQUIRE([AC_HEADER_STDC])
47AC_REQUIRE([AC_HEADER_TIME])
48
49AC_CHECK_HEADERS([\
50	arpa/inet.h				\
51	config.h				\
52	crypt.h					\
53	dirent.h				\
54	errno.h					\
55	err.h					\
56	fcntl.h					\
57	fnmatch.h				\
58	grp.h					\
59	ifaddrs.h				\
60	netinet/in.h				\
61	netinet/in6.h				\
62	netinet/in_systm.h			\
63	netinet6/in6.h				\
64	paths.h					\
65	poll.h					\
66	pwd.h					\
67	rpcsvc/ypclnt.h				\
68	search.h				\
69	shadow.h				\
70	stdint.h				\
71	sys/bswap.h				\
72	sys/ioctl.h				\
73	sys/mman.h				\
74	sys/param.h				\
75	sys/resource.h				\
76	sys/sockio.h				\
77	sys/stat.h				\
78	sys/time.h				\
79	sys/tty.h				\
80	sys/types.h				\
81	sys/uio.h				\
82	sys/utsname.h				\
83	sys/wait.h				\
84	syslog.h				\
85	termios.h				\
86	winsock2.h				\
87	ws2tcpip.h				\
88	unistd.h				\
89	userconf.h				\
90	usersec.h				\
91	util.h					\
92])
93
94AC_HAVE_TYPE([uintptr_t],[#ifdef HAVE_STDINT_H
95#include <stdint.h>
96#endif])
97
98dnl Sunpro 5.2 has a vis.h which is something different.
99AC_CHECK_HEADERS(vis.h, , , [
100#include <vis.h>
101#ifndef VIS_SP
102#error invis
103#endif])
104	
105AC_CHECK_HEADERS(netdb.h, , , [AC_INCLUDES_DEFAULT
106#ifdef HAVE_SYS_TYPES_H
107#include <sys/types.h>
108#endif
109])
110
111AC_CHECK_HEADERS(sys/socket.h, , , [AC_INCLUDES_DEFAULT
112#ifdef HAVE_SYS_TYPES_H
113#include <sys/types.h>
114#endif
115])
116
117AC_CHECK_HEADERS(net/if.h, , , [AC_INCLUDES_DEFAULT
118#ifdef HAVE_SYS_TYPES_H
119#include <sys/types.h>
120#endif
121#if HAVE_SYS_SOCKET_H
122#include <sys/socket.h>
123#endif])
124
125AC_CHECK_HEADERS(netinet6/in6_var.h, , , [AC_INCLUDES_DEFAULT
126#ifdef HAVE_SYS_TYPES_H
127#include <sys/types.h>
128#endif
129#if HAVE_SYS_SOCKET_H
130#include <sys/socket.h>
131#endif
132#ifdef HAVE_NETINET6_IN6_H
133#include <netinet6/in6.h>
134#endif
135])
136
137AC_CHECK_HEADERS(sys/sysctl.h, , , [AC_INCLUDES_DEFAULT
138#ifdef HAVE_SYS_PARAM_H
139#include <sys/param.h>
140#endif
141])
142
143AC_CHECK_HEADERS(sys/proc.h, , , [AC_INCLUDES_DEFAULT
144#ifdef HAVE_SYS_PARAM_H
145#include <sys/param.h>
146#endif
147])
148
149AC_REQUIRE([CHECK_NETINET_IP_AND_TCP])
150
151AM_CONDITIONAL(have_err_h, test "$ac_cv_header_err_h" = yes)
152AM_CONDITIONAL(have_ifaddrs_h, test "$ac_cv_header_ifaddrs_h" = yes)
153AM_CONDITIONAL(have_search_h, test "$ac_cv_header_search_h" = yes)
154AM_CONDITIONAL(have_vis_h, test "$ac_cv_header_vis_h" = yes)
155
156dnl Check for functions and libraries
157
158AC_FIND_FUNC(socket, socket)
159AC_FIND_FUNC(gethostbyname, nsl)
160AC_FIND_FUNC(syslog, syslog)
161
162AC_KRB_IPV6
163
164AC_FIND_FUNC(gethostbyname2, inet6 ip6)
165
166rk_RESOLV
167
168AC_BROKEN_SNPRINTF
169AC_BROKEN_VSNPRINTF
170
171AC_BROKEN_GLOB
172if test "$ac_cv_func_glob_working" != yes; then
173	AC_LIBOBJ(glob)
174fi
175AM_CONDITIONAL(have_glob_h, test "$ac_cv_func_glob_working" = yes)
176
177
178AC_CHECK_FUNCS([				\
179	asnprintf				\
180	asprintf				\
181	atexit					\
182	cgetent					\
183	getconfattr				\
184	getprogname				\
185	getrlimit				\
186	getspnam				\
187	issetugid				\
188	on_exit					\
189	poll					\
190	random					\
191	setprogname				\
192	strsvis					\
193	strsvisx				\
194	strunvis				\
195	strvis					\
196	strvisx					\
197	svis					\
198	sysconf					\
199	sysctl					\
200	tdelete					\
201	tfind					\
202	twalk					\
203	uname					\
204	unvis					\
205	vasnprintf				\
206	vasprintf				\
207	vis					\
208])
209
210if test "$ac_cv_func_cgetent" = no; then
211	AC_LIBOBJ(getcap)
212fi
213AM_CONDITIONAL(have_cgetent, test "$ac_cv_func_cgetent" = yes)
214
215AC_REQUIRE([AC_FUNC_GETLOGIN])
216
217AC_REQUIRE([AC_FUNC_MMAP])
218
219AC_FIND_FUNC_NO_LIBS(getsockopt,,
220[#ifdef HAVE_SYS_TYPES_H
221#include <sys/types.h>
222#endif
223#ifdef HAVE_SYS_SOCKET_H
224#include <sys/socket.h>
225#endif],
226[0,0,0,0,0])
227AC_FIND_FUNC_NO_LIBS(setsockopt,,
228[#ifdef HAVE_SYS_TYPES_H
229#include <sys/types.h>
230#endif
231#ifdef HAVE_SYS_SOCKET_H
232#include <sys/socket.h>
233#endif],
234[0,0,0,0,0])
235
236AC_FIND_IF_NOT_BROKEN(hstrerror, resolv,
237[#ifdef HAVE_NETDB_H
238#include <netdb.h>
239#endif],
24017)
241AC_NEED_PROTO([
242#ifdef HAVE_NETDB_H
243#include <netdb.h>
244#endif],
245hstrerror)
246
247AC_FOREACH([rk_func], [asprintf vasprintf asnprintf vasnprintf],
248	[AC_NEED_PROTO([
249	#include <stdio.h>
250	#include <string.h>],
251	rk_func)])
252
253AC_FIND_FUNC_NO_LIBS(bswap16,,
254[#ifdef HAVE_SYS_TYPES_H
255#include <sys/types.h>
256#endif
257#ifdef HAVE_SYS_BSWAP_H
258#include <sys/bswap.h>
259#endif],0)
260
261AC_FIND_FUNC_NO_LIBS(bswap32,,
262[#ifdef HAVE_SYS_TYPES_H
263#include <sys/types.h>
264#endif
265#ifdef HAVE_SYS_BSWAP_H
266#include <sys/bswap.h>
267#endif],0)
268
269AC_FIND_FUNC_NO_LIBS(pidfile,util,
270[#ifdef HAVE_UTIL_H
271#include <util.h>
272#endif],0)
273
274AC_FIND_IF_NOT_BROKEN(getaddrinfo,,
275[#ifdef HAVE_NETDB_H
276#include <netdb.h>
277#endif
278#ifdef HAVE_WS2TCPIP_H
279#include <ws2tcpip.h>
280#endif],[0,0,0,0])
281
282AC_FIND_IF_NOT_BROKEN(getnameinfo,,
283[#ifdef HAVE_NETDB_H
284#include <netdb.h>
285#endif
286#ifdef HAVE_WS2TCPIP_H
287#include <ws2tcpip.h>
288#endif],[0,0,0,0,0,0,0])
289
290AC_FIND_IF_NOT_BROKEN(freeaddrinfo,,
291[#ifdef HAVE_NETDB_H
292#include <netdb.h>
293#endif
294#ifdef HAVE_WS2TCPIP_H
295#include <ws2tcpip.h>
296#endif],[0])
297
298AC_FIND_IF_NOT_BROKEN(gai_strerror,,
299[#ifdef HAVE_NETDB_H
300#include <netdb.h>
301#endif
302#ifdef HAVE_WS2TCPIP_H
303#include <ws2tcpip.h>
304#endif],[0])
305
306dnl Darwin is weird, and in some senses not unix, launchd doesn't want
307dnl servers to use daemon(), so its deprecated.
308case "$host_os" in
309	darwin*)
310		;;
311	*)
312		AC_DEFINE([SUPPORT_DETACH], 1,
313		    [Define if os support want to detach is daemonens.])
314		AC_BROKEN([daemon]) ;;
315esac
316
317AC_BROKEN([					\
318	chown					\
319	copyhostent				\
320	closefrom				\
321	ecalloc					\
322	emalloc					\
323	erealloc				\
324	estrdup					\
325	err					\
326	errx					\
327	fchown					\
328	flock					\
329	fnmatch					\
330	freehostent				\
331	getcwd					\
332	getdtablesize				\
333	getegid					\
334	geteuid					\
335	getgid					\
336	gethostname				\
337	getifaddrs				\
338	getipnodebyaddr				\
339	getipnodebyname				\
340	getopt					\
341	gettimeofday				\
342	getuid					\
343	getusershell				\
344	initgroups				\
345	innetgr					\
346	iruserok				\
347	localtime_r				\
348	lstat					\
349	memmove					\
350	mkstemp					\
351	putenv					\
352	rcmd					\
353	readv					\
354	recvmsg					\
355	sendmsg					\
356	setegid					\
357	setenv					\
358	seteuid					\
359	strcasecmp				\
360	strdup					\
361	strerror				\
362	strftime				\
363	strlcat					\
364	strlcpy					\
365	strlwr					\
366	strncasecmp				\
367	strndup					\
368	strnlen					\
369	strptime				\
370	strsep					\
371	strsep_copy				\
372	strtok_r				\
373	strupr					\
374	swab					\
375	tsearch					\
376	timegm					\
377	unsetenv				\
378	verr					\
379	verrx					\
380	vsyslog					\
381	vwarn					\
382	vwarnx					\
383	warn					\
384	warnx					\
385	writev					\
386])
387
388AM_CONDITIONAL(have_fnmatch_h,
389	test "$ac_cv_header_fnmatch_h" = yes -a "$ac_cv_func_fnmatch" = yes)
390
391AC_FOREACH([rk_func], [strndup strsep strtok_r],
392	[AC_NEED_PROTO([#include <string.h>], rk_func)])
393
394AC_FOREACH([rk_func], [strsvis strsvisx strunvis strvis strvisx svis unvis vis],
395[AC_NEED_PROTO([#ifdef HAVE_VIS_H
396#include <vis.h>
397#endif], rk_func)])
398
399AC_MSG_CHECKING([checking for dirfd])
400AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
401#ifdef HAVE_DIRENT_H
402#include <dirent.h>
403#endif
404]],
405	[[DIR *d = 0; dirfd(d);]])],
406	[ac_rk_have_dirfd=yes], [ac_rk_have_dirfd=no])
407if test "$ac_rk_have_dirfd" = "yes" ; then
408	AC_DEFINE_UNQUOTED(HAVE_DIRFD, 1, [have a dirfd function/macro])
409fi
410AC_MSG_RESULT($ac_rk_have_dirfd)
411
412AC_HAVE_STRUCT_FIELD(DIR, dd_fd, [#include <sys/types.h>
413#ifdef HAVE_DIRENT_H
414#include <dirent.h>
415#endif])
416
417
418AC_BROKEN2(inet_aton,
419[#ifdef HAVE_SYS_TYPES_H
420#include <sys/types.h>
421#endif
422#ifdef HAVE_SYS_SOCKET_H
423#include <sys/socket.h>
424#endif
425#ifdef HAVE_NETINET_IN_H
426#include <netinet/in.h>
427#endif
428#ifdef HAVE_ARPA_INET_H
429#include <arpa/inet.h>
430#endif],
431[0,0])
432
433AC_BROKEN2(inet_ntop,
434[#ifdef HAVE_SYS_TYPES_H
435#include <sys/types.h>
436#endif
437#ifdef HAVE_SYS_SOCKET_H
438#include <sys/socket.h>
439#endif
440#ifdef HAVE_NETINET_IN_H
441#include <netinet/in.h>
442#endif
443#ifdef HAVE_ARPA_INET_H
444#include <arpa/inet.h>
445#endif],
446[0, 0, 0, 0])
447
448AC_BROKEN2(inet_pton,
449[#ifdef HAVE_SYS_TYPES_H
450#include <sys/types.h>
451#endif
452#ifdef HAVE_SYS_SOCKET_H
453#include <sys/socket.h>
454#endif
455#ifdef HAVE_NETINET_IN_H
456#include <netinet/in.h>
457#endif
458#ifdef HAVE_ARPA_INET_H
459#include <arpa/inet.h>
460#endif],
461[0,0,0])
462
463dnl
464dnl Check for sa_len in struct sockaddr, 
465dnl needs to come before the getnameinfo test
466dnl
467AC_HAVE_STRUCT_FIELD(struct sockaddr, sa_len, [#include <sys/types.h>
468#include <sys/socket.h>])
469
470if test "$ac_cv_func_getaddrinfo" = "yes"; then
471  rk_BROKEN_GETADDRINFO
472  if test "$ac_cv_func_getaddrinfo_numserv" = no; then
473	AC_LIBOBJ(getaddrinfo)
474	AC_LIBOBJ(freeaddrinfo)
475  fi
476fi
477
478AC_NEED_PROTO([#include <stdlib.h>], setenv)
479AC_NEED_PROTO([#include <stdlib.h>], unsetenv)
480AC_NEED_PROTO([#include <unistd.h>], gethostname)
481AC_NEED_PROTO([#include <unistd.h>], mkstemp)
482AC_NEED_PROTO([#include <unistd.h>], getusershell)
483AC_NEED_PROTO([#include <unistd.h>], daemon)
484AC_NEED_PROTO([
485#ifdef HAVE_SYS_TYPES_H
486#include <sys/types.h>
487#endif
488#ifdef HAVE_SYS_SOCKET_H
489#include <sys/socket.h>
490#endif
491#ifdef HAVE_NETINET_IN_H
492#include <netinet/in.h>
493#endif
494#ifdef HAVE_ARPA_INET_H
495#include <arpa/inet.h>
496#endif
497#ifdef HAVE_NETDB_H
498#include <netdb.h>
499#endif
500#ifdef HAVE_UNISTD_H
501#include <unistd.h>
502#endif],
503iruserok)
504
505AC_NEED_PROTO([
506#ifdef HAVE_SYS_TYPES_H
507#include <sys/types.h>
508#endif
509#ifdef HAVE_SYS_SOCKET_H
510#include <sys/socket.h>
511#endif
512#ifdef HAVE_NETINET_IN_H
513#include <netinet/in.h>
514#endif
515#ifdef HAVE_ARPA_INET_H
516#include <arpa/inet.h>
517#endif],
518inet_aton)
519
520AC_FIND_FUNC_NO_LIBS(crypt, crypt)dnl
521
522AC_REQUIRE([rk_BROKEN_REALLOC])dnl
523
524dnl AC_KRB_FUNC_GETCWD_BROKEN
525
526dnl strerror_r is great fun, on linux it exists before sus catched up,
527dnl so the return type is diffrent, lets check for both
528
529AC_PROTO_COMPAT([
530#include <stdio.h>
531#include <string.h>
532],
533strerror_r, int strerror_r(int, char *, size_t))
534
535AC_CHECK_FUNC([strerror_r],
536    [AC_DEFINE_UNQUOTED(HAVE_STRERROR_R, 1,
537        [Define if you have the function strerror_r.])])
538
539dnl
540dnl Checks for prototypes and declarations
541dnl
542
543AC_PROTO_COMPAT([
544#ifdef HAVE_SYS_TYPES_H
545#include <sys/types.h>
546#endif
547#ifdef HAVE_SYS_SOCKET_H
548#include <sys/socket.h>
549#endif
550#ifdef HAVE_NETINET_IN_H
551#include <netinet/in.h>
552#endif
553#ifdef HAVE_ARPA_INET_H
554#include <arpa/inet.h>
555#endif
556#ifdef HAVE_NETDB_H
557#include <netdb.h>
558#endif
559],
560gethostbyname, struct hostent *gethostbyname(const char *))
561
562AC_PROTO_COMPAT([
563#ifdef HAVE_SYS_TYPES_H
564#include <sys/types.h>
565#endif
566#ifdef HAVE_SYS_SOCKET_H
567#include <sys/socket.h>
568#endif
569#ifdef HAVE_NETINET_IN_H
570#include <netinet/in.h>
571#endif
572#ifdef HAVE_ARPA_INET_H
573#include <arpa/inet.h>
574#endif
575#ifdef HAVE_NETDB_H
576#include <netdb.h>
577#endif
578],
579gethostbyaddr, struct hostent *gethostbyaddr(const void *, size_t, int))
580
581AC_PROTO_COMPAT([
582#ifdef HAVE_SYS_TYPES_H
583#include <sys/types.h>
584#endif
585#ifdef HAVE_SYS_SOCKET_H
586#include <sys/socket.h>
587#endif
588#ifdef HAVE_NETINET_IN_H
589#include <netinet/in.h>
590#endif
591#ifdef HAVE_ARPA_INET_H
592#include <arpa/inet.h>
593#endif
594#ifdef HAVE_NETDB_H
595#include <netdb.h>
596#endif
597],
598getservbyname, struct servent *getservbyname(const char *, const char *))
599
600AC_PROTO_COMPAT([
601#ifdef HAVE_SYS_TYPES_H
602#include <sys/types.h>
603#endif
604#ifdef HAVE_SYS_SOCKET_H
605#include <sys/socket.h>
606#endif
607],
608getsockname, int getsockname(int, struct sockaddr*, socklen_t*))
609
610AC_PROTO_COMPAT([
611#ifdef HAVE_SYSLOG_H
612#include <syslog.h>
613#endif
614],
615openlog, void openlog(const char *, int, int))
616
617AC_NEED_PROTO([
618#ifdef HAVE_CRYPT_H
619#include <crypt.h>
620#endif
621#ifdef HAVE_UNISTD_H
622#include <unistd.h>
623#endif
624],
625crypt)
626
627dnl variables
628
629rk_CHECK_VAR(h_errno, 
630[#ifdef HAVE_SYS_TYPES_H
631#include <sys/types.h>
632#endif
633#ifdef HAVE_NETDB_H
634#include <netdb.h>
635#endif
636#ifdef HAVE_WS2TCPIP_H
637#include <ws2tcpip.h>
638#endif
639])
640
641rk_CHECK_VAR(h_errlist, 
642[#ifdef HAVE_NETDB_H
643#include <netdb.h>
644#endif
645#ifdef HAVE_WS2TCPIP_H
646#include <ws2tcpip.h>
647#endif])
648
649rk_CHECK_VAR(h_nerr, 
650[#ifdef HAVE_NETDB_H
651#include <netdb.h>
652#endif
653#ifdef HAVE_WS2TCPIP_H
654#include <ws2tcpip.h>
655#endif])
656
657rk_CHECK_VAR([__progname], 
658[#ifdef HAVE_ERR_H
659#include <err.h>
660#endif])
661
662AC_CHECK_DECLS([optarg, optind, opterr, optopt, environ],[],[],[
663#include <stdlib.h>
664#ifdef HAVE_UNISTD_H
665#include <unistd.h>
666#endif])
667
668dnl
669dnl Check for fields in struct tm
670dnl
671
672AC_HAVE_STRUCT_FIELD(struct tm, tm_gmtoff, [#include <time.h>])
673AC_HAVE_STRUCT_FIELD(struct tm, tm_zone, [#include <time.h>])
674
675dnl
676dnl or do we have a variable `timezone' ?
677dnl
678
679rk_CHECK_VAR(timezone,[#include <time.h>])
680rk_CHECK_VAR(altzone,[#include <time.h>])
681
682AC_HAVE_TYPE([sa_family_t],[
683#include <sys/types.h>
684#ifdef HAVE_SYS_SOCKET_H
685#include <sys/socket.h>
686#endif
687#ifdef HAVE_WS2TCPIP_H
688#include <ws2tcpip.h>
689#endif])
690AC_HAVE_TYPE([socklen_t],[
691#include <sys/types.h>
692#ifdef HAVE_SYS_SOCKET_H
693#include <sys/socket.h>
694#endif
695#ifdef HAVE_WS2TCPIP_H
696#include <ws2tcpip.h>
697#endif])
698AC_HAVE_TYPE([struct sockaddr], [
699#include <sys/types.h>
700#ifdef HAVE_SYS_SOCKET_H
701#include <sys/socket.h>
702#endif
703#ifdef HAVE_WS2TCPIP_H
704#include <ws2tcpip.h>
705#endif])
706AC_HAVE_TYPE([struct sockaddr_storage], [
707#include <sys/types.h>
708#ifdef HAVE_SYS_SOCKET_H
709#include <sys/socket.h>
710#endif
711#ifdef HAVE_WS2TCPIP_H
712#include <ws2tcpip.h>
713#endif])
714AC_HAVE_TYPE([struct addrinfo], [
715#include <sys/types.h>
716#ifdef HAVE_NETDB_H
717#include <netdb.h>
718#endif
719#ifdef HAVE_WS2TCPIP_H
720#include <ws2tcpip.h>
721#endif])
722AC_HAVE_TYPE([struct ifaddrs], [#include <ifaddrs.h>])
723AC_HAVE_TYPE([struct iovec],[
724#include <sys/types.h>
725#include <sys/uio.h>
726])
727AC_HAVE_TYPE([struct msghdr],[
728#include <sys/types.h>
729#ifdef HAVE_SYS_SOCKET_H
730#include <sys/socket.h>
731#endif
732#ifdef HAVE_WS2TCPIP_H
733#include <ws2tcpip.h>
734#endif])
735
736dnl
737dnl Check for struct winsize
738dnl
739
740AC_KRB_STRUCT_WINSIZE
741
742dnl
743dnl Check for struct spwd
744dnl
745
746AC_KRB_STRUCT_SPWD
747
748#
749# Check if we want samba's socket wrapper
750#
751
752samba_SOCKET_WRAPPER
753
754dnl won't work with automake
755dnl moved to AC_OUTPUT in configure.in
756dnl AC_CONFIG_FILES($1/Makefile)
757
758LIB_roken="${LIB_roken} \$(LIB_crypt) \$(LIB_dbopen)"
759
760AC_SUBST(DIR_roken)dnl
761AC_SUBST(LIB_roken)dnl
762AC_SUBST(INCLUDES_roken)dnl
763])
764