#	Makefile for f2c, a Fortran 77 to C converter
#
#       tested with MSC 5.1 and Dmake 3.7

YACC = bison
YFLAGS = -y

RM = rm
CC = %cl
CFLAGS = -Ox -AL -c

OBJECTSd = main.obj init.obj gram.obj lex.obj proc.obj equiv.obj \
		data.obj format.obj expr.obj exec.obj intr.obj io.obj misc.obj \
		error.obj mem.obj names.obj output.obj p1output.obj pread.obj \
		put.obj putpcc.obj vax.obj formatdata.obj \
		parse_args.obj niceprintf.obj cds.obj sysdep.obj version.obj

OBJECTS = $(OBJECTSd)
#malloc..obj

all: f2c

f2c: $(OBJECTS)
	link @linkfile
	fixstack f2c 4096
	lzexe f2c
#	$(CC) $(LDFLAGS) $(OBJECTS) -o f2c
#	size f2c

gram.c:	gram.head gram.dcl gram.expr gram.exc gram.io defs.h tokdefs.h
	sed -e `s/#define/%token/` tokdefs.h > gram.in
	cat gram.head gram.dcl gram.expr gram.exc gram.io >> gram.in
	$(YACC) $(YFLAGS) gram.in
	@echo (expect 4 shift/reduce)
	awk -f unline.awk y_tab.c >gram.c
	$(RM) gram.in y_tab.c

$(OBJECTSd): defs.h ftypes.h defines.h machdefs.h sysdep.h

tokdefs.h: tokens
	awk -f tokenize.awk tokens > tokdefs.h
#	grep -n . <tokens | sed "s/\([^:]*\):\(.*\)/#define \2 \1/" >tokdefs.h

cds.obj: sysdep.h
exec.obj: p1defs.h names.h
expr.obj: output.h niceprintf.h names.h
format.obj: p1defs.h format.h output.h niceprintf.h names.h iob.h
formatdata.obj: format.h output.h niceprintf.h names.h
gram.obj: gram.c p1defs.h
	$(CC) $(CFLAGS) gram.c
init.obj: output.h niceprintf.h iob.h
intr.obj: names.h
io.obj: names.h iob.h
lex.obj : tokdefs.h p1defs.h
main.obj: parse.h usignal.h
mem.obj: iob.h
names.obj: iob.h names.h output.h niceprintf.h
niceprintf.obj: defs.h names.h output.h niceprintf.h
output.obj: output.h niceprintf.h names.h
p1output.obj: p1defs.h output.h niceprintf.h names.h
parse_args.obj: parse.h
proc.obj: tokdefs.h names.h niceprintf.h output.h p1defs.h
put.obj: names.h pccdefs.h p1defs.h
putpcc.obj: names.h
vax.obj: defs.h output.h pccdefs.h
output.h: niceprintf.h

put.obj putpcc.obj: pccdefs.h

f2c.t: f2c.1t
	troff -man f2c.1t >f2c.t

f2c.1: f2c.1t
	nroff -man f2c.1t | col -b | uniq >f2c.1

clean:
	rm -f gram.c *.obj f2c tokdefs.h f2c.t

b = Notice README cds.c data.c defines.h defs.h equiv.c error.c \
	exec.c expr.c f2c.1 f2c.1t f2c.h format.c format.h formatdata.c \
	ftypes.h gram.dcl gram.exc gram.expr gram.head gram.io \
	init.c intr.c io.c iob.h lex.c machdefs.h main.c makefile \
	malloc.c mem.c memset.c misc.c names.c names.h niceprintf.c \
	niceprintf.h output.c output.h p1defs.h p1output.c \
	parse.h parse_args.c pccdefs.h pread.c proc.c put.c putpcc.c \
	safstrncpy.c sysdep.c sysdep.h tokens usignal.h vax.c version.c xsum.c

bundle:
	bundle $b xsum0.out >/tmp/f2c.bundle

xsum: xsum.c
	$(CC) -o xsum xsum.c

#Check validity of transmitted source...
xsum.out: xsum
	xsum $b >xsum1.out
	cmp xsum0.out xsum1.out && mv xsum1.out xsum.out

