The R Project SVN R

Rev

Rev 36821 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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