summaryrefslogtreecommitdiff
path: root/configure.ac
blob: ce134213528ce3bf9951f1bd6471d2cd18333f92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([skonfig-c],[0.1],[skonfig@dtnr.ch],[],[http://www.skonfig.li/])
AC_CONFIG_SRCDIR([src/skonfig.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_FILES([Makefile])

AM_INIT_AUTOMAKE([subdir-objects])

# scripts
AC_CONFIG_FILES([scripts/sdump], [chmod +x scripts/sdump])

# Checks for programs.
AC_LANG([C])

AC_PROG_CC
# autoconf 2.70 obsoletes AC_PROG_CC_C99 and includes it in AC_PROG_CC
m4_version_prereq([2.70],[],[AC_PROG_CC_C99])

AC_PROG_CPP
AC_PROG_MAKE_SET

# Checks for libraries.

# Check POSIX conformance level.
_want_posix_level=200112L
_posix_level_human=POSIX.1-2001
AC_MSG_CHECKING([if the POSIX conformance level can be set to ${_posix_level_human}])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#define _POSIX_C_SOURCE ${_want_posix_level}
#include <unistd.h>
#if _POSIX_VERSION != ${_want_posix_level}
#error incorrect _POSIX_VERSION
#endif
])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no]);
 AC_MSG_FAILURE([this system does not conform to the ${_posix_level_human} standard])
])
AC_DEFINE_UNQUOTED([_POSIX_C_SOURCE], [${_want_posix_level}], [define the POSIX conformance level])
CFLAGS=${CFLAGS-}${CFLAGS:+ }-D_POSIX_C_SOURCE=${_want_posix_level}

# Define X/Open conformance level.
_want_xopen_level=500
AC_DEFINE_UNQUOTED([_XOPEN_SOURCE], [${_want_xopen_level}], [define the X/Open conformance level])
CFLAGS=${CFLAGS-}${CFLAGS:+ }-D_XOPEN_SOURCE=${_want_xopen_level}

# Checks for header files.
AC_HEADER_STDC
AC_HEADER_STDBOOL
AC_HEADER_STAT

AC_CHECK_HEADERS_ONCE([stdarg.h])
AC_CHECK_HEADERS_ONCE([linux/limits.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_C_RESTRICT
AC_C_STRINGIZE
AC_C_VARARRAYS
AC_TYPE_SIZE_T
AC_TYPE_UINT8_T

if test x"$ac_cv_c_vararrays" != x'yes'
then
	AC_MSG_ERROR([$CC does not support variable-length arrays (VLAs)])
fi

# Checks for library functions.

AC_CHECK_FUNCS_ONCE([getenv getpwuid stat])
AC_CHECK_FUNCS_ONCE([strdup strncpy strncat])

AC_CHECK_FUNCS_ONCE([mktemp mkdtemp tempnam])
AC_CHECK_DECLS([mkdtemp, mktemp], [], [], [[#include <stdlib.h>]])
AC_CHECK_DECLS([tempnam], [], [], [[#include <stdio.h>]])

# Checks for compiler options.
_cccheckingopts=$(
	# clang (newer versions) don't fail if they see an unknown argument.
	CFLAGS=-Werror=unused-command-line-argument
	AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([], [])], [echo "${CFLAGS}"], [])
)
check_ccopt() { (
	_ccopt=${1:?}
	case ${CFLAGS-} in
		(*\ ${_ccopt}\ *|${_ccopt}\ *|*\ ${_ccopt})
			# option is already set
			return 0
			;;
	esac

	AC_MSG_CHECKING([whether ${CC} supports ${_ccopt}])
	CFLAGS="${CFLAGS-} ${_cccheckingopts-} ${_ccopt}"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM([], [])],
		[AC_MSG_RESULT([yes]); return 0],
		[AC_MSG_RESULT([no]); return 1])
); }
check_set_ccopt() {
	check_ccopt "${1:?}" && CFLAGS=${CFLAGS-}${CFLAGS:+ }${1:?}
}

check_set_ccopt -Wall
check_set_ccopt -Werror

check_set_ccopt -pedantic
check_set_ccopt -pedantic-errors
check_set_ccopt -Werror=pedantic

check_set_ccopt -Wformat=2
check_set_ccopt -Wformat-overflow=2

check_set_ccopt -fstack-protector-strong \
|| check_set_ccopt -fstack-protector  # fallback

check_set_ccopt -fstack-clash-protection \
|| check_set_ccopt -fstack-check  # fallback

check_set_ccopt -fsanitize=leak
check_set_ccopt -fsanitize=address && {
	check_set_ccopt -fsanitize=pointer-compare
	check_set_ccopt -fsanitize=pointer-subtract
}
check_set_ccopt -fsanitize=undefined

# Checks for compiler "C" capabilities
AX_C___ATTRIBUTE__

if test x"${ax_cv___attribute__}" = x'yes'
then
	_sk_attribute='__attribute__ ((__VA_ARGS__))'

	AX_GCC_FUNC_ATTRIBUTE([format])
	if test x"${ax_cv_have_func_attribute_format}" = x'yes'
	then
		_sk_printf='SK_ATTRIBUTE(format (printf, i, j))'
	fi

	AX_GCC_FUNC_ATTRIBUTE([malloc])
	if test x"${ax_cv_have_func_attribute_malloc}" = x'yes'
	then
		_sk_malloc='SK_ATTRIBUTE(malloc)'
		_sk_malloc_free='SK_ATTRIBUTE(malloc, malloc (f, i))'
	fi

	AX_GCC_FUNC_ATTRIBUTE([nonnull])
	if test x"${ax_cv_have_func_attribute_nonnull}" = x'yes'
	then
		_sk_nonnull='SK_ATTRIBUTE(nonnull (__VA_ARGS__))'
		_sk_cc_nonnull_check=1
	fi

	AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])
	if test x"${ax_cv_have_func_attribute_returns_nonnull}" = x'yes'
	then
		_sk_returns_nonnull='SK_ATTRIBUTE(returns_nonnull)'
	fi

	AX_GCC_FUNC_ATTRIBUTE([sentinel])
	if test x"${ax_cv_have_func_attribute_sentinel}" = x'yes'
	then
		_sk_sentinel='SK_ATTRIBUTE(sentinel(i))'
	fi

	AX_GCC_FUNC_ATTRIBUTE([warn_unused_result])
	if test x"${ax_cv_have_func_attribute_warn_unused_result}" = x'yes'
	then
		_sk_warn_unused_result='SK_ATTRIBUTE(warn_unused_result)'
	fi
fi
AC_DEFINE_UNQUOTED([SK_ATTRIBUTE(...)], [${_sk_attribute:-/* attribute(x) */}], [Define to the compiler name of its __attribute__])
AC_DEFINE_UNQUOTED([SK_PRINTF(i, j)], [${_sk_printf:-/* format(printf, i, j) */}], [Define to a code snippet your compiler uses for __attribute__ (format)])
AC_DEFINE_UNQUOTED([SK_MALLOC], [${_sk_malloc:-/* malloc */}], [...])
AC_DEFINE_UNQUOTED([SK_MALLOC_FREE(f, i)], [${_sk_malloc_free:-/* malloc (f, i) */}], [...])
AC_DEFINE_UNQUOTED([SK_NONNULL(...)], [${_sk_nonnull:-/* nonnull(__VA_ARGS__) */}], [...])
AC_DEFINE_UNQUOTED([SK_RETURNS_NONNULL], [${_sk_returns_nonnull:-/* returns_nonnull */}], [...])
AC_DEFINE_UNQUOTED([SK_SENTINEL(i)], [${_sk_sentinel:-/* sentinel */}], [...])
AC_DEFINE_UNQUOTED([SK_WARN_UNUSED_RESULT], [${_sk_warn_unused_result:-/* warn_unused_result */}], [...])

AC_DEFINE_UNQUOTED([HAVE_CC_NONNULL_CHECK], $((_sk_cc_nonnull_check)), [Define to 1 if the CC supports __attribute__(nonnull)])

# Add debug support
AC_ARG_ENABLE(
	[debug],
	AS_HELP_STRING([--enable-debug], [enable debugging, default: no]),
	[case ${enableval} in
		(yes)	debug=true ;;
		(no)	debug=false ;;
		(*)	AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
	 esac],
	[debug=false])
AM_CONDITIONAL(DEBUG, [${debug}])
AM_COND_IF(DEBUG,
	AC_DEFINE([DEBUG], [1], [Define to 1 if this is a debug build]),
	AC_DEFINE([DEBUG], [0], [Define to 1 if this is a debug build]))

# Defines
AC_DEFINE(DIRSEP, [/], [The directory separator in a file system path])
AC_DEFINE(PATHSEP, [:], [The separator of PATH components])

# Check if shebangs are supported on this system.
# This is required for execution of types.
AC_SYS_INTERPRETER
if test "x${interpval}" != 'xyes'
then
	AC_MSG_ERROR([cannot run types on this system because it does not support shebangs.])
fi


AC_OUTPUT