# Makefile compiling the whole project
# Don't forget before the first compilation to run that command:
# export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./Libs

CC=gcc
CFLAGS=-Wall -Werror -pedantic -fpic -g


LIBSDIR=-L/usr/lib -L./Libs
INCLUDEDIR=-I/usr/include -I. -I./LibCell -I./LibList

#Exe test variables
TARGET=main.exe
SOURCE=main

SOURCECFILE=$(SOURCE:=.c)
SOURCEOFILE=$(SOURCE:=.o)

#Library variables
# DEPENDENCE=libCellElement.so
# DEPENDENCENAME=CellElement

DEPENDENCELIST=libList.so
DEPENDENCENAMELIST=List


all: $(TARGET)
#Generating the main.exe
$(TARGET): $(SOURCEOFILE) $(DEPENDENCELIST) lib
	@echo "\n Generating the " $(TARGET) " binary"
	# $(CC) $(SOURCEOFILE) $(LIBSDIR) -l$(DEPENDENCENAME) -l$(DEPENDENCENAMELIST) -o $(TARGET)
	$(CC) $(SOURCEOFILE) $(LIBSDIR) -l$(DEPENDENCENAMELIST) -o $(TARGET)

#Generating the library binary
lib:
	@echo "\n Generating the automaton library binary"
	mkdir -p Libs
	# $(MAKE) -C LibCell

$(DEPENDENCELIST):
	@echo "\n Generating the list library binary"
	$(MAKE) -C LibList


#Generating object files
.c.o:
	@echo "\n Generating " $@ " from " $<
	$(CC) $(CFLAGS) $(INCLUDEDIR) -c -o $@ $<


#Cleaning
clean:
	@echo "\n Cleaning"
	rm -rf *.o ./Libs/*.so *.exe
	$(MAKE) -C LibCell clean
	$(MAKE) -C LibList clean