blob: adb524576ef013623c62d01337a2e1c723c0a376 [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
126SANITIZER_CFLAGS=""
127
128dnl Enable Undefined Behavior Sanitizer, if supported.
129AC_ARG_ENABLE([test-ubsan],
130 [AS_HELP_STRING([--disable-test-ubsan],
131 [Disable Undefined Behavior Sanitizer for tests])],
132 [disable_test_ubsan=$enableval], [disable_test_ubsan=maybe])
133AS_IF([test "x$disable_test_ubsan" != xno], [
134 AX_CHECK_COMPILE_FLAG([-fsanitize=undefined],
135 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=undefined"],
136 [
137 AS_IF([test "x$disable_test_ubsan" != xmaybe], [
138 AC_MSG_FAILURE(
Lev Walkin5c600f42017-09-15 21:57:29 -0700139[--disable-test-ubsan=$disable_test_ubsan is not supported on a target system.
Lev Walkincb4eddb2017-09-15 19:12:24 -0700140https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#how-to-build])])
141 ])
Lev Walkine0236da2017-09-17 22:03:57 -0700142 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=undefined],
143 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=undefined"])
144
145 dnl Unsigned integer overflow is enabled separately.
146 AX_CHECK_COMPILE_FLAG([-fsanitize=unsigned-integer-overflow],
147 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=unsigned-integer-overflow"])
148 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=unsigned-integer-overflow],
149 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=unsigned-integer-overflow"])
150
151 dnl Nullability is enabled separately.
152 AX_CHECK_COMPILE_FLAG([-fsanitize=nullability],
153 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=nullability"])
154 AX_CHECK_COMPILE_FLAG([-fno-sanitize-recover=nullability],
155 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-sanitize-recover=nullability"])
156
157 dnl Keep error messages nice. Also consider:
158 dnl export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
159 dnl export UBSAN_OPTIONS=print_stacktrace=1
160 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],
161 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-omit-frame-pointer"])
Lev Walkincb4eddb2017-09-15 19:12:24 -0700162])
163
Lev Walkina7d64002017-08-23 22:34:29 -0700164dnl Enable Address Sanitizer, if supported by gcc (4.8+) or clang.
165dnl http://clang.llvm.org/docs/AddressSanitizer.html
Lev Walkin33897e22017-09-26 21:17:39 -0700166ASAN_ENV_FLAGS=""
Lev Walkina7d64002017-08-23 22:34:29 -0700167AC_ARG_ENABLE([test-asan],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700168 [AS_HELP_STRING([--disable-test-asan],
169 [Disable Address Sanitizer for tests])],
170 [disable_test_asan=$enableval], [disable_test_asan=maybe])
171AS_IF([test "x$disable_test_asan" != xno], [
Lev Walkina7d64002017-08-23 22:34:29 -0700172 AX_CHECK_COMPILE_FLAG([-fsanitize=address],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700173 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fsanitize=address"],
174 [
175 AS_IF([test "x$disable_test_asan" != xmaybe], [
176 AC_MSG_FAILURE(
Lev Walkin5c600f42017-09-15 21:57:29 -0700177[--disable-test-asan=$disable_test_asan is not supported on a target system.
Lev Walkincb4eddb2017-09-15 19:12:24 -0700178Check out https://clang.llvm.org/docs/AddressSanitizer.html#how-to-build])])
179 ])
Lev Walkin33897e22017-09-26 21:17:39 -0700180 dnl Address sanitizer sometimes is equipped with the leak sanitizer,
181 dnl so we use -fsanitize=leak to permit ASAN_OPTIONS environment.
182 dnl If address sanitizer is not equipped with a leak sanitizer,
183 dnl invoking programs with ASAN_OPTIONS=detect_leaks=1 will break them.
184 AX_CHECK_COMPILE_FLAG([-fsanitize=leak], [
185 ASAN_ENV_FLAGS="${ASAN_ENV_FLAGS} ASAN_OPTIONS=detect_leaks=1"
186 ])
Lev Walkina7d64002017-08-23 22:34:29 -0700187 dnl Keep error messages nice. Also consider:
188 dnl export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
189 dnl export ASAN_OPTIONS=symbolize=1
190 AX_CHECK_COMPILE_FLAG([-fno-omit-frame-pointer],
Lev Walkincb4eddb2017-09-15 19:12:24 -0700191 [SANITIZER_CFLAGS="${SANITIZER_CFLAGS} -fno-omit-frame-pointer"])
192])
193
194
Lev Walkin5c600f42017-09-15 21:57:29 -0700195dnl Enable LibFuzzer, if supported.
196LIBFUZZER_CFLAGS=""
197AC_ARG_ENABLE([test-fuzzer],
198 [AS_HELP_STRING([--enable-test-fuzzer],
199 [Enable LLVM LibFuzzer for randomized testing])],
200 [enable_test_fuzzer=$enableval], [enable_test_fuzzer=no])
201AS_IF([test "x$enable_test_fuzzer" != xno], [
202 AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer],
Lev Walkin387a8f02017-09-15 23:24:00 -0700203 [LIBFUZZER_CFLAGS="${FUZZER_CFLAGS} -fsanitize=fuzzer -DENABLE_LIBFUZZER"],
Lev Walkin5c600f42017-09-15 21:57:29 -0700204 [
205 AC_MSG_FAILURE(
206[--enable-test-fuzzer=$enable_test_fuzzer is not supported on a target system.
207Check out http://llvm.org/docs/LibFuzzer.html])
208 ])
209])
210
Lev Walkincb4eddb2017-09-15 19:12:24 -0700211TESTSUITE_CFLAGS="${TESTSUICE_CFLAGS} ${SANITIZER_CFLAGS}"
212SKELETONS_CFLAGS="${SKELETONS_CFLAGS} ${SANITIZER_CFLAGS}"
Lev Walkina7d64002017-08-23 22:34:29 -0700213
214AC_SUBST(ADD_CFLAGS)
Lev Walkin5c600f42017-09-15 21:57:29 -0700215AC_SUBST(LIBFUZZER_CFLAGS)
Lev Walkincb4eddb2017-09-15 19:12:24 -0700216AC_SUBST(SANITIZER_CFLAGS)
Lev Walkina7d64002017-08-23 22:34:29 -0700217AC_SUBST(TESTSUITE_CFLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800218AC_SUBST(SKELETONS_CFLAGS)
Lev Walkin33897e22017-09-26 21:17:39 -0700219AC_SUBST(ASAN_ENV_FLAGS)
Lev Walkin97363482016-01-24 19:23:02 -0800220
Lev Walkinf15320b2004-06-03 03:38:44 +0000221dnl Checks for header files.
222AC_HEADER_STDC
Lev Walkin79f54952004-08-13 16:58:19 +0000223AC_CHECK_HEADERS(sys/param.h)
Lev Walkin619f0cd2016-07-02 19:55:23 +0000224AC_CHECK_HEADERS(alloca.h)
Lev Walkinf15320b2004-06-03 03:38:44 +0000225
226dnl Checks for typedefs, structures, and compiler characteristics.
227AC_C_BIGENDIAN
228AC_TYPE_OFF_T
229AC_TYPE_SIZE_T
230AC_STRUCT_TM
Lev Walkinda997b12017-08-04 01:38:41 -0700231AC_CHECK_TYPE([__int128],
232 [AC_DEFINE(HAVE_128_BIT_INT, 1, [Have 128-bit integer])])
Lev Walkinf15320b2004-06-03 03:38:44 +0000233AC_CHECK_TYPE(intmax_t, int64_t)
234
Lev Walkin1d84ea92017-08-02 12:40:13 -0700235dnl Test if we should test features that depend on 64-bitness.
236AC_CHECK_SIZEOF([void *])
237AM_CONDITIONAL([TEST_64BIT], [test "$ac_cv_sizeof_void_p" -eq 8])
Lev Walkinb40ec412014-02-24 00:57:18 -0800238
Lev Walkin058e2222007-12-04 00:27:38 +0000239dnl For mingw
240AC_SEARCH_LIBS(getopt, iberty)
241
Lev Walkinf15320b2004-06-03 03:38:44 +0000242AC_CHECK_FUNCS(strtoimax strtoll)
Lev Walkin49b0a3e2004-06-28 21:22:35 +0000243AC_CHECK_FUNCS(mergesort)
Lev Walkin27fd0b62007-08-27 23:57:45 +0000244AC_CHECK_FUNCS(mkstemps)
Lev Walkin04fbe622014-09-17 02:27:01 -0700245AC_CHECK_FUNCS(timegm)
Frank Morgnercab30af2013-05-21 14:28:35 +0200246AC_CHECK_DECLS(alloca strcasecmp)
Frank Morgner8a759ad2013-05-16 13:32:49 +0200247AC_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 +0000248
Lev Walkinc6080fd2016-01-23 06:35:34 -0800249dnl Use pandoc to generate manual pages.
250AC_PATH_PROG([PANDOC], pandoc)
251AM_CONDITIONAL([HAVE_PANDOC], [test -n "$PANDOC"])
252
Lev Walkin327bab22016-03-14 02:36:27 -0700253AC_CONFIG_FILES([\
Lev Walkin700df492017-08-10 14:59:15 -0700254tests/tests-c-compiler/check-src/Makefile \
255tests/tests-asn1c-compiler/Makefile \
Lev Walkincb523912017-09-30 19:33:23 -0700256tests/tests-randomized/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700257tests/tests-c-compiler/Makefile \
Lev Walkin56d59b42017-08-24 13:54:58 -0700258tests/tests-skeletons/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700259libasn1compiler/Makefile \
Lev Walkind9221842017-08-22 01:44:56 -0700260libasn1common/Makefile \
Lev Walkin700df492017-08-10 14:59:15 -0700261libasn1parser/Makefile \
262libasn1print/Makefile \
263libasn1fix/Makefile \
264doc/docsrc/Makefile \
265skeletons/Makefile \
266examples/Makefile \
267doc/man/Makefile \
268tests/Makefile \
269asn1c/Makefile \
270doc/Makefile \
271Makefile \
Lev Walkin327bab22016-03-14 02:36:27 -0700272])
273AC_OUTPUT
Lev Walkinf15320b2004-06-03 03:38:44 +0000274