#
# This software is Copyright (c)  1989 by Leroy Cain.
#
# Permission is hereby granted to copy, reproduce, redistribute or
# otherwise use this software as long as: there is no monetary
# profit gained specifically from the use or reproduction or this
# software, it is not sold, rented, traded or otherwise marketed
# except under licence from the author, and this copyright notice
# is included prominently in any copy made.
#
# The author makes no claims as to the fitness or correctness of
# this software for any use whatsoever, and it is provided as is. 
# Any use of this software is at the user's own risk.
#
#
#ESQL Languages
# C
# COBOL
# FORTRAN
# PASCAL
# PLI
LANG=C

# if you have ansi c
AFLAG= -Dansi

all: ansi_sql esql module

##############################################################################
# ansi_sql is an interactive version of SQL

ansi_sql: test.o libsql.a
	gcc263 -O2 -m486 -s -o ansi_sql test.o libsql.a

test.o: test.c
	gcc263 -O2 -m486 -s -c $(AFLAG) test.c

##############################################################################
# This section produces a library of function that is called by ESQL
# and MODULE programs.

libsql.a: y.inter.o sqlfunc.o
	ar r libsql.a y.inter.o sqlfunc.o
#      ranlib libsql.a

y.inter.o: y.inter.c ilex.yy.c
	gcc263 -O2 -m486 -s -c -DINTERNAL $(AFLAG) y.inter.c

y.inter.c: asql.y yf
	yf INTERNAL <asql.y >inter.y
	yacc -v inter.y
	mv y.tab.c y.inter.c

##############################################################################

esql: y.esql.o esqlc.o
	gcc263 -O2 -m486 -s -o esql esqlc.o y.esql.o

esqlc.o:esqlc.c
	gcc263 -O2 -m486 -s -c $(AFLAG) esqlc.c

y.esql.o: y.esql.c lex.yy.c
	gcc263 -O2 -m486 -s -c -DEMBEDDED y.esql.c

y.esql.c: asql.y yf
	yf EMBEDDED <asql.y >esql.y
	yacc -vd esql.y
	mv y.tab.c y.esql.c
	mv y.tab.h y.esql.h

##############################################################################

module: module.o y.mod.o
	gcc263 -O2 -m486 -s -o module module.o y.mod.o

module.o:module.c
	gcc263 -O2 -m486 -s -c $(AFLAG) module.c

y.mod.o: y.mod.c lex.yy.c
	gcc263 -O2 -m486 -s -c -DMODULE y.mod.c

y.mod.c: asql.y yf
	yf MODULE <asql.y >mod.y
	yacc -v mod.y
	mv y.tab.c y.mod.c

##############################################################################

lex.yy.c: asql.l
	lex asql.l

ilex.yy.c: asql.l
	lex asql.l
	sed -e "s/getc(yyin)/(*sqlbuf++)/1" lex.yy.c >ilex.yy.c

##############################################################################
# yf is a filter program to separate up asql.y into to three componets

yf:yf.c
	gcc263 -O2 -m486 -s -o yf yf.c

##############################################################################
# clean things up
clean:
	rm *.o esql.y inter.y mod.y ilex.yy.c lex.yy.c libsql.a \
	y.esql.c y.mod.c y.inter.c
