summaryrefslogtreecommitdiff
path: root/Makefile
blob: 3f1ec693bb1d4cec9387aeaef7c7eb6c8996e4ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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