-
Notifications
You must be signed in to change notification settings - Fork 315
/
f77_f2c
executable file
·150 lines (134 loc) · 3.67 KB
/
f77_f2c
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
144
145
146
147
148
149
150
#! /bin/sh
## f77 -- Simple shell script wrapper to compile/link FORTRAN 77 code
## using the FORTRAN-to-C converter.
##
## Usage:
## R CMD f77 [options] files [objs]
## Copyright (C) 2002-5 The R Core Development Team
##
## This document is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## A copy of the GNU General Public License is available via WWW at
## http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
## writing to the Free Software Foundation, Inc., 51 Franklin Street,
## Fifth Floor, Boston, MA 02110-1301 USA.
revision='$Rev$'
version=`set - ${revision}; echo ${2}`
version="R front-end script to f2c ${version}
Copyright (C) 2002-5 The R Core Development Team.
This is free software; see the GNU General Public Licence version 2
or later for copying conditions. There is NO warranty."
usage="Usage: R CMD f77 [options] files [objs]
The specified files should be FORTRAN 77 source files ending in '.f'.
Options:
-h, --help print short help message and exit
--version print version info and exit
-c compile and assemble, but do not link
-o FILE place the output into FILE
--verbose display the programs invoked
Report bugs to <r-bugs@r-project.org>."
## Possible user overrides
: ${F2C='f2c'}
: ${F2CLIBS='-lf2c'}
: ${CC='cc'}
: ${CPP='cpp'}
CFLAGS=
##
rc=0
tmp_stderr_file=${TMPDIR-/tmp}/f77_stderr.${$}
trap "rm -f ${tmp_stderr_file}; exit \$rc" 0
opt_c=no
opt_o=no
echo=echo
outfile=a.out
verbose=false
srcs=
objs=
## Argument loop.
while test -n "${1}"; do
case "${1}" in
-h|--help)
${echo} "${usage}"; exit 0 ;;
--version)
${echo} "${version}"; exit 0 ;;
--verbose)
verbose=${echo} ;;
-c)
opt_c=yes ;;
-o)
opt_o=yes
outfile="${2}"
shift
;;
-v)
${echo} "-lg2c -lm"; exit 0 ;;
*.f)
srcs="${srcs} ${1}" ;;
*.F)
srcs="${srcs} ${1}" ;;
*/*|*.a|*.o|*.s[lo]|*.s[lo].*)
objs="${objs} ${1}" ;;
*) # assume all the rest are C flags, -fPIC, -I etc.
CFLAGS="${CFLAGS} $1" ;;
esac
shift
done
set - "${srcs}"
if test ${#} -gt 1 \
&& test "${opt_c}" = yes \
&& test "${opt_o}" = yes; then
echo "cannot specify -o with -c and multiple compilations"
exit
fi
for f in ${*}; do
case ${f} in
*.f)
b=`basename ${f} .f`
${verbose} ${F2C} ${F2CFLAGS} ${f}
${F2C} ${F2CFLAGS} ${f}
rc=${?}
test ${rc} = 0 || exit
;;
*.F)
b=`basename ${f} .F`
${CPP} $1 >$b.i
rc=$?
case $rc in
0)
${verbose} ${F2C} ${F2CFLAGS} <$b.i >$b.c
${F2C} ${F2CFLAGS} <$b.i >$b.c
rc=$?
;;
esac
rm $b.i
test ${rc} = 0 || exit
;;
esac
if test "${opt_c}" = yes && test "${opt_o}" = yes; then
CFLAGS="${CFLAGS} -o ${outfile}"
fi
${verbose} ${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
rc=${?}
test ${rc} = 0 || exit
objs="${objs} ${b}.o"
rm -f ${b}.c
done
if test "${opt_c}" = no && test -n "${objs}"; then
${verbose} "${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${F2CLIBS}"
${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${F2CLIBS}
fi
rc=${?}
exit ${rc}
### Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***