The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
36746 ripley 1
#! /bin/sh
2
 
3
## f77 -- Simple shell script wrapper to compile/link FORTRAN 77 code
4
## using the FORTRAN-to-C converter.
5
##
6
## Usage:
7
##   R CMD f77 [options] files [objs]
8
 
9
## Copyright (C) 2002-5 The R Core Development Team
10
##
11
## This document is free software; you can redistribute it and/or modify
12
## it under the terms of the GNU General Public License as published by
13
## the Free Software Foundation; either version 2, or (at your option)
14
## any later version.
15
##
16
## This program is distributed in the hope that it will be useful, but
17
## WITHOUT ANY WARRANTY; without even the implied warranty of
18
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19
## General Public License for more details.
20
##
21
## A copy of the GNU General Public License is available via WWW at
22
## http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
36821 ripley 23
## writing to the Free Software Foundation, Inc., 51 Franklin Street,
24
## Fifth Floor, Boston, MA 02110-1301  USA.
36746 ripley 25
 
37351 ripley 26
revision='$Rev: 37351 $'
36746 ripley 27
version=`set - ${revision}; echo ${2}`
28
version="R front-end script to f2c ${version}
29
 
30
Copyright (C) 2002-5 The R Core Development Team.
31
This is free software; see the GNU General Public Licence version 2
32
or later for copying conditions.  There is NO warranty."
33
 
34
usage="Usage: R CMD f77 [options] files [objs]
35
 
36
The specified files should be FORTRAN 77 source files ending in '.f'.
37
 
38
Options:
39
  -h, --help            print short help message and exit
40
      --version         print version info and exit
41
  -c                    compile and assemble, but do not link
42
  -o FILE               place the output into FILE
43
  --verbose             display the programs invoked
44
 
45
Report bugs to <r-bugs@r-project.org>."
46
 
47
## Possible user overrides
48
: ${F2C='f2c'}
49
: ${F2CLIBS='-lf2c'}
50
: ${CC='cc'}
51
: ${CPP='cpp'}
52
CFLAGS=
53
 
54
## 
55
rc=0
56
tmp_stderr_file=${TMPDIR-/tmp}/f77_stderr.${$}
57
trap "rm -f ${tmp_stderr_file}; exit \$rc" 0
58
 
59
opt_c=no
60
opt_o=no
61
echo=echo
62
outfile=a.out
63
verbose=false
64
srcs=
65
objs=
66
 
67
## Argument loop.
68
while test -n "${1}"; do
69
  case "${1}" in
70
    -h|--help)
71
      ${echo} "${usage}"; exit 0 ;;
72
    --version)
73
      ${echo} "${version}"; exit 0 ;;
74
    --verbose)
75
      verbose=${echo} ;;
76
    -c)
77
      opt_c=yes ;;
78
    -o)
79
      opt_o=yes
80
      outfile="${2}"
81
      shift
82
      ;;
83
    -v)
84
      ${echo} "-lg2c -lm"; exit 0 ;;
85
    *.f)
86
      srcs="${srcs} ${1}" ;;
87
    *.F)
88
      srcs="${srcs} ${1}" ;;
89
    */*|*.a|*.o|*.s[lo]|*.s[lo].*)
90
      objs="${objs} ${1}" ;;
91
    *)  # assume all the rest are C flags, -fPIC, -I etc.
92
      CFLAGS="${CFLAGS} $1" ;;
93
  esac
94
  shift
95
done
96
 
97
set - "${srcs}"
98
if test ${#} -gt 1 \
99
     && test "${opt_c}" = yes \
100
     && test "${opt_o}" = yes; then
101
  echo "cannot specify -o with -c and multiple compilations"
102
  exit
103
fi
104
 
105
for f in ${*}; do
106
    case ${f} in
107
	*.f)
108
	    b=`basename ${f} .f`
109
	    ${verbose} ${F2C} ${F2CFLAGS} ${f}
110
	    ${F2C} ${F2CFLAGS} ${f}
111
	    rc=${?}
112
	    test ${rc} = 0 || exit
113
	    ;;
114
	*.F)
115
	    b=`basename ${f} .F`
116
	    ${CPP} $1 >$b.i
117
	    rc=$?
118
	    case $rc in 
119
		0)
120
		    ${verbose} ${F2C} ${F2CFLAGS} <$b.i >$b.c
121
		    ${F2C} ${F2CFLAGS} <$b.i >$b.c
122
		    rc=$?
123
		    ;;
124
	    esac
125
	    rm $b.i
126
	    test ${rc} = 0 || exit
127
	    ;;
128
    esac
129
  if test "${opt_c}" = yes && test "${opt_o}" = yes; then
130
    CFLAGS="${CFLAGS} -o ${outfile}"
131
  fi
132
  ${verbose} ${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
133
  ${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
134
  rc=${?}
135
  test ${rc} = 0 || exit
136
  objs="${objs} ${b}.o"
137
  rm -f ${b}.c
138
done
139
 
140
if test "${opt_c}" = no && test -n "${objs}"; then
141
  ${verbose} "${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${F2CLIBS}"
142
  ${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${F2CLIBS}
143
fi
144
rc=${?}
145
exit ${rc}
146
 
147
### Local Variables: ***
148
### mode: sh ***
149
### sh-indentation: 2 ***
150
### End: ***