-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathconfigure.ac
More file actions
254 lines (219 loc) · 8.84 KB
/
configure.ac
File metadata and controls
254 lines (219 loc) · 8.84 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# configure.ac — GNU Autoconf configuration for ruri
# SPDX-License-Identifier: MIT
# Run ./autogen.sh (autoreconf -fi) to regenerate the configure script.
AC_PREREQ([2.69])
AC_INIT([ruri], [3.9.3])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign -Wall -Werror subdir-objects silent-rules no-dist])
AM_SILENT_RULES([yes])
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_split_version.html
# ===========================================================================
AC_DEFUN([AX_SPLIT_VERSION],[
AC_REQUIRE([AC_PROG_SED])
VERSION="$1"
PROJECT_VERSION_MAJOR=`echo "$VERSION" | $SED 's/\([[^.]][[^.]]*\).*/\1/'`
PROJECT_VERSION_MINOR=`echo "$VERSION" | $SED 's/[[^.]][[^.]]*.\([[^.]][[^.]]*\).*/\1/'`
PROJECT_VERSION_PATCH=`echo "$VERSION" | $SED 's/[[^.]][[^.]]*.[[^.]][[^.]]*.\(.*\)/\1/'`
AC_SUBST([PROJECT_VERSION_MAJOR])
AC_SUBST([PROJECT_VERSION_MINOR])
AC_SUBST([PROJECT_VERSION_PATCH])
])
AX_SPLIT_VERSION(${PACKAGE_VERSION})
# Parse --enable-debug early so we can set default CFLAGS before AC_PROG_CC.
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[Enable debug logging (defines RURI_DEBUG)])],
[enable_debug=${enableval}],
[enable_debug=no])
# Set default CFLAGS before AC_PROG_CC (autoconf.texi recommended idiom).
# Only applies when user has not pre-set CFLAGS via environment or command line.
AS_IF([test "x${enable_debug}" = "xyes"],
[: ${CFLAGS="-O0 -g3"}],
[: ${CFLAGS="-O2 -g0"}])
AC_PROG_CC
# PKG_PROG_PKG_CONFIG
AC_PROG_INSTALL
AC_CANONICAL_HOST
AS_CASE([${host_os}],
[linux*], [],
[AC_MSG_ERROR([ruri only supports Linux. Detected: ${host_os}])])
# coreonly: Highest priority, disable libcap/libseccomp/rurienv
AC_ARG_ENABLE([coreonly],
[AS_HELP_STRING([--enable-coreonly],
[Core only: auto-disables libcap, libseccomp, and rurienv])],
[enable_coreonly=${enableval}],
[enable_coreonly=no])
AC_ARG_ENABLE([libcap],
[AS_HELP_STRING([--disable-libcap],
[Disable libcap support (capability management)])],
[enable_libcap=${enableval}],
[enable_libcap=yes])
AC_ARG_ENABLE([libseccomp],
[AS_HELP_STRING([--disable-libseccomp],
[Disable libseccomp support (syscall filtering)])],
[enable_libseccomp=${enableval}],
[enable_libseccomp=yes])
AC_ARG_ENABLE([rurienv],
[AS_HELP_STRING([--disable-rurienv],
[Disable .rurienv config file support])],
[enable_rurienv=${enableval}],
[enable_rurienv=yes])
AS_IF([test "x${enable_coreonly}" = "xyes"], [
enable_libcap=no
enable_libseccomp=no
enable_rurienv=no
])
AC_ARG_ENABLE([static],
[AS_HELP_STRING([--enable-static],
[Enable static linking (The corresponding static library is required.)])],
[enable_static=${enableval}],
[enable_static=no])
AC_ARG_ENABLE([static-pie],
[AS_HELP_STRING([--enable-static-pie],
[Enable static PIE linking (mutually exclusive with --enable-static)])],
[enable_static_pie=${enableval}],
[enable_static_pie=no])
AS_IF([test "x${enable_static}" = "xyes" && test "x${enable_static_pie}" = "xyes"], [
AC_MSG_ERROR([--enable-static and --enable-static-pie are mutually exclusive])])
AS_IF([test "x${enable_static}" = "xyes" || test "x${enable_static_pie}" = "xyes"],
[enable_dynamic=no],
[enable_dynamic=yes])
AC_ARG_ENABLE([dev],
[AS_HELP_STRING([--enable-dev],
[Enable dev build: strict warnings + defines RURI_DEV])],
[enable_dev=${enableval}],
[enable_dev=no])
# Flags/Link
AC_DEFUN([RURI_CHECK_CFLAG], [dnl
AC_MSG_CHECKING([whether $CC accepts $1])
save_CFLAGS="$CFLAGS"; CFLAGS="$CFLAGS $1"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
[AC_MSG_RESULT([yes]); CFLAGS="$save_CFLAGS"; SECURITY_CFLAGS="$SECURITY_CFLAGS $1"],
[AC_MSG_RESULT([no]); CFLAGS="$save_CFLAGS"])])
AC_DEFUN([RURI_CHECK_CFLAG_LINK], [dnl
AC_MSG_CHECKING([whether $CC accepts and links $1])
save_CFLAGS="$CFLAGS"; CFLAGS="$CFLAGS $1"
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[AC_MSG_RESULT([yes]); CFLAGS="$save_CFLAGS"; SECURITY_CFLAGS="$SECURITY_CFLAGS $1"],
[AC_MSG_RESULT([no]); CFLAGS="$save_CFLAGS"])])
AC_DEFUN([RURI_CHECK_LDFLAG], [dnl
AC_MSG_CHECKING([whether linker accepts $1])
save_LDFLAGS="$LDFLAGS"; LDFLAGS="$LDFLAGS $1"
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[AC_MSG_RESULT([yes]); LDFLAGS="$save_LDFLAGS"; SECURITY_LDFLAGS="$SECURITY_LDFLAGS $1"],
[AC_MSG_RESULT([no]); LDFLAGS="$save_LDFLAGS"])])
AC_DEFUN([RURI_CHECK_PIE], [dnl
AC_MSG_CHECKING([whether $CC and linker support -fPIE/-pie together])
save_CFLAGS="$CFLAGS"; save_LDFLAGS="$LDFLAGS"
CFLAGS="$CFLAGS -fPIE"; LDFLAGS="$LDFLAGS -pie"
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[AC_MSG_RESULT([yes])
CFLAGS="$save_CFLAGS"; LDFLAGS="$save_LDFLAGS"
SECURITY_CFLAGS="$SECURITY_CFLAGS -fPIE"
SECURITY_LDFLAGS="$SECURITY_LDFLAGS -pie"],
[AC_MSG_RESULT([no])
CFLAGS="$save_CFLAGS"; LDFLAGS="$save_LDFLAGS"])])
SECURITY_CFLAGS=""
SECURITY_LDFLAGS=""
RURI_CHECK_LDFLAG([-Wl,--build-id=sha1])
RURI_CHECK_LDFLAG([-Wl,-z,noexecstack])
RURI_CHECK_CFLAG([-pipe])
AS_IF([test "x${enable_debug}" = "xyes"], [
RURI_CHECK_CFLAG([-Wall])
RURI_CHECK_CFLAG([-Wextra])
RURI_CHECK_CFLAG([-pedantic])
RURI_CHECK_CFLAG([-Wstrict-prototypes])
RURI_CHECK_CFLAG([-Wextra-semi-stmt])
RURI_CHECK_CFLAG([-Wconversion])
RURI_CHECK_CFLAG([-Wno-gnu-zero-variadic-macro-arguments])
RURI_CHECK_CFLAG_LINK([-fsanitize=address,undefined])
RURI_CHECK_CFLAG([-fno-sanitize-recover=all])
RURI_CHECK_CFLAG([-fno-omit-frame-pointer])
RURI_CHECK_CFLAG([-fno-stack-protector])
])
AS_IF([test "x${enable_debug}" = "xno"], [
RURI_CHECK_CFLAG([-flto=auto])
RURI_CHECK_CFLAG([-ftrivial-auto-var-init=pattern])
RURI_CHECK_CFLAG([-fstack-protector-strong])
RURI_CHECK_CFLAG([-fstack-clash-protection])
RURI_CHECK_CFLAG([-fcf-protection=full])
RURI_CHECK_CFLAG([-ffunction-sections])
RURI_CHECK_CFLAG([-fdata-sections])
RURI_CHECK_LDFLAG([-Wl,--gc-sections])
RURI_CHECK_LDFLAG([-Wl,--strip-all])
AS_IF([test "x${enable_dynamic}" = "xyes"], [
RURI_CHECK_LDFLAG([-Wl,-z,relro])
RURI_CHECK_LDFLAG([-Wl,-z,now])
RURI_CHECK_PIE
])
AS_IF([test "x${enable_static_pie}" = "xyes"], [
RURI_CHECK_CFLAG([-fPIE])
RURI_CHECK_LDFLAG([-static-pie])
])
# RURI_CHECK_CFLAG([-Wno-unused-command-line-argument])
])
AS_IF([test "x${enable_dynamic}" = "xyes"], [
RURI_CHECK_LDFLAG([-Wl,--disable-new-dtags])
])
AS_CASE([${host_cpu}],
[x86_64 | i[[3-6]]86 | amd64], [
RURI_CHECK_CFLAG([-mshstk])
],
[aarch64 | arm64], [
RURI_CHECK_CFLAG([-mbranch-protection=standard])
])
AC_SUBST([SECURITY_CFLAGS])
AC_SUBST([SECURITY_LDFLAGS])
AC_CHECK_HEADERS([pthread.h])
AC_SEARCH_LIBS([pthread_create], [pthread],
[],
[AC_MSG_ERROR([libpthread is required but not found])],
[-pthread])
# libcap (optional)
AS_IF([test "x${enable_libcap}" = "xyes"], [
AC_CHECK_LIB([cap], [cap_init], [
AC_CHECK_HEADER([sys/capability.h], [
have_libcap=yes
CAP_LIBS="-lcap"
], [AC_MSG_ERROR([libcap found, but <sys/capability.h> header not found])])
], [AC_MSG_ERROR([libcap library not found])])
], [have_libcap=no])
# libseccomp (optional)
AS_IF([test "x${enable_libseccomp}" = "xyes"], [
AC_CHECK_LIB([seccomp], [seccomp_init], [
AC_CHECK_HEADER([seccomp.h], [
have_libseccomp=yes
SECCOMP_LIBS="-lseccomp"
], [AC_MSG_ERROR([libseccomp found, but <seccomp.h> header not found])])
], [AC_MSG_ERROR([libseccomp library not found])])
], [have_libseccomp=no])
AC_SUBST([CAP_LIBS])
AC_SUBST([SECCOMP_LIBS])
# git commit id (Valid only within the Git repo)
AC_MSG_CHECKING([for git commit id])
commit_id=""
if test -d "${srcdir}/.git"; then
commit_id=`git rev-parse --short=8 HEAD 2>/dev/null`
fi
AS_IF([test -z "$commit_id"], [
AC_MSG_RESULT([not available])
COMMIT_CFLAGS="-DRURI_COMMIT_ID=\\\"Unknown\\\""
], [
AC_MSG_RESULT([$commit_id])
COMMIT_CFLAGS="-DRURI_COMMIT_ID=\\\"$commit_id\\\""
])
AC_SUBST([COMMIT_CFLAGS])
AM_CONDITIONAL([HAVE_LIBCAP], [test "x${have_libcap}" = "xyes"])
AM_CONDITIONAL([HAVE_LIBSECCOMP], [test "x${have_libseccomp}" = "xyes"])
AM_CONDITIONAL([ENABLE_COREONLY], [test "x${enable_coreonly}" = "xyes"])
AM_CONDITIONAL([ENABLE_RURIENV], [test "x${enable_rurienv}" = "xyes"])
AM_CONDITIONAL([ENABLE_STATIC], [test "x${enable_static}" = "xyes"])
AM_CONDITIONAL([ENABLE_DEBUG], [test "x${enable_debug}" = "xyes"])
AM_CONDITIONAL([ENABLE_DEV], [test "x${enable_dev}" = "xyes"])
AC_CONFIG_FILES([
Makefile
src/include/version.h:src/include/version.h.in
])
AC_OUTPUT