configure.ac 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. dnl Process this file with autoconf 2.69 or later to produce
  2. dnl a configure script.
  3. AC_PREREQ(2.69)
  4. AC_INIT(config/config.h.in)
  5. AC_CONFIG_HEADERS(config/config.h)
  6. AC_PREFIX_PROGRAM(nasm)
  7. dnl Save initial CFLAGS, to see if -g -O2 came from configure or not
  8. pa_init_cflags="$CFLAGS"
  9. dnl This prevents us from running Wine and thinking we are not
  10. dnl cross-compiling when in fact we are; running Wine here is at
  11. dnl the best very slow and doesn't buy us a single thing at all.
  12. WINELOADER=/dev/null
  13. export WINELOADER
  14. dnl Checks for programs and enable necessary CC extensions
  15. AC_USE_SYSTEM_EXTENSIONS
  16. AC_SYS_LARGEFILE
  17. AC_PROG_CC
  18. AC_PROG_CC_STDC
  19. AC_PROG_LN_S
  20. AC_PROG_MAKE_SET
  21. AC_PROG_INSTALL
  22. dnl If the user did not specify a CFLAGS default, change default -O2
  23. dnl to either -O3 (normal) or -O0 (for debugging)
  24. PA_ARG_DISABLED([optimization],
  25. [compile without optimization (-O0) to help debugging],
  26. [pa_optimize=-O0], [pa_optimize=-O3])
  27. dnl Compile and link with dwarf debug
  28. PA_ARG_ENABLED([gdb],
  29. [disable optimization and compile with extra debug information for GDB debugger],
  30. [pa_optimize='-O0'
  31. PA_ADD_CFLAGS([-ggdb3])
  32. ])
  33. AS_IF([test x"$pa_init_cflags" = x],
  34. [CFLAGS=`echo "$CFLAGS" | sed -e "s/-O2/$pa_optimize/"`])
  35. AS_IF([test x"$pa_optimize" = "x-O0"],
  36. [PA_ADD_CFLAGS([-fno-omit-frame-pointer])])
  37. dnl Abort on panic
  38. PA_ARG_ENABLED([panic-abort],
  39. [call abort() on panic to trap in the debugger],
  40. [AC_DEFINE(ABORT_ON_PANIC)])
  41. AH_TEMPLATE(ABORT_ON_PANIC,
  42. [Define to 1 to call abort() on panics (internal errors), for debugging.])
  43. dnl Check for library extension
  44. PA_LIBEXT
  45. dnl Checks for typedefs, structures, and compiler characteristics.
  46. AC_C_CONST
  47. AC_C_INLINE
  48. AC_C_RESTRICT
  49. AC_TYPE_SIZE_T
  50. AC_C_BIGENDIAN(AC_DEFINE(WORDS_BIGENDIAN),AC_DEFINE(WORDS_LITTLEENDIAN),,)
  51. AH_TEMPLATE(WORDS_BIGENDIAN,
  52. [Define to 1 if your processor stores words with the most significant
  53. byte first (like Motorola and SPARC, unlike Intel and VAX).])
  54. AH_TEMPLATE(WORDS_LITTLEENDIAN,
  55. [Define to 1 if your processor stores words with the least significant
  56. byte first (like Intel and VAX, unlike Motorola and SPARC).])
  57. dnl Force gcc and gcc-compatible compilers treat signed integers
  58. dnl as 2's complement
  59. PA_ADD_CFLAGS([-fwrapv])
  60. dnl Some environments abuse __STRICT_ANSI__ to disable some
  61. dnl function declarations
  62. PA_ADD_CFLAGS([-U__STRICT_ANSI__])
  63. dnl Don't put things in common if we can avoid it. We don't want to
  64. dnl assume all compilers support common, and this will help find those
  65. dnl problems. This also works around an OSX linker problem.
  66. PA_ADD_CFLAGS([-fno-common])
  67. dnl Look for programs...
  68. AC_CHECK_PROGS(NROFF, nroff, false)
  69. AC_CHECK_PROGS(ASCIIDOC, asciidoc, false)
  70. AC_CHECK_PROGS(XMLTO, xmlto, false)
  71. dnl Check for progs needed for manpage generation
  72. AS_IF([test $ASCIIDOC = false],
  73. [AC_MSG_WARN([No asciidoc package found])]
  74. )
  75. AS_IF([test $XMLTO = false],
  76. [AC_MSG_WARN([No xmlto package found])]
  77. )
  78. dnl Check for host compiler tools
  79. AC_CHECK_TOOL(AR, ar)
  80. AC_CHECK_TOOL(RANLIB, ranlib, :)
  81. AC_CHECK_TOOL(STRIP, strip)
  82. dnl Checks for header files.
  83. AC_HEADER_STDC
  84. AC_CHECK_HEADERS(inttypes.h)
  85. AC_CHECK_HEADERS(strings.h)
  86. AC_HEADER_STDBOOL
  87. AC_CHECK_HEADERS(stdnoreturn.h)
  88. AC_CHECK_HEADERS(io.h)
  89. AC_CHECK_HEADERS(fcntl.h)
  90. AC_CHECK_HEADERS(unistd.h)
  91. AC_CHECK_HEADERS(sys/mman.h)
  92. AC_CHECK_HEADERS(sys/types.h)
  93. AC_CHECK_HEADERS(sys/stat.h)
  94. dnl Checks for library functions.
  95. AC_CHECK_FUNCS(strcasecmp stricmp)
  96. AC_CHECK_FUNCS(strncasecmp strnicmp)
  97. AC_CHECK_FUNCS(strsep)
  98. AC_CHECK_FUNCS(strnlen)
  99. AC_CHECK_FUNCS(strrchrnul)
  100. AC_CHECK_FUNCS(getuid)
  101. AC_CHECK_FUNCS(getgid)
  102. AC_CHECK_FUNCS(realpath)
  103. AC_CHECK_FUNCS(canonicalize_file_name)
  104. AC_CHECK_FUNCS(_fullpath)
  105. AC_CHECK_FUNCS(pathconf)
  106. AC_FUNC_FSEEKO
  107. AC_CHECK_FUNCS([_fseeki64])
  108. AC_CHECK_FUNCS([ftruncate _chsize _chsize_s])
  109. AC_CHECK_FUNCS([fileno _fileno])
  110. AC_CHECK_FUNCS(_filelengthi64)
  111. AC_FUNC_MMAP
  112. AC_CHECK_FUNCS(getpagesize)
  113. AC_CHECK_FUNCS(sysconf)
  114. AC_CHECK_FUNCS([access _access faccessat])
  115. PA_HAVE_FUNC(__builtin_expect, (1,1))
  116. dnl ilog2() building blocks
  117. PA_ADD_HEADERS(intrin.h)
  118. PA_HAVE_FUNC(__builtin_clz, (0U))
  119. PA_HAVE_FUNC(__builtin_clzl, (0UL))
  120. PA_HAVE_FUNC(__builtin_clzll, (0ULL))
  121. PA_HAVE_FUNC(_BitScanReverse, (0))
  122. PA_HAVE_FUNC(_BitScanReverse64, (0))
  123. dnl Functions for which we have replacements available in stdlib/
  124. AC_CHECK_FUNCS([vsnprintf _vsnprintf])
  125. AC_CHECK_FUNCS([snprintf _snprintf])
  126. AC_CHECK_FUNCS([strlcpy])
  127. AC_CHECK_FUNCS([strrchrnul])
  128. dnl These types are POSIX-specific, and Windows does it differently...
  129. AC_CHECK_TYPES([struct _stati64])
  130. AC_CHECK_TYPES([struct stat])
  131. AC_CHECK_FUNCS([stat _stati64])
  132. AC_CHECK_FUNCS([fstat _fstati64])
  133. dnl Check for functions that might not be declared in the headers for
  134. dnl various idiotic reasons (mostly because of library authors
  135. dnl abusing the meaning of __STRICT_ANSI__)
  136. AC_CHECK_DECLS(strcasecmp)
  137. AC_CHECK_DECLS(stricmp)
  138. AC_CHECK_DECLS(strncasecmp)
  139. AC_CHECK_DECLS(strnicmp)
  140. AC_CHECK_DECLS(strsep)
  141. AC_CHECK_DECLS(strlcpy)
  142. AC_CHECK_DECLS(strnlen)
  143. AC_CHECK_DECLS(strrchrnul)
  144. dnl Check for missing types
  145. AC_TYPE_UINTPTR_T
  146. dnl Documentation: should we generate an uncompressed PDF? It is
  147. dnl about twice as big, but it can be externally compressed (e.g. with xz)
  148. dnl and becomes significantly smaller than the original.
  149. PA_ARG_DISABLED([pdf-compression],
  150. [generate an uncompressed documentation PDF],
  151. [PDFOPT='-nocompress'])
  152. AC_SUBST([PDFOPT])
  153. dnl
  154. dnl Look for byte-swapping support...
  155. dnl
  156. PA_ADD_HEADERS(endian.h sys/endian.h machine/endian.h)
  157. PA_HAVE_FUNC(cpu_to_le16, (0))
  158. PA_HAVE_FUNC(cpu_to_le32, (0))
  159. PA_HAVE_FUNC(cpu_to_le64, (0))
  160. PA_HAVE_FUNC(__cpu_to_le16, (0))
  161. PA_HAVE_FUNC(__cpu_to_le32, (0))
  162. PA_HAVE_FUNC(__cpu_to_le64, (0))
  163. PA_HAVE_FUNC(htole16, (0))
  164. PA_HAVE_FUNC(htole32, (0))
  165. PA_HAVE_FUNC(htole64, (0))
  166. PA_HAVE_FUNC(__bswap_16, (0))
  167. PA_HAVE_FUNC(__bswap_32, (0))
  168. PA_HAVE_FUNC(__bswap_64, (0))
  169. PA_HAVE_FUNC(__builtin_bswap16, (0))
  170. PA_HAVE_FUNC(__builtin_bswap32, (0))
  171. PA_HAVE_FUNC(__builtin_bswap64, (0))
  172. PA_HAVE_FUNC(_byteswap_ushort, (0))
  173. PA_HAVE_FUNC(_byteswap_ulong, (0))
  174. PA_HAVE_FUNC(_byteswap_uint64, (0))
  175. dnl
  176. dnl Check for __builtin_constant_p()
  177. dnl
  178. PA_HAVE_FUNC(__builtin_constant_p, (0))
  179. dnl
  180. dnl Check for supported gcc attributes; some compilers (e.g. Sun CC)
  181. dnl support these, but don't define __GNUC__ as they don't support
  182. dnl some other features of gcc.
  183. dnl
  184. PA_ADD_CFLAGS([-Werror=attributes])
  185. PA_FUNC_ATTRIBUTE(noreturn)
  186. PA_FUNC_ATTRIBUTE(returns_nonnull)
  187. PA_FUNC_ATTRIBUTE(malloc)
  188. PA_FUNC_ATTRIBUTE(alloc_size, (1))
  189. PA_FUNC_ATTRIBUTE(sentinel,,, [const char *, ...], ["a","b",NULL])
  190. PA_FUNC_ATTRIBUTE(format, [(printf,1,2)], int, [const char *, ...], ["%d",1])
  191. PA_FUNC_ATTRIBUTE(const)
  192. PA_FUNC_ATTRIBUTE(pure)
  193. PA_FUNC_ATTRIBUTE(cold)
  194. PA_FUNC_ATTRIBUTE_ERROR
  195. dnl
  196. dnl support function sections (if available)
  197. dnl
  198. PA_ARG_ENABLED([sections],
  199. [compile with function/data section support],
  200. [PA_ADD_CLDFLAGS([-ffunction-sections])
  201. PA_ADD_CLDFLAGS([-fdata-sections])
  202. PA_ADD_CLDFLAGS([-Wl,--gc-sections])],
  203. [])
  204. dnl
  205. dnl support LTO
  206. dnl
  207. PA_ARG_ENABLED([lto],
  208. [compile with gcc-style link time optimization],
  209. [PA_ADD_CLDFLAGS([-flto])
  210. dnl Note: we use _PROG rather than _TOOL since we are prepending the full
  211. dnl CC name which ought to already contain the host triplet if needed
  212. ccbase=`echo "$CC" | awk '{ print $1; }'`
  213. AC_CHECK_PROGS(CC_AR, [${ccbase}-ar], [$ac_cv_prog_AR])
  214. AR="$CC_AR"
  215. AC_CHECK_PROGS(CC_RANLIB, [${ccbase}-ranlib], [$ac_cv_prog_RANLIB])
  216. RANLIB="$CC_RANLIB"], [])
  217. dnl
  218. dnl support sanitizers (if available)
  219. dnl
  220. PA_ARG_ENABLED([sanitizer],
  221. [compile with sanitizers enabled],
  222. [PA_ADD_CFLAGS([-fno-omit-frame-pointer])
  223. PA_ADD_CLDFLAGS([-fsanitize=address])
  224. PA_ADD_CLDFLAGS([-fsanitize=undefined])])
  225. dnl
  226. dnl Don't make symbols visible, there is no point and it just
  227. dnl makes the code slower.
  228. dnl
  229. PA_ADD_CLDFLAGS([-fvisibility=hidden])
  230. dnl If we have gcc, add appropriate code cleanliness options
  231. PA_ADD_CFLAGS([-W])
  232. PA_ADD_CFLAGS([-Wall])
  233. PA_ADD_CFLAGS([-pedantic])
  234. dnl LLVM doesn't error out on invalid -W options unless this option is
  235. dnl specified first. Enable this so this script can actually discover
  236. dnl which -W options are possible for this compiler.
  237. PA_ADD_CFLAGS([-Werror=unknown-warning-option])
  238. dnl Suppress format warning on Windows targets due to their <inttypes.h>
  239. PA_ADD_CFLAGS([-Wpedantic-ms-format],[-Wno-pedantic-ms-format])
  240. PA_ADD_CFLAGS([-Wc90-c99-compat])
  241. PA_ADD_CFLAGS([-Wlong-long],[-Wno-long-long])
  242. dnl This is needed because we intentionally expect strncpy() to fill
  243. dnl in a zero-padded (not zero-terminated) buffer in several backends
  244. PA_ADD_CFLAGS([-Wstringop-truncation],[-Wno-stringop-truncation])
  245. dnl This is needed because we assume 2's-completement signed arithmetic;
  246. dnl on compilers with gcc-like command line syntax we pass the -fwrapv
  247. dnl option for exactly that reason.
  248. PA_ADD_CFLAGS([-Wshift-negative-value],[-Wno-shift-negative-value])
  249. dnl PA_ADD_CFLAGS([-Wwrite-strings])
  250. PA_ARG_ENABLED([werror],
  251. [compile with -Werror to error out on any warning],
  252. [PA_ADD_CFLAGS([-Werror])],
  253. [PA_ADD_CFLAGS([-Werror=implicit])
  254. PA_ADD_CFLAGS([-Werror=missing-braces])
  255. PA_ADD_CFLAGS([-Werror=return-type])
  256. PA_ADD_CFLAGS([-Werror=trigraphs])
  257. PA_ADD_CFLAGS([-Werror=pointer-arith])
  258. PA_ADD_CFLAGS([-Werror=strict-prototypes])
  259. PA_ADD_CFLAGS([-Werror=missing-prototypes])
  260. PA_ADD_CFLAGS([-Werror=missing-declarations])
  261. PA_ADD_CFLAGS([-Werror=comment])
  262. PA_ADD_CFLAGS([-Werror=vla])]
  263. )
  264. dnl
  265. dnl On some versions of gcc, -Werror=missing-prototypes causes problems
  266. dnl with C99-style external inlines. Test this *after* adding the -Werror
  267. dnl options.
  268. dnl
  269. PA_CHECK_BAD_STDC_INLINE
  270. dnl
  271. dnl support ccache
  272. dnl
  273. PA_ARG_ENABLED([ccache], [compile with ccache], [CC="ccache $CC"], [])
  274. AC_OUTPUT_COMMANDS([mkdir -p config nasmlib nsis output stdlib x86 asm disasm rdoff macros common])
  275. AC_OUTPUT(Makefile doc/Makefile)