blob: 8adaa308f030f6dc87007eb97347d4fa0d4a35ce [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 ])
124
Lev Walkincb4eddb2017-09-15 19:12:24 -0700125
Lev Walkin249fd262017-10-18 10:05:26 -0700126dnl If -m32 is available to create 32-bit code,
127dnl treat it like a special case to be checked.
128AC_ARG_ENABLE([test-32bit],
129 [AS_HELP_STRING([--disable-test-32bit],
130 [Disable tests for 32-bit compatibility])],
131 [disable_test_32bit=$enableval], [disable_test_32bit=maybe])
132AS_IF([test "x$disable_test_32bit" != xno], [
133 AX_CHECK_COMPILE_FLAG([-m32], [CFLAGS_M32=-m32],
134 [
135 CFLAGS_M32=""
136 AS_IF([test "x$disable_test_32bit" != xmaybe], [
137 AC_MSG_FAILURE([--disable-test-32bit=$disable_test_32bit is not supported on a target system.])
138 ])
139 ])
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], [
152 AX_CHECK_COMPILE_FLAG([-fsanitize=undefined],
153 [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 Walkina7d64002017-08-23 22:34:29 -0700190 AX_CHECK_COMPILE_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
212
Lev Walkin5c600f42017-09-15 21:57:29 -0700213dnl Enable LibFuzzer, if supported.
214LIBFUZZER_CFLAGS=""
215AC_ARG_ENABLE([test-fuzzer],
216 [AS_HELP_STRING([--enable-test-fuzzer],
217 [Enable LLVM LibFuzzer for randomized testing])],
218 [enable_test_fuzzer=$enableval], [enable_test_fuzzer=no])
219AS_IF([test "x$enable_test_fuzzer" != xno], [
220 AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer],
Lev Walkin387a8f02017-09-15 23:24:00 -0700221 [LIBFUZZER_CFLAGS="${FUZZER_CFLAGS} -fsanitize=fuzzer -DENABLE_LIBFUZZER"],
Lev Walkin5c600f42017-09-15 21:57:29 -0700222 [
223 AC_MSG_FAILURE(
224[--enable-test-fuzzer=$enable_test_fuzzer is not supported on a target system.
225Check out http://llvm.org/docs/LibFuzzer.html])
226 ])
227])
228
Lev Walkin85d7a1b2017-10-06 16:35:21 -0700229TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} ${SANITIZER_CFLAGS}"
Lev Walkincb4eddb2017-09-15 19:12:24 -0700230SKELETONS_CFLAGS="${SKELETONS_CFLAGS} ${SANITIZER_CFLAGS}"
Lev Walkina7d64002017-08-23 22:34:29 -0700231
232AC_SUBST(ADD_CFLAGS)
Lev Walkin5c600f42017-09-15 21:57:29 -0700233AC_SUBST(LIBFUZZER_CFLAGS)
Lev Walkincb4eddb2017-09-15 19:12:24 -0700234AC_SUBST(SANITIZER_CFLAGS)
Lev Walkina7d64002017-08-23 22:34:29 -0700235AC_SUBST(TESTSUITE_CFLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800236AC_SUBST(SKELETONS_CFLAGS)
Lev Walkin33897e22017-09-26 21:17:39 -0700237AC_SUBST(ASAN_ENV_FLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800238
Lev Walkinf15320b2004-06-03 03:38:44 +0000239dnl Checks for header files.
240AC_HEADER_STDC
Lev Walkin79f54952004-08-13 16:58:19 +0000241AC_CHECK_HEADERS(sys/param.h)
Lev Walkinf15320b2004-06-03 03:38:44 +0000242
243dnl Checks for typedefs, structures, and compiler characteristics.
244AC_C_BIGENDIAN
245AC_TYPE_OFF_T
246AC_TYPE_SIZE_T
247AC_STRUCT_TM
Lev Walkinda997b12017-08-04 01:38:41 -0700248AC_CHECK_TYPE([__int128],
249 [AC_DEFINE(HAVE_128_BIT_INT, 1, [Have 128-bit integer])])
Lev Walkinf15320b2004-06-03 03:38:44 +0000250AC_CHECK_TYPE(intmax_t, int64_t)
251
Lev Walkin1d84ea92017-08-02 12:40:13 -0700252dnl Test if we should test features that depend on 64-bitness.
253AC_CHECK_SIZEOF([void *])
254AM_CONDITIONAL([TEST_64BIT], [test "$ac_cv_sizeof_void_p" -eq 8])
Lev Walkinb40ec412014-02-24 00:57:18 -0800255
Lev Walkin058e2222007-12-04 00:27:38 +0000256dnl For mingw
257AC_SEARCH_LIBS(getopt, iberty)
258
Lev Walkinf15320b2004-06-03 03:38:44 +0000259AC_CHECK_FUNCS(strtoimax strtoll)
Lev Walkin49b0a3e2004-06-28 21:22:35 +0000260AC_CHECK_FUNCS(mergesort)
Lev Walkin27fd0b62007-08-27 23:57:45 +0000261AC_CHECK_FUNCS(mkstemps)
Lev Walkin04fbe622014-09-17 02:27:01 -0700262AC_CHECK_FUNCS(timegm)
Lev Walkina4f8e942017-10-08 19:28:20 -0700263AC_CHECK_DECLS(strcasecmp)
Lev Walkina06b1b42017-10-05 23:07:22 -0700264AC_CHECK_DECLS(vasprintf)
Frank Morgner8a759ad2013-05-16 13:32:49 +0200265AC_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 +0000266
Lev Walkinc6080fd2016-01-23 06:35:34 -0800267dnl Use pandoc to generate manual pages.
268AC_PATH_PROG([PANDOC], pandoc)
269AM_CONDITIONAL([HAVE_PANDOC], [test -n "$PANDOC"])
270
Lev Walkin327bab22016-03-14 02:36:27 -0700271AC_CONFIG_FILES([\
Lev Walkin700df492017-08-10 14:59:15 -0700272tests/tests-c-compiler/check-src/Makefile \
273tests/tests-asn1c-compiler/Makefile \
Lev Walkincb523912017-09-30 19:33:23 -0700274tests/tests-randomized/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700275tests/tests-c-compiler/Makefile \
Lev Walkin56d59b42017-08-24 13:54:58 -0700276tests/tests-skeletons/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700277libasn1compiler/Makefile \
Lev Walkind9221842017-08-22 01:44:56 -0700278libasn1common/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700279libasn1parser/Makefile \
280libasn1print/Makefile \
281libasn1fix/Makefile \
282doc/docsrc/Makefile \
283skeletons/Makefile \
284examples/Makefile \
285doc/man/Makefile \
286tests/Makefile \
287asn1c/Makefile \
288doc/Makefile \
289Makefile \
Lev Walkin327bab22016-03-14 02:36:27 -0700290])
291AC_OUTPUT
Lev Walkinf15320b2004-06-03 03:38:44 +0000292