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


######## The main binary

ASPCOREBINARY="aspcore"
# When compiling under MINGW uncomment the following line.
#ASPCORE="aspcore.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


.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 $(ASPCOREBINARY)

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

MODULES= asp_core.o scanner_asp_core.o 

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

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

asp_core.o: asp_core.C parser_asp_core2.c asp_core.h

parser_asp_core2.o: parser_asp_core2.c

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

parser_asp_core.h: parser_asp_core.y asp_core.h
	$(YACC) -d -o parser_asp_core.c parser_asp_core.y
	rm -f parser_asp_core.c

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

scanner_asp_core2.c: scanner_asp_core.l parser_asp_core.h asp_core.h
	$(LEX) $(LFLAGS) -o $@ scanner_asp_core.l

scanner_asp_core.o: scanner_asp_core.C scanner_asp_core2.c
	$(CXX) scanner_asp_core.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_core2.c
	rm -f *parser_asp_core2.c
	rm -f *parser_asp_core.h
	rm -f *parser_asp_core.output
	rm -f *.ps
	rm -f aspcore


