# Unix version of Makefile for Fortran program checker
#
# Add machine-specific targets IBM-RS6000, GENERIC,
# SOLARIS2.x, STARDENT, SUNOS4.0, SUNOS4.1, SUNOS5.x, ULTRIX-MIPS

#    Copyright (C) 1991 by Robert K. Moniot.
#    This program is free software.  Permission is granted to
#    modify it and/or redistribute it, retaining this notice.
#    No guarantees accompany this software.

# Acknowledgements and thanks to Nelson H.F. Beebe of University of Utah
# for improvements to this makefile.

# These definitions should be customized for your local conventions
# if you want to do "make install" or "make uninstall"
BINDIR	=	/usr/local/bin
MV	=	/bin/mv
CP	=	/bin/cp
MANDIR	=	/usr/local/man

# YACC=parser name, YSTEM=stem on tab.c, tab.h
# for yacc as the parser
YACC	=	yacc
YSTEM	=	y

# for GNU bison as the parser
#YACC	=	bison
#YSTEM	=	fortran

# OPTIONS is used to define various characteristics.  Most commonly
# needed ones are given below; uncomment whichever you like.
# See ftnchek.h for others, with their defaults and explanations.

#  To use the defaults for everything uncomment this:
# OPTIONS=

#  To make all table sizes 10x bigger than defaults uncomment this:
OPTIONS= -DLARGE_MACHINE

#  To prohibit underscores in variable names, inline comments
#   starting with '!',  the DO ... ENDDO loop forms and INCLUDE statements:
#OPTIONS= -DSTRICT_SYNTAX


# CFLAGS is used to define the operating system and options
# Other

CC= gcc
CFLAGS= -DUNIX $(OPTIONS) -O -D_BSD -s
LDFLAGS=
YFLAGS= -d

# nice for OS/2
EXE=.exe
TARGET=ftnchek$(EXE)

OBJS= ftnchek.o fortran.o forlex.o \
	pgsymtab.o plsymtab.o symtab.o exprtype.o project.o

$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJS) -lm

install:	ftnchek
	$(CP) ftnchek $(BINDIR)
	- strip $(BINDIR)/ftnchek
	chmod 755 $(BINDIR)/ftnchek
	$(CP) ftnchek.man $(MANDIR)/man1/ftnchek.1
	chmod 744 $(MANDIR)/man1/ftnchek.1

uninstall:
	$(RM) $(BINDIR)/ftnchek
	$(RM) $(MANDIR)/man1/ftnchek.1

# N.B. tokdefs.h is copy of y.tab.h used to avoid remaking stuff when
# grammar changes but not tokens.
# The following copies y.tab.h to tokdefs.h if changed, then aborts make,
# since dependencies may have changed.
fortran.c: fortran.y
	$(YACC) $(YFLAGS) fortran.y
	$(MV) $(YSTEM).tab.c fortran.c
	@if [ `diff $(YSTEM).tab.h tokdefs.h | wc -c` != 0 ] ; then \
		echo; echo tokdefs.h changed -- repeat make ; \
		$(CP) $(YSTEM).tab.h tokdefs.h; \
		test x = y; \
	fi

ftnchek.o: ftnchek.h

exprtype.o: ftnchek.h symtab.h tokdefs.h

forlex.o: ftnchek.h keywords.h symtab.h tokdefs.h

fortran.o: ftnchek.h symtab.h fortran.c

pgsymtab.o: ftnchek.h symtab.h

plsymtab.o: ftnchek.h symtab.h

project.o: ftnchek.h symtab.h

symtab.o: ftnchek.h iokeywds.h intrins.h symtab.h tokdefs.h



check:
	lint $(LINTFLAGS) $(OBJS:.o=.c) -lm

RM = /bin/rm -f
clean:
	-$(RM) \#* *~ core *.o

clobber:	clean
	-$(RM) ftnchek

#=======================================================================
# Machine specific targets to build ftnchek with suitable compile options.
# Use 'MAKE_OPTIONS= "YACC=/usr/local/gnu/bin/bison" "YSTEM=fortran"'
# to select GNU bison parser, if you have touched fortran.y.

IBM-RS6000:
	make "CFLAGS= -DUNIX -DLARGE_MACHINE $(OPTIONS) \
		-DAIXC -DRAND_NO_ARG -O -D_BSD" \
		"CC = c89 -D_POSIX_SOURCE" $(MAKE_OPTIONS)

GENERIC STARDENT UNIX:
	make "CFLAGS= -DUNIX -DLARGE_MACHINE $(OPTIONS) -O -D_BSD" \
		$(MAKE_OPTIONS)

# Warning: do not split this quoted string across a line boundary; SGI
# IRIX 4.0.x make incorrectly preserves the newline, causing
# compilation commands to fail.
SGIFLAGS="CFLAGS= -DUNIX -DLARGE_MACHINE $(OPTIONS) -DVMS_IO -DVMS_TAB -O -D_BSD"
SGI:
	make $(SGIFLAGS) $(MAKE_OPTIONS)

SOLARIS2.x SUNOS5.x:
	make "CFLAGS= -DUNIX -DLARGE_MACHINE $(OPTIONS) -xO4 -D_BSD" \
		$(MAKE_OPTIONS)

SUNOS4.0:
	make "CFLAGS= -DUNIX -DLARGE_MACHINE $(OPTIONS) -O -D_BSD" \
		$(MAKE_OPTIONS)

SUNOS4.1:
	make "CFLAGS= -DUNIX -DLARGE_MACHINE $(OPTIONS) -O4 -D_BSD" \
		$(MAKE_OPTIONS)

ULTRIX-MIPS:
	make "CFLAGS= -DUNIX $(OPTIONS) -DLARGE_MACHINE -Olimit 2000 -O -D_BSD"\
		$(MAKE_OPTIONS)
