Home | History | Annotate | Line # | Download | only in compat
      1 #	$NetBSD: configure.ac,v 1.111 2025/09/18 20:24:48 christos 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 	AC_CHECK_TYPE(__uint][$1][_t,, [
    163 		AC_CHECK_TYPE(uint][$1][_t,
    164 			AC_DEFINE(__uint][$1][_t, uint][$1][_t, \
    165 			          [Define if you have uint][$1][_t, but not __uint][$1][_t.]),
    166 			AC_CHECK_TYPE(u_int][$1][_t,
    167 				AC_DEFINE(uint][$1][_t, u_int][$1][_t, \
    168 				          [Define if you have u_int][$1][_t, but not uint][$1][_t.]),
    169 				AC_MSG_ERROR([cannot find a suitable type for __uint][$1][_t])))
    170 	])
    171 	AC_CHECK_TYPE(__int][$1][_t,, [
    172 		AC_CHECK_TYPE(int][$1][_t,
    173 			AC_DEFINE(__int][$1][_t, int][$1][_t, \
    174 			          [Define if you have int][$1][_t, but not __int][$1][_t.]),
    175 			AC_MSG_ERROR([cannot find a suitable type for __int][$1][_t]))
    176 	])
    177 ])dnl NB_CHECK_INTTYPE
    178 
    179 NB_CHECK_INTTYPE(8)
    180 NB_CHECK_INTTYPE(16)
    181 NB_CHECK_INTTYPE(32)
    182 NB_CHECK_INTTYPE(64)
    183 
    184 # Struct members.
    185 AC_CHECK_MEMBERS([DIR.dd_fd, DIR.__dd_fd, struct dirent.d_namlen],,,
    186 [#include <sys/types.h>
    187 #include <dirent.h>])
    188 AC_CHECK_MEMBERS([struct stat.st_flags, struct stat.st_gen,
    189 	struct stat.st_birthtime, struct stat.st_birthtimensec,
    190 	struct stat.st_atim, struct stat.st_mtimensec],,, 
    191 	[#include <sys/stat.h>])
    192 AC_CHECK_MEMBERS(struct statvfs.f_iosize,,, [#include <sys/statvfs.h>])
    193 AC_CHECK_MEMBERS(struct tm.tm_gmtoff,,, [#include <time.h>])
    194 
    195 # Global variable decls.
    196 AC_CHECK_DECLS([asprintf, asnprintf, vasprintf, vasnprintf, vsnprintf, fgetln, fparseln,
    197 	fpurge, getdelim, getline, snprintf, vsyslog],,, [
    198 #include <stdio.h>
    199 ])
    200 
    201 AC_CHECK_DECLS([atoll, getsubopt, getprogname, heapsort,
    202 	mkdtemp, mkstemp, mkstemps,
    203 	reallocarr, reallocarray,
    204 	setenv, strtonum, strtoi, strtoll, strtou, setprogname, shquote],,, [
    205 #include <stdlib.h>
    206 ])
    207 
    208 AC_CHECK_DECLS([basename, dirname],,, [
    209 #include <libgen.h>
    210 ])
    211 
    212 AC_CHECK_DECLS([raise_default_signal],,, [
    213 #include <util.h>
    214 ])
    215 
    216 AC_CHECK_DECLS([issetugid, pread, pwrite],,, [
    217 #include <unistd.h>
    218 ])
    219 
    220 AC_CHECK_DECLS([strmode],,, [
    221 #include <unistd.h>
    222 #include <string.h>
    223 ])
    224 
    225 AC_CHECK_DECLS([isblank],,, [
    226 #include <ctype.h>
    227 ])
    228 
    229 
    230 AC_CHECK_DECLS([optind, optreset],,, [
    231 #include <stdio.h>
    232 #include <stdlib.h>
    233 #include <unistd.h>
    234 #ifdef HAVE_GETOPT_H
    235 #include <getopt.h>
    236 #endif
    237 ])
    238 AC_CHECK_DECLS(sys_signame,,, [#include <signal.h>])
    239 
    240 # Library functions (where a .h check isn't enough).
    241 AC_FUNC_ALLOCA()
    242 AC_CHECK_FUNCS(atoll asprintf asnprintf basename devname dirfd dirname \
    243 	dispatch_semaphore_create \
    244 	dprintf esetfunc fgetln flock fpurge __fpurge futimes getline \
    245 	getopt getopt_long group_from_gid gid_from_group \
    246 	heapsort isblank issetugid lchflags lchmod lchown lutimes mkstemp \
    247 	mkstemps mkdtemp poll posix_spawn pread putc_unlocked pwcache_userdb \
    248 	pwcache_groupdb \
    249 	pwrite raise_default_signal random reallocarr reallocarray setenv \
    250 	setgroupent setprogname setpassent \
    251 	snprintb_m snprintf strlcat strlcpy strmode \
    252 	strcasecmp strncasecmp strcasestr strndup strnlen strsep strsuftoll \
    253 	strtoi strtoll strtou strtonum \
    254 	user_from_uid uid_from_user vasprintf vasnprintf vsnprintf)
    255 
    256 AC_CHECK_DECLS([user_from_uid, uid_from_user, pwcache_userdb],,,[
    257 #include <pwd.h>
    258 ])
    259 AC_CHECK_DECLS([group_from_gid, gid_from_group, pwcache_groupdb],,,[
    260 #include <grp.h>
    261 ])
    262 AC_CHECK_DECLS([strcasecmp, strncasecmp, strcasestr, strlcpy, strlcat, strndup,
    263 		strnlen, strsep],,,[
    264 #include <string.h>
    265 ])
    266 AC_CHECK_DECLS([strsuftoll, mi_vector_hash],,,[#include <stdlib.h>])
    267 AC_CHECK_DECLS([lchflags, lchmod, lchown],,,[
    268 #include <sys/stat.h>
    269 #include <unistd.h>
    270 ])
    271 
    272 AC_CHECK_DECLS([err, errc, errx, verrc, verrx, warn, warnc, warnx, vwarnc,
    273 		vwarnx],,,[
    274 #ifdef HAVE_ERR_H
    275 #include <err.h>
    276 #endif
    277 ])
    278 
    279 AC_CHECK_DECLS([htobe16, htobe32, htobe64, htole16, htole32, htole64,
    280 		be16toh, be32toh, be64toh, le16toh, le32toh, le64toh],,,
    281 		[#include <sys/types.h>])
    282 
    283 AC_CHECK_DECLS([bswap16, bswap32, bswap64],,, [#include <machine/bswap.h>])
    284 
    285 AC_CHECK_DECLS([be16enc, le16enc, be16dec, le16dec, be32enc, le32enc,
    286 		be32dec, le32dec, be64enc, le64enc, be64dec, le64dec],,,
    287 		[#include <sys/endian.h>])
    288 
    289 AC_CHECK_DECLS([fstatvfs],,, [#include <sys/statvfs.h>])
    290 
    291 AC_CHECK_DECLS([setgroupent, setpassent],,, [
    292 #include <sys/types.h>
    293 #include <grp.h>
    294 #include <pwd.h>
    295 ])
    296 
    297 # regcomp() and regexec() are also names of functions in the old V8
    298 # regexp package.  To avoid them, we need to find out who has regfree().
    299 
    300 dnl # Cygwin: We *MUST* look at -lregex *before* the "no libs" condition.
    301 dnl # Thus AC_CHECK_LIB(regex...) comes first, and AC_SEARCHLIBS next.
    302 AC_CHECK_LIB(regex, regfree)
    303 AC_SEARCH_LIBS(regfree, rx posix)
    304 
    305 AC_CHECK_LIB(rt, clock_gettime)
    306 
    307 AC_CHECK_FUNCS(fparseln, [
    308     AC_MSG_CHECKING(if fparseln seems to work)
    309     AC_RUN_IFELSE(
    310         [AC_LANG_SOURCE([[
    311 #define _NETBSD_SOURCE
    312 #include <stdio.h>
    313 #include <stdlib.h>
    314 #define CONFTEST	"conftest.fparseln"
    315 #define COMMENT		'#'
    316 int
    317 main(void)
    318 {
    319 	static const char delim[3] = { '\0', '\0', COMMENT };
    320 	FILE *fp;
    321 	char *ptr;
    322 	fp = fopen(CONFTEST, "w+");
    323 	if (fp != NULL) {
    324 		unlink(CONFTEST);
    325 		ungetc(COMMENT, fp);
    326 		ptr = fparseln(fp, NULL, NULL, delim,
    327 		    FPARSELN_UNESCALL);
    328 		fclose(fp);
    329 		if (ptr == NULL)
    330 			exit(0);
    331 	}
    332 	exit(1);
    333 }
    334         ]])],
    335         [AC_MSG_RESULT(yes)],
    336         [AC_MSG_RESULT(no)
    337          AC_DEFINE(BROKEN_FPARSELN, 1,
    338             [Define to 1 if your 'fparseln' function is broken.])],
    339         [AC_MSG_WARN([cross compiling: not checking farseln])]
    340     )
    341 ])
    342 
    343 dnl
    344 dnl Set per-warning CC_* variables if supported by HOST_CC.
    345 dnl
    346 
    347 dnl Disable use of pre-compiled headers on Darwin.
    348 NB_CHECK_CC_FLAG([-no-cpp-precomp])
    349 
    350 dnl Detect HOST_CC support for <bsd.own.mk> CC_* warnings
    351 NB_CHECK_CC_FLAG([-Wno-address-of-packed-member])
    352 NB_CHECK_CC_FLAG([-Wno-cast-function-type])
    353 NB_CHECK_CC_FLAG([-Wno-error=address-of-packed-member])
    354 NB_CHECK_CC_FLAG([-Wno-format-overflow])
    355 NB_CHECK_CC_FLAG([-Wno-format-truncation])
    356 NB_CHECK_CC_FLAG([-Wno-implicit-fallthrough])
    357 NB_CHECK_CC_FLAG([-Wno-maybe-uninitialized])
    358 NB_CHECK_CC_FLAG([-Wno-return-local-addr])
    359 NB_CHECK_CC_FLAG([-Wno-stringop-overflow])
    360 NB_CHECK_CC_FLAG([-Wno-stringop-truncation])
    361 
    362 AC_OUTPUT()
    363 
    364 dnl Display results
    365 dnl
    366 AC_MSG_NOTICE([========= configure results for compat ==========])
    367 m4_foreach_w([NB_VAR], [CC LIBS ]NB_CHECK_CC_FLAG_VARS, [dnl
    368 AC_MSG_NOTICE(m4_format([%-40s],NB_VAR)[$NB_VAR])
    369 ])
    370 AC_MSG_NOTICE([================================================])
    371