From 0e22cb1232f4474f9b461661b621603312f37d3d Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Thu, 9 Oct 2003 03:20:34 +0000
Subject: [PATCH] This centralizes the optimization defaults into configure.in,
 rather than having CFLAGS= in the template files.

It uses -O2 for gcc (generated by autoconf), and -O for non-gcc, unless
the template overrides it.
---
 configure             |  4 ++++
 configure.in          |  6 +++++-
 src/template/beos     |  1 -
 src/template/bsdi     |  4 +---
 src/template/cygwin   |  1 -
 src/template/dgux     |  1 -
 src/template/freebsd  | 12 +++---------
 src/template/hpux     |  8 +++-----
 src/template/irix5    |  1 -
 src/template/linux    |  2 --
 src/template/netbsd   |  2 --
 src/template/nextstep |  1 -
 src/template/openbsd  |  1 -
 src/template/osf      |  4 +---
 src/template/qnx4     |  4 ++--
 src/template/sco      |  5 -----
 src/template/solaris  |  6 ++----
 src/template/sunos4   |  1 -
 src/template/svr4     |  1 -
 src/template/ultrix4  |  1 -
 src/template/univel   |  2 +-
 src/template/unixware |  1 -
 src/template/win      |  3 ---
 src/template/win32    |  3 ---
 24 files changed, 22 insertions(+), 53 deletions(-)

diff --git a/configure b/configure
index c4bb3df6018..0ee499a304d 100755
--- a/configure
+++ b/configure
@@ -2393,6 +2393,10 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 if test "$ac_env_CFLAGS_set" = set; then
   CFLAGS=$ac_env_CFLAGS_value
 fi
+# configure sets CFLAGS to -O2 for gcc, so this is only for non-gcc
+if test x"$CFLAGS" = x""; then
+	CFLAGS="-O"
+fi
 if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
   CFLAGS="$CFLAGS -g"
 fi
diff --git a/configure.in b/configure.in
index 62ede6dde00..18d612729b6 100644
--- a/configure.in
+++ b/configure.in
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.293 2003/10/03 03:08:14 pgsql Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.294 2003/10/09 03:20:33 momjian Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -238,6 +238,10 @@ AC_PROG_CC([$pgac_cc_list])
 if test "$ac_env_CFLAGS_set" = set; then
   CFLAGS=$ac_env_CFLAGS_value
 fi
+# configure sets CFLAGS to -O2 for gcc, so this is only for non-gcc
+if test x"$CFLAGS" = x""; then	
+	CFLAGS="-O"
+fi
 if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
   CFLAGS="$CFLAGS -g"
 fi
diff --git a/src/template/beos b/src/template/beos
index c435200929c..e69de29bb2d 100644
--- a/src/template/beos
+++ b/src/template/beos
@@ -1 +0,0 @@
-CFLAGS='-O2'
diff --git a/src/template/bsdi b/src/template/bsdi
index acb2c42d3c9..5e044ffad2d 100644
--- a/src/template/bsdi
+++ b/src/template/bsdi
@@ -5,9 +5,7 @@ case $host_cpu in
 esac
 
 case $host_os in
-  bsdi2.0 | bsdi2.1 | bsdi3*)
-    CC=gcc2
-    ;;
+  bsdi2.0 | bsdi2.1 | bsdi3*) CC=gcc2;;
 esac
 
 THREAD_SUPPORT=yes
diff --git a/src/template/cygwin b/src/template/cygwin
index eb8921984aa..8a9fa0051ea 100644
--- a/src/template/cygwin
+++ b/src/template/cygwin
@@ -1,2 +1 @@
-CFLAGS='-O2'
 SRCH_LIB='/usr/local/lib'
diff --git a/src/template/dgux b/src/template/dgux
index 7abc138a9f9..e69de29bb2d 100644
--- a/src/template/dgux
+++ b/src/template/dgux
@@ -1 +0,0 @@
-CFLAGS=
diff --git a/src/template/freebsd b/src/template/freebsd
index 082afc077b2..651593232d3 100644
--- a/src/template/freebsd
+++ b/src/template/freebsd
@@ -1,17 +1,11 @@
-CFLAGS='-pipe'
-
 case $host_cpu in
-  alpha*)   CFLAGS="$CFLAGS -O" ;;
+  alpha*)   CFLAGS="-O";;
 esac
 
 THREAD_SUPPORT=yes
 NEED_REENTRANT_FUNCS=yes
 THREAD_CPPFLAGS="-D_THREAD_SAFE"
 case $host_os in
-		freebsd2*|freebsd3*|freebsd4*)
-			THREAD_LIBS="-pthread"
-			;;
-		*)
-			THREAD_LIBS="-lc_r"
-			;;
+	freebsd2*|freebsd3*|freebsd4*) THREAD_LIBS="-pthread";;
+	*) THREAD_LIBS="-lc_r";;
 esac
diff --git a/src/template/hpux b/src/template/hpux
index 34a5e861442..28d836e0120 100644
--- a/src/template/hpux
+++ b/src/template/hpux
@@ -1,8 +1,6 @@
-if test "$GCC" = yes ; then
-  CPPFLAGS="-D_XOPEN_SOURCE_EXTENDED"
-  CFLAGS="-O2"
-else
+CPPFLAGS="-D_XOPEN_SOURCE_EXTENDED"
+
+if test "$GCC" != yes ; then
   CC="$CC -Ae"
-  CPPFLAGS="-D_XOPEN_SOURCE_EXTENDED"
   CFLAGS="+O2"
 fi
diff --git a/src/template/irix5 b/src/template/irix5
index 7abc138a9f9..e69de29bb2d 100644
--- a/src/template/irix5
+++ b/src/template/irix5
@@ -1 +0,0 @@
-CFLAGS=
diff --git a/src/template/linux b/src/template/linux
index 44b046033ab..529da9c1694 100644
--- a/src/template/linux
+++ b/src/template/linux
@@ -1,4 +1,3 @@
-CFLAGS=-O2
 # Force _GNU_SOURCE on; plperl is broken with Perl 5.8.0 otherwise
 CPPFLAGS="-D_GNU_SOURCE"
 
@@ -6,4 +5,3 @@ THREAD_SUPPORT=yes
 NEED_REENTRANT_FUNCS=yes	# Debian kernel 2.2 2003-09-27
 THREAD_CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS"
 THREAD_LIBS="-lpthread"
-
diff --git a/src/template/netbsd b/src/template/netbsd
index f510dc9ef0c..0d119a01361 100644
--- a/src/template/netbsd
+++ b/src/template/netbsd
@@ -1,4 +1,2 @@
-CFLAGS='-O2 -pipe'
-
 THREAD_SUPPORT=yes
 NEED_REENTRANT_FUNCS=yes	# 1.6 2003-09-14
diff --git a/src/template/nextstep b/src/template/nextstep
index c8b14f4d8b7..d6b3c35e6cb 100644
--- a/src/template/nextstep
+++ b/src/template/nextstep
@@ -1,4 +1,3 @@
 AROPT=rc
-CFLAGS=
 SHARED_LIB=
 DLSUFFIX=.o
diff --git a/src/template/openbsd b/src/template/openbsd
index bfbcbdd5975..e69de29bb2d 100644
--- a/src/template/openbsd
+++ b/src/template/openbsd
@@ -1 +0,0 @@
-CFLAGS='-O2 -pipe'
diff --git a/src/template/osf b/src/template/osf
index b5c60413de8..133a4516ab0 100644
--- a/src/template/osf
+++ b/src/template/osf
@@ -1,6 +1,4 @@
-if test "$GCC" = yes ; then
-  CFLAGS=
-else
+if test "$GCC" != yes ; then
   CC="$CC -std"
   CFLAGS='-O4 -Olimit 2000'
 fi
diff --git a/src/template/qnx4 b/src/template/qnx4
index d153324b9a6..c4bc9531b91 100644
--- a/src/template/qnx4
+++ b/src/template/qnx4
@@ -1,2 +1,2 @@
-CFLAGS=-I/usr/local/include
-LIBS=-lunix
+CFLAGS="-O2 -I/usr/local/include"
+LIBS="-lunix"
diff --git a/src/template/sco b/src/template/sco
index 3126e062ced..e0b08471db1 100644
--- a/src/template/sco
+++ b/src/template/sco
@@ -1,7 +1,2 @@
-if test "$GCC" = yes; then
-  CFLAGS=-O2
-else
-  CFLAGS=-O
-fi
 CC="$CC -b elf"
 
diff --git a/src/template/solaris b/src/template/solaris
index 083b1d3659f..f5ff36064be 100644
--- a/src/template/solaris
+++ b/src/template/solaris
@@ -1,8 +1,6 @@
-if test "$GCC" = yes ; then
-  CFLAGS=
-else
+if test "$GCC" != yes ; then
   CC="$CC -Xa"			# relaxed ISO C mode
-  CFLAGS=-v			# -v is like gcc -Wall
+  CFLAGS="-O -v"		# -v is like gcc -Wall
 fi
 
 THREAD_SUPPORT=yes
diff --git a/src/template/sunos4 b/src/template/sunos4
index 7abc138a9f9..e69de29bb2d 100644
--- a/src/template/sunos4
+++ b/src/template/sunos4
@@ -1 +0,0 @@
-CFLAGS=
diff --git a/src/template/svr4 b/src/template/svr4
index 7abc138a9f9..e69de29bb2d 100644
--- a/src/template/svr4
+++ b/src/template/svr4
@@ -1 +0,0 @@
-CFLAGS=
diff --git a/src/template/ultrix4 b/src/template/ultrix4
index 7abc138a9f9..e69de29bb2d 100644
--- a/src/template/ultrix4
+++ b/src/template/ultrix4
@@ -1 +0,0 @@
-CFLAGS=
diff --git a/src/template/univel b/src/template/univel
index 025fbda7bf4..d48aa7c3111 100644
--- a/src/template/univel
+++ b/src/template/univel
@@ -1,2 +1,2 @@
 CFLAGS='-v -O -K i486,host,inline,loop_unroll -Dsvr4'
-LIBS=-lc89 
+LIBS="-lc89"
diff --git a/src/template/unixware b/src/template/unixware
index e1991bcc9c8..cb1381d8fbd 100644
--- a/src/template/unixware
+++ b/src/template/unixware
@@ -1,5 +1,4 @@
 if test "$GCC" = yes; then
-  CFLAGS=-O2
   THREAD_CPPFLAGS="-pthread"
 else
 # the -Kno_host is temporary for a bug in the compiler.  See -hackers
diff --git a/src/template/win b/src/template/win
index 736e0f293d3..e69de29bb2d 100644
--- a/src/template/win
+++ b/src/template/win
@@ -1,3 +0,0 @@
-if test "$GCC" = yes; then
-  CFLAGS="-O2"
-fi
diff --git a/src/template/win32 b/src/template/win32
index 736e0f293d3..e69de29bb2d 100644
--- a/src/template/win32
+++ b/src/template/win32
@@ -1,3 +0,0 @@
-if test "$GCC" = yes; then
-  CFLAGS="-O2"
-fi
-- 
GitLab