]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | dnl |
5a1d7a17 | 2 | dnl Compiler stuff for CUPS. |
ef416fc2 | 3 | dnl |
6276d173 | 4 | dnl Copyright 2007-2018 by Apple Inc. |
5a1d7a17 | 5 | dnl Copyright 1997-2007 by Easy Software Products, all rights reserved. |
ef416fc2 | 6 | dnl |
e3101897 | 7 | dnl Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
ef416fc2 | 8 | dnl |
9 | ||
10 | dnl Clear the debugging and non-shared library options unless the user asks | |
11 | dnl for them... | |
50fe7201 | 12 | INSTALL_STRIP="" |
50fe7201 | 13 | AC_SUBST(INSTALL_STRIP) |
f518bf7e MS |
14 | |
15 | AC_ARG_WITH(optim, [ --with-optim set optimization flags ], | |
16 | OPTIM="$withval", | |
17 | OPTIM="") | |
ef416fc2 | 18 | AC_SUBST(OPTIM) |
19 | ||
bf3816c7 MS |
20 | AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols]) |
21 | AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards]) | |
22 | AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support]) | |
23 | AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests]) | |
839a51c8 MS |
24 | |
25 | dnl For debugging, keep symbols, otherwise strip them... | |
f518bf7e | 26 | if test x$enable_debug = xyes -a "x$OPTIM" = x; then |
839a51c8 MS |
27 | OPTIM="-g" |
28 | else | |
29 | INSTALL_STRIP="-s" | |
30 | fi | |
ef416fc2 | 31 | |
5f64df29 | 32 | dnl Debug printfs can slow things down, so provide a separate option for that |
52f6f666 | 33 | if test x$enable_debug_printfs = xyes; then |
5f64df29 | 34 | CFLAGS="$CFLAGS -DDEBUG" |
94da7e34 | 35 | CXXFLAGS="$CXXFLAGS -DDEBUG" |
5f64df29 MS |
36 | fi |
37 | ||
745129be MS |
38 | dnl Debug guards use an extra 4 bytes for some structures like strings in the |
39 | dnl string pool, so provide a separate option for that | |
40 | if test x$enable_debug_guards = xyes; then | |
41 | CFLAGS="$CFLAGS -DDEBUG_GUARDS" | |
94da7e34 | 42 | CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS" |
745129be MS |
43 | fi |
44 | ||
5f64df29 MS |
45 | dnl Unit tests take up time during a compile... |
46 | if test x$enable_unit_tests = xyes; then | |
105922ec MS |
47 | if test "$build" != "$host"; then |
48 | AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.]) | |
49 | fi | |
50 | ||
5f64df29 MS |
51 | UNITTESTS="unittests" |
52 | else | |
53 | UNITTESTS="" | |
54 | fi | |
55 | AC_SUBST(UNITTESTS) | |
56 | ||
ed486911 | 57 | dnl Setup general architecture flags... |
bf3816c7 MS |
58 | AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ]) |
59 | AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ]) | |
ed486911 | 60 | |
61 | if test -z "$with_archflags"; then | |
62 | ARCHFLAGS="" | |
63 | else | |
64 | ARCHFLAGS="$with_archflags" | |
a603edef MS |
65 | fi |
66 | ||
67 | if test -z "$with_ldarchflags"; then | |
105922ec | 68 | if test "$host_os_name" = darwin; then |
12f89d24 MS |
69 | # Only create Intel programs by default |
70 | LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`" | |
09a101d6 | 71 | else |
72 | LDARCHFLAGS="$ARCHFLAGS" | |
73 | fi | |
a603edef | 74 | else |
839a51c8 | 75 | LDARCHFLAGS="$with_ldarchflags" |
ed486911 | 76 | fi |
77 | ||
78 | AC_SUBST(ARCHFLAGS) | |
09a101d6 | 79 | AC_SUBST(LDARCHFLAGS) |
ed486911 | 80 | |
f7deaa1a | 81 | dnl Read-only data/program support on Linux... |
bf3816c7 | 82 | AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option]) |
f7deaa1a | 83 | |
f518bf7e MS |
84 | dnl Clang/GCC address sanitizer... |
85 | AC_ARG_ENABLE(sanitizer, [ --enable-sanitizer build with AddressSanitizer]) | |
86 | ||
ef416fc2 | 87 | dnl Update compiler options... |
ac884b6a MS |
88 | CXXLIBS="${CXXLIBS:=}" |
89 | AC_SUBST(CXXLIBS) | |
90 | ||
a74454a7 | 91 | PIEFLAGS="" |
92 | AC_SUBST(PIEFLAGS) | |
93 | ||
f7deaa1a | 94 | RELROFLAGS="" |
95 | AC_SUBST(RELROFLAGS) | |
96 | ||
f518bf7e MS |
97 | WARNING_OPTIONS="" |
98 | AC_SUBST(WARNING_OPTIONS) | |
99 | ||
ef416fc2 | 100 | if test -n "$GCC"; then |
2abf387c | 101 | # Add GCC-specific compiler options... |
f518bf7e MS |
102 | |
103 | # Address sanitizer is a useful tool to use when developing/debugging | |
104 | # code but adds about 2x overhead... | |
c028bdf7 MS |
105 | if test x$enable_sanitizer = xyes; then |
106 | # Use -fsanitize=address with debugging... | |
f518bf7e | 107 | OPTIM="$OPTIM -g -fsanitize=address" |
c028bdf7 MS |
108 | else |
109 | # Otherwise use the Fortify enhancements to catch any unbounded | |
110 | # string operations... | |
111 | CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" | |
112 | CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2" | |
113 | fi | |
f518bf7e MS |
114 | |
115 | # Default optimization options... | |
ef416fc2 | 116 | if test -z "$OPTIM"; then |
f518bf7e MS |
117 | # Default to optimize-for-size and debug |
118 | OPTIM="-Os -g" | |
ef416fc2 | 119 | fi |
120 | ||
a4924f6c | 121 | # Generate position-independent code as needed... |
5a1d7a17 | 122 | if test $PICFLAG = 1; then |
ef416fc2 | 123 | OPTIM="-fPIC $OPTIM" |
124 | fi | |
125 | ||
a4924f6c MS |
126 | # The -fstack-protector option is available with some versions of |
127 | # GCC and adds "stack canaries" which detect when the return address | |
128 | # has been overwritten, preventing many types of exploit attacks. | |
9483577f | 129 | AC_MSG_CHECKING(whether compiler supports -fstack-protector) |
a4924f6c MS |
130 | OLDCFLAGS="$CFLAGS" |
131 | CFLAGS="$CFLAGS -fstack-protector" | |
68b10830 | 132 | AC_TRY_LINK(,, |
db8b865d MS |
133 | if test "x$LSB_BUILD" = xy; then |
134 | # Can't use stack-protector with LSB binaries... | |
135 | OPTIM="$OPTIM -fno-stack-protector" | |
136 | else | |
137 | OPTIM="$OPTIM -fstack-protector" | |
138 | fi | |
a4924f6c MS |
139 | AC_MSG_RESULT(yes), |
140 | AC_MSG_RESULT(no)) | |
141 | CFLAGS="$OLDCFLAGS" | |
142 | ||
db8b865d MS |
143 | if test "x$LSB_BUILD" != xy; then |
144 | # The -fPIE option is available with some versions of GCC and | |
145 | # adds randomization of addresses, which avoids another class of | |
146 | # exploits that depend on a fixed address for common functions. | |
147 | # | |
148 | # Not available to LSB binaries... | |
9483577f | 149 | AC_MSG_CHECKING(whether compiler supports -fPIE) |
db8b865d | 150 | OLDCFLAGS="$CFLAGS" |
105922ec MS |
151 | case "$host_os_name" in |
152 | darwin*) | |
483fc76b MS |
153 | CFLAGS="$CFLAGS -fPIE -Wl,-pie" |
154 | AC_TRY_COMPILE(,,[ | |
155 | PIEFLAGS="-fPIE -Wl,-pie" | |
156 | AC_MSG_RESULT(yes)], | |
157 | AC_MSG_RESULT(no)) | |
158 | ;; | |
159 | ||
160 | *) | |
161 | CFLAGS="$CFLAGS -fPIE -pie" | |
162 | AC_TRY_COMPILE(,,[ | |
163 | PIEFLAGS="-fPIE -pie" | |
164 | AC_MSG_RESULT(yes)], | |
165 | AC_MSG_RESULT(no)) | |
166 | ;; | |
167 | esac | |
db8b865d MS |
168 | CFLAGS="$OLDCFLAGS" |
169 | fi | |
ef416fc2 | 170 | |
f518bf7e MS |
171 | # Add useful warning options for tracking down problems... |
172 | WARNING_OPTIONS="-Wall -Wno-format-y2k -Wunused -Wno-unused-result -Wsign-conversion" | |
f228370c | 173 | |
f518bf7e MS |
174 | # Test GCC version for certain warning flags since -Werror |
175 | # doesn't trigger... | |
176 | gccversion=`$CC --version | head -1 | awk '{print $NF}'` | |
177 | case "$gccversion" in | |
82e3ee0e | 178 | 7.* | 8.*) |
179 | WARNING_OPTIONS="$WARNING_OPTIONS -Wno-format-truncation -Wno-tautological-compare" | |
e1d6a774 | 180 | ;; |
181 | esac | |
f518bf7e MS |
182 | |
183 | # Additional warning options for development testing... | |
184 | if test -d .git; then | |
7d730d0c | 185 | WARNING_OPTIONS="-Werror -Wno-error=deprecated-declarations $WARNING_OPTIONS" |
f518bf7e | 186 | fi |
ef416fc2 | 187 | else |
2abf387c | 188 | # Add vendor-specific compiler options... |
105922ec MS |
189 | case $host_os_name in |
190 | sunos*) | |
ef416fc2 | 191 | # Solaris |
192 | if test -z "$OPTIM"; then | |
f518bf7e | 193 | OPTIM="-xO2" |
ef416fc2 | 194 | fi |
195 | ||
ef416fc2 | 196 | if test $PICFLAG = 1; then |
197 | OPTIM="-KPIC $OPTIM" | |
198 | fi | |
199 | ;; | |
200 | *) | |
f518bf7e MS |
201 | # Running some other operating system; inform the user |
202 | # they should contribute the necessary options via | |
203 | # Github... | |
204 | echo "Building CUPS with default compiler optimizations; contact the CUPS developers on Github" | |
205 | echo "(https://github.com/apple/cups/issues) with the uname and compiler options needed for" | |
206 | echo "your platform, or set the CFLAGS and LDFLAGS environment variables before running" | |
207 | echo "configure." | |
ef416fc2 | 208 | ;; |
209 | esac | |
210 | fi | |
211 | ||
2abf387c | 212 | # Add general compiler options per platform... |
105922ec MS |
213 | case $host_os_name in |
214 | linux*) | |
dd1abb6b MS |
215 | # glibc 2.8 and higher breaks peer credentials unless you |
216 | # define _GNU_SOURCE... | |
217 | OPTIM="$OPTIM -D_GNU_SOURCE" | |
f518bf7e MS |
218 | |
219 | # The -z relro option is provided by the Linux linker command to | |
220 | # make relocatable data read-only. | |
221 | if test x$enable_relro = xyes; then | |
222 | RELROFLAGS="-Wl,-z,relro,-z,now" | |
223 | fi | |
dd1abb6b | 224 | ;; |
2abf387c | 225 | esac |