The R Project SVN R

Rev

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

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