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