# Makefile for the Core Join Calculus Compiler cjcc 
# Copyright (C) 1996, 1997, 2004 Peter Selinger 
# This is free software under the terms of the GNU General Public License. 

# the following is "l" for the standard lexer, "fl" for flex
LEXLIB = fl

VERSION = 0.5.3

all: cjcc

# ----------------------------------------------------------------------

join.tab.c: join.y
	bison join.y

lex.yy.c: join.lex
	lex join.lex

cjcc: join.tab.c types.h datatypes.c semantics.c header.sc
cjcc: serverdef.sc serverinc.sc lex.yy.c main.c README.sc
	gcc -o cjcc join.tab.c -l$(LEXLIB)

# ----------------------------------------------------------------------

makestrconst: makestrconst.c
	gcc makestrconst.c -o makestrconst

serverdef.sc: serverdef.c makestrconst
	./makestrconst < serverdef.c > serverdef.sc

serverinc.sc: serverinc.c makestrconst
	./makestrconst < serverinc.c > serverinc.sc

header.sc: header.c makestrconst
	./makestrconst < header.c > header.sc

README.sc: README makestrconst
	./makestrconst < README > README.sc

README: join.html
	lynx -dump -nolist join.html | grep -v '\[home\]' > README

# ----------------------------------------------------------------------
# Distribution

DIST=join-$(VERSION)
DISTFILES=Makefile README join.html j join.lex join.y datatypes.c declarations.h header.c main.c makestrconst.c semantics.c serverdef.c serverinc.c types.h
SAMPLEFILES=examples/numbers.j examples/gcd.j

dist: $(DIST).tar.gz

$(DIST).tar.gz: $(DISTFILES)
	rm -rf "$(DIST)"
	mkdir "$(DIST)"
	cp $(DISTFILES) "$(DIST)"
	mkdir "$(DIST)/examples"
	cp $(SAMPLEFILES) "$(DIST)/examples"
	tar zcf "$(DIST).tar.gz" "$(DIST)"
	rm -rf "$(DIST)"

# ----------------------------------------------------------------------
# auxiliary targets

clean:
	rm -f *~ *.o */*.o core *.sc
	rm -f README join.tab.c lex.yy.c makestrconst

distclean: clean
	rm -f cjcc
