aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschnetter <schnetter@51d2df92-0e4f-0410-a727-bd43d766d6b6>2007-05-10 19:19:35 +0000
committerschnetter <schnetter@51d2df92-0e4f-0410-a727-bd43d766d6b6>2007-05-10 19:19:35 +0000
commita9b098dab8e0e8fdf596a539b867fd1ffebdbeba (patch)
tree5f326d3a0f1c4ebcb9f00d0068154830034bb74a
parent340c9a3315cc402fbacdc5d7b31f9f85f36c11f5 (diff)
Provide macros for stringification and string concatenation
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/Fortran/trunk@35 51d2df92-0e4f-0410-a727-bd43d766d6b6
-rw-r--r--configuration.ccl6
-rw-r--r--fortran.sh54
-rw-r--r--interface.ccl2
-rw-r--r--src/fortran.h23
4 files changed, 83 insertions, 2 deletions
diff --git a/configuration.ccl b/configuration.ccl
index 508357c..bde52b6 100644
--- a/configuration.ccl
+++ b/configuration.ccl
@@ -3,6 +3,8 @@
PROVIDES Fortran
{
- SCRIPT
- LANG
+ SCRIPT fortran.sh
+ LANG sh
}
+
+REQUIRES Fortran
diff --git a/fortran.sh b/fortran.sh
new file mode 100644
index 0000000..acebc9f
--- /dev/null
+++ b/fortran.sh
@@ -0,0 +1,54 @@
+#! /bin/sh
+# $Header$
+
+# Try to use ## for token concatenation.
+# If this works, we likely have an ANSI cpp.
+
+rm config.tmp config.out 2> /dev/null
+
+if test -z "${FPP}"; then
+ # FPP is not defined; try to guess which fpp will be chosen later
+ FPP=cpp
+fi
+
+cat > config.tmp <<EOF
+#define CONCAT(a,b) a##b
+CONCAT(hello,world)
+EOF
+${FPP} ${FPPFLAGS} config.tmp > config.out
+grep 'helloworld' config.out > /dev/null 2> /dev/null
+# grep returns 0 for success, non-zero for failure
+cpp_ansi=$?
+rm config.tmp config.out 2> /dev/null
+
+cat > config.tmp <<EOF
+#define CONCAT(a,b) a/**/b
+CONCAT(hello,world)
+EOF
+${FPP} ${FPPFLAGS} config.tmp > config.out
+grep 'helloworld' config.out > /dev/null 2> /dev/null
+# grep returns 0 for success, non-zero for failure
+cpp_traditional=$?
+rm config.tmp config.out 2> /dev/null
+
+
+
+if test ${cpp_ansi} = 0; then
+ echo 'BEGIN MESSAGE'
+ echo 'Found an ANSI-like Fortran cpp'
+ echo 'END MESSAGE'
+ echo 'BEGIN DEFINE'
+ echo 'FORTRAN_CPP_ANSI 1'
+ echo 'END DEFINE'
+elif test ${cpp_traditional} = 0; then
+ echo 'BEGIN MESSAGE'
+ echo 'Found a traditional Fortran cpp'
+ echo 'END MESSAGE'
+ echo 'BEGIN DEFINE'
+ echo 'FORTRAN_CPP_ANSI 0'
+ echo 'END DEFINE'
+else
+ echo 'BEGIN ERROR'
+ echo 'No Fortran preprocessor defined'
+ echo 'END ERROR'
+fi
diff --git a/interface.ccl b/interface.ccl
index 2d41c41..c4dde52 100644
--- a/interface.ccl
+++ b/interface.ccl
@@ -2,3 +2,5 @@
# $Header$
IMPLEMENTS: Fortran
+
+INCLUDES SOURCE: fortran.h IN fortran.h
diff --git a/src/fortran.h b/src/fortran.h
new file mode 100644
index 0000000..65442c8
--- /dev/null
+++ b/src/fortran.h
@@ -0,0 +1,23 @@
+/* $Header$ */
+
+#ifndef FORTRAN_H
+#define FORTRAN_H
+
+#include "cctk.h"
+
+#if FORTRAN_CPP_ANSI
+/* For an ANSI-like cpp */
+
+#define CONCAT(a,b) a##b
+#define STRINGIFY(a) STRINGIFY_(a)
+#define STRINGIFY_(a) #a
+
+#else
+/* For a traditional cpp */
+
+#define CONCAT(a,b) a/**/b
+#define STRINGIFY(a) "a"
+
+#endif
+
+#endif /* #ifdef FORTRAN_H */