-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
333 lines (281 loc) · 10.3 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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
dnl -*- Autoconf -*-
dnl Process this file with autoconf to produce a configure script.
AC_INIT([displayutil],[0.4.6],[ranga@calalum.org])
AC_CANONICAL_BUILD
# 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
AC_CONFIG_SRCDIR([displayutil.m])
# Check basic types.
AC_C_CONST
# basic source files
PGM_SRCS="displayutil_listDisplays.m displayutil_grayscale.m"
PGM_SRCS="$PGM_SRCS displayutil_brightness.m displayutil_argutils.m"
PGM_SRCS="$PGM_SRCS displayutil_resolution.m displayutil_display.m"
PGM_SRCS="$PGM_SRCS displayutil.m"
# check for libm
AC_MSG_CHECKING([for libm])
LIBS="$LIBS -lm"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <math.h>], [
sqrt(2)])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_ERROR([libm is required])
else
AC_MSG_RESULT([yes])
fi
# check for frameworks
LIBS="$LIBS -F /System/Library/PrivateFrameworks"
# check for ApplicationServices
AC_MSG_CHECKING([for ApplicationServices])
LIBS="$LIBS -framework ApplicationServices"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <ApplicationServices/ApplicationServices.h>], [])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_ERROR([ApplicationServices is required])
else
AC_MSG_RESULT([yes])
fi
# check for Foundation
AC_MSG_CHECKING([for Foundation])
LIBS="$LIBS -framework Foundation"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <Foundation/Foundation.h>], [])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_ERROR([Foundation is required])
else
AC_MSG_RESULT([yes])
fi
# check for CoreBrightness (for nightshift and truetone)
AC_MSG_CHECKING([for Night Shift support in CoreBrightness])
SAVE_LIBS="$LIBS"
LIBS="$LIBS -framework CoreBrightness"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <Foundation/Foundation.h>
#import "./CBBlueLightClient.h"], [
CBBlueLightClient *blueLightClient = nil;])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_RESULT([no])
LIBS="$SAVE_LIBS"
CFLAGS="$CFLAGS -DNO_NS -DNO_TT"
else
AC_MSG_RESULT([yes])
PGM_SRCS="$PGM_SRCS displayutil_nightshift.m"
# since CoreBrightness is available, check if it supports truetone
AC_MSG_CHECKING([for True Tone support in CoreBrightness])
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <Foundation/Foundation.h>
#import "./CBTrueToneClient.h"], [
CBTrueToneClient *trueToneClient = nil;])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_RESULT([no])
CFLAGS="$CFLAGS -DNO_TT"
else
AC_MSG_RESULT([yes])
PGM_SRCS="$PGM_SRCS displayutil_truetone.m"
fi
fi
# check for Skylight (for darkmode)
AC_MSG_CHECKING([for SkyLight])
SAVE_LIBS="$LIBS"
LIBS="$LIBS -framework SkyLight"
AC_LINK_IFELSE([AC_LANG_PROGRAM([#import <ApplicationServices/ApplicationServices.h>], [
extern BOOL SLSGetAppearanceThemeLegacy(void);])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_RESULT([no])
LIBS="$SAVE_LIBS"
CFLAGS="$CFLAGS -DNO_DM"
else
AC_MSG_RESULT([yes])
PGM_SRCS="$PGM_SRCS displayutil_darkmode.m"
fi
# check for DisplayServices (for brightness)
AC_MSG_CHECKING([for DisplayServices])
SAVE_LIBS="$LIBS"
LIBS="$LIBS -framework DisplayServices"
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#import <ApplicationServices/ApplicationServices.h>
], [
extern int DisplayServicesGetBrightness(CGDirectDisplayID id,
float *brightness)
__attribute__((weak_import));])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_RESULT([no])
LIBS="$SAVE_LIBS"
else
AC_MSG_RESULT([yes])
CFLAGS="$CFLAGS -DUSE_DS"
fi
# check for UniversalAccess (for grayscale)
AC_MSG_CHECKING([for UniversalAccess])
SAVE_LIBS="$LIBS"
LIBS="$LIBS -framework UniversalAccess -lUniversalAccess"
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
extern void UAGrayscaleSetEnabled(int enabled);])
],[has_framework=1],[has_framework=0])
if test $has_framework = 0; then
AC_MSG_RESULT([no])
LIBS="$SAVE_LIBS"
else
AC_MSG_RESULT([yes])
CFLAGS="$CFLAGS -DUSE_UA"
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
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)
# disable due to warnings on Ventura
#TEST_AND_SET_CFLAG(-Wformat-overflow=2)
#TEST_AND_SET_CFLAG(-Wformat-truncation=2)
#TEST_AND_SET_CFLAG(-Wformat-signedness)
#TEST_AND_SET_CFLAG(-Wtraditional-conversion)
#TEST_AND_SET_CFLAG(-Warith-conversion)
#TEST_AND_SET_CFLAG(-Wstack-usage)
#TEST_AND_SET_CFLAG(-Wstringop-overflow=4)
#TEST_AND_SET_CFLAG(-Wjump-misses-init)
#TEST_AND_SET_CFLAG(-Wtrampolines)
TEST_AND_SET_CFLAG(-Wformat-security)
TEST_AND_SET_CFLAG(-Wformat-y2k)
TEST_AND_SET_CFLAG(-Walloca)
#TEST_AND_SET_CFLAG(-Wcast-qual)
TEST_AND_SET_CFLAG(-Wconversion)
TEST_AND_SET_CFLAG(-Wstack-protector)
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)
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)
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(-Wunused)
TEST_AND_SET_CFLAG(-Wno-missing-braces)
TEST_AND_SET_CFLAG(-Werror=implicit-function-declaration)
TEST_AND_SET_CFLAG(-Wold-style-cast)
# disable due to warnings on Ventura
#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)
# disable due to warnings on Ventura
#TEST_AND_SET_CFLAG(-mshstk)
TEST_AND_SET_CFLAG(-fcf-protection=full)
TEST_AND_SET_CFLAG(-fpic)
TEST_AND_SET_CFLAG(-fPIE)
# disable due to warnings on Ventura
#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(-fstack-limit-register)
TEST_AND_SET_CFLAG(-fstack-limit-symbol)
TEST_AND_SET_CFLAG(-fno-stack-array)
# temporarily disable
#TEST_AND_SET_CFLAG(-mbranch-protection=standard)
# optimize the size of the executable
# based on: https://serge-sans-paille.github.io/pythran-stories/shrinking-a-shared-library.html
TEST_AND_SET_CFLAG(-Oz)
TEST_AND_SET_CFLAG(-flto=full)
TEST_AND_SET_CFLAG(-gline-tables-only)
# test and set these options on arm only
# see: https://stackoverflow.com/questions/64126942/
case "$build_cpu" in
aarch64)
TEST_AND_SET_CFLAG(-fsanitize=safe-stack)
#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)
# disable due to runtime warnings from libmalloc
# on Ventura, see:
# https://stackoverflow.com/questions/64126942
#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)
;;
esac
OBJCFLAGS="$OBJCFLAGS $CFLAGS"
dnl Process Makefile.in to create Makefile
AC_CONFIG_FILES([Makefile])
AC_SUBST([PGM_SRCS])
AC_OUTPUT