From bdd07e3f832e180bbc987e9a16753d9e29ed5fa2 Mon Sep 17 00:00:00 2001 From: okuji Date: Sun, 27 Jun 1999 06:18:02 +0000 Subject: [PATCH] set CFLAGS to "-Os -g" if the optimization flag for size is available --- ChangeLog | 7 ++++ configure | 104 ++++++++++++++++++++++++++++++++++++--------------- configure.in | 19 ++++++++++ 3 files changed, 100 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 275343d8d..e531b719f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +1999-06-27 Pavel Roskin + + * configure.in: set CFLAGS to "-Os -g" for compilers which + understand "-Os" if CFLAGS is not already set. Use + "-O2 -fno-strength-reduce -fno-unroll-loops -g" for older gcc + versions. + 1999-06-25 OKUJI Yoshinori * stage2/disk_io.c (attempt_mount) [STAGE1_5]: Set FSYS_TYPE to diff --git a/configure b/configure index 97cc545e9..8154b5ac8 100644 --- a/configure +++ b/configure @@ -904,13 +904,18 @@ else GRUB_MAINT_FALSE= fi +# This should be checked before AC_PROG_CC +if test "x$CFLAGS" = x; then + default_CFLAGS=yes +fi + # # Programs # echo $ac_n "checking build system type""... $ac_c" 1>&6 -echo "configure:914: checking build system type" >&5 +echo "configure:919: checking build system type" >&5 if test "x$ac_cv_build" = "x" || (test "x$build" != "xNONE" && test "x$build" != "x$ac_cv_build_alias"); then # Make sure we can run config.sub. @@ -957,7 +962,7 @@ fi # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:961: checking for $ac_word" >&5 +echo "configure:966: checking for $ac_word" >&5 if eval "test \"\${ac_cv_prog_CC+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -989,7 +994,7 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:993: checking for $ac_word" >&5 +echo "configure:998: checking for $ac_word" >&5 if eval "test \"\${ac_cv_prog_CC+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1019,7 +1024,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1023: checking for $ac_word" >&5 +echo "configure:1028: checking for $ac_word" >&5 if eval "test \"\${ac_cv_prog_CC+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1070,7 +1075,7 @@ fi # Extract the first word of "cl", so it can be a program name with args. set dummy cl; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1074: checking for $ac_word" >&5 +echo "configure:1079: checking for $ac_word" >&5 if eval "test \"\${ac_cv_prog_CC+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1102,7 +1107,7 @@ fi fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $CPPFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:1106: checking whether the C compiler ($CC $CFLAGS $CPPFLAGS $LDFLAGS) works" >&5 +echo "configure:1111: checking whether the C compiler ($CC $CFLAGS $CPPFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -1113,12 +1118,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 1117 "configure" +#line 1122 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:1122: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1127: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -1144,12 +1149,12 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $CPPFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:1148: checking whether the C compiler ($CC $CFLAGS $CPPFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:1153: checking whether the C compiler ($CC $CFLAGS $CPPFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:1153: checking whether we are using GNU C" >&5 +echo "configure:1158: checking whether we are using GNU C" >&5 if eval "test \"\${ac_cv_prog_gcc+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1158,7 +1163,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1162: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1167: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -1177,7 +1182,7 @@ ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:1181: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:1186: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"\${ac_cv_prog_cc_g+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1211,7 +1216,7 @@ fi # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1215: checking for $ac_word" >&5 +echo "configure:1220: checking for $ac_word" >&5 if eval "test \"\${ac_cv_prog_RANLIB+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1239,13 +1244,52 @@ else fi +if test "x$ac_cv_prog_gcc" = xyes; then + if test "x$default_CFLAGS" = xyes; then + echo $ac_n "checking whether optimization for size works""... $ac_c" 1>&6 +echo "configure:1251: checking whether optimization for size works" >&5 +if eval "test \"\${size_flag+set}\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + + CFLAGS="-Os -g" + cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + size_flag=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + size_flag=no +fi +rm -f conftest* + +fi + +echo "$ac_t""$size_flag" 1>&6 + if test "x$size_flag" = xyes; then + CFLAGS="-Os -g" + else + CFLAGS="-O2 -fno-strength-reduce -fno-unroll-loops -g" + fi + fi +fi + # Enforce coding standards. CPPFLAGS="$CPPFLAGS -Wall -Wmissing-prototypes -Wunused" # Extract the first word of "${ac_tool_prefix}ld", so it can be a program name with args. set dummy ${ac_tool_prefix}ld; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1249: checking for $ac_word" >&5 +echo "configure:1293: checking for $ac_word" >&5 if eval "test \"\${ac_cv_prog_LD+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1277,7 +1321,7 @@ fi # Extract the first word of "${ac_tool_prefix}objcopy", so it can be a program name with args. set dummy ${ac_tool_prefix}objcopy; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1281: checking for $ac_word" >&5 +echo "configure:1325: checking for $ac_word" >&5 if eval "test \"\${ac_cv_prog_OBJCOPY+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1310,7 +1354,7 @@ fi # Defined in acinclude.m4. echo $ac_n "checking symbol names produced by ${CC-cc}""... $ac_c" 1>&6 -echo "configure:1314: checking symbol names produced by ${CC-cc}" >&5 +echo "configure:1358: checking symbol names produced by ${CC-cc}" >&5 if eval "test \"\${grub_cv_asm_ext_c+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1323,7 +1367,7 @@ func (int *list) } EOF -if { ac_try='${CC-cc} -S conftest.c'; { (eval echo configure:1327: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.s; then : +if { ac_try='${CC-cc} -S conftest.c'; { (eval echo configure:1371: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.s; then : else { echo "configure: error: ${CC-cc} failed to produce assembly code" 1>&2; exit 1; } fi @@ -1352,7 +1396,7 @@ EOF echo $ac_n "checking whether ${OBJCOPY} works for absolute addresses""... $ac_c" 1>&6 -echo "configure:1356: checking whether ${OBJCOPY} works for absolute addresses" >&5 +echo "configure:1400: checking whether ${OBJCOPY} works for absolute addresses" >&5 if eval "test \"\${grub_cv_prog_objcopy_absolute+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1364,21 +1408,21 @@ blah (void) } EOF -if { (eval echo configure:1368: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.o; then : +if { (eval echo configure:1412: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.o; then : else { echo "configure: error: ${CC-cc} cannot compile C source code" 1>&2; exit 1; } fi grub_cv_prog_objcopy_absolute=yes for link_addr in 2000 8000 7C00; do - if { ac_try='${LD-ld} -N -Ttext $link_addr conftest.o -o conftest.exec'; { (eval echo configure:1374: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : + if { ac_try='${LD-ld} -N -Ttext $link_addr conftest.o -o conftest.exec'; { (eval echo configure:1418: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : else { echo "configure: error: ${LD-ld} cannot link at address $link_addr" 1>&2; exit 1; } fi - if { ac_try='${OBJCOPY-objcopy} -O binary conftest.exec conftest'; { (eval echo configure:1378: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : + if { ac_try='${OBJCOPY-objcopy} -O binary conftest.exec conftest'; { (eval echo configure:1422: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then : else { echo "configure: error: ${OBJCOPY-objcopy} cannot create binary files" 1>&2; exit 1; } fi - if test ! -f conftest.old || { ac_try='cmp -s conftest.old conftest'; { (eval echo configure:1382: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then + if test ! -f conftest.old || { ac_try='cmp -s conftest.old conftest'; { (eval echo configure:1426: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then mv -f conftest conftest.old else grub_cv_prog_objcopy_absolute=no @@ -1395,7 +1439,7 @@ fi echo $ac_n "checking for .code16 addr32 assembler support""... $ac_c" 1>&6 -echo "configure:1399: checking for .code16 addr32 assembler support" >&5 +echo "configure:1443: checking for .code16 addr32 assembler support" >&5 if eval "test \"\${grub_cv_asm_addr32+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1405,7 +1449,7 @@ l1: addr32 movb %al, l1 EOF -if { ac_try='${CC-cc} -c conftest.s'; { (eval echo configure:1409: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.o; then +if { ac_try='${CC-cc} -c conftest.s'; { (eval echo configure:1453: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } && test -s conftest.o; then grub_cv_asm_addr32=yes else grub_cv_asm_addr32=no @@ -1420,7 +1464,7 @@ fi # Check for curses libraries. echo $ac_n "checking for getch in -lncurses""... $ac_c" 1>&6 -echo "configure:1424: checking for getch in -lncurses" >&5 +echo "configure:1468: checking for getch in -lncurses" >&5 ac_lib_var=`echo ncurses'_'getch | sed 'y%./+-:%__p__%'` if eval "test \"\${ac_cv_lib_$ac_lib_var+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1428,7 +1472,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lncurses $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1487: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1462,7 +1506,7 @@ EOF else echo "$ac_t""no" 1>&6 echo $ac_n "checking for getch in -lcurses""... $ac_c" 1>&6 -echo "configure:1466: checking for getch in -lcurses" >&5 +echo "configure:1510: checking for getch in -lcurses" >&5 ac_lib_var=`echo curses'_'getch | sed 'y%./+-:%__p__%'` if eval "test \"\${ac_cv_lib_$ac_lib_var+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1470,7 +1514,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lcurses $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1529: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else diff --git a/configure.in b/configure.in index 837ea689c..c956d1a69 100644 --- a/configure.in +++ b/configure.in @@ -43,6 +43,11 @@ AC_ARG_ENABLE(maintainer-mode, esac],[maintainermode=no]) AM_CONDITIONAL(GRUB_MAINT, test "x${maintainermode}" = xyes) +# This should be checked before AC_PROG_CC +if test "x$CFLAGS" = x; then + default_CFLAGS=yes +fi + # # Programs # @@ -51,6 +56,20 @@ AC_CHECK_TOOL(CC, gcc) AC_PROG_CC AC_PROG_RANLIB +if test "x$ac_cv_prog_gcc" = xyes; then + if test "x$default_CFLAGS" = xyes; then + AC_CACHE_CHECK([whether optimization for size works], size_flag, [ + CFLAGS="-Os -g" + AC_TRY_COMPILE(, , size_flag=yes, size_flag=no) + ]) + if test "x$size_flag" = xyes; then + CFLAGS="-Os -g" + else + CFLAGS="-O2 -fno-strength-reduce -fno-unroll-loops -g" + fi + fi +fi + # Enforce coding standards. CPPFLAGS="$CPPFLAGS -Wall -Wmissing-prototypes -Wunused"