1dnl Process this file with autoconf 2.69 or later to produce 2dnl a configure script. 3AC_PREREQ(2.69) 4AC_INIT([config/config.h.in]) 5AC_CONFIG_HEADERS([config/config.h]) 6AC_PREFIX_PROGRAM(nasm) 7AC_CONFIG_AUX_DIR(autoconf/helpers) 8 9dnl Mark where in config.h.in macros auto-generated by the configuration 10dnl start; this is used to generate config/unconfig.h. 11AH_BOTTOM([ 12/* Begin unconfig.h */]) 13 14dnl Save initial CFLAGS, to see if -g -O2 came from configure or not 15pa_init_cflags="$CFLAGS" 16 17dnl This prevents us from running Wine and thinking we are not 18dnl cross-compiling when in fact we are; running Wine here is at 19dnl the best very slow and doesn't buy us a single thing at all. 20WINELOADER=/dev/null 21export WINELOADER 22 23dnl Get the canonical target system name 24AC_CANONICAL_HOST 25 26dnl Enable any available C extensions 27AC_USE_SYSTEM_EXTENSIONS 28AC_SYS_LARGEFILE 29AC_PROG_CC 30AC_PROG_CC_STDC 31PA_ADD_CFLAGS([-std=c17], [], [], 32[PA_ADD_CFLAGS([-std=c11], [], [], 33 [PA_ADD_CFLAGS([-std=c99])])]) 34 35dnl If the user did not specify a CFLAGS default, change default 36dnl to -O0 for debugging 37PA_ARG_DISABLED([optimization], 38 [compile without optimization (-O0) to help debugging], 39 [pa_no_optimize=true]) 40 41dnl Other programs 42pa_no_optimize=false 43 44dnl Compile and link with dwarf debug 45PA_ARG_ENABLED([gdb], 46 [disable optimization and compile with extra debug information for GDB debugger], 47 [PA_ADD_CFLAGS([-ggdb3]) 48 pa_no_optimize=true]) 49 50AS_IF([$pa_no_optimize], 51 [PA_ADD_CFLAGS([-O0]) 52 PA_ADD_CFLAGS([-fno-omit-frame-pointer])]) 53 54dnl Profiling 55PA_ARG_ENABLED([profiling], 56 [compile with profiling (-pg option)], 57 [PA_ADD_CFLAGS([-pg])]) 58 59dnl Abort on panic 60PA_ARG_ENABLED([panic-abort], 61 [call abort() on panic to trap in the debugger], 62 [AC_DEFINE(ABORT_ON_PANIC)]) 63AH_TEMPLATE(ABORT_ON_PANIC, 64[Define to 1 to call abort() on panics (internal errors), for debugging.]) 65 66dnl Checks for typedefs, structures, and compiler characteristics. 67AC_TYPE_SIZE_T 68AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,) 69AH_TEMPLATE(WORDS_BIGENDIAN, 70[Define to 1 if your processor stores words with the most significant 71byte first (like Motorola and SPARC, unlike Intel and VAX).]) 72AH_TEMPLATE(WORDS_LITTLEENDIAN, 73[Define to 1 if your processor stores words with the least significant 74byte first (like Intel and VAX, unlike Motorola and SPARC).]) 75 76dnl LLVM doesn't error out on invalid -W options unless this option is 77dnl specified first. Enable this so this script can actually discover 78dnl which -W options are possible for this compiler. 79PA_ADD_CFLAGS([-Werror=unknown-warning-option]) 80 81dnl Force gcc and gcc-compatible compilers treat signed integers 82dnl as 2's complement 83PA_ADD_CFLAGS([-fwrapv]) 84 85dnl Force clang to behave in a predictable manner, in order to make bugs 86dnl possible to track down. gcc appears to have this behavior by default. 87PA_ADD_CFLAGS([-ftrivial-auto-var-init=zero]) 88 89dnl Some environments abuse __STRICT_ANSI__ to disable some 90dnl function declarations 91PA_ADD_CFLAGS([-U__STRICT_ANSI__]) 92 93dnl Don't put things in common if we can avoid it. We don't want to 94dnl assume all compilers support common, and this will help find those 95dnl problems. This also works around an OSX linker problem. 96PA_ADD_CFLAGS([-fno-common]) 97 98dnl Check for library extension 99PA_LIBEXT 100 101dnl Look for programs... 102AC_PROG_LN_S 103AC_PROG_MAKE_SET 104AC_PROG_INSTALL 105AC_PROG_MKDIR_P 106 107AC_CHECK_PROGS(NROFF, nroff, false) 108AC_CHECK_PROGS(ASCIIDOC, asciidoc, false) 109AC_CHECK_PROGS(XMLTO, xmlto, false) 110AC_CHECK_PROGS(XZ, xz, false) 111 112dnl Check for progs needed for manpage generation 113MANPAGES=manpages 114AS_IF([test x$ASCIIDOC = xfalse], 115 [AC_MSG_WARN([No asciidoc package found, cannot build man pages]) 116 MANPAGES=''] 117) 118AS_IF([test x"$XMLTO" = xfalse], 119 [AC_MSG_WARN([No xmlto package found, cannot build man pages]) 120 MANPAGES=''] 121) 122AC_SUBST([MANPAGES]) 123 124dnl Don't create .pdf.xz if there is no xz 125AS_IF([test x"$XZ" = xfalse], 126 [], 127 [XZFILES=xzfiles]) 128AC_SUBST([XZFILES]) 129 130dnl Can't create NSIS package if there is no makensis 131dnl ... but it only applies to a Windows target ... 132dnl Note: AC_CHECK_TOOLS is supposed to check for the "plain" 133dnl version of the program name, but it doesn't seem to. 134AC_ARG_WITH([nsis], 135[AS_HELP_STRING([[--with-nsis[=makensis]]], 136 [build an install .exe using NSIS on Windows hosts])], 137 [], [with_nsis=yes]) 138AS_IF([test x"$MAKENSIS" = x], [], 139 [AS_IF([test x"$with_nsis" = xno], [] 140 [with_nsis="$MAKENSIS"])]) 141 142MAKENSIS=false 143 144AS_CASE([$host], 145 [*-win* | *-mingw*], 146 [AS_IF([test x"$with_nsis" = xno], [], 147 [NSIS=nsis 148 AS_IF([test x"$with_nsis" = xyes], 149 [AC_CHECK_TOOL(MAKENSIS_TOOL, makensis, false) 150 MAKENSIS="$MAKENSIS_TOOL" 151 AS_IF([test x"$MAKENSIS" = xfalse], 152 [AC_CHECK_PROGS(MAKENSIS_PLAIN, makensis, false) 153 MAKENSIS="$MAKENSIS_PLAIN"]) 154 AS_IF([test x"$MAKENSIS" = xfalse], 155 [AC_MSG_WARN([no makensis found, cannot build installer]) 156 NSIS=''])], 157 [MAKENSIS="$with_nsis"])])]) 158AC_SUBST([MAKENSIS]) 159AC_SUBST([NSIS]) 160 161dnl Check for host compiler tools 162AC_CHECK_TOOL(AR, ar) 163AC_CHECK_TOOL(RANLIB, ranlib, :) 164AC_CHECK_TOOL(STRIP, strip) 165 166dnl 167dnl NOTE: the tests for header files and library functions use constructs 168dnl that create warnings on modern compilers, due to lack of prototypes, 169dnl etc. Therefore, do not add the -Werror options before this. 170dnl 171 172dnl Tests which may trigger warnings on some compilers 173AC_C_CONST 174AC_C_INLINE 175AC_C_RESTRICT 176 177dnl Checks for header files. 178AC_HEADER_STDC 179PA_ADD_HEADERS(string.h) 180PA_ADD_HEADERS(stdarg.h) 181AC_CHECK_HEADERS(inttypes.h) 182AC_CHECK_HEADERS(strings.h) 183AC_HEADER_STDBOOL 184AC_CHECK_HEADERS(stdnoreturn.h) 185AC_CHECK_HEADERS(io.h) 186AC_CHECK_HEADERS(fcntl.h) 187AC_CHECK_HEADERS(unistd.h) 188AC_CHECK_HEADERS(sys/mman.h) 189AC_CHECK_HEADERS(sys/types.h) 190AC_CHECK_HEADERS(sys/stat.h) 191AC_CHECK_HEADERS(sys/resource.h) 192 193dnl Checks for library functions. 194AC_CHECK_FUNCS(strcasecmp stricmp) 195AC_CHECK_FUNCS(strncasecmp strnicmp) 196AC_CHECK_FUNCS(strsep) 197AC_CHECK_FUNCS(strnlen) 198AC_CHECK_FUNCS(strrchrnul) 199AC_CHECK_FUNCS(iscntrl) 200AC_CHECK_FUNCS(isascii) 201AC_CHECK_FUNCS(mempcpy) 202 203AC_CHECK_FUNCS(getuid) 204AC_CHECK_FUNCS(getgid) 205AC_CHECK_FUNCS(getrlimit) 206 207AC_CHECK_FUNCS(realpath) 208AC_CHECK_FUNCS(canonicalize_file_name) 209AC_CHECK_FUNCS(_fullpath) 210AC_CHECK_FUNCS(pathconf) 211 212AC_FUNC_FSEEKO 213AC_CHECK_FUNCS([_fseeki64]) 214AC_CHECK_FUNCS([ftruncate _chsize _chsize_s]) 215AC_CHECK_FUNCS([fileno _fileno]) 216 217AC_FUNC_MMAP 218AC_CHECK_FUNCS(getpagesize) 219AC_CHECK_FUNCS(sysconf) 220 221AC_CHECK_FUNCS([access _access faccessat]) 222 223PA_HAVE_FUNC(__builtin_expect, (1,1)) 224 225dnl ilog2() building blocks 226PA_ADD_HEADERS(intrin.h) 227PA_HAVE_FUNC(__builtin_clz, (0U)) 228PA_HAVE_FUNC(__builtin_clzl, (0UL)) 229PA_HAVE_FUNC(__builtin_clzll, (0ULL)) 230PA_HAVE_FUNC(_BitScanReverse, (0)) 231PA_HAVE_FUNC(_BitScanReverse64, (0)) 232 233PA_FUNC_SNPRINTF 234PA_FUNC_VSNPRINTF 235AC_CHECK_FUNCS([strlcpy]) 236AC_CHECK_FUNCS([strrchrnul]) 237 238dnl These types are POSIX-specific, and Windows does it differently... 239AC_CHECK_TYPES([struct _stati64]) 240AC_CHECK_TYPES([struct stat]) 241AC_CHECK_FUNCS([stat _stati64]) 242AC_CHECK_FUNCS([fstat _fstati64]) 243AC_CHECK_FUNCS([S_ISREG]) 244 245dnl Check for functions that might not be declared in the headers for 246dnl various idiotic reasons (mostly because of library authors 247dnl abusing the meaning of __STRICT_ANSI__) 248AC_CHECK_DECLS(strcasecmp) 249AC_CHECK_DECLS(stricmp) 250AC_CHECK_DECLS(strncasecmp) 251AC_CHECK_DECLS(strnicmp) 252AC_CHECK_DECLS(strsep) 253AC_CHECK_DECLS(strlcpy) 254AC_CHECK_DECLS(strnlen) 255AC_CHECK_DECLS(strrchrnul) 256 257dnl Check for missing types 258AC_TYPE_UINTPTR_T 259 260dnl Documentation: should we generate an uncompressed PDF? It is 261dnl about twice as big, but it can be externally compressed (e.g. with xz) 262dnl and becomes significantly smaller than the original. 263PA_ARG_DISABLED([pdf-compression], 264 [generate an uncompressed documentation PDF], 265 [PDFOPT='-nocompress']) 266AC_SUBST([PDFOPT]) 267 268dnl 269dnl Look for byte-swapping support... 270dnl 271PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h) 272PA_HAVE_FUNC(cpu_to_le16, (0)) 273PA_HAVE_FUNC(cpu_to_le32, (0)) 274PA_HAVE_FUNC(cpu_to_le64, (0)) 275PA_HAVE_FUNC(__cpu_to_le16, (0)) 276PA_HAVE_FUNC(__cpu_to_le32, (0)) 277PA_HAVE_FUNC(__cpu_to_le64, (0)) 278PA_HAVE_FUNC(htole16, (0)) 279PA_HAVE_FUNC(htole32, (0)) 280PA_HAVE_FUNC(htole64, (0)) 281PA_HAVE_FUNC(__bswap_16, (0)) 282PA_HAVE_FUNC(__bswap_32, (0)) 283PA_HAVE_FUNC(__bswap_64, (0)) 284PA_HAVE_FUNC(__builtin_bswap16, (0)) 285PA_HAVE_FUNC(__builtin_bswap32, (0)) 286PA_HAVE_FUNC(__builtin_bswap64, (0)) 287PA_HAVE_FUNC(_byteswap_ushort, (0)) 288PA_HAVE_FUNC(_byteswap_ulong, (0)) 289PA_HAVE_FUNC(_byteswap_uint64, (0)) 290 291dnl 292dnl Some rather useful gcc extensions... 293dnl 294PA_HAVE_FUNC(__builtin_constant_p, (0)) 295PA_HAVE_FUNC(__builtin_choose_expr, (0,1,2)) 296 297dnl 298dnl Check for supported gcc attributes; some compilers (e.g. Sun CC) 299dnl support these, but don't define __GNUC__ as they don't support 300dnl some other features of gcc. 301dnl 302PA_ADD_CFLAGS([-Werror=attributes]) 303PA_FUNC_ATTRIBUTE(noreturn) 304PA_FUNC_ATTRIBUTE(returns_nonnull,,,,,never_null) 305PA_FUNC_ATTRIBUTE(malloc) 306PA_FUNC_ATTRIBUTE(alloc_size,[1]) 307PA_FUNC_ATTRIBUTE(alloc_size,[1,2]) 308PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL],end_with_null) 309PA_FUNC_ATTRIBUTE(format, [printf,1,2], int, [const char *, ...], ["%d",1]) 310PA_FUNC_ATTRIBUTE(const) 311PA_FUNC_ATTRIBUTE(pure) 312PA_FUNC_ATTRIBUTE(cold,,,,,unlikely_func) 313PA_FUNC_ATTRIBUTE(unused) 314PA_FUNC_ATTRIBUTE_ERROR 315 316dnl 317dnl support function sections (if available) 318dnl 319PA_ARG_DISABLED([sections], 320 [do not try to compile with function/data section support], 321 [], 322 [PA_ADD_CFLAGS([-ffunction-sections]) 323 PA_ADD_CFLAGS([-fdata-sections]) 324 PA_ADD_LDFLAGS([-Wl,--gc-sections])] 325 ) 326 327dnl 328dnl support LTO 329dnl 330PA_ARG_ENABLED([lto], 331 [compile with gcc-style link time optimization], 332 [PA_ADD_CFLAGS([-flto]) 333 dnl Note: we use _PROG rather than _TOOL since we are prepending the full 334 dnl CC name which ought to already contain the host triplet if needed 335 ccbase=`echo "$CC" | awk '{ print $1; }'` 336 AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR]) 337 AR="$CC_AR" 338 AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB]) 339 RANLIB="$CC_RANLIB"], []) 340 341dnl 342dnl support sanitizers (if available) 343dnl 344PA_ARG_ENABLED([sanitizer], 345 [compile with sanitizers enabled], 346 [PA_ADD_CFLAGS([-fno-omit-frame-pointer]) 347 PA_ADD_CFLAGS([-fsanitize=address]) 348 PA_ADD_CFLAGS([-fsanitize=undefined])]) 349 350dnl 351dnl Don't make symbols visible, there is no point and it just 352dnl makes the code slower. This mainly affects ELF. 353dnl 354PA_ADD_CFLAGS([-fvisibility=hidden]) 355 356dnl 357dnl If we have gcc, add appropriate code cleanliness options. Do this 358dnl here at the end, because configure relies on being able to use 359dnl some very, very old C constructs. 360dnl 361PA_ADD_CFLAGS([-Wall]) 362PA_ARG_DISABLED([pedantic], 363[disable some extra paranoid compiler warnings], 364[], 365[PA_ADD_CFLAGS([-W]) 366 PA_ADD_CFLAGS([-pedantic]) 367 PA_ADD_CFLAGS([-Wc90-c99-compat]) 368 PA_ADD_CFLAGS([-Wc99-compat]) 369 PA_ADD_CFLAGS([-Wc99-extensions]) 370]) 371dnl Suppress format warning on Windows targets due to their <inttypes.h> 372PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format]) 373PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long]) 374dnl This is needed because we intentionally expect strncpy() to fill 375dnl in a zero-padded (not zero-terminated) buffer in several backends 376PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation]) 377dnl This is needed because we assume 2's-completement signed arithmetic; 378dnl on compilers with gcc-like command line syntax we pass the -fwrapv 379dnl option for exactly that reason. 380PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value]) 381 382dnl Want to turn this on at some point... 383dnl PA_ADD_CFLAGS([-Wwrite-strings]) 384PA_ARG_ENABLED([werror], 385 [compile with -Werror to error out on any warning], 386 [PA_ADD_CFLAGS([-Werror])], 387 [PA_ADD_CFLAGS([-Werror=implicit]) 388 PA_ADD_CFLAGS([-Werror=missing-braces]) 389 PA_ADD_CFLAGS([-Werror=return-type]) 390 PA_ADD_CFLAGS([-Werror=trigraphs]) 391 PA_ADD_CFLAGS([-Werror=pointer-arith]) 392 PA_ADD_CFLAGS([-Werror=strict-prototypes]) 393 PA_ADD_CFLAGS([-Werror=missing-prototypes]) 394 PA_ADD_CFLAGS([-Werror=missing-declarations]) 395 PA_ADD_CFLAGS([-Werror=comment]) 396 PA_ADD_CFLAGS([-Werror=vla])] 397) 398 399dnl Warnings that are probabilistic based on the compiler version, and 400dnl only should be used specifically when looking for opportunities to 401dnl address or optimize these cases. 402PA_ARG_ENABLED([suggestions], 403 [compile with compiler suggestion warnings enabled], 404 [PA_ADD_CFLAGS([-Wsuggest-attribute=pure]) 405 PA_ADD_CFLAGS([-Wsuggest-attribute=const]) 406 PA_ADD_CFLAGS([-Wsuggest-attribute=noreturn]) 407 PA_ADD_CFLAGS([-Wsuggest-attribute=format]) 408 PA_ADD_CFLAGS([-Wsuggest-attribute=cold]) 409 PA_ADD_CFLAGS([-Wsuggest-attribute=malloc])]) 410 411dnl 412dnl Test compiler features. On some compilers, this can be affected 413dnl by -Werror options, so run this *after* those options are added. 414dnl 415PA_CHECK_BAD_STDC_INLINE 416PA_C_TYPEOF 417 418dnl 419dnl support ccache 420dnl 421PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], []) 422 423AC_CONFIG_FILES([Makefile doc/Makefile]) 424AC_OUTPUT 425