Commit 9a13e4f8cb8a1baf48cc6a85d15c3ce9cf329874

brlcad 2010-09-28T19:01:23

implement a quick check for __FUNCTION__ and __func__ based on whether the compiler can actually use one or the other at runtime. cache the checks and provide __FUNC__ for use via FTGL_CPP_FUNC.

diff --git a/Makefile.am b/Makefile.am
index 2ac07fc..92498d0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,9 +22,11 @@ EXTRA_DIST = \
 	autogen.sh \
 	configure.ac \
 	ftgl.pc.in \
+	m4/compiler.m4 \
 	m4/cxx.m4 \
 	m4/font.m4 \
 	m4/freetype2.m4 \
+	m4/func.m4 \
 	m4/gl.m4 \
 	m4/glut.m4 \
 	m4/pkg.m4 \
diff --git a/configure.ac b/configure.ac
index 84a3d7c..007e581 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,6 +38,8 @@ dnl AC_C_CONST
 dnl AC_C_INLINE
 AM_PROG_CC_C_O
 
+FTGL_CPP_FUNC
+
 # Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADER([stdlib.h])
diff --git a/m4/func.m4 b/m4/func.m4
new file mode 100644
index 0000000..ca1caa6
--- /dev/null
+++ b/m4/func.m4
@@ -0,0 +1,28 @@
+dnl FTGL_CPP_FUNC()
+dnl Check for __func__ or __FUNCTION__ and set __FUNC__ accordingly
+dnl
+
+AC_DEFUN([FTGL_CPP_FUNC], [dnl
+
+AC_REQUIRE([AC_PROG_CC_STDC])
+
+AC_CACHE_CHECK([for __func__], ac_cv_cpp_func,
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+        [[char *function = __func__;]])],
+        [ac_cv_cpp_func=yes],
+        [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+            [[char *function = __FUNCTION__;]])],
+            [ac_cv_cpp_func=__FUNCTION__],
+            [ac_cv_cpp_func=no]
+        )]
+    )]
+)
+             
+if test $ac_cv_cpp_func = yes; then
+    AC_DEFINE(__FUNC__, __func__, [Define to __FUNCTION__ or  "" if __func__ is not available.])
+elif test $ac_cv_cpp_func = __FUNCTION__; then
+    AC_DEFINE(__FUNC__, __FUNCTION__, [Define to __FUNCTION__ or "" if __func__ is not available.])
+elif test $ac_cv_cpp_func = no; then
+    AC_DEFINE(__FUNC__, "", [Define to __FUNCTION__ or "" if __func__ is not available.])
+fi
+])
diff --git a/src/FTFont/FTFontGlue.cpp b/src/FTFont/FTFontGlue.cpp
index 30a14d6..8a78dee 100644
--- a/src/FTFont/FTFontGlue.cpp
+++ b/src/FTFont/FTFontGlue.cpp
@@ -151,7 +151,7 @@ void ftglDestroyFont(FTGLfont *f)
 {
     if(!f || !f->ptr)
     {
-        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNC__);
         return;
     }
     delete f->ptr;
diff --git a/src/FTGlyph/FTGlyphGlue.cpp b/src/FTGlyph/FTGlyphGlue.cpp
index 9cf84b7..e8120c3 100644
--- a/src/FTGlyph/FTGlyphGlue.cpp
+++ b/src/FTGlyph/FTGlyphGlue.cpp
@@ -150,7 +150,7 @@ void ftglDestroyGlyph(FTGLglyph *g)
 {
     if(!g || !g->ptr)
     {
-        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNC__);
         return;
     }
     delete g->ptr;
diff --git a/src/FTLayout/FTLayoutGlue.cpp b/src/FTLayout/FTLayoutGlue.cpp
index c941912..5295347 100644
--- a/src/FTLayout/FTLayoutGlue.cpp
+++ b/src/FTLayout/FTLayoutGlue.cpp
@@ -67,7 +67,7 @@ void ftglDestroyLayout(FTGLlayout *l)
 {
     if(!l || !l->ptr)
     {
-        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNC__);
         return;
     }
     delete l->ptr;
@@ -100,13 +100,13 @@ void ftglSetLayoutFont(FTGLlayout *l, FTGLfont *font)
 {
     if(!l || !l->ptr)
     {
-        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNC__);
         return;
     }
     if(l->type != FTGL::LAYOUT_SIMPLE)
     {
         fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
-                        __FUNCTION__, l->type);
+                        __FUNC__, l->type);
     }
     l->font = font;
     return dynamic_cast<FTSimpleLayout*>(l->ptr)->SetFont(font->ptr);
@@ -117,13 +117,13 @@ FTGLfont *ftglGetLayoutFont(FTGLlayout *l)
 {
     if(!l || !l->ptr)
     {
-        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNCTION__);
+        fprintf(stderr, "FTGL warning: NULL pointer in %s\n", __FUNC__);
         return NULL;
     }
     if(l->type != FTGL::LAYOUT_SIMPLE)
     {
         fprintf(stderr, "FTGL warning: %s not implemented for %d\n",
-                        __FUNCTION__, l->type);
+                        __FUNC__, l->type);
     }
     return l->font;
 }
@@ -141,7 +141,7 @@ FTGLfont *ftglGetLayoutFont(FTGLlayout *l)
         if(l->type != FTGL::LAYOUT_SIMPLE) \
         { \
             fprintf(stderr, "FTGL warning: %s not implemented for %d\n", \
-                            __FUNCTION__, l->type); \
+                            __FUNC__, l->type); \
             cxxerr; \
         } \
         return dynamic_cast<FTSimpleLayout*>(l->ptr)->cxxname cxxarg; \