The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
46821 ripley 1
#!@R_SHELL@
36746 ripley 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
 
59036 ripley 9
## Copyright (C) 2002-5 The R Core Team
36746 ripley 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
##
42314 ripley 21
## A copy of the GNU General Public License is available at
22
## http://www.r-project.org/Licenses/
36746 ripley 23
 
37351 ripley 24
revision='$Rev: 59036 $'
36746 ripley 25
version=`set - ${revision}; echo ${2}`
47522 ripley 26
version="R front-end script to f2c: ${R_VERSION} (r${version})
36746 ripley 27
 
59036 ripley 28
Copyright (C) 2002-5 The R Core Team.
42192 ripley 29
This is free software; see the GNU General Public License version 2
36746 ripley 30
or later for copying conditions.  There is NO warranty."
31
 
32
usage="Usage: R CMD f77 [options] files [objs]
33
 
34
The specified files should be FORTRAN 77 source files ending in '.f'.
35
 
36
Options:
37
  -h, --help            print short help message and exit
38
      --version         print version info and exit
39
  -c                    compile and assemble, but do not link
40
  -o FILE               place the output into FILE
41
  --verbose             display the programs invoked
42
 
58676 ripley 43
Report bugs at bugs.r-project.org ."
36746 ripley 44
 
45
## Possible user overrides
46
: ${F2C='f2c'}
47
: ${F2CLIBS='-lf2c'}
48
: ${CC='cc'}
49
: ${CPP='cpp'}
50
CFLAGS=
51
 
46994 ripley 52
##
36746 ripley 53
rc=0
54
tmp_stderr_file=${TMPDIR-/tmp}/f77_stderr.${$}
55
trap "rm -f ${tmp_stderr_file}; exit \$rc" 0
56
 
57
opt_c=no
58
opt_o=no
59
echo=echo
60
outfile=a.out
61
verbose=false
62
srcs=
63
objs=
64
 
65
## Argument loop.
66
while test -n "${1}"; do
67
  case "${1}" in
68
    -h|--help)
69
      ${echo} "${usage}"; exit 0 ;;
70
    --version)
71
      ${echo} "${version}"; exit 0 ;;
72
    --verbose)
73
      verbose=${echo} ;;
74
    -c)
75
      opt_c=yes ;;
76
    -o)
77
      opt_o=yes
78
      outfile="${2}"
79
      shift
80
      ;;
81
    -v)
82
      ${echo} "-lg2c -lm"; exit 0 ;;
83
    *.f)
84
      srcs="${srcs} ${1}" ;;
85
    *.F)
86
      srcs="${srcs} ${1}" ;;
87
    */*|*.a|*.o|*.s[lo]|*.s[lo].*)
88
      objs="${objs} ${1}" ;;
89
    *)  # assume all the rest are C flags, -fPIC, -I etc.
90
      CFLAGS="${CFLAGS} $1" ;;
91
  esac
92
  shift
93
done
94
 
95
set - "${srcs}"
96
if test ${#} -gt 1 \
97
     && test "${opt_c}" = yes \
98
     && test "${opt_o}" = yes; then
99
  echo "cannot specify -o with -c and multiple compilations"
100
  exit
101
fi
102
 
103
for f in ${*}; do
104
    case ${f} in
105
	*.f)
106
	    b=`basename ${f} .f`
107
	    ${verbose} ${F2C} ${F2CFLAGS} ${f}
108
	    ${F2C} ${F2CFLAGS} ${f}
109
	    rc=${?}
110
	    test ${rc} = 0 || exit
111
	    ;;
112
	*.F)
113
	    b=`basename ${f} .F`
114
	    ${CPP} $1 >$b.i
115
	    rc=$?
46994 ripley 116
	    case $rc in
36746 ripley 117
		0)
118
		    ${verbose} ${F2C} ${F2CFLAGS} <$b.i >$b.c
119
		    ${F2C} ${F2CFLAGS} <$b.i >$b.c
120
		    rc=$?
121
		    ;;
122
	    esac
123
	    rm $b.i
124
	    test ${rc} = 0 || exit
125
	    ;;
126
    esac
127
  if test "${opt_c}" = yes && test "${opt_o}" = yes; then
128
    CFLAGS="${CFLAGS} -o ${outfile}"
129
  fi
130
  ${verbose} ${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
131
  ${CC} -c ${CFLAGS} ${b}.c 2>${tmp_stderr_file}
132
  rc=${?}
133
  test ${rc} = 0 || exit
134
  objs="${objs} ${b}.o"
135
  rm -f ${b}.c
136
done
137
 
138
if test "${opt_c}" = no && test -n "${objs}"; then
139
  ${verbose} "${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${F2CLIBS}"
140
  ${CC} ${CFLAGS} -o ${outfile} -u MAIN__ ${objs} ${F2CLIBS}
141
fi
142
rc=${?}
143
exit ${rc}
144
 
145
### Local Variables: ***
146
### mode: sh ***
147
### sh-indentation: 2 ***
148
### End: ***