]> git.ipfire.org Git - thirdparty/cups.git/blob - config-scripts/cups-compiler.m4
49963934f5ec6ecc1427d83a34faa9b64036c458
[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 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
11 dnl missing or damaged, see the license at "http://www.cups.org/".
12 dnl
13
14 dnl Clear the debugging and non-shared library options unless the user asks
15 dnl for them...
16 INSTALL_STRIP=""
17 OPTIM=""
18 AC_SUBST(INSTALL_STRIP)
19 AC_SUBST(OPTIM)
20
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])
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
33
34 dnl Debug printfs can slow things down, so provide a separate option for that
35 if test x$enable_debug_printfs = xyes; then
36 CFLAGS="$CFLAGS -DDEBUG"
37 CXXFLAGS="$CXXFLAGS -DDEBUG"
38 fi
39
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"
44 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
45 fi
46
47 dnl Unit tests take up time during a compile...
48 if test x$enable_unit_tests = xyes; then
49 if test "$build" != "$host"; then
50 AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
51 fi
52
53 UNITTESTS="unittests"
54 else
55 UNITTESTS=""
56 fi
57 AC_SUBST(UNITTESTS)
58
59 dnl Setup general architecture flags...
60 AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
61 AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
62
63 if test -z "$with_archflags"; then
64 ARCHFLAGS=""
65 else
66 ARCHFLAGS="$with_archflags"
67 fi
68
69 if test -z "$with_ldarchflags"; then
70 if test "$host_os_name" = darwin; then
71 # Only create Intel programs by default
72 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
73 else
74 LDARCHFLAGS="$ARCHFLAGS"
75 fi
76 else
77 LDARCHFLAGS="$with_ldarchflags"
78 fi
79
80 AC_SUBST(ARCHFLAGS)
81 AC_SUBST(LDARCHFLAGS)
82
83 dnl Read-only data/program support on Linux...
84 AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
85
86 dnl Update compiler options...
87 CXXLIBS="${CXXLIBS:=}"
88 AC_SUBST(CXXLIBS)
89
90 PIEFLAGS=""
91 AC_SUBST(PIEFLAGS)
92
93 RELROFLAGS=""
94 AC_SUBST(RELROFLAGS)
95
96 if test -n "$GCC"; then
97 # Add GCC-specific compiler options...
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
107 # Generate position-independent code as needed...
108 if test $PICFLAG = 1; then
109 OPTIM="-fPIC $OPTIM"
110 fi
111
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.
115 AC_MSG_CHECKING(whether compiler supports -fstack-protector)
116 OLDCFLAGS="$CFLAGS"
117 CFLAGS="$CFLAGS -fstack-protector"
118 AC_TRY_LINK(,,
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
125 AC_MSG_RESULT(yes),
126 AC_MSG_RESULT(no))
127 CFLAGS="$OLDCFLAGS"
128
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...
135 AC_MSG_CHECKING(whether compiler supports -fPIE)
136 OLDCFLAGS="$CFLAGS"
137 case "$host_os_name" in
138 darwin*)
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
154 CFLAGS="$OLDCFLAGS"
155 fi
156
157 if test "x$with_optim" = x; then
158 # Add useful warning options for tracking down problems...
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"
169
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)
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"
187
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
197 # Additional warning options for development testing...
198 if test -d .svn; then
199 OPTIM="-Werror $OPTIM"
200 fi
201 fi
202
203 case "$host_os_name" in
204 darwin*)
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
209 # this will catch any additions that are broken.
210 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
211 ;;
212
213 linux*)
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
217 RELROFLAGS="-Wl,-z,relro,-z,now"
218 fi
219 ;;
220 esac
221 else
222 # Add vendor-specific compiler options...
223 case $host_os_name in
224 sunos*)
225 # Solaris
226 if test -z "$OPTIM"; then
227 if test "x$with_optim" = x; then
228 OPTIM="-xO2"
229 else
230 OPTIM="$with_optim $OPTIM"
231 fi
232 fi
233
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"
243 echo "cups-devel@cups.org with uname and compiler options needed"
244 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
245 echo "variables before running configure."
246 ;;
247 esac
248 fi
249
250 # Add general compiler options per platform...
251 case $host_os_name in
252 linux*)
253 # glibc 2.8 and higher breaks peer credentials unless you
254 # define _GNU_SOURCE...
255 OPTIM="$OPTIM -D_GNU_SOURCE"
256 ;;
257 esac