From 802b79e3ca114e5958e12e57c5eb7f0569f45c77 Mon Sep 17 00:00:00 2001
From: "Kevin P. Fleming" <kpfleming@digium.com>
Date: Fri, 28 Aug 2009 20:01:21 +0000
Subject: [PATCH] Ensure that CFLAGS and/or LDFLAGS provided to configure
 script are preserved.

Cross-compilation environments want to provide 'defaults' for compiler and
linker options, and frequently do this by specifying CFLAGS and LDFLAGS in the
environment or as command-line arguments to the configure script. This patch
modifies the configure script and Makefile to preserve these settings and
ensure they are used in the build process.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@214696 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 Makefile                         | 13 ++++++---
 configure.ac                     |  6 +++++
 include/asterisk/autoconfig.h.in | 46 ++++++++++++--------------------
 makeopts.in                      |  3 +++
 4 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/Makefile b/Makefile
index b3e102def4..7d4020838d 100644
--- a/Makefile
+++ b/Makefile
@@ -95,10 +95,17 @@ ifneq ($(wildcard makeopts),)
   include makeopts
 endif
 
+# start the primary CFLAGS and LDFLAGS with any that were provided
+# to the configure script
+_ASTCFLAGS:=$(CONFIG_CFLAGS)
+_ASTLDFLAGS:=$(CONFIG_LDFLAGS)
+
 # Some build systems, such as the one in openwrt, like to pass custom target
-# CFLAGS and LDFLAGS in the COPTS and LDOPTS variables.
-ASTCFLAGS+=$(COPTS)
-ASTLDFLAGS+=$(LDOPTS)
+# CFLAGS and LDFLAGS in the COPTS and LDOPTS variables; these should also
+# go before any build-system computed flags, since they are defaults, not
+# overrides
+_ASTCFLAGS+=$(COPTS)
+_ASTLDFLAGS+=$(LDOPTS)
 
 # libxml2 cflags
 _ASTCFLAGS+=$(LIBXML2_INCLUDE)
diff --git a/configure.ac b/configure.ac
index 37bb2010a5..c7ae196cf7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,12 @@ AC_REVISION($Revision$)
 
 AC_USE_SYSTEM_EXTENSIONS	# note- does not work on FreeBSD
 
+# preserve any CFLAGS or LDFLAGS that may be set
+CONFIG_CFLAGS="${CFLAGS}"
+CONFIG_LDFLAGS="${LDFLAGS}"
+AC_SUBST(CONFIG_CFLAGS)
+AC_SUBST(CONFIG_LDFLAGS)
+
 case "${host_os}" in
      freebsd*)
      ac_default_prefix=/usr/local
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index 4d29d8b48f..5dd0f54276 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -1243,9 +1243,6 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
-/* Define to 1 if the C compiler supports function prototypes. */
-#undef PROTOTYPES
-
 /* Define to necessary symbol if this constant uses a non-standard name on
    your system. */
 #undef PTHREAD_CREATE_JOINABLE
@@ -1262,11 +1259,6 @@
 /* Define to the type of arg 5 for `select'. */
 #undef SELECT_TYPE_ARG5
 
-/* Define to 1 if the `setvbuf' function takes the buffering type as its
-   second argument and the buffer pointer as the third, as on System V before
-   release 3. */
-#undef SETVBUF_REVERSED
-
 /* The size of `int', as computed by sizeof. */
 #undef SIZEOF_INT
 
@@ -1287,20 +1279,30 @@
 /* Define to 1 if your <sys/time.h> declares `struct tm'. */
 #undef TM_IN_SYS_TIME
 
-/* Define to 1 if on AIX 3.
-   System headers sometimes define this.
-   We just want to avoid a redefinition error message.  */
+/* Enable extensions on AIX 3, Interix.  */
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
 #endif
-
-/* Number of bits in a file offset, on hosts where this is settable. */
-#undef _FILE_OFFSET_BITS
-
 /* Enable GNU extensions on systems that have them.  */
 #ifndef _GNU_SOURCE
 # undef _GNU_SOURCE
 #endif
+/* Enable threading extensions on Solaris.  */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# undef _POSIX_PTHREAD_SEMANTICS
+#endif
+/* Enable extensions on HP NonStop.  */
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif
+/* Enable general extensions on Solaris.  */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
+
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#undef _FILE_OFFSET_BITS
 
 /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
 #undef _LARGEFILE_SOURCE
@@ -1318,20 +1320,6 @@
 /* Define to 1 if you need to in order for `stat' and other things to work. */
 #undef _POSIX_SOURCE
 
-/* Enable extensions on Solaris.  */
-#ifndef __EXTENSIONS__
-# undef __EXTENSIONS__
-#endif
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# undef _POSIX_PTHREAD_SEMANTICS
-#endif
-#ifndef _TANDEM_SOURCE
-# undef _TANDEM_SOURCE
-#endif
-
-/* Define like PROTOTYPES; this can be used by system headers. */
-#undef __PROTOTYPES
-
 /* Define to empty if `const' does not conform to ANSI C. */
 #undef const
 
diff --git a/makeopts.in b/makeopts.in
index 5b73b26f1d..d6bc6bee65 100644
--- a/makeopts.in
+++ b/makeopts.in
@@ -47,6 +47,9 @@ GC_LDFLAGS=@GC_LDFLAGS@
 PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
 PTHREAD_LIBS=@PTHREAD_LIBS@
 
+CONFIG_CFLAGS=@CONFIG_CFLAGS@
+CONFIG_LDFLAGS=@CONFIG_LDFLAGS@
+
 GNU_LD=@GNU_LD@
 
 prefix = @prefix@
-- 
GitLab