]> git.ipfire.org Git - thirdparty/cups.git/blame - config-scripts/cups-compiler.m4
Fix makefile errors on install.
[thirdparty/cups.git] / config-scripts / cups-compiler.m4
CommitLineData
ef416fc2 1dnl
5a1d7a17 2dnl Compiler stuff for CUPS.
ef416fc2 3dnl
105922ec 4dnl Copyright 2007-2017 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=""
ef416fc2 13OPTIM=""
50fe7201 14AC_SUBST(INSTALL_STRIP)
ef416fc2 15AC_SUBST(OPTIM)
16
bf3816c7
MS
17AC_ARG_WITH(optim, [ --with-optim set optimization flags ])
18AC_ARG_ENABLE(debug, [ --enable-debug build with debugging symbols])
19AC_ARG_ENABLE(debug_guards, [ --enable-debug-guards build with memory allocation guards])
20AC_ARG_ENABLE(debug_printfs, [ --enable-debug-printfs build with CUPS_DEBUG_LOG support])
21AC_ARG_ENABLE(unit_tests, [ --enable-unit-tests build and run unit tests])
839a51c8
MS
22
23dnl For debugging, keep symbols, otherwise strip them...
24if test x$enable_debug = xyes; then
25 OPTIM="-g"
26else
27 INSTALL_STRIP="-s"
28fi
ef416fc2 29
5f64df29 30dnl Debug printfs can slow things down, so provide a separate option for that
52f6f666 31if test x$enable_debug_printfs = xyes; then
5f64df29 32 CFLAGS="$CFLAGS -DDEBUG"
94da7e34 33 CXXFLAGS="$CXXFLAGS -DDEBUG"
5f64df29
MS
34fi
35
745129be
MS
36dnl Debug guards use an extra 4 bytes for some structures like strings in the
37dnl string pool, so provide a separate option for that
38if test x$enable_debug_guards = xyes; then
39 CFLAGS="$CFLAGS -DDEBUG_GUARDS"
94da7e34 40 CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
745129be
MS
41fi
42
5f64df29
MS
43dnl Unit tests take up time during a compile...
44if test x$enable_unit_tests = xyes; then
105922ec
MS
45 if test "$build" != "$host"; then
46 AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
47 fi
48
5f64df29
MS
49 UNITTESTS="unittests"
50else
51 UNITTESTS=""
52fi
53AC_SUBST(UNITTESTS)
54
ed486911 55dnl Setup general architecture flags...
bf3816c7
MS
56AC_ARG_WITH(archflags, [ --with-archflags set default architecture flags ])
57AC_ARG_WITH(ldarchflags, [ --with-ldarchflags set program architecture flags ])
ed486911 58
59if test -z "$with_archflags"; then
60 ARCHFLAGS=""
61else
62 ARCHFLAGS="$with_archflags"
a603edef
MS
63fi
64
65if test -z "$with_ldarchflags"; then
105922ec 66 if test "$host_os_name" = darwin; then
12f89d24
MS
67 # Only create Intel programs by default
68 LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
09a101d6 69 else
70 LDARCHFLAGS="$ARCHFLAGS"
71 fi
a603edef 72else
839a51c8 73 LDARCHFLAGS="$with_ldarchflags"
ed486911 74fi
75
76AC_SUBST(ARCHFLAGS)
09a101d6 77AC_SUBST(LDARCHFLAGS)
ed486911 78
f7deaa1a 79dnl Read-only data/program support on Linux...
bf3816c7 80AC_ARG_ENABLE(relro, [ --enable-relro build with the GCC relro option])
f7deaa1a 81
ef416fc2 82dnl Update compiler options...
ac884b6a
MS
83CXXLIBS="${CXXLIBS:=}"
84AC_SUBST(CXXLIBS)
85
a74454a7 86PIEFLAGS=""
87AC_SUBST(PIEFLAGS)
88
f7deaa1a 89RELROFLAGS=""
90AC_SUBST(RELROFLAGS)
91
ef416fc2 92if test -n "$GCC"; then
2abf387c 93 # Add GCC-specific compiler options...
ef416fc2 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
a4924f6c 103 # Generate position-independent code as needed...
5a1d7a17 104 if test $PICFLAG = 1; then
ef416fc2 105 OPTIM="-fPIC $OPTIM"
106 fi
107
a4924f6c
MS
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.
9483577f 111 AC_MSG_CHECKING(whether compiler supports -fstack-protector)
a4924f6c
MS
112 OLDCFLAGS="$CFLAGS"
113 CFLAGS="$CFLAGS -fstack-protector"
68b10830 114 AC_TRY_LINK(,,
db8b865d
MS
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
a4924f6c
MS
121 AC_MSG_RESULT(yes),
122 AC_MSG_RESULT(no))
123 CFLAGS="$OLDCFLAGS"
124
db8b865d
MS
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...
9483577f 131 AC_MSG_CHECKING(whether compiler supports -fPIE)
db8b865d 132 OLDCFLAGS="$CFLAGS"
105922ec
MS
133 case "$host_os_name" in
134 darwin*)
483fc76b
MS
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
db8b865d
MS
150 CFLAGS="$OLDCFLAGS"
151 fi
ef416fc2 152
153 if test "x$with_optim" = x; then
154 # Add useful warning options for tracking down problems...
e87e23e7
MS
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"
7e86f2f6 165
9483577f
MS
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)
7e86f2f6
MS
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"
f228370c 183
a4924f6c 184 # Additional warning options for development testing...
171b7064 185 if test -d .git; then
7e86f2f6 186 OPTIM="-Werror $OPTIM"
d9bca400 187 fi
ef416fc2 188 fi
e1d6a774 189
105922ec
MS
190 case "$host_os_name" in
191 darwin*)
a4924f6c
MS
192 # -D_FORTIFY_SOURCE=2 adds additional object size
193 # checking, basically wrapping all string functions
194 # with buffer-limited ones. Not strictly needed for
195 # CUPS since we already use buffer-limited calls, but
22c9029b 196 # this will catch any additions that are broken.
a4924f6c
MS
197 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
198 ;;
199
105922ec 200 linux*)
a4924f6c
MS
201 # The -z relro option is provided by the Linux linker command to
202 # make relocatable data read-only.
203 if test x$enable_relro = xyes; then
9ee955fe 204 RELROFLAGS="-Wl,-z,relro,-z,now"
a4924f6c 205 fi
e1d6a774 206 ;;
207 esac
ef416fc2 208else
2abf387c 209 # Add vendor-specific compiler options...
105922ec
MS
210 case $host_os_name in
211 sunos*)
ef416fc2 212 # Solaris
213 if test -z "$OPTIM"; then
214 if test "x$with_optim" = x; then
ed486911 215 OPTIM="-xO2"
ef416fc2 216 else
217 OPTIM="$with_optim $OPTIM"
218 fi
219 fi
220
ef416fc2 221 if test $PICFLAG = 1; then
222 OPTIM="-KPIC $OPTIM"
223 fi
224 ;;
225 *)
226 # Running some other operating system; inform the user they
227 # should contribute the necessary options to
228 # cups-support@cups.org...
229 echo "Building CUPS with default compiler optimizations; contact"
9483577f 230 echo "cups-devel@cups.org with uname and compiler options needed"
5bd77a73
MS
231 echo "for your platform, or set the CFLAGS and LDFLAGS environment"
232 echo "variables before running configure."
ef416fc2 233 ;;
234 esac
235fi
236
2abf387c 237# Add general compiler options per platform...
105922ec
MS
238case $host_os_name in
239 linux*)
dd1abb6b
MS
240 # glibc 2.8 and higher breaks peer credentials unless you
241 # define _GNU_SOURCE...
242 OPTIM="$OPTIM -D_GNU_SOURCE"
243 ;;
2abf387c 244esac