summaryrefslogtreecommitdiff
path: root/lang/f2c/files/f2c-f77.in
blob: 2aa8b10fe2b4f76967eb2eac888c7e00987cf8fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#!@SHELL@
PATH=$PATH:/bin:/usr/bin:@PREFIX@/bin
#
# This script has deviated so much from "fc" that it is now easier to
# maintain it as its own file instead of a patch.  Some improvements
# over "fc" are:
#
# -O    for optimization
# -fPIC for PIC support
# -Wxxx for gcc warnings
# -Wl,  for additional linker arguments
# -pg   for profiled code
# -r8   promote REAL and COMPLEX to DOUBLE REAL and DOUBLE COMPLEX
# -s    to strip executible 
# -v    for verbose output
# -compatibility_version, -install_name, -current_version    for libtool on darwin gcc
# 
# Also only pass -m* to the C compiler not f2c.
# 
# Unknown options are passed on to the C compiler and C preprocessor.
# 
#USAGESTART
# f77-style shell script to compile and load fortran, C, and assembly codes
#
#	usage:	f2c-f77 [options] files [-l library]
#
#	Options:
#
#		-c		Do not call linker, leave relocatables in *.o.
#
#		-C		Check that subscripts are in bounds.
#
#		-D def		passed to C compiler (for .c files)
#				or to cpp (for .F files)
#
#		-fPIC		turn on the -fPIC flag to the c compiler
#
#		-g		produce debugging information.
#
#		-I includepath	passed to C compiler (for .c files)
#				or to cpp (for .F files), and to f2c
#
#		-l library	(passed to ld).
#
#		-L includepath	passed to ld.  Library include path
#
#		-m xxx		passed to the C compiler as -mxxx
#
#		-Ntnnn		allow nnn entries in table t
#
#		-o objfile	Override default executable name a.out.
#
#		-pg		pass -pg (generate profile information) to the c
#				compiler.
#
#		-O		turn on the -O flag to the c compiler
#
#		-O1		turn on the -O1 flag to the c compiler
#
#		-O2		turn on the -O2 flag to the c compiler
#
#		-O3		turn on the -O3 flag to the c compiler
#
#		-P		emit .P files
#
#		-r8		promote REAL to DOUBLE PRECISION,
#				COMPLEX to DOUBLE COMPLEX
#
#		-s		Strip the symbol table from the executable file
#
#		-S		leave assembler output on file.s
#
#		-u		complain about undeclared variables
#
#		-U def				passed to C compiler (for .c files) or to
#				cpp (for .F files) to remove def
#
#		-v		be verbose.  Output is produced on the standard
#				error output.
#
#		-w		omit all warning messages
#
#		-w66		omit Fortran 66 compatibility warning messages
#
#		-Wxxx		turn on the -Wxxx flag to the c compiler
#
#		-Wl,		Pass options to the linker.  For example, 
#				-Wl,-R/usr/X11R6/lib
#				passes "-R/usr/X11R6/lib" to the linker
#
#		files		FORTRAN source files ending in .f
#				FORTRAN with cpp preprocessor directives
#					ending in .F 
#				C source files ending in .c
#				Assembly language files ending in .s 
#				efl source files ending in .e 
#				RATFOR files ending in .r 
#				Object files ending in .o
#				Shared libraries ending in .so
#
#				f2c prototype files ending in .P ; such
#				files only affect subsequent files.

# if no input arguments, then spit out the help stuff from the beginning
# of this file.
if [ $# = 0 ]; then
 cat $0 | awk '$1 == "#USAGESTART", $1 == ""' | tail +2 | sed 's/#//g'
fi

# Quote args to make them safe in the shell.
#
# After building up a quoted list, use it by evaling it inside
# double quotes, like this:
#    eval "set -- $quotedlist"
# or like this:
#    eval "\$command $quotedlist \$filename"
shell_quote()
{
	local result=''
	local arg
	for arg in "$@" ; do
		# Append a space if necessary
		result="${result}${result:+ }"
		# Convert each embedded ' to '\'',
		# then insert ' at the beginning of the first line,
		# and append ' at the end of the last line.
		result="${result}$(printf "%s\n" "$arg" | \
			sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
		# For shells that don't understand $(...), try the following:
		#result="${result}`printf \"%s\\n\" \"\$arg\" | \
		#	sed -e \"s/'/'\\\\\\\\''/g\" -e \"1s/^/'/\" -e \"\\\$s/\\\$/'/\"`"
    done
    printf "%s\n" "$result"
}

tmpd=${TMPDIR:-/tmp}
mytmp=${tmpd}/f2c_$$
mkdir -m 0700 $mytmp
if test $? -ne 0 ; then
	echo "ERROR:  Could not create temporary directory ${mytmp}"
	echo "Either you do not have write permission to ${tmpd} or"
	echo "${mytmp} already exists"
	exit 1
fi
s=${mytmp}/stderr
t=${mytmp}/f77.o
CC=${CC_f2c:-'@CC@ '}
EFL=${EFL:-efl}
EFLFLAGS=${EFLFLAGS:-'system=portable deltastno=10'}
RATFOR=${RATFOR:-ratfor}
RFLAGS=${RFLAGS:-'-6&'}
F2C=${F2C:-@PREFIX@/bin/f2c}
F2CFLAGS=${F2CFLAGS:='-Aw8 -Nn802 -Nx400'}
S2DBLFLAG="-R"
CPP=${CPP:-'@CPP@ '}
rc=0
trap "rm -fr $s $t $mytmp ; exit \$rc" 0
OUTF=a.out
cOPT=1
ARGS=
CPPFLAGS=
CFLAGS=-I@PREFIX@/include 
LIBS=
FLIBS="-Wl,-R@PREFIX@/lib -L@PREFIX@/lib -lF77 -lI77 -lm"
VERBOSE=no

while
	test -n "$1"
do
	case "$1"
	in
	-c)	cOPT=0
		shift
		;;

	-C)	F2CFLAGS="$F2CFLAGS -C"
		shift;;

	-D*)	CPPFLAGS="$CPPFLAGS $(shell_quote "$1")"
		shift;;

        -fPIC)  CFLAGS="$CFLAGS $1"
                shift;;

	-g)	CFLAGS="$CFLAGS -g"
		F2CFLAGS="$F2CFLAGS -g"
		G="-g"
		shift;;

	-I)	CFLAGS="$CFLAGS $(shell_quote "-I$2")"
		CPPFLAGS="$CPPFLAGS $(shell_quote "-I$2")"
		F2CFLAGS="$F2CFLAGS $(shell_quote "-I$2")"
		shift 2
		;;

        -I*)    CFLAGS="$CFLAGS $(shell_quote "$1")"
		CPPFLAGS="$CPPFLAGS $(shell_quote "$1")"
		F2CFLAGS="$F2CFLAGS $(shell_quote "$1")"
                shift 1
                ;;

        -l*)    LIBS="$LIBS $(shell_quote "$1")"
                shift 1
                ;;

        -L*)    LIBS="$LIBS $(shell_quote "$1")"
                shift 1
                ;;

	-m)	CFLAGS="$CFLAGS $(shell_quote "-m$2")"
		CPPFLAGS="$CPPFLAGS $(shell_quote "-m$2")"
		shift 2
		;;

        -m*)    CFLAGS="$CFLAGS $(shell_quote "$1")"
		CPPFLAGS="$CPPFLAGS $(shell_quote "$1")"
                shift 1
                ;;

	-o)	OUTF="$2"
		shift 2
		;;

	-N)	F2CFLAGS="$F2CFLAGS $(shell_quote "$1""$2")"
		shift 2
		;;

	-O|-O1|-O2|-O3)	
		CFLAGS="$CFLAGS $1"
		shift
		;;

        -pg)    CFLAGS="$CFLAGS $1"
                shift;;

	-P)	F2CFLAGS="$F2CFLAGS $1"
		shift
		;;

	-r8)    S2DBLFLAG="-r8"
		shift
		;;

	-s)	CFLAGS="$CFLAGS -s"
		shift
		;;

	-S)	CFLAGS="$CFLAGS -S"
		cOPT=0
		shift
		;;

	-u)	F2CFLAGS="$F2CFLAGS -u"
		shift
		;;

	-U*)	CPPFLAGS="$CPPFLAGS $(shell_quote "$1")"
		shift;;

	-v)	VERBOSE=yes
		shift
		;;

	-w)	F2CFLAGS="$F2CFLAGS -w"
		shift
		;;

	-w66)	F2CFLAGS="$F2CFLAGS -w66"
		shift
		;;

	-Wl*)	CFLAGS="$CFLAGS $(shell_quote "$1")"
		shift
		;;

	-W*)	CFLAGS="$CFLAGS $(shell_quote "$1")"
		shift
		;;

	-install_name)
		CFLAGS="$CFLAGS $1 $(shell_quote "$2")"
		shift 2;
		;;

	-compatibility_version)
		CFLAGS="$CFLAGS $1 $(shell_quote "$2")"
		shift 2;
		;;

	-current_version)
		CFLAGS="$CFLAGS $1 $(shell_quote "$2")"
		shift 2;
		;;

	-*)	CFLAGS="$CFLAGS $(shell_quote "$1")"
		CPPFLAGS="$CPPFLAGS $(shell_quote "$1")"
		if test $VERBOSE = "yes"; then
			echo "Warning:  Passing unknown option $1 on to the c compiler"
		fi
		shift
		;;

	*)
		ARGS="$ARGS $(shell_quote "$1")"
		shift
		;;
	esac
done

if test $cOPT = 0; then
  if test "$OUTF" != "a.out"; then
    CFLAGS="$CFLAGS -o $(shell_quote "$OUTF")"
  fi
fi

# set the flag that controls if REAL's are promoted to 
# DOUBLE PRECISION or not
F2CFLAGS="$F2CFLAGS $S2DBLFLAGS"

eval "set -- $ARGS"

# strip off lines which just are for the linker in cases where
# we are not linkng.  Otherwise we produce gcc warnings
# like:
#
# cc: -R/usr/pkg/lib: linker input file unused because linking not done
#
# which messes up the autoconf tests for fortran libraries.
 
CFLAGS_NOLINK=`echo $CFLAGS |  sed -e 's; '\''-Wl,[^ ]*; ;g' -e 's; -Wl,[^ ]*; ;g'`

if test $VERBOSE = "yes"; then
  F2CVER=`$F2C < /dev/null | awk '/.*version/ {print $6" "$7}'`
  echo "f2c-f77:"
  echo "F2C= $F2C, $F2CVER"
  echo "CC= $CC"
  echo "CFLAGS= $CFLAGS"
  echo "CFLAGS_NOLINK= $CFLAGS_NOLINK"
  echo "CPPFLAGS= $CPPFLAGS"
  echo "FLIBS= $FLIBS"
  echo "LD_RUN_PATH= @PREFIX@/lib"
fi

while
	test -n "$1"
do
	case "$1"
	in
	*.[fF])
		case "$1" in *.f) f=".f";; *.F) f=".F";; esac
		case "$1" in
			*.f)	b=`basename $1 .f`
				if test $VERBOSE = "yes"; then
					echo "$F2C $F2CFLAGS $1"
				fi
				eval "\$F2C $F2CFLAGS \$1"
				rc=$?
				;;
			*.F)	b=`basename $1 .F`
				eval "\$CPP $CPPFLAGS \$1" >$b.i
				rc=$?
				case $rc in 0)
					if test $VERBOSE="yes"; then
						echo "$F2C $F2CFLAGS <$b.i >$b.c"
					fi
					eval "\$F2C $F2CFLAGS" <$b.i >$b.c
					rc=$?
					;;esac
				rm $b.i
				;;
			esac
		case $rc in 0);; *) exit;; esac
                eval "\$CC -c $CFLAGS_NOLINK \$b.c" 2>$s
		rc=$?
		sed '/parameter .* is not referenced/d;/warning: too many parameters/d' $s 1>&2
		case $rc in 0);; *) exit;; esac
		OFILES="$OFILES $b.o"
		rm $b.c
		case $cOPT in 1) cOPT=2;; esac
		shift
		;;
	*.e)
		b=`basename $1 .e`
		eval "\$EFL $EFLFLAGS \$1" >$b.f
		case $? in 0);; *) rc=$?; exit;; esac
		eval "\$F2C $F2CFLAGS \$b.f"
		case $? in 0);; *) rc=$?; exit;; esac
                eval "\$CC -c $CFLAGS_NOLINK \$b.c"
		case $? in 0);; *) rc=$?; exit;; esac
		OFILES="$OFILES $b.o"
		rm $b.[cf]
		case $cOPT in 1) cOPT=2;; esac
		shift
		;;
	*.r)
		b=`basename $1 .r`
		eval "\$RATFOR $RFLAGS \$1" >$b.f
		case $? in 0);; *) rc=$?; exit;; esac
		eval "\$F2C $F2CFLAGS \$b.f"
		case $? in 0);; *) rc=$?; exit;; esac
		eval "\$CC -c $CFLAGS_NOLINK \$b.c"
		case $? in 0);; *) rc=$?; exit;; esac
		OFILES="$OFILES $b.o"
		rm $b.[cf]
		case $cOPT in 1) cOPT=2;; esac
		shift
		;;
	*.s)
		echo $1: 1>&2
		OFILE=`basename $1 .s`.o
		eval "\${AS:-as} -o \$OFILE $AFLAGS \$1"
		case $? in 0);; *) rc=$?; exit;; esac
		OFILES="$OFILES $OFILE"
		case $cOPT in 1) cOPT=2;; esac
		shift
		;;
	*.c)
		echo $1: 1>&2
		OFILE=`basename $1 .c`.o
                eval "\$CC -c $CPPFLAGS $CFLAGS_NOLINK \$1"
		rc=$?; case $rc in 0);; *) rc=$?; exit;; esac
		OFILES="$OFILES $OFILE"
		case $cOPT in 1) cOPT=2;; esac
		shift
		;;
	*.o)
		OFILES="$OFILES $1"
		case $cOPT in 1) cOPT=2;; esac
		shift
		;;
	*.so)
		OFILES="$OFILES $1"
		case $cOPT in 1) cOPT=2;; esac
		shift
		;;
	-l)
		OFILES="$OFILES -l$2"
		shift 2
		case $cOPT in 1) cOPT=2;; esac
		;;
	-l*)
		OFILES="$OFILES $1"
		shift
		case $cOPT in 1) cOPT=2;; esac
		;;
	-o)
		OUTF=$2; shift 2;;
	*.P)
		F2CFLAGS="$F2CFLAGS $(shell_quote "$1")"
		shift
		;;
	*)
		OFILES="$OFILES $1"
		shift
		case $cOPT in 1) cOPT=2;; esac
		;;
	esac
done

case $cOPT 
in 
  2) eval "\$CC $CFLAGS -o \$OUTF @MAIN@ $OFILES $LIBS $FLIBS"
     ;; 
esac

rc=$?
exit $rc