5
|
1 #!/bin/sh |
|
2 # |
|
3 # f2c-compat -- try to see if calling a Fortran compiled routine from |
|
4 # a C compiled main program will work as if the Fortran routine has |
|
5 # been translated to C via f2c. |
|
6 # |
|
7 # John W. Eaton |
|
8 # jwe@che.utexas.edu |
|
9 # Department of Chemical Engineering |
|
10 # The University of Texas at Austin |
|
11 |
|
12 # trap 'rm -f ftest* ctest* core; exit 1' 1 3 15 |
|
13 |
|
14 status=1 |
|
15 |
|
16 if test $# -eq 0; then |
|
17 FLIBS_SH="./flibs.sh" |
|
18 elif test $# -eq 1; then |
|
19 FLIBS_SH="$1" |
|
20 else |
|
21 echo "usage: f2c-compat.sh [flibs_script]" |
|
22 exit 1 |
|
23 fi |
|
24 |
|
25 # Write a minimal program, compile it, and see if it works as |
|
26 # expected. |
|
27 |
|
28 cat << EOF > ftest.f |
|
29 INTEGER FUNCTION FORSUB (C, D) |
|
30 CHARACTER *(*) C |
|
31 INTEGER L |
|
32 DOUBLE PRECISION D |
|
33 L = LEN (C) |
|
34 WRITE (*, '(A,1X,I2)') C(1:L), INT (D) |
|
35 FORSUB = 1 |
|
36 RETURN |
|
37 END |
|
38 EOF |
|
39 ${F77-f77} -c ftest.f > /dev/null 2>&1 |
|
40 |
|
41 cat << EOF > ctest.c |
|
42 extern int strlen (); |
|
43 extern int strcpy (); |
|
44 extern int forsub_ (); |
|
45 static char s[14]; |
|
46 int |
|
47 main (argc, argv) |
|
48 int argc; |
|
49 char **argv; |
|
50 { |
|
51 double d = 10.0; |
|
52 int len; |
|
53 strcpy (s, "FOO-I-HITHERE"); |
|
54 len = strlen (s); |
|
55 return (! forsub_ (s, &d, len)); |
|
56 } |
|
57 /* For Sun f77 */ |
|
58 int |
|
59 MAIN_ () |
|
60 { |
|
61 return 0; |
|
62 } |
|
63 EOF |
|
64 |
|
65 ${CC-cc} -c ctest.c > /dev/null 2>&1 |
|
66 |
|
67 FLIBS=`F77="${F77-f77}" $FLIBS_SH` |
|
68 |
|
69 ${CC-cc} -o ctest ctest.o ftest.o $FLIBS -lm > /dev/null 2>&1 |
|
70 |
|
71 ctest_output=`./ctest 2>&1` |
|
72 status=$? |
|
73 |
|
74 if test $status -eq 0 && test "$ctest_output" = "FOO-I-HITHERE 10" |
|
75 then |
|
76 echo '-DF77_APPEND_UNDERSCORE=1' |
|
77 status=0 |
|
78 else |
|
79 cat << EOF > ctest.c |
|
80 extern int strlen (); |
|
81 extern int strcpy (); |
|
82 extern int forsub (); |
|
83 static char s[14]; |
|
84 int |
|
85 main (argc, argv) |
|
86 int argc; |
|
87 char **argv; |
|
88 { |
|
89 double d = 10.0; |
|
90 int len; |
|
91 strcpy (s, "FOO-I-HITHERE"); |
|
92 len = strlen (s); |
|
93 return (! forsub (s, &d, len)); |
|
94 } |
|
95 /* For Sun f77 */ |
|
96 int |
|
97 MAIN_ () |
|
98 { |
|
99 return 0; |
|
100 } |
|
101 EOF |
|
102 |
|
103 ${CC-cc} -c ctest.c > /dev/null 2>&1 |
|
104 |
|
105 ${CC-cc} -o ctest ctest.o ftest.o $FLIBS -lm > /dev/null 2>&1 |
|
106 |
|
107 ctest_output=`./ctest 2>&1` |
|
108 status=$? |
|
109 |
|
110 if test $status -eq 0 && test "$ctest_output" = "FOO-I-HITHERE 10" |
|
111 then |
|
112 status=0 |
|
113 fi |
|
114 fi |
|
115 |
|
116 rm -f ftest* ctest* core |
|
117 |
|
118 # Bye-bye. |
|
119 |
|
120 exit $status |