#
# Makefile template
# Since I didn't actually test it out, I don't guarrantee it to work!!!!
#
# all strings after # are considered as comment
#

# specify the C compiler here
CC=gcc

# either lex or flex can be used.
LEX=flex

# either yacc or bison can be used
YACC=bison -d

# specify the debugging flag here
# -g tells gcc to generate debugging information
DEBUG=-g

# specify compile flag here
CFLAG=$(DEBUG) -DLEX_TO_PRINT_LEXER_DEBUG_MESSAGE=0 -DLEX_TO_PRINT_LEXER_ERROR_MESSAGE=1 -DLEX_TO_PRINT_LEXER_ERROR_MESAGE=1 -DLEX_TO_PRINT_LEXER_OUTPUT=0 -DLEX_TO_RETURN_TOKEN_FOR_PASER=1

# specify link flag here
LFLAG=$(DEBUG)

# specify library files
LIBS=-L/usr/local/flex-2.5.4a/lib -lfl -lstdc++

#####################################
# specify source code here
#####################################

# C source codes
C_SRCS=

# C++ source codes
CC_SRCS=hash.cc

# C header files
C_HEADERS=hash.h

# Lex source code
LEX_SRC=src3.l

# Yacc source code
YACC_SRC=src3.y

# target executable
FINAL=parse

# all the files to be turned in
TURNIN_FILES=$(C_SRCS) $(CC_SRCS) $(C_HEADERS) $(LEX_SRC) $(YACC_SRC) README Makefile

# tar file for submission
TAR_FILE=homework.tar

# generate a list of C files
ALL_C_SRCS=$(C_SRCS) lex.yy.c src3.tab.c
# generate a list of .o files
ALL_OBJS=$(ALL_C_SRCS:.c=.o) $(CC_SRCS:.cc=.o)

.c.o:	$<
	$(CC) $(CFLAG) -c $< -o $@

.cc.o:	$<
	g++ $(CFLAG) -c $< -o $@

$(FINAL):	$(ALL_OBJS)
	$(CC) $(LFLAG) -o $@ $(ALL_OBJS) $(LIBS)

$(TAR_FILE):	$(TURNIN_FILES)
	tar -cf	$@ $(TURNIN_FILES)

$(TAR_FILE).gz:	$(TAR_FILE)
	gzip $(TAR_FILE)

lex.yy.c:	$(LEX_SRC) src3.tab.h
	$(LEX) $(LEX_SRC)

src3.tab.c:	$(YACC_SRC)
	$(YACC) $(YACC_SRC)

src3.tab.h:	$(YACC_SRC)
	$(YACC) $(YACC_SRC)

.PHONY:	turnin clean

turnin:	$(TAR_FILE).gz
	submit cs132 $(TAR_FILE).gz

clean:
	rm -f *.o lex.yy.c src3.tab.c src3.tab.h
