1# $NetBSD: configure.ac,v 1.107 2023/07/20 16:21:23 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]) 25AC_CONFIG_MACRO_DIR([buildaux]) 26 27m4_pattern_forbid([^AX_]) 28m4_pattern_forbid([^NB_]) 29 30# Autoheader header and footer 31AH_TOP([/* $][NetBSD$ */ 32 33#ifndef __NETBSD_NBTOOL_CONFIG_H__ 34#define __NETBSD_NBTOOL_CONFIG_H__]) 35 36AH_BOTTOM([#include "compat_defs.h" 37#endif /* !__NETBSD_NBTOOL_CONFIG_H__ */]) 38 39AC_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 55NB_NETBSD() 56AC_PATH_PROG(BSHELL, sh, ) 57if test x"$BSHELL" = x; then 58 AC_MSG_ERROR([sh must be somewhere on \$PATH]) 59fi 60AC_DEFINE_UNQUOTED([PATH_BSHELL], "$BSHELL", [Path to sh(1).]) 61 62AC_C_BIGENDIAN() 63AC_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.) 68AC_CHECK_HEADER(zlib.h,, 69 AC_MSG_ERROR([zlib must be installed in a compiler-visible path])) 70AC_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. 76AC_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. 84AC_HEADER_DIRENT() 85AC_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) 87AC_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]) 91AC_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]) 100AC_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. 111AC_TYPE_SIZE_T() 112AC_CHECK_TYPES([id_t, long long, u_long, u_char, u_short, u_int, u_quad_t]) 113AC_CHECK_TYPES([uchar_t, ushort_t, uint_t, ulong_t]) 114AC_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 122AC_MSG_CHECKING([for enum uio_rw]) 123AC_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 134AC_MSG_CHECKING([for enum uio_seg]) 135AC_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 146dnl XXX - This is UGLY. Need a better way to homogenize the bitsized types, 147dnl including use of compiler primitive types via AC_CHECK_SIZEOF. 148dnl 149AC_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 164NB_CHECK_INTTYPE(8) 165NB_CHECK_INTTYPE(16) 166NB_CHECK_INTTYPE(32) 167NB_CHECK_INTTYPE(64) 168 169# Struct members. 170AC_CHECK_MEMBERS([DIR.dd_fd, DIR.__dd_fd, struct dirent.d_namlen],,, 171[#include <sys/types.h> 172#include <dirent.h>]) 173AC_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>]) 177AC_CHECK_MEMBERS(struct statvfs.f_iosize,,, [#include <sys/statvfs.h>]) 178AC_CHECK_MEMBERS(struct tm.tm_gmtoff,,, [#include <time.h>]) 179 180# Global variable decls. 181AC_CHECK_DECLS([asprintf, asnprintf, vasprintf, vasnprintf, vsnprintf, fgetln, fparseln, 182 fpurge, getdelim, getline, snprintf],,, [ 183#include <stdio.h> 184]) 185 186AC_CHECK_DECLS([atoll, heapsort, mkdtemp, mkstemp, reallocarr, reallocarray, 187 getsubopt, setenv, strtoi, strtoll, strtou, setprogname, 188 getprogname],,, [ 189#include <stdlib.h> 190]) 191 192AC_CHECK_DECLS([basename, dirname],,, [ 193#include <libgen.h> 194]) 195 196AC_CHECK_DECLS([raise_default_signal],,, [ 197#include <util.h> 198]) 199 200AC_CHECK_DECLS([issetugid, pread, pwrite],,, [ 201#include <unistd.h> 202]) 203 204AC_CHECK_DECLS([strmode],,, [ 205#include <unistd.h> 206#include <string.h> 207]) 208 209AC_CHECK_DECLS([isblank],,, [ 210#include <ctype.h> 211]) 212 213 214AC_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]) 222AC_CHECK_DECLS(sys_signame,,, [#include <signal.h>]) 223 224# Library functions (where a .h check isn't enough). 225AC_FUNC_ALLOCA() 226AC_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 posix_spawn 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 239AC_CHECK_DECLS([user_from_uid, uid_from_user, pwcache_userdb],,,[ 240#include <pwd.h> 241]) 242AC_CHECK_DECLS([group_from_gid, gid_from_group, pwcache_groupdb],,,[ 243#include <grp.h> 244]) 245AC_CHECK_DECLS([strcasecmp, strncasecmp, strlcpy, strlcat, strndup, 246 strnlen, strsep],,,[ 247#include <string.h> 248]) 249AC_CHECK_DECLS([strsuftoll, mi_vector_hash],,,[#include <stdlib.h>]) 250AC_CHECK_DECLS([lchflags, lchmod, lchown],,,[ 251#include <sys/stat.h> 252#include <unistd.h> 253]) 254 255AC_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 262AC_CHECK_DECLS([htobe16, htobe32, htobe64, htole16, htole32, htole64, 263 be16toh, be32toh, be64toh, le16toh, le32toh, le64toh],,, 264 [#include <sys/types.h>]) 265 266AC_CHECK_DECLS([bswap16, bswap32, bswap64],,, [#include <machine/bswap.h>]) 267 268AC_CHECK_DECLS([be16enc, le16enc, be16dec, le16dec, be32enc, le32enc, 269 be32dec, le32dec, be64enc, le64enc, be64dec, le64dec],,, 270 [#include <sys/endian.h>]) 271 272AC_CHECK_DECLS([fstatvfs],,, [#include <sys/statvfs.h>]) 273 274AC_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 283dnl # Cygwin: We *MUST* look at -lregex *before* the "no libs" condition. 284dnl # Thus AC_CHECK_LIB(regex...) comes first, and AC_SEARCHLIBS next. 285AC_CHECK_LIB(regex, regfree) 286AC_SEARCH_LIBS(regfree, rx posix) 287 288AC_CHECK_LIB(rt, clock_gettime) 289 290AC_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 '#' 299int 300main(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 326dnl 327dnl Set per-warning CC_* variables if supported by HOST_CC. 328dnl 329 330dnl Disable use of pre-compiled headers on Darwin. 331NB_CHECK_CC_FLAG([-no-cpp-precomp]) 332 333dnl Detect HOST_CC support for <bsd.own.mk> CC_* warnings 334NB_CHECK_CC_FLAG([-Wno-address-of-packed-member]) 335NB_CHECK_CC_FLAG([-Wno-cast-function-type]) 336NB_CHECK_CC_FLAG([-Wno-error=address-of-packed-member]) 337NB_CHECK_CC_FLAG([-Wno-format-overflow]) 338NB_CHECK_CC_FLAG([-Wno-format-truncation]) 339NB_CHECK_CC_FLAG([-Wno-implicit-fallthrough]) 340NB_CHECK_CC_FLAG([-Wno-maybe-uninitialized]) 341NB_CHECK_CC_FLAG([-Wno-return-local-addr]) 342NB_CHECK_CC_FLAG([-Wno-stringop-overflow]) 343NB_CHECK_CC_FLAG([-Wno-stringop-truncation]) 344 345AC_OUTPUT() 346 347dnl Display results 348dnl 349AC_MSG_NOTICE([========= configure results for compat ==========]) 350m4_foreach_w([NB_VAR], [CC LIBS ]NB_CHECK_CC_FLAG_VARS, [dnl 351AC_MSG_NOTICE(m4_format([%-40s],NB_VAR)[$NB_VAR]) 352]) 353AC_MSG_NOTICE([================================================]) 354