configure.ac revision 1.45
1#	$NetBSD: configure.ac,v 1.45 2004/07/24 12:24:59 dbj Exp $
2#
3# Autoconf definition file for libnbcompat.
4#
5
6AC_INIT([libnbcompat], [noversion], [lib-bug-people@NetBSD.org])
7AC_CONFIG_HEADERS(nbtool_config.h)
8AC_CONFIG_FILES(defs.mk)
9
10AC_DEFUN([AC_NETBSD],
11[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
12      AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
13      AC_MSG_CHECKING([for NetBSD])
14      AC_EGREP_CPP(yes,
15      [#ifdef __NetBSD__
16	yes
17	#endif
18	],
19	[AC_MSG_RESULT([yes])
20	AC_DEFINE(_POSIX_SOURCE, 1) AC_DEFINE(_POSIX_C_SOURCE, 200112L) AC_DEFINE(_XOPEN_SOURCE, 600)],
21	[AC_MSG_RESULT([no])])
22])# AC_NETBSD
23
24AC_NETBSD
25AC_PATH_PROG(BSHELL, sh, )
26if test x"$BSHELL" = x; then
27	AC_MSG_ERROR([sh must be somewhere on \$PATH])
28fi
29AC_DEFINE_UNQUOTED(PATH_BSHELL, "$BSHELL")
30
31AC_C_BIGENDIAN
32AC_HEADER_STDC
33
34# Confirm existence of zlib.  (This is available as a default install
35# option on many OS's; this could be added as a reachover build in the
36# future.)
37AC_CHECK_HEADER(zlib.h,,
38	AC_MSG_ERROR([zlib must be installed in a compiler-visible path]))
39AC_CHECK_LIB(z, gzdopen,,
40	AC_MSG_ERROR([zlib must be installed in a compiler-visible path]))
41
42# Make sure certain required headers are available.
43# These are not necessarily required by the code, but they are not
44# currently conditionalized.
45AC_CHECK_HEADERS(sys/ioctl.h sys/mman.h sys/mtio.h sys/param.h \
46	sys/socket.h sys/stat.h sys/time.h sys/types.h sys/utsname.h \
47	sys/wait.h assert.h ctype.h errno.h fcntl.h grp.h limits.h locale.h \
48	netdb.h pwd.h signal.h stdarg.h stdio.h stdlib.h string.h \
49	termios.h unistd.h,,
50	AC_MSG_ERROR([standard system header file not found]))
51
52# Find headers that may not be available.
53AC_HEADER_DIRENT
54AC_CHECK_HEADERS(sys/sysmacros.h sys/syslimits.h \
55	getopt.h features.h malloc.h sys/poll.h stddef.h)
56AC_CHECK_HEADERS(machine/bswap.h sys/cdefs.h sys/endian.h sys/featuretest.h \
57	err.h inttypes.h libgen.h paths.h stdint.h util.h,,
58	[test -f include/$ac_header || touch include/$ac_header])
59AC_CHECK_HEADERS(rpc/types.h netconfig.h,,
60	[echo '#include "nbtool_config.h"' >include/$ac_header.new
61	echo '#include "'$srcdir/../../include/$ac_header'"' >>include/$ac_header.new
62	if cmp include/$ac_header.new include/$ac_header >/dev/null 2>&1; then
63		rm -f include/$ac_header.new
64	else
65		mv -f include/$ac_header.new include/$ac_header
66	fi])
67
68# Typedefs.
69AC_TYPE_SIZE_T
70AC_CHECK_TYPES([id_t, long long, u_long, u_char, u_short, u_int, u_quad_t])
71AC_CHECK_TYPE(socklen_t, [AC_DEFINE(HAVE_SOCKLEN_T)],,
72[#include <sys/types.h>
73#include <sys/socket.h>])
74
75dnl XXX - This is UGLY.  Need a better way to homogenize the bitsized types,
76dnl including use of compiler primitive types via AC_CHECK_SIZEOF.
77dnl
78define([NB_CHECK_INTTYPE], [
79	AC_CHECK_TYPE(uint][$1][_t,, [
80		AC_CHECK_TYPE(u_int][$1][_t,
81			AC_DEFINE(uint][$1][_t, u_int][$1][_t),
82			AC_MSG_ERROR([cannot find a suitable type for uint][$1][_t]))
83	])
84	AC_CHECK_TYPE(u_int][$1][_t,, [
85		AC_CHECK_TYPE(uint][$1][_t,
86			AC_DEFINE(u_int][$1][_t, uint][$1][_t),
87			AC_MSG_ERROR([cannot find a suitable type for u_int][$1][_t]))
88	])
89])
90
91NB_CHECK_INTTYPE(8)
92NB_CHECK_INTTYPE(16)
93NB_CHECK_INTTYPE(32)
94NB_CHECK_INTTYPE(64)
95
96# Struct members.
97AC_CHECK_MEMBERS([DIR.dd_fd, struct dirent.d_namlen],,,
98[#include <sys/types.h>
99#include <dirent.h>])
100AC_CHECK_MEMBERS([struct stat.st_flags, struct stat.st_gen,
101	struct stat.st_birthtime, struct stat.st_atim,
102	struct stat.st_mtimensec],,, [#include <sys/stat.h>])
103
104# Global variable decls.
105AC_CHECK_DECLS([optind, optreset],,, [
106#include <stdio.h>
107#include <stdlib.h>
108#include <unistd.h>
109])
110AC_CHECK_DECLS(sys_signame,,, [#include <signal.h>])
111
112# Library functions (where a .h check isn't enough).
113AC_FUNC_ALLOCA
114AC_CHECK_FUNCS(atoll asprintf asnprintf basename devname dirfd dirname \
115	fgetln flock fparseln futimes getopt getopt_long group_from_gid \
116	isblank issetugid lchflags lchmod lchown lutimes mkstemp mkdtemp \
117	poll pread putc_unlocked pwcache_userdb pwrite random setenv \
118	setgroupent setprogname setpassent snprintf strlcat strlcpy strsep \
119	strsuftoll strtoll \
120	user_from_uid vasprintf vasnprintf vsnprintf)
121
122AC_CHECK_FUNCS([htobe16, htobe32, htobe64, htole16, htole32, htole64, be16toh, be32toh, be64toh, le16toh, le32toh, le64toh],,, [
123#include <sys/types.h>
124])
125
126AC_CHECK_FUNCS([bswap16, bswap32, bswap64],,, [
127#include <machine/bswap.h>
128])
129
130AC_CHECK_DECLS([setgroupent, setpassent],,, [
131#include <sys/types.h>
132#include <grp.h>
133#include <pwd.h>
134])
135
136# regcomp() and regexec() are also names of functions in the old V8
137# regexp package.  To avoid them, we need to find out who has regfree().
138
139dnl # Cygwin: We *MUST* look at -lregex *before* the "no libs" condition.
140dnl # Thus AC_CHECK_LIB(regex...) comes first, and AC_SEARCHLIBS next.
141AC_CHECK_LIB(regex, regfree)
142AC_SEARCH_LIBS(regfree, rx posix)
143
144AC_OUTPUT
145