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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
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; \