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