# Makefile file for maintaining the ddlparsers.  Part of the CifSieve package.
# J. R. Hester
# January 1998
# 

### Compiler Options 

# Uncomment only if another name(s) required
CC= cc
FC= f77
CXX= c++
NW= notangle
FLEX = flex
YACC = bison

# Optimised code - no debug options
#CFLAGS= -O 
#FFLAGS= -O

# Debug compilation
# linux gcc and f2c (f77 script) options
CFLAGS = -g 
FFLAGS = -g 

# The compiled program names
#
PROGRAMS= ddl1parse ddl2parse

# Library locations
#
LIBS= -lm 

# Link with flex library on Linux system
LIBS := -lfl $(LIBS)

# Include directories
#
INCDIR = .

####### Implicit rules

.SUFFIXES: .cpp .cc .c .f

.cpp.o:
	$(CXX) -c $(CFLAGS) -I$(INCDIR) $<

.cc.o:
	$(CXX) -c $(CFLAGS) -I$(INCDIR) $<

.c.o:
	$(CC) -c $(CFLAGS) -I$(INCDIR) $<

.f.o:
	$(FC) -c $(FFLAGS) -I$(INCDIR) $<

####### Build rules

all: $(PROGRAMS)

# We extract the Fortran and C files from the main literate source:
#ddltest.c: ddltest.nw
#	$(NW) -L $@ >! $< 
#
ddl2parse: ddl2parse.lex ddl2parse.y ddlwrap.c
	$(YACC) -b ddl2parse -d -t ddl2parse.y
	$(FLEX) -Cf ddl2parse.lex
	$(CC) $(CFLAGS) -c ddl2parse.tab.c lex.yy.c ddlwrap.c
	$(CC) $(CFLAGS) -o $@ ddl2parse.tab.o lex.yy.o ddlwrap.o $(LIBS)
	rm -f lex.yy.c lex.yy.o ddl2parse.tab.c 

ddl1parse: ddl1parse.lex ddl1parse.y ddlwrap.c
	$(YACC) -b ddl1parse -d -t ddl1parse.y
	$(FLEX) -Cf ddl1parse.lex
	$(CC) $(CFLAGS) -c ddl1parse.tab.c lex.yy.c ddlwrap.c
	$(CC) $(CFLAGS) -o $@ ddl1parse.tab.o lex.yy.o ddlwrap.o $(LIBS)
	rm -f lex.yy.c lex.yy.o

clean: FORCE
	@rm -f core $(PROGRAMS) *.o lex.yy.c *.tab.h *.tab.c

FORCE:
