{"thread":{"id":"4785","subject":"[PATCH 3/3] configure: Try to figure out compiler options","startedAt":"2006-07-06T12:41:24Z","lastAt":"2006-07-06T12:41:24Z","messageCount":1,"participants":["Dennis Stosberg"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"23313","messageId":"20060706124124.G1358ce5f@leonov.stosberg.net","threadId":"4785","inReplyTo":null,"subject":"[PATCH 3/3] configure: Try to figure out compiler options","fromName":"Dennis Stosberg","fromEmail":"dennis@stosberg.net","sentAt":"2006-07-06T12:41:24Z","receivedAt":"2006-07-06T12:41:24Z","isPatch":true,"sender":{"key":"dennis@stosberg.net","avatar":null},"body":"This patch adds tests to determine of what flavour the used\ncompiler is and sets CFLAGS and the PIC flag appropriately.\n\nSigned-off-by: Dennis Stosberg <dennis@stosberg.net>\n---\n Makefile      |    3 ++-\n config-lib.sh |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++-----\n 2 files changed, 53 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 4dc5379..23c784e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -96,6 +96,7 @@ ALL_CFLAGS = $(CFLAGS)\n ALL_LDFLAGS = $(LDFLAGS)\n PERL_CFLAGS =\n PERL_LDFLAGS =\n+PICFLAG = -fPIC\n STRIP ?= strip\n \n prefix = $(HOME)\n@@ -483,7 +484,7 @@ endif\n endif\n endif\n ifdef USE_PIC\n-\tALL_CFLAGS += -fPIC\n+\tALL_CFLAGS += $(PICFLAG)\n endif\n ifdef NO_ACCURATE_DIFF\n \tBASIC_CFLAGS += -DNO_ACCURATE_DIFF\ndiff --git a/config-lib.sh b/config-lib.sh\nindex 50ad6e9..6000ec9 100755\n--- a/config-lib.sh\n+++ b/config-lib.sh\n@@ -35,9 +35,9 @@ compile_check() {\n \techo\n \tcat \"$1\"\n \techo\n-\techo \"$_cc $CFLAGS $_inc_extra $_ld_static $_ld_extra -o $TMPO $@\"\n+\techo \"$_cc $_cflags $_inc_extra $_ld_static $_ld_extra -o $TMPO $@\"\n \trm -f \"$TMPO\"\n-\t$_cc $CFLAGS $_inc_extra $_ld_static $_ld_extra -o \"$TMPO\" \"$@\" || return $?\n+\t$_cc $_cflags $_inc_extra $_ld_static $_ld_extra -o \"$TMPO\" \"$@\" || return $?\n \techo\n \techo \"ldd $TMPO\"\n \t$_ldd \"$TMPO\" || return $?\n@@ -261,7 +261,7 @@ Installation directories:\n   --gitpythondir=DIR     use this prefix for python libraries [PREFIX/share/git-core/python]\n \n Miscellaneous options:\n-  --cc=COMPILER          use this C compiler to build MPlayer [gcc]\n+  --cc=COMPILER          use this C compiler to build Git [cc]\n   --perl=PATH            path to perl binary [autodetect]\n   --python=PATH          path to python binary [autodetect]\n   --target=PLATFORM      target platform (i386-linux, arm-linux, etc)\n@@ -351,8 +351,8 @@ EOF\n \t\t\t\ti[3-9]86*|x86|x86pc|k5|k6|k6_2|k6_3|k6-2|k6-3|pentium*|athlon*|i586_i686|i586-i686|BePC) host_arch=i386 ;;\n \t\t\t\tia64) host_arch=ia64 ;;\n \t\t\t\tx86_64|amd64)\n-\t\t\t\tif [ -n \"`$_cc -dumpmachine | sed -n '/^x86_64-/p;/^amd64-/p'`\" -a \\\n-\t\t\t\t\t-z \"`echo $CFLAGS | grep -- -m32`\"  ]; then\n+\t\t\t\tif [ -n \"`$_cc -dumpmachine 2>/dev/null | sed -n '/^x86_64-/p;/^amd64-/p'`\" -a \\\n+\t\t\t\t\t-z \"`echo $_cflags | grep -- -m32`\"  ]; then\n \t\t\t\t\thost_arch=x86_64\n \t\t\t\telse\n \t\t\t\t\thost_arch=i386\n@@ -408,7 +408,51 @@ test_setup() {\n \tTMPS=\"$I/git-conf-$RANDOM-$$.S\"\n }\n \n+cc_flavour() {\n+\n+\techocheck \"whether cc is GCC\"\n+\tcat > $TMPC <<EOF\n+#ifndef __GNUC__\n+#error Not GCC\n+#endif\n+int main(void) { return 0; }\n+EOF\n+\tif cc_check ; then\n+\t\techores \"yes\"\n+\t\t_cc_flavour=\"gcc\"\n+\t\treturn\n+\tfi\n+\techores \"no\"\n+\n+\techocheck \"whether cc is Sun CC\"\n+\tcat > $TMPC <<EOF\n+#ifndef __SUNPRO_C\n+#error Not SUN CC\n+#endif\n+int main(void) { return 0; }\n+EOF\n+\tif cc_check ; then\n+\t\techores \"yes\"\n+\t\t_cc_flavour=\"suncc\"\n+\t\treturn\n+\tfi\n+\techores \"no\"\n+}\n+\n basic_tests() {\n+\t_cc_flavour=unknown\n+\tcc_flavour\n+\n+\tif test \"$_cc_flavour\" = \"gcc\" ; then\n+\t\t_cflags=\"-g -O2 -Wall\"\n+\t\t_picflag=\"-fPIC\"\n+\telif test \"$_cc_flavour\" = \"suncc\"; then\n+\t\t_cflags=\"-g -xO3\"\n+\t\t_picflag=\"-KPIC\"\n+\tfi\n+\ttest \"$CFLAGS\" && _cflags=\"$CFLAGS\"\n+\ttest \"$PICFLAG\" && _picflag=\"$PICFLAG\"\n+\n \techocheck \"if your build environment is sane\"\n \tcat > $TMPC <<EOF\n int main(void) { return 0; }\n@@ -457,6 +501,8 @@ write_config() {\n # -------- Generated by configure -----------\n \n CC = $_cc\n+CFLAGS = $_cflags\n+PICFLAG = $_picflag\n PERL_PATH = $_perl\n PYTHON_PATH = $_python\n INSTALL = $_install\n-- \n1.4.1\n"}]}