The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
19165 hornik 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 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
23
## writing to the Free Software Foundation, Inc., 59 Temple Place,
24
## Suite 330, Boston, MA  02111-1307, U.S.A.
25
 
26
revision='$Revision: 1.1 $'
27
version=`set - ${revision}; echo ${2}`
28
version="R front-end script to f2c ${version}
29
 
30
Copyright (C) 2002 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
  -v, --verbose         display the programs invoked
44
 
45
Report bugs to <r-bugs@r-project.org>."
46
 
47
## Defaults from configure
48
: ${F77='@F77@'}
49
: ${F2C='@F2C@'}
50
: ${CC='@CC@'}
51
: ${CFLAGS='@CFLAGS@'}
52
FLIBS='@FLIBS@'
53
 
54
## For sake of completeness: if we have a real FORTRAN 77 compiler then
55
## use it.
56
if test -z "${F2C}"; then
57
  exec ${F77} "${@}"
58
fi
59
 
60
## 
61
rc=0
62
tmp_stderr_file=${TMPDIR-/tmp}/f77_stderr.${$}
63
trap "rm -f ${tmp_stderr_file}; exit \$rc" 0
64
 
65
opt_c=no
66
opt_o=no
67
echo=echo
68
outfile=a.out
69
verbose=false
70
srcs=
71
objs=
72
 
73
## Argument loop.
74
while test -n "${1}"; do
75
  case "${1}" in
76
    -h|--help)
77
      ${echo} "${usage}"; exit 0 ;;
78
    --version)
79
      ${echo} "${version}"; exit 0 ;;
80
    -v|--verbose)
81
      verbose=${echo} ;;
82
    -c)
83
      opt_c=yes ;;
84
    -o)
85
      opt_o=yes
86
      outfile="${2}"
87
      shift
88
      ;;
89
    *.f)
90
      srcs="${srcs} ${1}" ;;
91
    */*|*.a|*.o|*.s[lo]|*.s[lo].*)
92
      objs="${objs} ${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
  b=`basename ${f} .f`
107
  ${verbose} ${F2C} ${F2CFLAGS} ${f}
108
  ${F2C} ${F2CFLAGS} ${f}
109
  rc=${?}
110
  test ${rc} = 0 || exit
111
  if test "${opt_c}" = yes && test "${opt_o}" = yes; then
112
    CFLAGS="${CFLAGS} -o ${outfile}"
113
  fi
114
  ${verbose} ${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
115
  ${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
116
  rc=${?}
117
  test ${rc} = 0 || exit
118
  objs="${objs} ${b}.o"
119
  rm -f ${b}.c
120
done
121
 
122
if test "${opt_c}" = no && test -n "${objs}"; then
123
  ${verbose} "${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${FLIBS}"
124
  ${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${FLIBS}
125
fi
126
rc=${?}
127
exit ${rc}
128
 
129
### Local Variables: ***
130
### mode: sh ***
131
### sh-indentation: 2 ***
132
### End: ***