From 46bc0e432e756fcb8fc4f703b47cd25b9fc7139c Mon Sep 17 00:00:00 2001 From: Paul P Komkoff Jr Date: Wed, 13 Aug 2008 16:17:04 +0100 Subject: [build] Test for GNU-style PIE support in toolchain and enable 2008-08-13 Paul P Komkoff Jr * configure.ac: add a configure flag and autoconf macro, which will determine if your toolchain supports PIE. * */Makefile.am: add corresponding CFLAGS and LDFLAGS into appropriate places. Signed-off-by: Paul Jakma --- configure.ac | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 746b5cea..5c6c0d7d 100755 --- a/configure.ac +++ b/configure.ac @@ -60,9 +60,10 @@ fi dnl -------------------- dnl Check CC and friends dnl -------------------- +AC_LANG([C]) AC_PROG_CC AC_PROG_CPP - +AM_PROG_CC_C_O AC_PROG_EGREP dnl autoconf 2.59 appears not to support AC_PROG_SED @@ -1395,6 +1396,31 @@ dnl ---------- CONFDATE=`date '+%Y%m%d'` AC_SUBST(CONFDATE) +dnl Conditionally enable PIE support for GNU toolchains. +enable_pie=yes + +AC_ARG_ENABLE(pie, AS_HELP_STRING([--disable-pie], [Do not build tools as a Position Independent Executables])) +if test "$enable_pie" = "yes"; then + AC_CACHE_CHECK([whether $CC accepts PIE flags], [ap_cv_cc_pie], [ + save_CFLAGS=$CFLAGS + save_LDFLAGS=$LDFLAGS + CFLAGS="$CFLAGS -fPIE" + LDFLAGS="$LDFLAGS -pie" + AC_LINK_IFELSE([AC_LANG_SOURCE([[static int foo[30000]; int main () { return 0; }]])], + [ap_cv_cc_pie=yes], [ap_cv_cc_pie=no] + ) + CFLAGS=$save_CFLAGS + LDFLAGS=$save_LDFLAGS + ]) + if test "$ap_cv_cc_pie" = "yes"; then + PICFLAGS="-fPIE" + PILDFLAGS="-pie" + fi +fi + +AC_SUBST(PICFLAGS) +AC_SUBST(PILDFLAGS) + dnl ------------------------------ dnl set paths for state directory dnl ------------------------------ -- cgit v1.2.1