PROJECT=agni CC=gcc CFLAGS=-g3 -Wall SOURCES=$(wildcard *.c) OBJECTS=$(SOURCES:.c=.o) LDFLAGS=-lrt -lm -lsqlite3 -llua INCLUDE=-I./extlibs/ -I./ all: createcmd createextlib $(OBJECTS) $(PROJECT) $(PROJECT): version $(SOURCES) agni.c $(CC) $(OBJECTS) $(CFLAGS) $(LDFLAGS) -std=c11 -o $(PROJECT) #objdump -S $(PROJECT) > $(PROJECT).S #make: version # $(CC) $(CFLAGS) agni.c \ # -o $(PROJECT) -std=c11 -lrt -lm %.o: %.c @echo $@ $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $(subst .c,.o,$<) #autogenerate version from git commit and date when it was compiled version: #could have bug if commit message have somethign bad in it rm -f version.h echo "#ifndef __VERSION_H">>version.h echo "#define __VERSION_H">>version.h echo "#define VERSION_DATE \""`date`"\"">>version.h echo "#define VERSION_COMMIT \""`git log -1 --oneline`"\"">>version.h echo "#endif">>version.h #get all C files in cmd firectory and compile all of them CMD_SOURCES=$(wildcard cmd/*.c) CMD_HEADERS=$(wildcard cmd/*.h) #output header with all includes to commands CMD_INC_HEADER=config_all_cmds.h #cmd object files CMD_OBJECTS=$(CMD_SOURCES:.c=.o) #add commands objects to all objects OBJECTS+=$(CMD_OBJECTS) createcmd: headerscmd $(CMD_OBJECTS) #echo $(CMD_SOURCES) #echo $(CMD_OBJECTS) #generate header files with all commands in directory, to include all cmd header files in single include headerscmd: rm -f $(CMD_INC_HEADER) echo "#ifndef __CONFIG_CMD_HEADERS_H">>$(CMD_INC_HEADER) echo "#define __CONFIG_CMD_HEADERS_H">>$(CMD_INC_HEADER) for header in $(CMD_HEADERS); do echo -e "#include \"$$header\"">>$(CMD_INC_HEADER); done echo "#endif">>$(CMD_INC_HEADER) EXTLIB_SOURCES=$(wildcard extlibs/*.c) EXTLIB_OBJECTS=$(EXTLIB_SOURCES:.c=.o) OBJECTS+=$(EXTLIB_OBJECTS) createextlib: $(EXTLIB_OBJECTS) #asd leak: valgrind --leak-check=full --track-origins=yes --log-file=log.txt ./$(PROJECT) -c config/test.ini clean: rm -f agni *.o cmd/*.o extlibs/*.o