
# tools

LINK		= gcc
CC		= gcc
CXX		= gcc

LEX		= flex
YACC		= bison

ECHO		= echo
MAKE		= make

CP		= cp
MV		= mv
INSTALL		= install

# flags

RCFLAGS		=
RLFLAGS		= -L/usr/lib
RINCFLAGS	=
RLIBRARIES	= -lstdc++

DCFLAGS		= -g
DLFLAGS		= -L/usr/lib
DINCFLAGS	=
DLIBRARIES	= /usr/lib/libstdc++.a

# status

ifndef STATUS
STATUS		= Release
endif

ifeq ($(STATUS),Release)
CFLAGS		= $(RCFLAGS)
LFLAGS		= $(RLFLAGS)
INCFLAGS	= $(RINCFLAGS)
LIBRARIES	= $(RLIBRARIES)
endif

ifeq ($(STATUS),Debug)
CFLAGS		= $(DCFLAGS)
LFLAGS		= $(DLFLAGS)
INCFLAGS	= $(DINCFLAGS)
LIBRARIES	= $(DLIBRARIES)
endif

# variables

MODULES		= api bin dist docs etc examples include lib platforms src test var

SOURCES		= 
OBJECTS		=
TARGETS		=
OUTPUTS		= 

#rules

all:
	$(MAKE) descend-all

#################

###########

descend-all: 
ifneq ($(MODULES),) #checking for empty value
	-@(for d in $(MODULES); \
	do \
		$(ECHO) 'Building ===>' $$d; \
		cd $$d; \
		$(MAKE) all; \
		cd ..; \
	done)
endif

descend-clean: 
ifneq ($(MODULES),) #checking for empty value
	-@(for d in $(MODULES); \
	do \
		$(ECHO) 'Building ===>' $$d; \
		cd $$d; \
		$(MAKE) clean; \
		cd ..; \
	done)
endif

descend-cleanall: 
ifneq ($(MODULES),) #checking for empty value
	-@(for d in $(MODULES); \
	do \
		$(ECHO) 'Building ===>' $$d; \
		cd $$d; \
		$(MAKE) cleanall; \
		cd ..; \
	done)
endif

descend-install: 
ifneq ($(MODULES),) #checking for empty value
	-@(for d in $(MODULES); \
	do \
		$(ECHO) 'Building ===>' $$d; \
		cd $$d; \
		$(MAKE) install; \
		cd ..; \
	done)
endif

clean:
	$(MAKE) descend-clean
	rm -f core $(OBJECTS) *~

cleanall:
	$(MAKE) descend-cleanall
	rm -f $(TARGETS) $(OUTPUTS) core $(OBJECTS) *~

install:
	$(MAKE) descend-install

test:	$(TARGETS)
	./src/fsmgenerator "./examples/test.fsm" "Cpp" "."

help:
	@echo "To compile, please, run: 'make all' and 'make install'"
	@echo "---------------------------------------------------------------------"
	@echo " make targets"
	@echo "---------------------------------------------------------------------"
	@echo " all		- Build all binaries and distribution"
	@echo " clean		- Clean all previous build files"
	@echo " cleanall	- Clean all previous build files and binraies and distribution"
	@echo " install 	- Install all binaries"
	@echo " help		- Display this help screen"
	@echo " test		- Run some tests"
	@echo "---------------------------------------------------------------------"

docs:
	@doxygen Doxygen

PHONY-TARGETS = all \
		clean \
		cleanall \
		descend-all \
		descend-clean \
		install \
		help \
		test
.PHONY: $(PHONY-TARGETS)
