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