1 AC_DEFUN([AC_PROG_CC_PIE], [
2 AC_CACHE_CHECK([whether ${CC-cc} accepts -fPIE], ac_cv_prog_cc_pie, [
3 echo 'void f(){}' > conftest.c
4 if test -z "`${CC-cc} -fPIE -pie -c conftest.c 2>&1`"; then
13 AC_DEFUN([AC_PROG_CC_ASAN], [
14 AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=address],
16 echo 'void f(){}' > asan.c
17 if test -z "`${CC-cc} -fsanitize=address -c asan.c 2>&1`"; then
18 ac_cv_prog_cc_asan=yes
26 AC_DEFUN([AC_PROG_CC_LSAN], [
27 AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=leak],
29 echo 'void f(){}' > lsan.c
30 if test -z "`${CC-cc} -fsanitize=leak -c lsan.c 2>&1`"; then
31 ac_cv_prog_cc_lsan=yes
39 AC_DEFUN([AC_PROG_CC_UBSAN], [
40 AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=undefined],
41 ac_cv_prog_cc_ubsan, [
42 echo 'void f(){}' > ubsan.c
43 if test -z "`${CC-cc} -fsanitize=undefined -c ubsan.c 2>&1`"; then
44 ac_cv_prog_cc_ubsan=yes
46 ac_cv_prog_cc_ubsan=no
52 AC_DEFUN([COMPILER_FLAGS], [
54 if (test "$USE_MAINTAINER_MODE" = "yes"); then
55 with_cflags="$with_cflags -Wall -Werror -Wextra"
56 with_cflags="$with_cflags -Wno-unused-parameter"
57 with_cflags="$with_cflags -Wno-missing-field-initializers"
58 with_cflags="$with_cflags -Wdeclaration-after-statement"
59 with_cflags="$with_cflags -Wmissing-declarations"
60 with_cflags="$with_cflags -Wredundant-decls"
61 with_cflags="$with_cflags -Wcast-align"
62 with_cflags="$with_cflags -Wswitch-enum"
63 with_cflags="$with_cflags -Wformat -Wformat-security"
64 with_cflags="$with_cflags -DG_DISABLE_DEPRECATED"
65 with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
66 with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
68 AC_SUBST([WARNING_CFLAGS], $with_cflags)
71 AC_DEFUN([MISC_FLAGS], [
74 AC_ARG_ENABLE(optimization, AS_HELP_STRING([--disable-optimization],
75 [disable code optimization through compiler]), [
76 if (test "${enableval}" = "no"); then
77 misc_cflags="$misc_cflags -O0"
80 AC_ARG_ENABLE(asan, AS_HELP_STRING([--enable-asan],
81 [enable linking with address sanitizer]), [
83 AC_CHECK_LIB(asan, _init)
85 if (test "${enableval}" = "yes" &&
86 test "${ac_cv_lib_asan__init}" = "yes" &&
87 test "${ac_cv_prog_cc_asan}" = "yes"); then
88 misc_cflags="$misc_cflags -fsanitize=address";
89 misc_ldflags="$misc_ldflags -fsanitize=address"
90 AC_SUBST([ASAN_LIB], ${ac_cv_lib_asan__init})
93 AC_ARG_ENABLE(lsan, AS_HELP_STRING([--enable-lsan],
94 [enable linking with address sanitizer]), [
96 AC_CHECK_LIB(lsan, _init)
98 if (test "${enableval}" = "yes" &&
99 test "${ac_cv_lib_lsan__init}" = "yes" &&
100 test "${ac_cv_prog_cc_lsan}" = "yes"); then
101 misc_cflags="$misc_cflags -fsanitize=leak";
102 misc_ldflags="$misc_ldflags -fsanitize=leak"
103 AC_SUBST([ASAN_LIB], ${ac_cv_lib_lsan__init})
106 AC_ARG_ENABLE(ubsan, AS_HELP_STRING([--enable-ubsan],
107 [enable linking with address sanitizer]), [
109 AC_CHECK_LIB(ubsan, _init)
111 if (test "${enableval}" = "yes" &&
112 test "${ac_cv_lib_ubsan__init}" = "yes" &&
113 test "${ac_cv_prog_cc_ubsan}" = "yes"); then
114 misc_cflags="$misc_cflags -fsanitize=undefined";
115 misc_ldflags="$misc_ldflags -fsanitize=undefined";
118 AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],
119 [enable compiling with debugging information]), [
120 if (test "${enableval}" = "yes" &&
121 test "${ac_cv_prog_cc_g}" = "yes"); then
122 misc_cflags="$misc_cflags -g"
125 AC_ARG_ENABLE(pie, AS_HELP_STRING([--enable-pie],
126 [enable position independent executables flag]), [
127 if (test "${enableval}" = "yes" &&
128 test "${ac_cv_prog_cc_pie}" = "yes"); then
129 misc_cflags="$misc_cflags -fPIC"
130 misc_ldflags="$misc_ldflags -pie -Wl,-z,now"
133 if (test "$enable_coverage" = "yes"); then
134 misc_cflags="$misc_cflags --coverage"
135 misc_ldflags="$misc_ldflags --coverage"
137 AC_SUBST([MISC_CFLAGS], $misc_cflags)
138 AC_SUBST([MISC_LDFLAGS], $misc_ldflags)