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