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