# 
# $Id$
# 
# [ Description ]
# 
# Makefile
# 

#-----[ Directory ]----------------------------------------
DIR_SRC				= src
DIR_INC				= include

#-----[ Commands ]-----------------------------------------
ECHO				= echo
RM				= rm -f
MV				= mv
PWD				= `pwd`

LEXER				= flex -v -d
PARSER				= bison -d

LEXER_FILES			= $(patsubst $(DIR_SRC)/%.l,$(DIR_SRC)/%_lexer.cpp,$(wildcard $(DIR_SRC)/*.l))
PARSER_FILES			= $(patsubst $(DIR_SRC)/%.y,$(DIR_SRC)/%_parser.cpp,$(wildcard $(DIR_SRC)/*.y))	\
				  $(patsubst $(DIR_SRC)/%.y,$(DIR_INC)/%_parser.h,$(wildcard $(DIR_SRC)/*.y))

#-----[ Rules ]--------------------------------------------
.PRECIOUS			: $(DIR_SRC)/%_lexer.cpp $(DIR_SRC)/%_parser.cpp $(DIR_INC)/%_parser.h

all				: $(PARSER_FILES) $(LEXER_FILES) 

$(DIR_SRC)/%_lexer.cpp		: $(DIR_SRC)/%.l
				@$(ECHO) "Generate Lexical analyser   : $*"
				@$(LEXER) -o$*_lexer.cpp $<
				@$(MV)	$*_lexer.cpp $@

$(DIR_SRC)/%_parser.cpp		: $(DIR_SRC)/%.y
				@$(ECHO) "Generate Parser             : $*"
				@$(PARSER) -o $*_parser.cpp $<
				@$(MV) $*_parser.cpp $@

$(DIR_INC)/%_parser.h		: $(DIR_SRC)/%_parser.cpp
				@$(MV) $*_parser.hpp $(DIR_INC)/$*_parser.h
#				@$(MV) $*_parser.cpp.h $(DIR_INC)/$*_parser.h

clean				:
				@$(ECHO) "Delete     temporary files in directory "$(PWD)
				@$(RM) 	$(PARSER_FILES) 	\
					$(LEXER_FILES) 		\
					*~ 			\
					$(DIR_SRC)/*~

