]> git.ipfire.org Git - thirdparty/cups.git/blame - config-scripts/cups-compiler.m4
Update version to 2.3.3 for:
[thirdparty/cups.git] / config-scripts / cups-compiler.m4
CommitLineData
ef416fc2 1dnl
5a1d7a17 2dnl Compiler stuff for CUPS.
ef416fc2 3dnl
6276d173 4dnl Copyright 2007-2018 by Apple Inc.
5a1d7a17 5dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
ef416fc2 6dnl
e3101897 7dnl Licensed under Apache License v2.0. See the file "LICENSE" for more information.
ef416fc2 8dnl
9
10dnl Clear the debugging and non-shared library options unless the user asks
11dnl for them...
50fe7201 12INSTALL_STRIP=""
50fe7201 13AC_SUBST(INSTALL_STRIP)
f518bf7e
MS
14
15AC_ARG_WITH(optim, [ --with-optim set optimization flags ],
16 OPTIM="$withval",
17 OPTIM="")
ef416fc2 18AC_SUBST(OPTIM)
19
bf3816c7
MS
20AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
21AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
22AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
23AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
839a51c8
MS
24
25dnl For debugging, keep symbols, otherwise strip them...
f518bf7e 26if test x$enable_debug = xyes -a "x$OPTIM" = x; then
839a51c8
MS
27 OPTIM="-g"
28else
29 INSTALL_STRIP="-s"
30fi
ef416fc2 31
5f64df29 32dnl Debug printfs can slow things down, so provide a separate option for that
52f6f666 33if test x$enable_debug_printfs = xyes; then
5f64df29 34 CFLAGS="$CFLAGS -DDEBUG"
94da7e34 35 CXXFLAGS="$CXXFLAGS -DDEBUG"
5f64df29
MS
36fi
37
745129be
MS
38dnl Debug guards use an extra 4 bytes for some structures like strings in the
39dnl string pool, so provide a separate option for that
40if test x$enable_debug_guards = xyes; then
41 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
94da7e34 42 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
745129be
MS
43fi
44
5f64df29
MS
45dnl Unit tests take up time during a compile...
46if test x$enable_unit_tests = xyes; then
105922ec
MS
47 if test "$build" != "$host"; then
48 AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
49 fi
50
5f64df29
MS
51 UNITTESTS="unittests"
52else
53 UNITTESTS=""
54fi
55AC_SUBST(UNITTESTS)
56
ed486911 57dnl Setup general architecture flags...
bf3816c7
MS
58AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
59AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
ed486911 60
61if test -z "$with_archflags"; then
62 ARCHFLAGS=""
63else
64 ARCHFLAGS="$with_archflags"
a603edef
MS
65fi
66
67if test -z "$with_ldarchflags"; then
105922ec 68 if test "$host_os_name" = darwin; then
12f89d24
MS
69 # Only create Intel programs by default
70 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
09a101d6 71 else
72 LDARCHFLAGS="$ARCHFLAGS"
73 fi
a603edef 74else
839a51c8 75 LDARCHFLAGS="$with_ldarchflags"
ed486911 76fi
77
78AC_SUBST(ARCHFLAGS)
09a101d6 79AC_SUBST(LDARCHFLAGS)
ed486911 80
f7deaa1a 81dnl Read-only data/program support on Linux...
bf3816c7 82AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
f7deaa1a 83
f518bf7e
MS
84dnl Clang/GCC address sanitizer...
85AC_ARG_ENABLE(sanitizer, [ --enable-sanitizer build with AddressSanitizer])
86
ef416fc2 87dnl Update compiler options...
ac884b6a
MS
88CXXLIBS="${CXXLIBS:=}"
89AC_SUBST(CXXLIBS)
90
a74454a7 91PIEFLAGS=""
92AC_SUBST(PIEFLAGS)
93
f7deaa1a 94RELROFLAGS=""
95AC_SUBST(RELROFLAGS)
96
f518bf7e
MS
97WARNING_OPTIONS=""
98AC_SUBST(WARNING_OPTIONS)
99
ef416fc2 100if test -n "$GCC"; then
2abf387c 101 # Add GCC-specific compiler options...
f518bf7e
MS
102
103 # Address sanitizer is a useful tool to use when developing/debugging
104 # code but adds about 2x overhead...
c028bdf7
MS
105 if test x$enable_sanitizer = xyes; then
106 # Use -fsanitize=address with debugging...
f518bf7e 107 OPTIM="$OPTIM -g -fsanitize=address"
c028bdf7
MS
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
f518bf7e
MS
114
115 # Default optimization options...
ef416fc2 116 if test -z "$OPTIM"; then
f518bf7e
MS
117 # Default to optimize-for-size and debug
118 OPTIM="-Os -g"
ef416fc2 119 fi
120
a4924f6c 121 # Generate position-independent code as needed...
5a1d7a17 122 if test $PICFLAG = 1; then
ef416fc2 123 OPTIM="-fPIC $OPTIM"
124 fi
125
a4924f6c
MS
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.
9483577f 129 AC_MSG_CHECKING(whether compiler supports -fstack-protector)
a4924f6c
MS
130 OLDCFLAGS="$CFLAGS"
131 CFLAGS="$CFLAGS -fstack-protector"
68b10830 132 AC_TRY_LINK(,,
db8b865d
MS
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
a4924f6c
MS
139 AC_MSG_RESULT(yes),
140 AC_MSG_RESULT(no))
141 CFLAGS="$OLDCFLAGS"
142
db8b865d
MS
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...
9483577f 149 AC_MSG_CHECKING(whether compiler supports -fPIE)
db8b865d 150 OLDCFLAGS="$CFLAGS"
105922ec
MS
151 case "$host_os_name" in
152 darwin*)
483fc76b
MS
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
db8b865d
MS
168 CFLAGS="$OLDCFLAGS"
169 fi
ef416fc2 170
f518bf7e
MS
171 # Add useful warning options for tracking down problems...
172 WARNING_OPTIONS="-Wall -Wno-format-y2k -Wunused -Wno-unused-result -Wsign-conversion"
f228370c 173
f518bf7e
MS
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
82e3ee0e 178 7.* | 8.*)
179 WARNING_OPTIONS="$WARNING_OPTIONS -Wno-format-truncation -Wno-tautological-compare"
e1d6a774 180 ;;
181 esac
f518bf7e
MS
182
183 # Additional warning options for development testing...
184 if test -d .git; then
7d730d0c 185 WARNING_OPTIONS="-Werror -Wno-error=deprecated-declarations $WARNING_OPTIONS"
f518bf7e 186 fi
ef416fc2 187else
2abf387c 188 # Add vendor-specific compiler options...
105922ec
MS
189 case $host_os_name in
190 sunos*)
ef416fc2 191 # Solaris
192 if test -z "$OPTIM"; then
f518bf7e 193 OPTIM="-xO2"
ef416fc2 194 fi
195
ef416fc2 196 if test $PICFLAG = 1; then
197 OPTIM="-KPIC $OPTIM"
198 fi
199 ;;
200 *)
f518bf7e
MS
201 # Running some other operating system; inform the user
202 # they should contribute the necessary options via
203 # Github...
204 echo "Building CUPS with default compiler optimizations; contact the CUPS developers on Github"
205 echo "(https://github.com/apple/cups/issues) with the uname and compiler options needed for"
206 echo "your platform, or set the CFLAGS and LDFLAGS environment variables before running"
207 echo "configure."
ef416fc2 208 ;;
209 esac
210fi
211
2abf387c 212# Add general compiler options per platform...
105922ec
MS
213case $host_os_name in
214 linux*)
dd1abb6b
MS
215 # glibc 2.8 and higher breaks peer credentials unless you
216 # define _GNU_SOURCE...
217 OPTIM="$OPTIM -D_GNU_SOURCE"
f518bf7e
MS
218
219 # The -z relro option is provided by the Linux linker command to
220 # make relocatable data read-only.
221 if test x$enable_relro = xyes; then
222 RELROFLAGS="-Wl,-z,relro,-z,now"
223 fi
dd1abb6b 224 ;;
2abf387c 225esac