blob: 88b73575bd84f00d4c9e70c8127d3d38abcc17d3 [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
Lev Walkin85d7a1b2017-10-06 16:35:21 -070071dnl If -m32 is available to reate 32-bit code,
72dnl treat it like a special case to be checked.
73AX_CHECK_COMPILE_FLAG([-m32], [CFLAGS_M32=-m32], [CFLAGS_M32=""])
74AC_SUBST(CFLAGS_M32)
75AM_CONDITIONAL([EXPLICIT_M32], [test "x${CFLAGS_M32}" != "x"])
76
Lev Walkine0236da2017-09-17 22:03:57 -070077dnl Lower the optimization level in tests to aid debugging.
78dnl AX_CHECK_COMPILE_FLAG([-O1],
79dnl [TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -O1"])
80dnl AX_CHECK_COMPILE_FLAG([-fno-inline],
81dnl [TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -fno-inline"])
Lev Walkin65907f02014-09-14 17:19:21 -070082
Vasil Velichkove3187592016-07-18 22:46:36 +030083AX_CODE_COVERAGE
84AS_IF([test x$enable_code_coverage != xno], [
85 CFLAGS="$CFLAGS $CODE_COVERAGE_CFLAGS"
86 # The CODE_COVERAGE_CPPFLAGS contains -DNDEBUG flag
87 # which removes assert(...) macros from code coverage and improves the
88 # branches score. But when it is defined it results in few
89 # unsed-but-set-variable warnings that are treated as errors in the travis-ci
90 # build because these variables are only used inside assert macros.
91 # error: variable ‘ret’ set but not used [-Werror=unused-but-set-variable]
92 #CPPFLAGS="$CPPFLAGS $CODE_COVERAGE_CPPFLAGS"
93 CXXFLAGS="$CXXFLAGS $CODE_COVERAGE_CXXFLAGS"
Lev Walkinefded512017-03-26 16:12:11 -070094 AC_SEARCH_LIBS(gcov_open, gcov, [LDFLAGS="$LDFLAGS $CODE_COVERAGE_LDFLAGS"])
Vasil Velichkove3187592016-07-18 22:46:36 +030095])
96
Lev Walkin97363482016-01-24 19:23:02 -080097dnl Skeletons should be very compatible with most of the compilers, hence
98dnl very strict backward compatibility flags.
Lev Walkin64dd70c2016-03-14 05:14:07 -070099SKELETONS_CFLAGS="${ADD_CFLAGS} ${SKELETONS_CFLAGS}"
Lev Walkin97363482016-01-24 19:23:02 -0800100AX_CHECK_COMPILE_FLAG([-std=c89],
Lev Walkin104af192016-01-24 22:13:27 -0800101 [SKELETONS_CFLAGS="$SKELETONS_CFLAGS -std=c89"])
Lev Walkin97363482016-01-24 19:23:02 -0800102AX_CHECK_COMPILE_FLAG([-Wpedantic],
Vasil Velichkov1144b352016-07-19 19:09:33 +0300103 [SKELETONS_CFLAGS="$SKELETONS_CFLAGS -Wpedantic"],
104 [
105 dnl When -Wpedantic is not supported try the -pedantic instead. (gcc-4.7)
106 dnl See https://gcc.gnu.org/gcc-4.8/changes.html
107 AX_CHECK_COMPILE_FLAG([-pedantic],
108 [SKELETONS_CFLAGS="$SKELETONS_CFLAGS -pedantic"], [], [-Werror])
109 ],
110 [-Werror]) #clang 3.0 prints warning when the flag is not supported
Lev Walkin0f5dd342017-09-13 22:52:39 +0000111
112AC_ARG_ENABLE(Werror,
113 [AS_HELP_STRING([--enable-Werror],
114 [abort compilation after any C compiler warning])],
115 [enable_werror=$enableval], [enable_werror=no])
116 AS_IF([test x$enable_werror != xno], [
117 ADD_CFLAGS="${ADD_CFLAGS} -Werror -W -Wall -Wpointer-arith"
118 SKELETONS_CFLAGS="${SKELETONS_CFLAGS} -Werror -W -Wall -Wpointer-arith"
119 AX_CHECK_COMPILE_FLAG([-Wgnu],
120 [SKELETONS_CFLAGS="${SKELETONS_CFLAGS} -Wgnu"])
121 ])
122
123AC_ARG_ENABLE(test-Werror,
124 [AS_HELP_STRING([--enable-test-Werror],
125 [abort compiling tests after any C compiler warning])],
126 [enable_test_werror=$enableval], [enable_test_werror=no])
127 AS_IF([test x$enable_test_werror != xno], [
128 TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} -Werror -W -Wpointer-arith"
129 ])
130
Lev Walkincb4eddb2017-09-15 19:12:24 -0700131
132SANITIZER_CFLAGS=""
133
134dnl Enable Undefined Behavior Sanitizer, if supported.
135AC_ARG_ENABLE([test-ubsan],
136 [AS_HELP_STRING([--disable-test-ubsan],
137 [Disable Undefined Behavior Sanitizer for tests])],
138 [disable_test_ubsan=$enableval], [disable_test_ubsan=maybe])
139AS_IF([test "x$disable_test_ubsan" != xno], [
140 AX_CHECK_COMPILE_FLAG([-fsanitize=undefined],
141 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=undefined"],
142 [
143 AS_IF([test "x$disable_test_ubsan" != xmaybe], [
144 AC_MSG_FAILURE(
Lev Walkin5c600f42017-09-15 21:57:29 -0700145[--disable-test-ubsan=$disable_test_ubsan is not supported on a target system.
Lev Walkincb4eddb2017-09-15 19:12:24 -0700146https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#how-to-build])])
147 ])
Lev Walkine0236da2017-09-17 22:03:57 -0700148 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=undefined],
149 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=undefined"])
150
151 dnl Unsigned integer overflow is enabled separately.
152 AX_CHECK_COMPILE_FLAG([-fsanitize=unsigned-integer-overflow],
153 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=unsigned-integer-overflow"])
154 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=unsigned-integer-overflow],
155 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=unsigned-integer-overflow"])
156
157 dnl Nullability is enabled separately.
158 AX_CHECK_COMPILE_FLAG([-fsanitize=nullability],
159 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=nullability"])
160 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=nullability],
161 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=nullability"])
162
163 dnl Keep error messages nice. Also consider:
164 dnl export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
165 dnl export UBSAN_OPTIONS=print_stacktrace=1
166 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],
167 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-omit-frame-pointer"])
Lev Walkincb4eddb2017-09-15 19:12:24 -0700168])
169
Lev Walkina7d64002017-08-23 22:34:29 -0700170dnl Enable Address Sanitizer, if supported by gcc (4.8+) or clang.
171dnl http://clang.llvm.org/docs/AddressSanitizer.html
Lev Walkin33897e22017-09-26 21:17:39 -0700172ASAN_ENV_FLAGS=""
Lev Walkina7d64002017-08-23 22:34:29 -0700173AC_ARG_ENABLE([test-asan],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700174 [AS_HELP_STRING([--disable-test-asan],
175 [Disable Address Sanitizer for tests])],
176 [disable_test_asan=$enableval], [disable_test_asan=maybe])
177AS_IF([test "x$disable_test_asan" != xno], [
Lev Walkina7d64002017-08-23 22:34:29 -0700178 AX_CHECK_COMPILE_FLAG([-fsanitize=address],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700179 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=address"],
180 [
181 AS_IF([test "x$disable_test_asan" != xmaybe], [
182 AC_MSG_FAILURE(
Lev Walkin5c600f42017-09-15 21:57:29 -0700183[--disable-test-asan=$disable_test_asan is not supported on a target system.
Lev Walkincb4eddb2017-09-15 19:12:24 -0700184Check out https://clang.llvm.org/docs/AddressSanitizer.html#how-to-build])])
185 ])
Lev Walkin33897e22017-09-26 21:17:39 -0700186 dnl Address sanitizer sometimes is equipped with the leak sanitizer,
187 dnl so we use -fsanitize=leak to permit ASAN_OPTIONS environment.
188 dnl If address sanitizer is not equipped with a leak sanitizer,
189 dnl invoking programs with ASAN_OPTIONS=detect_leaks=1 will break them.
190 AX_CHECK_COMPILE_FLAG([-fsanitize=leak], [
191 ASAN_ENV_FLAGS="${ASAN_ENV_FLAGS} ASAN_OPTIONS=detect_leaks=1"
192 ])
Lev Walkina7d64002017-08-23 22:34:29 -0700193 dnl Keep error messages nice. Also consider:
194 dnl export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
195 dnl export ASAN_OPTIONS=symbolize=1
196 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700197 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-omit-frame-pointer"])
198])
199
200
Lev Walkin5c600f42017-09-15 21:57:29 -0700201dnl Enable LibFuzzer, if supported.
202LIBFUZZER_CFLAGS=""
203AC_ARG_ENABLE([test-fuzzer],
204 [AS_HELP_STRING([--enable-test-fuzzer],
205 [Enable LLVM LibFuzzer for randomized testing])],
206 [enable_test_fuzzer=$enableval], [enable_test_fuzzer=no])
207AS_IF([test "x$enable_test_fuzzer" != xno], [
208 AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer],
Lev Walkin387a8f02017-09-15 23:24:00 -0700209 [LIBFUZZER_CFLAGS="${FUZZER_CFLAGS} -fsanitize=fuzzer -DENABLE_LIBFUZZER"],
Lev Walkin5c600f42017-09-15 21:57:29 -0700210 [
211 AC_MSG_FAILURE(
212[--enable-test-fuzzer=$enable_test_fuzzer is not supported on a target system.
213Check out http://llvm.org/docs/LibFuzzer.html])
214 ])
215])
216
Lev Walkin85d7a1b2017-10-06 16:35:21 -0700217TESTSUITE_CFLAGS="${TESTSUITE_CFLAGS} ${SANITIZER_CFLAGS}"
Lev Walkincb4eddb2017-09-15 19:12:24 -0700218SKELETONS_CFLAGS="${SKELETONS_CFLAGS} ${SANITIZER_CFLAGS}"
Lev Walkina7d64002017-08-23 22:34:29 -0700219
220AC_SUBST(ADD_CFLAGS)
Lev Walkin5c600f42017-09-15 21:57:29 -0700221AC_SUBST(LIBFUZZER_CFLAGS)
Lev Walkincb4eddb2017-09-15 19:12:24 -0700222AC_SUBST(SANITIZER_CFLAGS)
Lev Walkina7d64002017-08-23 22:34:29 -0700223AC_SUBST(TESTSUITE_CFLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800224AC_SUBST(SKELETONS_CFLAGS)
Lev Walkin33897e22017-09-26 21:17:39 -0700225AC_SUBST(ASAN_ENV_FLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800226
Lev Walkinf15320b2004-06-03 03:38:44 +0000227dnl Checks for header files.
228AC_HEADER_STDC
Lev Walkin79f54952004-08-13 16:58:19 +0000229AC_CHECK_HEADERS(sys/param.h)
Lev Walkin619f0cd2016-07-02 19:55:23 +0000230AC_CHECK_HEADERS(alloca.h)
Lev Walkinf15320b2004-06-03 03:38:44 +0000231
232dnl Checks for typedefs, structures, and compiler characteristics.
233AC_C_BIGENDIAN
234AC_TYPE_OFF_T
235AC_TYPE_SIZE_T
236AC_STRUCT_TM
Lev Walkinda997b12017-08-04 01:38:41 -0700237AC_CHECK_TYPE([__int128],
238 [AC_DEFINE(HAVE_128_BIT_INT, 1, [Have 128-bit integer])])
Lev Walkinf15320b2004-06-03 03:38:44 +0000239AC_CHECK_TYPE(intmax_t, int64_t)
240
Lev Walkin1d84ea92017-08-02 12:40:13 -0700241dnl Test if we should test features that depend on 64-bitness.
242AC_CHECK_SIZEOF([void *])
243AM_CONDITIONAL([TEST_64BIT], [test "$ac_cv_sizeof_void_p" -eq 8])
Lev Walkinb40ec412014-02-24 00:57:18 -0800244
Lev Walkin058e2222007-12-04 00:27:38 +0000245dnl For mingw
246AC_SEARCH_LIBS(getopt, iberty)
247
Lev Walkinf15320b2004-06-03 03:38:44 +0000248AC_CHECK_FUNCS(strtoimax strtoll)
Lev Walkin49b0a3e2004-06-28 21:22:35 +0000249AC_CHECK_FUNCS(mergesort)
Lev Walkin27fd0b62007-08-27 23:57:45 +0000250AC_CHECK_FUNCS(mkstemps)
Lev Walkin04fbe622014-09-17 02:27:01 -0700251AC_CHECK_FUNCS(timegm)
Frank Morgnercab30af2013-05-21 14:28:35 +0200252AC_CHECK_DECLS(alloca strcasecmp)
Lev Walkina06b1b42017-10-05 23:07:22 -0700253AC_CHECK_DECLS(vasprintf)
Frank Morgner8a759ad2013-05-16 13:32:49 +0200254AC_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 +0000255
Lev Walkinc6080fd2016-01-23 06:35:34 -0800256dnl Use pandoc to generate manual pages.
257AC_PATH_PROG([PANDOC], pandoc)
258AM_CONDITIONAL([HAVE_PANDOC], [test -n "$PANDOC"])
259
Lev Walkin327bab22016-03-14 02:36:27 -0700260AC_CONFIG_FILES([\
Lev Walkin700df492017-08-10 14:59:15 -0700261tests/tests-c-compiler/check-src/Makefile \
262tests/tests-asn1c-compiler/Makefile \
Lev Walkincb523912017-09-30 19:33:23 -0700263tests/tests-randomized/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700264tests/tests-c-compiler/Makefile \
Lev Walkin56d59b42017-08-24 13:54:58 -0700265tests/tests-skeletons/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700266libasn1compiler/Makefile \
Lev Walkind9221842017-08-22 01:44:56 -0700267libasn1common/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700268libasn1parser/Makefile \
269libasn1print/Makefile \
270libasn1fix/Makefile \
271doc/docsrc/Makefile \
272skeletons/Makefile \
273examples/Makefile \
274doc/man/Makefile \
275tests/Makefile \
276asn1c/Makefile \
277doc/Makefile \
278Makefile \
Lev Walkin327bab22016-03-14 02:36:27 -0700279])
280AC_OUTPUT
Lev Walkinf15320b2004-06-03 03:38:44 +0000281