]> git.ipfire.org Git - thirdparty/cups.git/blob - config-scripts/cups-compiler.m4
Merge pull request #5621 from zdohnal/cgigetarray-sigsegv
[thirdparty/cups.git] / config-scripts / cups-compiler.m4
1 dnl
2 dnl Compiler stuff for CUPS.
3 dnl
4 dnl Copyright 2007-2018 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 AC_SUBST(INSTALL_STRIP)
14
15 AC_ARG_WITH(optim, [ --with-optim set optimization flags ],
16 OPTIM="$withval",
17 OPTIM="")
18 AC_SUBST(OPTIM)
19
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])
24
25 dnl For debugging, keep symbols, otherwise strip them...
26 if test x$enable_debug = xyes -a "x$OPTIM" = x; then
27 OPTIM="-g"
28 else
29 INSTALL_STRIP="-s"
30 fi
31
32 dnl Debug printfs can slow things down, so provide a separate option for that
33 if test x$enable_debug_printfs = xyes; then
34 CFLAGS="$CFLAGS -DDEBUG"
35 CXXFLAGS="$CXXFLAGS -DDEBUG"
36 fi
37
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"
42 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
43 fi
44
45 dnl Unit tests take up time during a compile...
46 if test x$enable_unit_tests = xyes; then
47 if test "$build" != "$host"; then
48 AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
49 fi
50
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 "$host_os_name" = 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 Clang/GCC address sanitizer...
85 AC_ARG_ENABLE(sanitizer, [ --enable-sanitizer build with AddressSanitizer])
86
87 dnl Update compiler options...
88 CXXLIBS="${CXXLIBS:=}"
89 AC_SUBST(CXXLIBS)
90
91 PIEFLAGS=""
92 AC_SUBST(PIEFLAGS)
93
94 RELROFLAGS=""
95 AC_SUBST(RELROFLAGS)
96
97 WARNING_OPTIONS=""
98 AC_SUBST(WARNING_OPTIONS)
99
100 if test -n "$GCC"; then
101 # Add GCC-specific compiler options...
102
103 # Address sanitizer is a useful tool to use when developing/debugging
104 # code but adds about 2x overhead...
105 if test x$enable_sanitizer = xyes; then
106 # Use -fsanitize=address with debugging...
107 OPTIM="$OPTIM -g -fsanitize=address"
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
114
115 # Default optimization options...
116 if test -z "$OPTIM"; then
117 # Default to optimize-for-size and debug
118 OPTIM="-Os -g"
119 fi
120
121 # Generate position-independent code as needed...
122 if test $PICFLAG = 1; then
123 OPTIM="-fPIC $OPTIM"
124 fi
125
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.
129 AC_MSG_CHECKING(whether compiler supports -fstack-protector)
130 OLDCFLAGS="$CFLAGS"
131 CFLAGS="$CFLAGS -fstack-protector"
132 AC_TRY_LINK(,,
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
139 AC_MSG_RESULT(yes),
140 AC_MSG_RESULT(no))
141 CFLAGS="$OLDCFLAGS"
142
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...
149 AC_MSG_CHECKING(whether compiler supports -fPIE)
150 OLDCFLAGS="$CFLAGS"
151 case "$host_os_name" in
152 darwin*)
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
168 CFLAGS="$OLDCFLAGS"
169 fi
170
171 # Add useful warning options for tracking down problems...
172 WARNING_OPTIONS="-Wall -Wno-format-y2k -Wunused -Wno-unused-result -Wsign-conversion"
173
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
178 1.* | 2.* | 3.* | 4.* | 5.* | 6.* | \(clang-*)
179 ;;
180 *)
181 WARNING_OPTIONS="$WARNING_OPTIONS -Wno-format-truncation -Wno-format-overflow -Wno-tautological-compare"
182 ;;
183 esac
184
185 # Additional warning options for development testing...
186 if test -d .git; then
187 WARNING_OPTIONS="-Werror -Wno-error=deprecated-declarations $WARNING_OPTIONS"
188 fi
189 else
190 # Add vendor-specific compiler options...
191 case $host_os_name in
192 sunos*)
193 # Solaris
194 if test -z "$OPTIM"; then
195 OPTIM="-xO2"
196 fi
197
198 if test $PICFLAG = 1; then
199 OPTIM="-KPIC $OPTIM"
200 fi
201 ;;
202 *)
203 # Running some other operating system; inform the user
204 # they should contribute the necessary options via
205 # Github...
206 echo "Building CUPS with default compiler optimizations; contact the CUPS developers on Github"
207 echo "(https://github.com/apple/cups/issues) with the uname and compiler options needed for"
208 echo "your platform, or set the CFLAGS and LDFLAGS environment variables before running"
209 echo "configure."
210 ;;
211 esac
212 fi
213
214 # Add general compiler options per platform...
215 case $host_os_name in
216 linux*)
217 # glibc 2.8 and higher breaks peer credentials unless you
218 # define _GNU_SOURCE...
219 OPTIM="$OPTIM -D_GNU_SOURCE"
220
221 # The -z relro option is provided by the Linux linker command to
222 # make relocatable data read-only.
223 if test x$enable_relro = xyes; then
224 RELROFLAGS="-Wl,-z,relro,-z,now"
225 fi
226 ;;
227 esac