-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
211 lines (177 loc) · 6.6 KB
/
configure.ac
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
dnl -*- Autoconf -*-
dnl Process this file with autoconf to produce a configure script.
AC_INIT([xdict],[0.2.1],[ranga@calalum.org])
# We want to turn on warnings if we are using gcc and the user did
# not specify CFLAGS. The autoconf check for the C compiler sets the
# CFLAGS if gcc is used, so we will save it before we run that check.
#
# TODO: Enable caching of some results:
# https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Caching-Results.html
#
save_CFLAGS="$CFLAGS $OBJCFLAGS"
# use objective-c
AC_LANG_PUSH([Objective C])
# check for install
AC_PROG_INSTALL
CFLAGS="$save_CFLAGS $CFLAGS"
# check for source files
PGM_SRCS=xdict.m
AC_CONFIG_SRCDIR(["$PGM_SRCS"])
# Check basic types.
AC_C_CONST
# check for objc ARC is available
AC_MSG_CHECKING([for Objective-C ARC])
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fobjc-arc"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <AppKit/AppKit.h>], [])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_ERROR([ARC is required])
else
AC_MSG_RESULT([yes])
fi
# check for Dictionary Services in AppKit
AC_MSG_CHECKING([for Dictionary Services in AppKit])
LIBS="$LIBS -fobjc-arc -framework AppKit"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <AppKit/AppKit.h>
#import <CoreServices/CoreServices.h>
extern extern CFArrayRef DCSCopyAvailableDictionaries();], [
NSArray *d = (__bridge_transfer NSArray *)DCSCopyAvailableDictionaries();])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_ERROR([Dictionary Services are required])
else
AC_MSG_RESULT([yes])
fi
dnl TEST_AND_SET_CFLAG(flag, [program])
dnl
dnl This attempts to compile a program with a certain compiler flag.
dnl If no program is given, then the minimal program is compiled, and
dnl this tests just the validity of the compiler flag.
dnl
dnl based on: https://github.com/edrosten/autoconf_tutorial
define([TEST_AND_SET_CFLAG],[
AC_MSG_CHECKING([if compiler flag $1 works])
dnl Store the current CXXFLAGS
save_CFLAGS="$OBJCFLAGS"
dnl Append the flag of interest
OBJCFLAGS="$OBJCFLAGS $1"
dnl Create an M4 macro, "prog", which expands to a C program.
dnl This should either be a default one or the one specified.
dnl Note that macros are not local, but there is a stack so push
dnl the definition on to the stack to prevent clobbering a definition
dnl that might already exist.
m4_if([$2],[],[pushdef(prog, [int main(){}])], [pushdef(prog, [$2])])
flag_test=0
dnl See if the compiler runs
AC_COMPILE_IFELSE([AC_LANG_SOURCE([prog])], [flag_test=1],[flag_test=0])
dnl De-clobber the "prog" macro
popdef([prog])
if test $flag_test = 1
then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
dnl The flag doesn't work, so restore the old OBJCFLAGS
OBJCFLAGS="$save_CFLAGS"
fi
])
# test and set compiler flags
# based on:
# https://airbus-seclab.github.io/c-compiler-security/clang_compilation.html
# https://developers.redhat.com/articles/2022/06/02/use-compiler-flags-stack-protection-gcc-and-clang
TEST_AND_SET_CFLAG(-W)
TEST_AND_SET_CFLAG(-Wall)
TEST_AND_SET_CFLAG(-Wextra)
TEST_AND_SET_CFLAG(-Wpedantic)
TEST_AND_SET_CFLAG(-Werror)
TEST_AND_SET_CFLAG(-Wformat=2)
TEST_AND_SET_CFLAG(-Wformat-nonliteral)
TEST_AND_SET_CFLAG(-Wformat-overflow=2)
TEST_AND_SET_CFLAG(-Wformat-truncation=2)
TEST_AND_SET_CFLAG(-Wformat-security)
TEST_AND_SET_CFLAG(-Wformat-y2k)
TEST_AND_SET_CFLAG(-Wformat-signedness)
TEST_AND_SET_CFLAG(-Wtrampolines)
TEST_AND_SET_CFLAG(-Walloca)
TEST_AND_SET_CFLAG(-Wcast-qual)
TEST_AND_SET_CFLAG(-Wconversion)
TEST_AND_SET_CFLAG(-Wtraditional-conversion)
TEST_AND_SET_CFLAG(-Warith-conversion)
TEST_AND_SET_CFLAG(-Wstack-protector)
TEST_AND_SET_CFLAG(-Wstack-usage)
TEST_AND_SET_CFLAG(-Winfinite-recursion)
TEST_AND_SET_CFLAG(-Wnull-dereference)
TEST_AND_SET_CFLAG(-Wvla)
TEST_AND_SET_CFLAG(-Warray-bounds-pointer-arithmetic)
TEST_AND_SET_CFLAG(-Warray-bounds=2)
TEST_AND_SET_CFLAG(-Wimplicit-fallthrough)
TEST_AND_SET_CFLAG(-Wconditional-uninitialized)
TEST_AND_SET_CFLAG(-Wloop-analysis)
TEST_AND_SET_CFLAG(-Wshift-sign-overflow)
TEST_AND_SET_CFLAG(-Wshift-overflow=2)
TEST_AND_SET_CFLAG(-Wstringop-overflow=4)
TEST_AND_SET_CFLAG(-Wswitch-default)
TEST_AND_SET_CFLAG(-Wswitch-enum)
TEST_AND_SET_CFLAG(-Wtautological-constant-in-range-compare)
TEST_AND_SET_CFLAG(-Wcomma)
TEST_AND_SET_CFLAG(-Wassign-enum)
TEST_AND_SET_CFLAG(-Wbad-function-cast)
TEST_AND_SET_CFLAG(-Wfloat-equal)
TEST_AND_SET_CFLAG(-Wformat-type-confusion)
TEST_AND_SET_CFLAG(-Wpointer-arith)
TEST_AND_SET_CFLAG(-Widiomatic-parentheses)
TEST_AND_SET_CFLAG(-Wunreachable-code-aggressive)
TEST_AND_SET_CFLAG(-Wthread-safety)
TEST_AND_SET_CFLAG(-Wstrict-overflow=5)
TEST_AND_SET_CFLAG(-Wstrict-prototypes)
TEST_AND_SET_CFLAG(-Wmissing-declarations)
TEST_AND_SET_CFLAG(-Wmissing-prototypes)
TEST_AND_SET_CFLAG(-Wshadow)
TEST_AND_SET_CFLAG(-Wcast-align)
TEST_AND_SET_CFLAG(-Wjump-misses-init)
TEST_AND_SET_CFLAG(-Wunused)
TEST_AND_SET_CFLAG(-Wno-missing-braces)
TEST_AND_SET_CFLAG(-Werror=implicit-function-declaration)
TEST_AND_SET_CFLAG(-Wold-style-cast)
TEST_AND_SET_CFLAG(-Wlogical-op)
TEST_AND_SET_CFLAG(-Wduplicated-cond)
TEST_AND_SET_CFLAG(-Wduplicated-branches)
TEST_AND_SET_CFLAG(-Wundef)
TEST_AND_SET_CFLAG(-fstack-usage)
TEST_AND_SET_CFLAG(-fstack-protector-all)
TEST_AND_SET_CFLAG(-fstack-protector-strong)
TEST_AND_SET_CFLAG(-fstack-protector-explicit)
TEST_AND_SET_CFLAG(-mshstk)
TEST_AND_SET_CFLAG(-fsanitize=safe-stack)
# Not support on MacOSX
#TEST_AND_SET_CFLAG(-fsanitize=shadow-call-stack)
TEST_AND_SET_CFLAG(-fsanitize=cfi)
TEST_AND_SET_CFLAG(-fsanitize=memory)
TEST_AND_SET_CFLAG(-fsanitize=integer)
TEST_AND_SET_CFLAG(-fsanitize=address)
TEST_AND_SET_CFLAG(-fsanitize=thread)
TEST_AND_SET_CFLAG(-fsanitize=leak)
TEST_AND_SET_CFLAG(-fsanitize=undefined)
TEST_AND_SET_CFLAG(-fno-sanitize-recover=all)
TEST_AND_SET_CFLAG(-fcf-protection=full)
TEST_AND_SET_CFLAG(-fpic)
TEST_AND_SET_CFLAG(-fPIE)
TEST_AND_SET_CFLAG(-fstack-clash-protection)
TEST_AND_SET_CFLAG(-pedantic)
TEST_AND_SET_CFLAG(-pedantic-errors)
TEST_AND_SET_CFLAG(-D_FORTIFY_SOURCE=2)
TEST_AND_SET_CFLAG(-D_GLIBCXX_ASSERTIONS)
TEST_AND_SET_CFLAG(-fasynchronous-unwind-tables)
TEST_AND_SET_CFLAG(-fwrapv)
TEST_AND_SET_CFLAG(-flto)
TEST_AND_SET_CFLAG(-fsplit-stack)
TEST_AND_SET_CFLAG(-fstack-limit-register)
TEST_AND_SET_CFLAG(-fstack-limit-symbol)
TEST_AND_SET_CFLAG(-fno-stack-array)
#TEST_AND_SET_CFLAG(-mbranch-protection=standard)
OBJCFLAGS="$OBJCFLAGS $CFLAGS"
dnl Process Makefile.in to create Makefile
AC_CONFIG_FILES([Makefile])
AC_SUBST([PGM_SRCS])
AC_OUTPUT