Blame config-scripts/cups-compiler.m4

Packit Service 4ae4ad
dnl
Packit Service 4ae4ad
dnl Compiler stuff for CUPS.
Packit Service 4ae4ad
dnl
Packit Service 4ae4ad
dnl Copyright 2007-2017 by Apple Inc.
Packit Service 4ae4ad
dnl Copyright 1997-2007 by Easy Software Products, all rights reserved.
Packit Service 4ae4ad
dnl
Packit Service 4ae4ad
dnl These coded instructions, statements, and computer programs are the
Packit Service 4ae4ad
dnl property of Apple Inc. and are protected by Federal copyright
Packit Service 4ae4ad
dnl law.  Distribution and use rights are outlined in the file "LICENSE.txt"
Packit Service 4ae4ad
dnl which should have been included with this file.  If this file is
Packit Service 4ae4ad
dnl missing or damaged, see the license at "http://www.cups.org/".
Packit Service 4ae4ad
dnl
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl Clear the debugging and non-shared library options unless the user asks
Packit Service 4ae4ad
dnl for them...
Packit Service 4ae4ad
INSTALL_STRIP=""
Packit Service 4ae4ad
OPTIM=""
Packit Service 4ae4ad
AC_SUBST(INSTALL_STRIP)
Packit Service 4ae4ad
AC_SUBST(OPTIM)
Packit Service 4ae4ad
Packit Service 4ae4ad
AC_ARG_WITH(optim, [  --with-optim            set optimization flags ])
Packit Service 4ae4ad
AC_ARG_ENABLE(debug, [  --enable-debug          build with debugging symbols])
Packit Service 4ae4ad
AC_ARG_ENABLE(debug_guards, [  --enable-debug-guards   build with memory allocation guards])
Packit Service 4ae4ad
AC_ARG_ENABLE(debug_printfs, [  --enable-debug-printfs  build with CUPS_DEBUG_LOG support])
Packit Service 4ae4ad
AC_ARG_ENABLE(unit_tests, [  --enable-unit-tests     build and run unit tests])
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl For debugging, keep symbols, otherwise strip them...
Packit Service 4ae4ad
if test x$enable_debug = xyes; then
Packit Service 4ae4ad
	OPTIM="-g"
Packit Service 4ae4ad
else
Packit Service 4ae4ad
	INSTALL_STRIP="-s"
Packit Service 4ae4ad
fi
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl Debug printfs can slow things down, so provide a separate option for that
Packit Service 4ae4ad
if test x$enable_debug_printfs = xyes; then
Packit Service 4ae4ad
	CFLAGS="$CFLAGS -DDEBUG"
Packit Service 4ae4ad
	CXXFLAGS="$CXXFLAGS -DDEBUG"
Packit Service 4ae4ad
fi
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl Debug guards use an extra 4 bytes for some structures like strings in the
Packit Service 4ae4ad
dnl string pool, so provide a separate option for that
Packit Service 4ae4ad
if test x$enable_debug_guards = xyes; then
Packit Service 4ae4ad
	CFLAGS="$CFLAGS -DDEBUG_GUARDS"
Packit Service 4ae4ad
	CXXFLAGS="$CXXFLAGS -DDEBUG_GUARDS"
Packit Service 4ae4ad
fi
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl Unit tests take up time during a compile...
Packit Service 4ae4ad
if test x$enable_unit_tests = xyes; then
Packit Service 4ae4ad
        if test "$build" != "$host"; then
Packit Service 4ae4ad
                AC_MSG_ERROR([Sorry, cannot build unit tests when cross-compiling.])
Packit Service 4ae4ad
        fi
Packit Service 4ae4ad
Packit Service 4ae4ad
	UNITTESTS="unittests"
Packit Service 4ae4ad
else
Packit Service 4ae4ad
	UNITTESTS=""
Packit Service 4ae4ad
fi
Packit Service 4ae4ad
AC_SUBST(UNITTESTS)
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl Setup general architecture flags...
Packit Service 4ae4ad
AC_ARG_WITH(archflags, [  --with-archflags        set default architecture flags ])
Packit Service 4ae4ad
AC_ARG_WITH(ldarchflags, [  --with-ldarchflags      set program architecture flags ])
Packit Service 4ae4ad
Packit Service 4ae4ad
if test -z "$with_archflags"; then
Packit Service 4ae4ad
	ARCHFLAGS=""
Packit Service 4ae4ad
else
Packit Service 4ae4ad
	ARCHFLAGS="$with_archflags"
Packit Service 4ae4ad
fi
Packit Service 4ae4ad
Packit Service 4ae4ad
if test -z "$with_ldarchflags"; then
Packit Service 4ae4ad
	if test "$host_os_name" = darwin; then
Packit Service 4ae4ad
		# Only create Intel programs by default
Packit Service 4ae4ad
		LDARCHFLAGS="`echo $ARCHFLAGS | sed -e '1,$s/-arch ppc64//'`"
Packit Service 4ae4ad
	else
Packit Service 4ae4ad
		LDARCHFLAGS="$ARCHFLAGS"
Packit Service 4ae4ad
	fi
Packit Service 4ae4ad
else
Packit Service 4ae4ad
	LDARCHFLAGS="$with_ldarchflags"
Packit Service 4ae4ad
fi
Packit Service 4ae4ad
Packit Service 4ae4ad
AC_SUBST(ARCHFLAGS)
Packit Service 4ae4ad
AC_SUBST(LDARCHFLAGS)
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl Read-only data/program support on Linux...
Packit Service 4ae4ad
AC_ARG_ENABLE(relro, [  --enable-relro          build with the GCC relro option])
Packit Service 4ae4ad
Packit Service 4ae4ad
dnl Update compiler options...
Packit Service 4ae4ad
CXXLIBS="${CXXLIBS:=}"
Packit Service 4ae4ad
AC_SUBST(CXXLIBS)
Packit Service 4ae4ad
Packit Service 4ae4ad
PIEFLAGS=""
Packit Service 4ae4ad
AC_SUBST(PIEFLAGS)
Packit Service 4ae4ad
Packit Service 4ae4ad
RELROFLAGS=""
Packit Service 4ae4ad
AC_SUBST(RELROFLAGS)
Packit Service 4ae4ad
Packit Service 4ae4ad
if test -n "$GCC"; then
Packit Service 4ae4ad
	# Add GCC-specific compiler options...
Packit Service 4ae4ad
	if test -z "$OPTIM"; then
Packit Service 4ae4ad
		if test "x$with_optim" = x; then
Packit Service 4ae4ad
			# Default to optimize-for-size and debug
Packit Service 4ae4ad
       			OPTIM="-Os -g"
Packit Service 4ae4ad
		else
Packit Service 4ae4ad
			OPTIM="$with_optim $OPTIM"
Packit Service 4ae4ad
		fi
Packit Service 4ae4ad
	fi
Packit Service 4ae4ad
Packit Service 4ae4ad
	# Generate position-independent code as needed...
Packit Service 4ae4ad
	if test $PICFLAG = 1; then
Packit Service 4ae4ad
    		OPTIM="-fPIC $OPTIM"
Packit Service 4ae4ad
	fi
Packit Service 4ae4ad
Packit Service 4ae4ad
	# The -fstack-protector option is available with some versions of
Packit Service 4ae4ad
	# GCC and adds "stack canaries" which detect when the return address
Packit Service 4ae4ad
	# has been overwritten, preventing many types of exploit attacks.
Packit Service 4ae4ad
	AC_MSG_CHECKING(whether compiler supports -fstack-protector)
Packit Service 4ae4ad
	OLDCFLAGS="$CFLAGS"
Packit Service 4ae4ad
	CFLAGS="$CFLAGS -fstack-protector"
Packit Service 4ae4ad
	AC_TRY_LINK(,,
Packit Service 4ae4ad
		if test "x$LSB_BUILD" = xy; then
Packit Service 4ae4ad
			# Can't use stack-protector with LSB binaries...
Packit Service 4ae4ad
			OPTIM="$OPTIM -fno-stack-protector"
Packit Service 4ae4ad
		else
Packit Service 4ae4ad
			OPTIM="$OPTIM -fstack-protector"
Packit Service 4ae4ad
		fi
Packit Service 4ae4ad
		AC_MSG_RESULT(yes),
Packit Service 4ae4ad
		AC_MSG_RESULT(no))
Packit Service 4ae4ad
	CFLAGS="$OLDCFLAGS"
Packit Service 4ae4ad
Packit Service 4ae4ad
	if test "x$LSB_BUILD" != xy; then
Packit Service 4ae4ad
		# The -fPIE option is available with some versions of GCC and
Packit Service 4ae4ad
		# adds randomization of addresses, which avoids another class of
Packit Service 4ae4ad
		# exploits that depend on a fixed address for common functions.
Packit Service 4ae4ad
		#
Packit Service 4ae4ad
		# Not available to LSB binaries...
Packit Service 4ae4ad
		AC_MSG_CHECKING(whether compiler supports -fPIE)
Packit Service 4ae4ad
		OLDCFLAGS="$CFLAGS"
Packit Service 4ae4ad
		case "$host_os_name" in
Packit Service 4ae4ad
			darwin*)
Packit Service 4ae4ad
				CFLAGS="$CFLAGS -fPIE -Wl,-pie"
Packit Service 4ae4ad
				AC_TRY_COMPILE(,,[
Packit Service 4ae4ad
					PIEFLAGS="-fPIE -Wl,-pie"
Packit Service 4ae4ad
					AC_MSG_RESULT(yes)],
Packit Service 4ae4ad
					AC_MSG_RESULT(no))
Packit Service 4ae4ad
				;;
Packit Service 4ae4ad
Packit Service 4ae4ad
			*)
Packit Service 4ae4ad
				CFLAGS="$CFLAGS -fPIE -pie"
Packit Service 4ae4ad
				AC_TRY_COMPILE(,,[
Packit Service 4ae4ad
					PIEFLAGS="-fPIE -pie"
Packit Service 4ae4ad
					AC_MSG_RESULT(yes)],
Packit Service 4ae4ad
					AC_MSG_RESULT(no))
Packit Service 4ae4ad
				;;
Packit Service 4ae4ad
		esac
Packit Service 4ae4ad
		CFLAGS="$OLDCFLAGS"
Packit Service 4ae4ad
	fi
Packit Service 4ae4ad
Packit Service 4ae4ad
	if test "x$with_optim" = x; then
Packit Service 4ae4ad
		# Add useful warning options for tracking down problems...
Packit Service 4ae4ad
		OPTIM="-Wall -Wno-format-y2k -Wunused $OPTIM"
Packit Service 4ae4ad
Packit Service 4ae4ad
		AC_MSG_CHECKING(whether compiler supports -Wno-unused-result)
Packit Service 4ae4ad
		OLDCFLAGS="$CFLAGS"
Packit Service 4ae4ad
		CFLAGS="$CFLAGS -Werror -Wno-unused-result"
Packit Service 4ae4ad
		AC_TRY_COMPILE(,,
Packit Service 4ae4ad
			[OPTIM="$OPTIM -Wno-unused-result"
Packit Service 4ae4ad
			AC_MSG_RESULT(yes)],
Packit Service 4ae4ad
			AC_MSG_RESULT(no))
Packit Service 4ae4ad
		CFLAGS="$OLDCFLAGS"
Packit Service 4ae4ad
Packit Service 4ae4ad
		AC_MSG_CHECKING(whether compiler supports -Wsign-conversion)
Packit Service 4ae4ad
		OLDCFLAGS="$CFLAGS"
Packit Service 4ae4ad
		CFLAGS="$CFLAGS -Werror -Wsign-conversion"
Packit Service 4ae4ad
		AC_TRY_COMPILE(,,
Packit Service 4ae4ad
			[OPTIM="$OPTIM -Wsign-conversion"
Packit Service 4ae4ad
			AC_MSG_RESULT(yes)],
Packit Service 4ae4ad
			AC_MSG_RESULT(no))
Packit Service 4ae4ad
		CFLAGS="$OLDCFLAGS"
Packit Service 4ae4ad
Packit Service 4ae4ad
		AC_MSG_CHECKING(whether compiler supports -Wno-tautological-compare)
Packit Service 4ae4ad
		OLDCFLAGS="$CFLAGS"
Packit Service 4ae4ad
		CFLAGS="$CFLAGS -Werror -Wno-tautological-compare"
Packit Service 4ae4ad
		AC_TRY_COMPILE(,,
Packit Service 4ae4ad
			[OPTIM="$OPTIM -Wno-tautological-compare"
Packit Service 4ae4ad
			AC_MSG_RESULT(yes)],
Packit Service 4ae4ad
			AC_MSG_RESULT(no))
Packit Service 4ae4ad
		CFLAGS="$OLDCFLAGS"
Packit Service 4ae4ad
Packit Service 4ae4ad
		AC_MSG_CHECKING(whether compiler supports -Wno-format-truncation)
Packit Service 4ae4ad
		OLDCFLAGS="$CFLAGS"
Packit Service 4ae4ad
		CFLAGS="$CFLAGS -Werror -Wno-format-truncation"
Packit Service 4ae4ad
		AC_TRY_COMPILE(,,
Packit Service 4ae4ad
			[OPTIM="$OPTIM -Wno-format-truncation"
Packit Service 4ae4ad
			AC_MSG_RESULT(yes)],
Packit Service 4ae4ad
			AC_MSG_RESULT(no))
Packit Service 4ae4ad
		CFLAGS="$OLDCFLAGS"
Packit Service 4ae4ad
Packit Service 4ae4ad
		# Additional warning options for development testing...
Packit Service 4ae4ad
		if test -d .svn; then
Packit Service 4ae4ad
			OPTIM="-Werror $OPTIM"
Packit Service 4ae4ad
		fi
Packit Service 4ae4ad
	fi
Packit Service 4ae4ad
Packit Service 4ae4ad
	case "$host_os_name" in
Packit Service 4ae4ad
		darwin*)
Packit Service 4ae4ad
			# -D_FORTIFY_SOURCE=2 adds additional object size
Packit Service 4ae4ad
			# checking, basically wrapping all string functions
Packit Service 4ae4ad
			# with buffer-limited ones.  Not strictly needed for
Packit Service 4ae4ad
			# CUPS since we already use buffer-limited calls, but
Packit Service 4ae4ad
			# this will catch any additions that are broken.
Packit Service 4ae4ad
			CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
Packit Service 4ae4ad
			;;
Packit Service 4ae4ad
Packit Service 4ae4ad
		linux*)
Packit Service 4ae4ad
			# The -z relro option is provided by the Linux linker command to
Packit Service 4ae4ad
			# make relocatable data read-only.
Packit Service 4ae4ad
			if test x$enable_relro = xyes; then
Packit Service 4ae4ad
				RELROFLAGS="-Wl,-z,relro,-z,now"
Packit Service 4ae4ad
			fi
Packit Service 4ae4ad
			;;
Packit Service 4ae4ad
	esac
Packit Service 4ae4ad
else
Packit Service 4ae4ad
	# Add vendor-specific compiler options...
Packit Service 4ae4ad
	case $host_os_name in
Packit Service 4ae4ad
		sunos*)
Packit Service 4ae4ad
			# Solaris
Packit Service 4ae4ad
			if test -z "$OPTIM"; then
Packit Service 4ae4ad
				if test "x$with_optim" = x; then
Packit Service 4ae4ad
					OPTIM="-xO2"
Packit Service 4ae4ad
				else
Packit Service 4ae4ad
					OPTIM="$with_optim $OPTIM"
Packit Service 4ae4ad
				fi
Packit Service 4ae4ad
			fi
Packit Service 4ae4ad
Packit Service 4ae4ad
			if test $PICFLAG = 1; then
Packit Service 4ae4ad
				OPTIM="-KPIC $OPTIM"
Packit Service 4ae4ad
			fi
Packit Service 4ae4ad
			;;
Packit Service 4ae4ad
		*)
Packit Service 4ae4ad
			# Running some other operating system; inform the user they
Packit Service 4ae4ad
			# should contribute the necessary options to
Packit Service 4ae4ad
			# cups-support@cups.org...
Packit Service 4ae4ad
			echo "Building CUPS with default compiler optimizations; contact"
Packit Service 4ae4ad
			echo "cups-devel@cups.org with uname and compiler options needed"
Packit Service 4ae4ad
			echo "for your platform, or set the CFLAGS and LDFLAGS environment"
Packit Service 4ae4ad
			echo "variables before running configure."
Packit Service 4ae4ad
			;;
Packit Service 4ae4ad
	esac
Packit Service 4ae4ad
fi
Packit Service 4ae4ad
Packit Service 4ae4ad
# Add general compiler options per platform...
Packit Service 4ae4ad
case $host_os_name in
Packit Service 4ae4ad
	linux*)
Packit Service 4ae4ad
		# glibc 2.8 and higher breaks peer credentials unless you
Packit Service 4ae4ad
		# define _GNU_SOURCE...
Packit Service 4ae4ad
		OPTIM="$OPTIM -D_GNU_SOURCE"
Packit Service 4ae4ad
		;;
Packit Service 4ae4ad
esac