# Makefile
#############################################################################


######## The main binary

ASPRFCBINARY="asprfc"
# When compiling under MINGW uncomment the following line.
#ASPRFC="asprfc.exe"

######## C++ Compiler and linker

#### GCC 2.95 and later

## Uncomment at most one of the following entries:
# CODE=-DBISON_DEBUG           # for debugging the parsers
# CODE=-g                      # for debugging
CODE=-O3 -DNDEBUG -DCHECK_OPT=3

WARN=-Wall -W -Wcast-align -Wcast-qual \
     -Wdisabled-optimization -Woverloaded-virtual \
     -Wpointer-arith -Wwrite-strings

GCC=g++

CXX=$(GCC) -c -ansi -pedantic -Wno-long-long  -fno-exceptions $(WARN) $(CODE) $(CODE2) $(DB)
LINK=$(GCC)
LINKFLAGS=-lm

#### ICC 9.0
# CXX=/suse/rguenther/bin/opt/intel/cc/9.0/bin/icc -c -I /suse/rguenther/bin/opt/intel/cc/9.0/include/ -I /suse/rguenther/bin/opt/intel/cc/9.0/include/c++/
# CXX=/suse/rguenther/bin/opt/intel/cc/9.0/bin/icc -c
# LINK=/suse/rguenther/bin/opt/intel/cc/9.0/bin/icc -lstdc++ -static

#### Borland C++ 5.0
# CXX=bcc32 -c -P -4 -Ix:\bc5\include
# LINK=tlink

.C.o:
	$(CXX) $< -o $@
	
######## lex and yacc

LEX=flex

# YACC=bison -y -v  	# to generate an extra output file (parser_asp_core.output) containing verbose descriptions of the parser states 
YACC=bison -y

#############################################################################
# It should not be necessary to apply changes to anything below this...     #

all: buildinfo $(ASPRFCBINARY)

buildinfo:
	printf "Building ${DLVBINARY} with ${GCC} CODE=${CODE} CODE2=${CODE2}\n"
	
## Invididual modules and special development targets

MODULES= asp_rfc.o scanner_asp_rfc.o 

$(ASPRFCBINARY): $(MODULES)
	L=$(LIBS); \
	echo "Linking with additional libs: $${L}" ; \
	$(LINK) $(MODULES) $(LINKFLAGS) $${L} -o asprfc

# Link without checking any dependencies.
linkonly:
	$(LINK) $(MODULES) $(LINKFLAGS) -o asprfc 

asp_rfc.o: asp_rfc.C parser_asp_rfc2.c asp_rfc.h

parser_asp_rfc2.o: parser_asp_rfc2.c

##### scanner & parser #####

parser_asp_rfc.h: parser_asp_rfc.y asp_rfc.h
	$(YACC) -d -o parser_asp_rfc.c parser_asp_rfc.y
	rm -f parser_asp_rfc.c

parser_asp_rfc2.c: parser_asp_rfc.y asp_rfc.h
	$(YACC) -o parser_asp_rfc.tmp parser_asp_rfc.y
	sed -e 's#parse error#syntax error#g' parser_asp_rfc.tmp > parser_asp_rfc2.c
	rm -f parser_asp_rfc.tmp

scanner_asp_rfc2.c: scanner_asp_rfc.l parser_asp_rfc.h asp_rfc.h
	$(LEX) $(LFLAGS) -o $@ scanner_asp_rfc.l

scanner_asp_rfc.o: scanner_asp_rfc.C scanner_asp_rfc2.c
	$(CXX) scanner_asp_rfc.C -o $@

########## Clean ###########

clean.tmp:
	rm -f tmp.*
	rm -f *.o
	rm -f core.*
	rm -f *.*~
	rm -f *~

clean: clean.tmp 
	rm -f lex.yy.c
	rm -f y.tab.*

# Win32 (Borland C++)
	rm -f *.obj
	rm -f *.bak
	rm -f *.obr
	rm -f *.~de

distclean: clean
	rm -f *scanner_asp_rfc2.c
	rm -f *parser_asp_rfc2.c
	rm -f *parser_asp_rfc.h
	rm -f *parser_asp_rfc.output
	rm -f *.ps
	rm -f asprfc


