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