]>
Commit | Line | Data |
---|---|---|
1 | dnl | |
2 | dnl "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $" | |
3 | dnl | |
4 | dnl Compiler stuff for CUPS. | |
5 | dnl | |
6 | dnl Copyright 2007-2013 by Apple Inc. | |
7 | dnl Copyright 1997-2007 by Easy Software Products, all rights reserved. | |
8 | dnl | |
9 | dnl These coded instructions, statements, and computer programs are the | |
10 | dnl property of Apple Inc. and are protected by Federal copyright | |
11 | dnl law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | dnl which should have been included with this file. If this file is | |
13 | dnl file is missing or damaged, see the license at "http://www.cups.org/". | |
14 | dnl | |
15 | ||
16 | dnl Clear the debugging and non-shared library options unless the user asks | |
17 | dnl for them... | |
18 | INSTALL_STRIP="" | |
19 | OPTIM="" | |
20 | AC_SUBST(INSTALL_STRIP) | |
21 | AC_SUBST(OPTIM) | |
22 | ||
23 | AC_ARG_WITH(optim, [ --with-optim set optimization flags ]) | |
24 | AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols]) | |
25 | AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards]) | |
26 | AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support]) | |
27 | AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests]) | |
28 | ||
29 | dnl For debugging, keep symbols, otherwise strip them... | |
30 | if test x$enable_debug = xyes; then | |
31 | OPTIM="-g" | |
32 | else | |
33 | INSTALL_STRIP="-s" | |
34 | fi | |
35 | ||
36 | dnl Debug printfs can slow things down, so provide a separate option for that | |
37 | if test x$enable_debug_printfs = xyes; then | |
38 | CFLAGS="$CFLAGS -DDEBUG" | |
39 | CXXFLAGS="$CXXFLAGS -DDEBUG" | |
40 | fi | |
41 | ||
42 | dnl Debug guards use an extra 4 bytes for some structures like strings in the | |
43 | dnl string pool, so provide a separate option for that | |
44 | if test x$enable_debug_guards = xyes; then | |
45 | CFLAGS="$CFLAGS -DDEBUG_GUARDS" | |
46 | CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS" | |
47 | fi | |
48 | ||
49 | dnl Unit tests take up time during a compile... | |
50 | if test x$enable_unit_tests = xyes; then | |
51 | UNITTESTS="unittests" | |
52 | else | |
53 | UNITTESTS="" | |
54 | fi | |
55 | AC_SUBST(UNITTESTS) | |
56 | ||
57 | dnl Setup general architecture flags... | |
58 | AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ]) | |
59 | AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ]) | |
60 | ||
61 | if test -z "$with_archflags"; then | |
62 | ARCHFLAGS="" | |
63 | else | |
64 | ARCHFLAGS="$with_archflags" | |
65 | fi | |
66 | ||
67 | if test -z "$with_ldarchflags"; then | |
68 | if test "$uname" = Darwin; then | |
69 | # Only create Intel programs by default | |
70 | LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`" | |
71 | else | |
72 | LDARCHFLAGS="$ARCHFLAGS" | |
73 | fi | |
74 | else | |
75 | LDARCHFLAGS="$with_ldarchflags" | |
76 | fi | |
77 | ||
78 | AC_SUBST(ARCHFLAGS) | |
79 | AC_SUBST(LDARCHFLAGS) | |
80 | ||
81 | dnl Read-only data/program support on Linux... | |
82 | AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option]) | |
83 | ||
84 | dnl Update compiler options... | |
85 | CXXLIBS="${CXXLIBS:=}" | |
86 | AC_SUBST(CXXLIBS) | |
87 | ||
88 | PIEFLAGS="" | |
89 | AC_SUBST(PIEFLAGS) | |
90 | ||
91 | RELROFLAGS="" | |
92 | AC_SUBST(RELROFLAGS) | |
93 | ||
94 | if test -n "$GCC"; then | |
95 | # Add GCC-specific compiler options... | |
96 | if test -z "$OPTIM"; then | |
97 | if test "x$with_optim" = x; then | |
98 | # Default to optimize-for-size and debug | |
99 | OPTIM="-Os -g" | |
100 | else | |
101 | OPTIM="$with_optim $OPTIM" | |
102 | fi | |
103 | fi | |
104 | ||
105 | # Generate position-independent code as needed... | |
106 | if test $PICFLAG = 1 -a $uname != AIX; then | |
107 | OPTIM="-fPIC $OPTIM" | |
108 | fi | |
109 | ||
110 | # The -fstack-protector option is available with some versions of | |
111 | # GCC and adds "stack canaries" which detect when the return address | |
112 | # has been overwritten, preventing many types of exploit attacks. | |
113 | AC_MSG_CHECKING(if GCC supports -fstack-protector) | |
114 | OLDCFLAGS="$CFLAGS" | |
115 | CFLAGS="$CFLAGS -fstack-protector" | |
116 | AC_TRY_LINK(,, | |
117 | if test "x$LSB_BUILD" = xy; then | |
118 | # Can't use stack-protector with LSB binaries... | |
119 | OPTIM="$OPTIM -fno-stack-protector" | |
120 | else | |
121 | OPTIM="$OPTIM -fstack-protector" | |
122 | fi | |
123 | AC_MSG_RESULT(yes), | |
124 | AC_MSG_RESULT(no)) | |
125 | CFLAGS="$OLDCFLAGS" | |
126 | ||
127 | if test "x$LSB_BUILD" != xy; then | |
128 | # The -fPIE option is available with some versions of GCC and | |
129 | # adds randomization of addresses, which avoids another class of | |
130 | # exploits that depend on a fixed address for common functions. | |
131 | # | |
132 | # Not available to LSB binaries... | |
133 | AC_MSG_CHECKING(if GCC supports -fPIE) | |
134 | OLDCFLAGS="$CFLAGS" | |
135 | case "$uname" in | |
136 | Darwin*) | |
137 | CFLAGS="$CFLAGS -fPIE -Wl,-pie" | |
138 | AC_TRY_COMPILE(,,[ | |
139 | PIEFLAGS="-fPIE -Wl,-pie" | |
140 | AC_MSG_RESULT(yes)], | |
141 | AC_MSG_RESULT(no)) | |
142 | ;; | |
143 | ||
144 | *) | |
145 | CFLAGS="$CFLAGS -fPIE -pie" | |
146 | AC_TRY_COMPILE(,,[ | |
147 | PIEFLAGS="-fPIE -pie" | |
148 | AC_MSG_RESULT(yes)], | |
149 | AC_MSG_RESULT(no)) | |
150 | ;; | |
151 | esac | |
152 | CFLAGS="$OLDCFLAGS" | |
153 | fi | |
154 | ||
155 | if test "x$with_optim" = x; then | |
156 | # Add useful warning options for tracking down problems... | |
157 | OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM" | |
158 | ||
159 | # Additional warning options for development testing... | |
160 | if test -d .svn; then | |
161 | OPTIM="-Wshadow -Werror $OPTIM" | |
162 | else | |
163 | AC_MSG_CHECKING(if GCC supports -Wno-tautological-compare) | |
164 | OLDCFLAGS="$CFLAGS" | |
165 | CFLAGS="$CFLAGS -Werror -Wno-tautological-compare" | |
166 | AC_TRY_COMPILE(,, | |
167 | [OPTIM="$OPTIM -Wno-tautological-compare" | |
168 | AC_MSG_RESULT(yes)], | |
169 | AC_MSG_RESULT(no)) | |
170 | CFLAGS="$OLDCFLAGS" | |
171 | fi | |
172 | fi | |
173 | ||
174 | case "$uname" in | |
175 | Darwin*) | |
176 | # -D_FORTIFY_SOURCE=2 adds additional object size | |
177 | # checking, basically wrapping all string functions | |
178 | # with buffer-limited ones. Not strictly needed for | |
179 | # CUPS since we already use buffer-limited calls, but | |
180 | # this will catch any additions that are broken. | |
181 | CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" | |
182 | ;; | |
183 | ||
184 | Linux*) | |
185 | # The -z relro option is provided by the Linux linker command to | |
186 | # make relocatable data read-only. | |
187 | if test x$enable_relro = xyes; then | |
188 | RELROFLAGS="-Wl,-z,relro" | |
189 | fi | |
190 | ;; | |
191 | esac | |
192 | else | |
193 | # Add vendor-specific compiler options... | |
194 | case $uname in | |
195 | AIX*) | |
196 | if test -z "$OPTIM"; then | |
197 | if test "x$with_optim" = x; then | |
198 | OPTIM="-O2 -qmaxmem=6000" | |
199 | else | |
200 | OPTIM="$with_optim $OPTIM" | |
201 | fi | |
202 | fi | |
203 | ;; | |
204 | HP-UX*) | |
205 | if test -z "$OPTIM"; then | |
206 | if test "x$with_optim" = x; then | |
207 | OPTIM="+O2" | |
208 | else | |
209 | OPTIM="$with_optim $OPTIM" | |
210 | fi | |
211 | fi | |
212 | ||
213 | CFLAGS="-Ae $CFLAGS" | |
214 | ||
215 | if test $PICFLAG = 1; then | |
216 | OPTIM="+z $OPTIM" | |
217 | fi | |
218 | ;; | |
219 | OSF*) | |
220 | # Tru64 UNIX aka Digital UNIX aka OSF/1 | |
221 | if test -z "$OPTIM"; then | |
222 | if test "x$with_optim" = x; then | |
223 | OPTIM="-O" | |
224 | else | |
225 | OPTIM="$with_optim" | |
226 | fi | |
227 | fi | |
228 | ;; | |
229 | SunOS*) | |
230 | # Solaris | |
231 | if test -z "$OPTIM"; then | |
232 | if test "x$with_optim" = x; then | |
233 | OPTIM="-xO2" | |
234 | else | |
235 | OPTIM="$with_optim $OPTIM" | |
236 | fi | |
237 | fi | |
238 | ||
239 | if test $PICFLAG = 1; then | |
240 | OPTIM="-KPIC $OPTIM" | |
241 | fi | |
242 | ;; | |
243 | UNIX_SVR*) | |
244 | # UnixWare | |
245 | if test -z "$OPTIM"; then | |
246 | if test "x$with_optim" = x; then | |
247 | OPTIM="-O" | |
248 | else | |
249 | OPTIM="$with_optim $OPTIM" | |
250 | fi | |
251 | fi | |
252 | ||
253 | if test $PICFLAG = 1; then | |
254 | OPTIM="-KPIC $OPTIM" | |
255 | fi | |
256 | ;; | |
257 | *) | |
258 | # Running some other operating system; inform the user they | |
259 | # should contribute the necessary options to | |
260 | # cups-support@cups.org... | |
261 | echo "Building CUPS with default compiler optimizations; contact" | |
262 | echo "cups-bugs@cups.org with uname and compiler options needed" | |
263 | echo "for your platform, or set the CFLAGS and LDFLAGS environment" | |
264 | echo "variables before running configure." | |
265 | ;; | |
266 | esac | |
267 | fi | |
268 | ||
269 | # Add general compiler options per platform... | |
270 | case $uname in | |
271 | HP-UX*) | |
272 | # HP-UX 10.20 (at least) needs this definition to get the | |
273 | # h_errno global... | |
274 | OPTIM="$OPTIM -D_XOPEN_SOURCE_EXTENDED" | |
275 | ||
276 | # HP-UX 11.00 (at least) needs this definition to get the | |
277 | # u_short type used by the IP headers... | |
278 | OPTIM="$OPTIM -D_INCLUDE_HPUX_SOURCE" | |
279 | ||
280 | # HP-UX 11.23 (at least) needs this definition to get the | |
281 | # IPv6 header to work... | |
282 | OPTIM="$OPTIM -D_HPUX_SOURCE" | |
283 | ;; | |
284 | ||
285 | Linux*) | |
286 | # glibc 2.8 and higher breaks peer credentials unless you | |
287 | # define _GNU_SOURCE... | |
288 | OPTIM="$OPTIM -D_GNU_SOURCE" | |
289 | ;; | |
290 | ||
291 | OSF*) | |
292 | # Tru64 UNIX aka Digital UNIX aka OSF/1 need to be told | |
293 | # to be POSIX-compliant... | |
294 | OPTIM="$OPTIM -D_XOPEN_SOURCE=500 -D_XOPEN_SOURCE_EXTENDED -D_OSF_SOURCE" | |
295 | ;; | |
296 | esac | |
297 | ||
298 | dnl | |
299 | dnl End of "$Id: cups-compiler.m4 7871 2008-08-27 21:12:43Z mike $". | |
300 | dnl |