configure.ac revision 1.100
1#	$NetBSD: configure.ac,v 1.100 2023/05/23 19:53:24 lukem Exp $
2#
3# Autoconf definition file for libnbcompat.
4#
5# When you edit configure.ac:
6# 0. Create the tools versions of autoconf and autoheader:
7#        cd ${SRCDIR} && ./build.sh -V MKMAINTAINERTOOLS=yes tools
8#    (This might not work if you try it after editing configure.ac.)
9# 1. edit configure.ac
10# 2. Regenerate "configure" and "nbtool_config.h.in" from "configure.ac":
11#        cd ${SRCDIR}/tools/compat && ${TOOLDIR}/bin/nbmake-${MACHINE} regen
12#    (Please don't use a non-tools version of autoconf or autoheader.)
13# 3. Test that the tools still build:
14#        mv ${TOOLDIR} ${TOOLDIR}.bak
15#        cd ${SRCDIR} && ./build.sh -V MKMAINTAINERTOOLS=yes tools
16# 4. cvs commit files that you edited.
17# 5. Regen again, to pick up changed RCS IDs from the above commit:
18#        cd ${SRCDIR}/tools/compat && ${TOOLDIR}/bin/nbmake-${MACHINE} regen
19# 6. cvs commit files that were generated.
20#
21
22AC_INIT([libnbcompat], [noversion], [lib-bug-people@NetBSD.org])
23AC_CONFIG_HEADERS(nbtool_config.h)
24AC_CONFIG_FILES(defs.mk)
25
26# Autoheader header and footer
27AH_TOP([/*      $][NetBSD$    */
28 
29#ifndef __NETBSD_NBTOOL_CONFIG_H__
30#define __NETBSD_NBTOOL_CONFIG_H__])
31
32AH_BOTTOM([#include "compat_defs.h"
33#endif /* !__NETBSD_NBTOOL_CONFIG_H__ */])
34
35AC_DEFUN([AC_NETBSD],
36[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
37      AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
38      AC_MSG_CHECKING([for NetBSD])
39      AC_EGREP_CPP(yes,
40      [#ifdef __NetBSD__
41	yes
42	#endif
43	],
44	[AC_MSG_RESULT([yes])
45	 AC_DEFINE([_POSIX_SOURCE], 1, [Define for NetBSD headers.])
46	 AC_DEFINE([_POSIX_C_SOURCE], 200112L, [Define for NetBSD headers.])
47	 AC_DEFINE([_XOPEN_SOURCE], 600, [Define for NetBSD headers.])],
48	[AC_MSG_RESULT([no])])
49])# AC_NETBSD
50
51AC_NETBSD
52AC_PATH_PROG(BSHELL, sh, )
53if test x"$BSHELL" = x; then
54	AC_MSG_ERROR([sh must be somewhere on \$PATH])
55fi
56AC_DEFINE_UNQUOTED([PATH_BSHELL], "$BSHELL", [Path to sh(1).])
57
58AC_C_BIGENDIAN
59AC_HEADER_STDC
60
61# Confirm existence of zlib.  (This is available as a default install
62# option on many OS's; this could be added as a reachover build in the
63# future.)
64AC_CHECK_HEADER(zlib.h,,
65	AC_MSG_ERROR([zlib must be installed in a compiler-visible path]))
66AC_CHECK_LIB(z, gzdopen,,
67	AC_MSG_ERROR([zlib must be installed in a compiler-visible path]))
68
69# Make sure certain required headers are available.
70# These are not necessarily required by the code, but they are not
71# currently conditionalized.
72AC_CHECK_HEADERS(sys/ioctl.h sys/mman.h sys/param.h \
73	sys/socket.h sys/stat.h sys/time.h sys/types.h sys/utsname.h \
74	sys/wait.h assert.h ctype.h errno.h fcntl.h grp.h limits.h locale.h \
75	netdb.h pwd.h signal.h stdarg.h stdio.h stdlib.h string.h \
76	termios.h unistd.h,,
77	AC_MSG_ERROR([standard system header file not found]))
78
79# Find headers that may not be available.
80AC_HEADER_DIRENT
81AC_CHECK_HEADERS(sys/mtio.h sys/sysmacros.h sys/syslimits.h stdio_ext.h \
82	getopt.h features.h malloc.h sys/poll.h pthread.h stddef.h sys/uio.h)
83AC_CHECK_HEADERS(sys/bswap.h machine/bswap.h sys/cdefs.h machine/endian.h \
84	sys/endian.h sys/featuretest.h err.h inttypes.h libgen.h paths.h \
85	libgen.h stdint.h util.h resolv.h arpa/nameser.h,,
86	[test -f include/$ac_header || touch include/$ac_header])
87AC_CHECK_HEADERS(rpc/types.h,,
88	[echo '#include "nbtool_config.h"' >include/$ac_header.new
89	echo '#include "'$srcdir/../../common/include/$ac_header'"' \
90		>>include/$ac_header.new
91	if cmp include/$ac_header.new include/$ac_header >/dev/null 2>&1; then
92		rm -f include/$ac_header.new
93	else
94		mv -f include/$ac_header.new include/$ac_header
95	fi])
96AC_CHECK_HEADERS(netconfig.h,,
97	[echo '#include "nbtool_config.h"' >include/$ac_header.new
98	echo '#include "'$srcdir/../../include/$ac_header'"' \
99		>>include/$ac_header.new
100	if cmp include/$ac_header.new include/$ac_header >/dev/null 2>&1; then
101		rm -f include/$ac_header.new
102	else
103		mv -f include/$ac_header.new include/$ac_header
104	fi])
105
106# Typedefs.
107AC_TYPE_SIZE_T
108AC_CHECK_TYPES([id_t, long long, u_long, u_char, u_short, u_int, u_quad_t])
109AC_CHECK_TYPES([uchar_t, ushort_t, uint_t, ulong_t])
110AC_CHECK_TYPE(socklen_t, [AC_DEFINE([HAVE_SOCKLEN_T], 1,
111			  [Define if you have the socklen_t type.])],,
112[#include <sys/types.h>
113#ifdef HAVE_RPC_TYPES_H
114#include <rpc/types.h>
115#endif
116#include <sys/socket.h>])
117
118AC_MSG_CHECKING([for enum uio_rw])
119AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
120#include <sys/types.h>
121#ifdef HAVE_SYS_UIO_H
122#include <sys/uio.h>
123#endif]],
124[[enum uio_rw rw;]])],
125[AC_MSG_RESULT(yes)
126 AC_DEFINE([HAVE_ENUM_UIO_RW], 1,
127    [Define if you have the enum uio_rw type.])],
128[AC_MSG_RESULT(no)])
129
130AC_MSG_CHECKING([for enum uio_seg])
131AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
132#include <sys/types.h>
133#ifdef HAVE_SYS_UIO_H
134#include <sys/uio.h>
135#endif]],
136[[enum uio_seg seg;]])],
137[AC_MSG_RESULT(yes)
138 AC_DEFINE([HAVE_ENUM_UIO_SEG], 1,
139    [Define if you have the enum uio_seg type.])],
140[AC_MSG_RESULT(no)])
141
142dnl XXX - This is UGLY.  Need a better way to homogenize the bitsized types,
143dnl including use of compiler primitive types via AC_CHECK_SIZEOF.
144dnl
145define([NB_CHECK_INTTYPE], [
146	AC_CHECK_TYPE(uint][$1][_t,, [
147		AC_CHECK_TYPE(u_int][$1][_t,
148			AC_DEFINE(uint][$1][_t, u_int][$1][_t, \
149			          [Define if you have u_int][$1][_t, but not uint][$1][_t.]),
150			AC_MSG_ERROR([cannot find a suitable type for uint][$1][_t]))
151	])
152	AC_CHECK_TYPE(u_int][$1][_t,, [
153		AC_CHECK_TYPE(uint][$1][_t,
154			AC_DEFINE(u_int][$1][_t, uint][$1][_t, \
155				  [Define if you have uint][$1][_t, but not u_int][$1][_t.]),
156			AC_MSG_ERROR([cannot find a suitable type for u_int][$1][_t]))
157	])
158])
159
160NB_CHECK_INTTYPE(8)
161NB_CHECK_INTTYPE(16)
162NB_CHECK_INTTYPE(32)
163NB_CHECK_INTTYPE(64)
164
165# Struct members.
166AC_CHECK_MEMBERS([DIR.dd_fd, DIR.__dd_fd, struct dirent.d_namlen],,,
167[#include <sys/types.h>
168#include <dirent.h>])
169AC_CHECK_MEMBERS([struct stat.st_flags, struct stat.st_gen,
170	struct stat.st_birthtime, struct stat.st_birthtimensec,
171	struct stat.st_atim, struct stat.st_mtimensec],,, 
172	[#include <sys/stat.h>])
173AC_CHECK_MEMBERS(struct statvfs.f_iosize,,, [#include <sys/statvfs.h>])
174AC_CHECK_MEMBERS(struct tm.tm_gmtoff,,, [#include <time.h>])
175
176# Global variable decls.
177AC_CHECK_DECLS([asprintf, asnprintf, vasprintf, vasnprintf, vsnprintf, fgetln, fparseln,
178	fpurge, getdelim, getline, snprintf],,, [
179#include <stdio.h>
180])
181
182AC_CHECK_DECLS([atoll, heapsort, mkdtemp, mkstemp, reallocarr, reallocarray,
183	getsubopt, setenv, strtoi, strtoll, strtou, setprogname,
184	getprogname],,, [
185#include <stdlib.h>
186])
187
188AC_CHECK_DECLS([basename, dirname],,, [
189#include <libgen.h>
190])
191
192AC_CHECK_DECLS([raise_default_signal],,, [
193#include <util.h>
194])
195
196AC_CHECK_DECLS([issetugid, pread, pwrite],,, [
197#include <unistd.h>
198])
199
200AC_CHECK_DECLS([strmode],,, [
201#include <unistd.h>
202#include <string.h>
203])
204
205AC_CHECK_DECLS([isblank],,, [
206#include <ctype.h>
207])
208
209
210AC_CHECK_DECLS([optind, optreset],,, [
211#include <stdio.h>
212#include <stdlib.h>
213#include <unistd.h>
214#ifdef HAVE_GETOPT_H
215#include <getopt.h>
216#endif
217])
218AC_CHECK_DECLS(sys_signame,,, [#include <signal.h>])
219
220# Library functions (where a .h check isn't enough).
221AC_FUNC_ALLOCA
222AC_CHECK_FUNCS(atoll asprintf asnprintf basename devname dirfd dirname \
223	dispatch_semaphore_create \
224	dprintf esetfunc fgetln flock fpurge __fpurge futimes getline \
225	getopt getopt_long group_from_gid gid_from_group \
226	heapsort isblank issetugid lchflags lchmod lchown lutimes mkstemp \
227	mkdtemp poll pread putc_unlocked pwcache_userdb pwcache_groupdb \
228	pwrite raise_default_signal random reallocarr reallocarray setenv \
229	setgroupent setprogname setpassent \
230	snprintb_m snprintf strlcat strlcpy strmode \
231	strcasecmp strncasecmp strndup strnlen strsep strsuftoll strtoi \
232	strtoll strtou \
233	user_from_uid uid_from_user vasprintf vasnprintf vsnprintf)
234
235AC_CHECK_DECLS([user_from_uid, uid_from_user, pwcache_userdb],,,[
236#include <pwd.h>
237])
238AC_CHECK_DECLS([group_from_gid, gid_from_group, pwcache_groupdb],,,[
239#include <grp.h>
240])
241AC_CHECK_DECLS([strcasecmp, strncasecmp, strlcpy, strlcat, strndup,
242		strnlen, strsep],,,[
243#include <string.h>
244])
245AC_CHECK_DECLS([strsuftoll, mi_vector_hash],,,[#include <stdlib.h>])
246AC_CHECK_DECLS([lchflags, lchmod, lchown],,,[
247#include <sys/stat.h>
248#include <unistd.h>
249])
250
251AC_CHECK_DECLS([err, errc, errx, verrc, verrx, warn, warnc, warnx, vwarnc,
252		vwarnx],,,[
253#ifdef HAVE_ERR_H
254#include <err.h>
255#endif
256])
257
258AC_CHECK_DECLS([htobe16, htobe32, htobe64, htole16, htole32, htole64,
259		be16toh, be32toh, be64toh, le16toh, le32toh, le64toh],,,
260		[#include <sys/types.h>])
261
262AC_CHECK_DECLS([bswap16, bswap32, bswap64],,, [#include <machine/bswap.h>])
263
264AC_CHECK_DECLS([be16enc, le16enc, be16dec, le16dec, be32enc, le32enc,
265		be32dec, le32dec, be64enc, le64enc, be64dec, le64dec],,,
266		[#include <sys/endian.h>])
267
268AC_CHECK_DECLS([fstatvfs],,, [#include <sys/statvfs.h>])
269
270AC_CHECK_DECLS([setgroupent, setpassent],,, [
271#include <sys/types.h>
272#include <grp.h>
273#include <pwd.h>
274])
275
276# regcomp() and regexec() are also names of functions in the old V8
277# regexp package.  To avoid them, we need to find out who has regfree().
278
279dnl # Cygwin: We *MUST* look at -lregex *before* the "no libs" condition.
280dnl # Thus AC_CHECK_LIB(regex...) comes first, and AC_SEARCHLIBS next.
281AC_CHECK_LIB(regex, regfree)
282AC_SEARCH_LIBS(regfree, rx posix)
283
284AC_CHECK_LIB(rt, clock_gettime)
285
286AC_CHECK_FUNCS(fparseln, [
287    AC_MSG_CHECKING(if fparseln seems to work)
288    AC_RUN_IFELSE(
289        [AC_LANG_SOURCE([[
290#define _NETBSD_SOURCE
291#include <stdio.h>
292#include <stdlib.h>
293#define CONFTEST	"conftest.fparseln"
294#define COMMENT		'#'
295int
296main(void)
297{
298	static const char delim[3] = { '\0', '\0', COMMENT };
299	FILE *fp;
300	char *ptr;
301	fp = fopen(CONFTEST, "w+");
302	if (fp != NULL) {
303		unlink(CONFTEST);
304		ungetc(COMMENT, fp);
305		ptr = fparseln(fp, NULL, NULL, delim,
306		    FPARSELN_UNESCALL);
307		fclose(fp);
308		if (ptr == NULL)
309			exit(0);
310	}
311	exit(1);
312}
313        ]])],
314        [AC_MSG_RESULT(yes)],
315        [AC_MSG_RESULT(no)
316         AC_DEFINE(BROKEN_FPARSELN, 1,
317            [Define to 1 if your 'fparseln' function is broken.])],
318        [AC_MSG_WARN([cross compiling: not checking farseln])]
319    )
320])
321
322# Variables substituted via @VARNAME@ in defs.mk.in
323AC_SUBST(HAVE_PTHREAD_H, $ac_cv_header_pthread_h)
324
325AC_OUTPUT
326