blob: 92b04c21fa703ce46bd32bd52edbe0a17c181f92 [file] [log] [blame]
Lev Walkinfa9bb6d2017-03-26 03:48:43 -07001AC_INIT([asn1c],[0.9.29],[vlm@lionet.info])
Lev Walkin1b03c792014-10-12 17:31:26 -07002
3AC_CONFIG_AUX_DIR(config)
Lev Walkine7c4b962010-11-09 03:10:36 -08004AC_CONFIG_HEADER([config.h])
Lev Walkinf7613202016-01-10 13:27:18 -08005AM_INIT_AUTOMAKE([foreign])
Lev Walkine7c4b962010-11-09 03:10:36 -08006AC_CONFIG_MACRO_DIR([m4])
Lev Walkinf15320b2004-06-03 03:38:44 +00007
Lev Walkinf15320b2004-06-03 03:38:44 +00008dnl Checks for programs.
9AC_PROG_CC
10AC_PROG_CPP
11AC_PROG_INSTALL
12AC_PROG_LN_S
13AC_PROG_MAKE_SET
14AC_PROG_YACC
15AM_PROG_LEX
theirixb577d4d2016-07-30 17:14:59 +030016dnl locate ar using standard macro (old automake 1.11 does not know about AM_PROG_AR)
17m4_ifdef([AM_PROG_AR],
18 [AM_PROG_AR],
19 [AC_PATH_PROG(AR, ar, ar, $PATH:/usr/ucb:/usr/ccs/bin)])
20
Lev Walkin5c600f42017-09-15 21:57:29 -070021AC_PROG_CXX
22CXXFLAGS="-std=c++11"
23
theirixb577d4d2016-07-30 17:14:59 +030024LT_INIT
Lev Walkinf15320b2004-06-03 03:38:44 +000025
Lev Walkin32789952014-10-12 18:51:52 -070026dnl If you need to see the details, just run make V=1.
27m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
Frank Morgnerfb63c012013-05-21 09:56:38 +020028
Lev Walkinbec70d82004-08-23 10:40:21 +000029case "$host_os" in
Lev Walkin19abe222006-03-18 06:39:12 +000030cygwin)
Lev Walkinbec70d82004-08-23 10:40:21 +000031 case "$target" in
32 *mingw*)
33 CC="$CC -mno-cygwin"
34 esac
35 ;;
Lev Walkin615a7fa2006-03-18 06:24:33 +000036esac
37
Lev Walkin58ecc7b2014-09-17 00:32:03 -070038AC_ARG_ENABLE([ASN_DEBUG],
Lev Walkin271131c2015-04-10 00:09:57 -070039 [AS_HELP_STRING([--enable-ASN_DEBUG],
40 [produce debug log during `make check` testing])],
41 [enable_asn_debug=$enableval], [enable_asn_debug=no])
42 AS_IF([test x$enable_asn_debug != xno], [
43 TESTSUITE_CFLAGS="-DEMIT_ASN_DEBUG"
Lev Walkin64dd70c2016-03-14 05:14:07 -070044 SKELETONS_CFLAGS="-DEMIT_ASN_DEBUG"
Lev Walkin271131c2015-04-10 00:09:57 -070045 ])
Lev Walkin58ecc7b2014-09-17 00:32:03 -070046
Lev Walkinf84cc012014-01-14 02:12:24 -080047AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"])
48AX_CHECK_COMPILE_FLAG([-Wcast-qual], [CFLAGS="$CFLAGS -Wcast-qual"])
49AX_CHECK_COMPILE_FLAG([-Wchar-subscripts],
Lev Walkin65907f02014-09-14 17:19:21 -070050 [CFLAGS="$CFLAGS -Wchar-subscripts"])
Lev Walkinf84cc012014-01-14 02:12:24 -080051AX_CHECK_COMPILE_FLAG([-Wmissing-prototypes],
Lev Walkin65907f02014-09-14 17:19:21 -070052 [CFLAGS="$CFLAGS -Wmissing-prototypes"])
Lev Walkinf84cc012014-01-14 02:12:24 -080053AX_CHECK_COMPILE_FLAG([-Wmissing-declarations],
Lev Walkin65907f02014-09-14 17:19:21 -070054 [CFLAGS="$CFLAGS -Wmissing-declarations"])
Lev Walkinf15320b2004-06-03 03:38:44 +000055
Lev Walkinf84cc012014-01-14 02:12:24 -080056dnl There are legitimate uses for these features, disable warnings/errors.
Lev Walkin84556d52017-09-26 23:13:10 -070057AX_CHECK_COMPILE_FLAG([-Wno-error=attributes],
58 [CFLAGS="$CFLAGS -Wno-error=attributes"])
Lev Walkinf84cc012014-01-14 02:12:24 -080059AX_CHECK_COMPILE_FLAG([-Wno-error=cast-align],
Lev Walkin65907f02014-09-14 17:19:21 -070060 [CFLAGS="$CFLAGS -Wno-error=cast-align"])
Lev Walkinf84cc012014-01-14 02:12:24 -080061AX_CHECK_COMPILE_FLAG([-Wno-error=visibility],
Lev Walkin65907f02014-09-14 17:19:21 -070062 [CFLAGS="$CFLAGS -Wno-error=visibility"])
Lev Walkinf84cc012014-01-14 02:12:24 -080063AX_CHECK_COMPILE_FLAG([-Wno-error=parentheses-equality],
Lev Walkin65907f02014-09-14 17:19:21 -070064 [CFLAGS="$CFLAGS -Wno-error=parentheses-equality"])
Lev Walkin3798f342016-03-14 04:07:45 -070065AX_CHECK_COMPILE_FLAG([-std=gnu99],
Lev Walkin62d95d22017-08-06 23:41:11 -070066 [CFLAGS="$CFLAGS -std=gnu99"
Lev Walkine0236da2017-09-17 22:03:57 -070067 TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -std=gnu99"])
Lev Walkin65907f02014-09-14 17:19:21 -070068AX_CHECK_COMPILE_FLAG([-Wno-error=unused-variable],
Lev Walkine0236da2017-09-17 22:03:57 -070069 [TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -Wno-error=unused-variable"])
70
71dnl Lower the optimization level in tests to aid debugging.
72dnl AX_CHECK_COMPILE_FLAG([-O1],
73dnl [TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -O1"])
74dnl AX_CHECK_COMPILE_FLAG([-fno-inline],
75dnl [TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -fno-inline"])
Lev Walkin65907f02014-09-14 17:19:21 -070076
Vasil Velichkove3187592016-07-18 22:46:36 +030077AX_CODE_COVERAGE
78AS_IF([test x$enable_code_coverage != xno], [
79 CFLAGS="$CFLAGS $CODE_COVERAGE_CFLAGS"
80 # The CODE_COVERAGE_CPPFLAGS contains -DNDEBUG flag
81 # which removes assert(...) macros from code coverage and improves the
82 # branches score. But when it is defined it results in few
83 # unsed-but-set-variable warnings that are treated as errors in the travis-ci
84 # build because these variables are only used inside assert macros.
85 # error: variable ‘ret’ set but not used [-Werror=unused-but-set-variable]
86 #CPPFLAGS="$CPPFLAGS $CODE_COVERAGE_CPPFLAGS"
87 CXXFLAGS="$CXXFLAGS $CODE_COVERAGE_CXXFLAGS"
Lev Walkinefded512017-03-26 16:12:11 -070088 AC_SEARCH_LIBS(gcov_open, gcov, [LDFLAGS="$LDFLAGS $CODE_COVERAGE_LDFLAGS"])
Vasil Velichkove3187592016-07-18 22:46:36 +030089])
90
Lev Walkin97363482016-01-24 19:23:02 -080091dnl Skeletons should be very compatible with most of the compilers, hence
92dnl very strict backward compatibility flags.
Lev Walkin64dd70c2016-03-14 05:14:07 -070093SKELETONS_CFLAGS="${ADD_CFLAGS} ${SKELETONS_CFLAGS}"
Lev Walkin97363482016-01-24 19:23:02 -080094AX_CHECK_COMPILE_FLAG([-std=c89],
Lev Walkin104af192016-01-24 22:13:27 -080095 [SKELETONS_CFLAGS="$SKELETONS_CFLAGS -std=c89"])
Lev Walkin97363482016-01-24 19:23:02 -080096AX_CHECK_COMPILE_FLAG([-Wpedantic],
Vasil Velichkov1144b352016-07-19 19:09:33 +030097 [SKELETONS_CFLAGS="$SKELETONS_CFLAGS -Wpedantic"],
98 [
99 dnl When -Wpedantic is not supported try the -pedantic instead. (gcc-4.7)
100 dnl See https://gcc.gnu.org/gcc-4.8/changes.html
101 AX_CHECK_COMPILE_FLAG([-pedantic],
102 [SKELETONS_CFLAGS="$SKELETONS_CFLAGS -pedantic"], [], [-Werror])
103 ],
104 [-Werror]) #clang 3.0 prints warning when the flag is not supported
Lev Walkin0f5dd342017-09-13 22:52:39 +0000105
106AC_ARG_ENABLE(Werror,
107 [AS_HELP_STRING([--enable-Werror],
108 [abort compilation after any C compiler warning])],
109 [enable_werror=$enableval], [enable_werror=no])
110 AS_IF([test x$enable_werror != xno], [
111 ADD_CFLAGS="${ADD_CFLAGS} -Werror -W -Wall -Wpointer-arith"
112 SKELETONS_CFLAGS="${SKELETONS_CFLAGS} -Werror -W -Wall -Wpointer-arith"
113 AX_CHECK_COMPILE_FLAG([-Wgnu],
114 [SKELETONS_CFLAGS="${SKELETONS_CFLAGS} -Wgnu"])
115 ])
116
117AC_ARG_ENABLE(test-Werror,
118 [AS_HELP_STRING([--enable-test-Werror],
119 [abort compiling tests after any C compiler warning])],
120 [enable_test_werror=$enableval], [enable_test_werror=no])
121 AS_IF([test x$enable_test_werror != xno], [
122 TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -Werror -W -Wpointer-arith"
123 ])
Vasil Velichkov12e91c92017-10-18 18:57:47 +0300124AX_CHECK_COMPILE_FLAG([-Wno-format],
125 [SKELETONS_CFLAGS="$SKELETONS_CFLAGS -Wno-format"])
Lev Walkin0f5dd342017-09-13 22:52:39 +0000126
Lev Walkincb4eddb2017-09-15 19:12:24 -0700127
Lev Walkin0a3bf612017-10-19 00:33:54 -0700128dnl If requested and -m32 is available to create 32-bit code,
Lev Walkin249fd262017-10-18 10:05:26 -0700129dnl treat it like a special case to be checked.
130AC_ARG_ENABLE([test-32bit],
Lev Walkin0a3bf612017-10-19 00:33:54 -0700131 [AS_HELP_STRING([--enable-test-32bit],
132 [Enable tests for 32-bit compatibility])],
133 [enable_test_32bit=$enableval], [enable_test_32bit=no])
134AS_IF([test "x$enable_test_32bit" != xno], [
Lev Walkin249fd262017-10-18 10:05:26 -0700135 AX_CHECK_COMPILE_FLAG([-m32], [CFLAGS_M32=-m32],
136 [
137 CFLAGS_M32=""
Lev Walkin0a3bf612017-10-19 00:33:54 -0700138 AC_MSG_FAILURE([--enable-test-32bit=$enable_test_32bit is requested but not supported by the _AC_LANG compiler])
Lev Walkin249fd262017-10-18 10:05:26 -0700139 ])
140])
141AC_SUBST(CFLAGS_M32)
142AM_CONDITIONAL([EXPLICIT_M32], [test "x${CFLAGS_M32}" != "x"])
143
Lev Walkincb4eddb2017-09-15 19:12:24 -0700144SANITIZER_CFLAGS=""
145
146dnl Enable Undefined Behavior Sanitizer, if supported.
147AC_ARG_ENABLE([test-ubsan],
148 [AS_HELP_STRING([--disable-test-ubsan],
149 [Disable Undefined Behavior Sanitizer for tests])],
150 [disable_test_ubsan=$enableval], [disable_test_ubsan=maybe])
151AS_IF([test "x$disable_test_ubsan" != xno], [
Lev Walkin1fef87a2017-10-19 00:25:09 -0700152 AX_CHECK_COMPILE_AND_LINK_FLAG([-fsanitize=undefined],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700153 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=undefined"],
154 [
155 AS_IF([test "x$disable_test_ubsan" != xmaybe], [
156 AC_MSG_FAILURE(
Lev Walkin5c600f42017-09-15 21:57:29 -0700157[--disable-test-ubsan=$disable_test_ubsan is not supported on a target system.
Lev Walkincb4eddb2017-09-15 19:12:24 -0700158https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#how-to-build])])
159 ])
Lev Walkine0236da2017-09-17 22:03:57 -0700160 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=undefined],
161 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=undefined"])
162
163 dnl Unsigned integer overflow is enabled separately.
164 AX_CHECK_COMPILE_FLAG([-fsanitize=unsigned-integer-overflow],
165 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=unsigned-integer-overflow"])
166 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=unsigned-integer-overflow],
167 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=unsigned-integer-overflow"])
168
169 dnl Nullability is enabled separately.
170 AX_CHECK_COMPILE_FLAG([-fsanitize=nullability],
171 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=nullability"])
172 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=nullability],
173 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=nullability"])
174
175 dnl Keep error messages nice. Also consider:
176 dnl export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
177 dnl export UBSAN_OPTIONS=print_stacktrace=1
178 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],
179 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-omit-frame-pointer"])
Lev Walkincb4eddb2017-09-15 19:12:24 -0700180])
181
Lev Walkina7d64002017-08-23 22:34:29 -0700182dnl Enable Address Sanitizer, if supported by gcc (4.8+) or clang.
183dnl http://clang.llvm.org/docs/AddressSanitizer.html
Lev Walkin33897e22017-09-26 21:17:39 -0700184ASAN_ENV_FLAGS=""
Lev Walkina7d64002017-08-23 22:34:29 -0700185AC_ARG_ENABLE([test-asan],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700186 [AS_HELP_STRING([--disable-test-asan],
187 [Disable Address Sanitizer for tests])],
188 [disable_test_asan=$enableval], [disable_test_asan=maybe])
189AS_IF([test "x$disable_test_asan" != xno], [
Lev Walkin1fef87a2017-10-19 00:25:09 -0700190 AX_CHECK_COMPILE_AND_LINK_FLAG([-fsanitize=address],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700191 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=address"],
192 [
193 AS_IF([test "x$disable_test_asan" != xmaybe], [
194 AC_MSG_FAILURE(
Lev Walkin5c600f42017-09-15 21:57:29 -0700195[--disable-test-asan=$disable_test_asan is not supported on a target system.
Lev Walkincb4eddb2017-09-15 19:12:24 -0700196Check out https://clang.llvm.org/docs/AddressSanitizer.html#how-to-build])])
197 ])
Lev Walkin33897e22017-09-26 21:17:39 -0700198 dnl Address sanitizer sometimes is equipped with the leak sanitizer,
199 dnl so we use -fsanitize=leak to permit ASAN_OPTIONS environment.
200 dnl If address sanitizer is not equipped with a leak sanitizer,
201 dnl invoking programs with ASAN_OPTIONS=detect_leaks=1 will break them.
202 AX_CHECK_COMPILE_FLAG([-fsanitize=leak], [
203 ASAN_ENV_FLAGS="${ASAN_ENV_FLAGS} ASAN_OPTIONS=detect_leaks=1"
204 ])
Lev Walkina7d64002017-08-23 22:34:29 -0700205 dnl Keep error messages nice. Also consider:
206 dnl export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
207 dnl export ASAN_OPTIONS=symbolize=1
208 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700209 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-omit-frame-pointer"])
210])
211
Lev Walkin5c600f42017-09-15 21:57:29 -0700212dnl Enable LibFuzzer, if supported.
213LIBFUZZER_CFLAGS=""
214AC_ARG_ENABLE([test-fuzzer],
215 [AS_HELP_STRING([--enable-test-fuzzer],
216 [Enable LLVM LibFuzzer for randomized testing])],
217 [enable_test_fuzzer=$enableval], [enable_test_fuzzer=no])
218AS_IF([test "x$enable_test_fuzzer" != xno], [
Lev Walkin03531df2017-10-19 00:23:12 -0700219 AX_CHECK_COMPILE_AND_LINK_FLAG([-fsanitize=fuzzer],
220 [LIBFUZZER_CFLAGS="-fsanitize=fuzzer -DENABLE_LIBFUZZER"],
221 [AC_MSG_FAILURE(
Lev Walkin5c600f42017-09-15 21:57:29 -0700222[--enable-test-fuzzer=$enable_test_fuzzer is not supported on a target system.
Lev Walkin03531df2017-10-19 00:23:12 -0700223Check out http://llvm.org/docs/LibFuzzer.html])],
224 [],
225 [AC_LANG_SOURCE([[
226 #include <sys/types.h>
227 int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size);
228 int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size) {
229 (void)Data;
230 (void)Size;
231 return 0;
232 }
233 ]])])
Lev Walkin5c600f42017-09-15 21:57:29 -0700234])
235
Lev Walkin85d7a1b2017-10-06 16:35:21 -0700236TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} ${SANITIZER_CFLAGS}"
Lev Walkincb4eddb2017-09-15 19:12:24 -0700237SKELETONS_CFLAGS="${SKELETONS_CFLAGS} ${SANITIZER_CFLAGS}"
Lev Walkina7d64002017-08-23 22:34:29 -0700238
239AC_SUBST(ADD_CFLAGS)
Lev Walkin5c600f42017-09-15 21:57:29 -0700240AC_SUBST(LIBFUZZER_CFLAGS)
Lev Walkincb4eddb2017-09-15 19:12:24 -0700241AC_SUBST(SANITIZER_CFLAGS)
Lev Walkina7d64002017-08-23 22:34:29 -0700242AC_SUBST(TESTSUITE_CFLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800243AC_SUBST(SKELETONS_CFLAGS)
Lev Walkin33897e22017-09-26 21:17:39 -0700244AC_SUBST(ASAN_ENV_FLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800245
Lev Walkinf15320b2004-06-03 03:38:44 +0000246dnl Checks for header files.
247AC_HEADER_STDC
Lev Walkin79f54952004-08-13 16:58:19 +0000248AC_CHECK_HEADERS(sys/param.h)
Lev Walkinf15320b2004-06-03 03:38:44 +0000249
250dnl Checks for typedefs, structures, and compiler characteristics.
251AC_C_BIGENDIAN
252AC_TYPE_OFF_T
253AC_TYPE_SIZE_T
254AC_STRUCT_TM
Lev Walkinda997b12017-08-04 01:38:41 -0700255AC_CHECK_TYPE([__int128],
256 [AC_DEFINE(HAVE_128_BIT_INT, 1, [Have 128-bit integer])])
Lev Walkinf15320b2004-06-03 03:38:44 +0000257AC_CHECK_TYPE(intmax_t, int64_t)
258
Lev Walkin1d84ea92017-08-02 12:40:13 -0700259dnl Test if we should test features that depend on 64-bitness.
260AC_CHECK_SIZEOF([void *])
261AM_CONDITIONAL([TEST_64BIT], [test "$ac_cv_sizeof_void_p" -eq 8])
Lev Walkinb40ec412014-02-24 00:57:18 -0800262
Lev Walkin058e2222007-12-04 00:27:38 +0000263dnl For mingw
264AC_SEARCH_LIBS(getopt, iberty)
265
Lev Walkinf15320b2004-06-03 03:38:44 +0000266AC_CHECK_FUNCS(strtoimax strtoll)
Lev Walkin49b0a3e2004-06-28 21:22:35 +0000267AC_CHECK_FUNCS(mergesort)
Lev Walkin27fd0b62007-08-27 23:57:45 +0000268AC_CHECK_FUNCS(mkstemps)
Lev Walkin04fbe622014-09-17 02:27:01 -0700269AC_CHECK_FUNCS(timegm)
Lev Walkina4f8e942017-10-08 19:28:20 -0700270AC_CHECK_DECLS(strcasecmp)
Lev Walkina06b1b42017-10-05 23:07:22 -0700271AC_CHECK_DECLS(vasprintf)
Frank Morgner8a759ad2013-05-16 13:32:49 +0200272AC_TRY_LINK_FUNC([symlink],[AC_DEFINE([HAVE_SYMLINK], 1, [Define to 1 if you have the symlink function.])])
Lev Walkin27fd0b62007-08-27 23:57:45 +0000273
Lev Walkinc6080fd2016-01-23 06:35:34 -0800274dnl Use pandoc to generate manual pages.
275AC_PATH_PROG([PANDOC], pandoc)
276AM_CONDITIONAL([HAVE_PANDOC], [test -n "$PANDOC"])
277
Lev Walkin327bab22016-03-14 02:36:27 -0700278AC_CONFIG_FILES([\
Lev Walkin700df492017-08-10 14:59:15 -0700279tests/tests-c-compiler/check-src/Makefile \
280tests/tests-asn1c-compiler/Makefile \
Lev Walkincb523912017-09-30 19:33:23 -0700281tests/tests-randomized/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700282tests/tests-c-compiler/Makefile \
Lev Walkin56d59b42017-08-24 13:54:58 -0700283tests/tests-skeletons/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700284libasn1compiler/Makefile \
Lev Walkind9221842017-08-22 01:44:56 -0700285libasn1common/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700286libasn1parser/Makefile \
287libasn1print/Makefile \
288libasn1fix/Makefile \
289doc/docsrc/Makefile \
290skeletons/Makefile \
291examples/Makefile \
292doc/man/Makefile \
293tests/Makefile \
294asn1c/Makefile \
295doc/Makefile \
296Makefile \
Lev Walkin327bab22016-03-14 02:36:27 -0700297])
298AC_OUTPUT
Lev Walkinf15320b2004-06-03 03:38:44 +0000299