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