On 16 Jun 2000, Akim Demaille wrote:
> >>>>> "Alexandre" == Alexandre Oliva <[EMAIL PROTECTED]> writes:
>
> Alexandre> On Jun 14, 2000, Mo DeJong <[EMAIL PROTECTED]> wrote:
> >> Perhaps this is a silly idea, but why don't you just run the
> >> compiler without the -g flag to make sure that it created a
> >> conftest.o file, and then run with the -g flag but check that the
> >> produced conftest.o is larger than the first one.
>
> Alexandre> I like this approach!
>
> Fine with me too.
>
> Mo, yet another patch? :)
Well, something like the following patch would work.
This is kind of wacky because the only way I could figure
out how to get the length of a binary file was to use
od and then measure the string length of that. If someone
else has a better idea I am all for it. Also, _AC_PROG_CXX_G
would need to do the same thing. Of course, there does not
seem to be any need to have two macros. How about merging
them into a more generic AC_PROG_COMPILER_G macro
that could test any compiler for the -g flag?
Mo DeJong
Red Hat Inc
Index: aclang.m4
===================================================================
RCS file: /cvs/autoconf/aclang.m4,v
retrieving revision 1.30
diff -u -r1.30 aclang.m4
--- aclang.m4 2000/06/07 07:16:16 1.30
+++ aclang.m4 2000/06/16 15:44:37
@@ -604,10 +609,32 @@
# _AC_PROG_CC_G
# ------------
+# There is no dependable way to check to see if a compiler
+# supports a given flag. In the case of the -g flag, we can
+# test to see if -g adds debug info the the object file by
+# seeing if the produced object file get bigger when the
+# -g option is passed in to the compiler.
define([_AC_PROG_CC_G],
[AC_CACHE_CHECK(whether ${CC-cc} accepts -g, ac_cv_prog_cc_g,
[echo 'void f(){}' >conftest.c
-if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
+# First, make sure an object file is generated
+AC_TRY_COMMAND(${CC-cc} -c conftest.c)
+if test ! -s conftest.${ac_objext} ; then
+ AC_MSG_ERROR([Compiler did not produce an object file with -c flag])
+fi
+mv conftest.${ac_objext} conftest_smaller.${ac_objext}
+# Run the compiler with the -g flag
+AC_TRY_COMMAND(${CC-cc} -c -g conftest.c)
+mv conftest.${ac_objext} conftest_bigger.${ac_objext}
+# Now figure out how big each file is
+ac_cv_prog_cc_g_smaller=`od conftest_smaller.o`
+ac_cv_prog_cc_g_smaller=${#ac_cv_prog_cc_g_smaller}
+ac_cv_prog_cc_g_bigger=`od conftest_bigger.o`
+ac_cv_prog_cc_g_bigger=${#ac_cv_prog_cc_g_bigger}
+dnl echo "ac_cv_prog_cc_g_smaller = $ac_cv_prog_cc_g_smaller" >&AC_FD_LOG
+dnl echo "ac_cv_prog_cc_g_bigger = $ac_cv_prog_cc_g_bigger" >&AC_FD_LOG
+# If the object file generated with -g is bigger, then -g works
+if test $ac_cv_prog_cc_g_bigger -gt $ac_cv_prog_cc_g_smaller ; then
ac_cv_prog_cc_g=yes
else
ac_cv_prog_cc_g=no