summaryrefslogtreecommitdiff
path: root/makefile
blob: 906516f1256931e21b0ea8b05d39cb7cc365164a (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
##### DIRECTORIES
SRC_DIR := src
TEST_DIR := test
INCL_DIR := include
DOC_DIR := doc
BIN_DIR := bin


##### CC PARAMS
CC := gcc
CFLAGS := -ansi -Wall -pedantic -std=gnu99 -O2
IFLAGS += -I$(INCL_DIR)
LFLAGS := $(LLFLAGS) -lMLV -lm


##### UTILS
PERCENT := %


##### MAIN TARGETS
.PHONY: all check build report clean

all: build check api-doc report;

.SECONDEXPANSION:
build: $$(patsubst $(SRC_DIR)/$$(PERCENT).c,$(BIN_DIR)/$$(PERCENT).o,$$(wildcard $(SRC_DIR)/**/*.c));

.SECONDEXPANSION:
check: $$(patsubst $(TEST_DIR)/$$(PERCENT).c,$(BIN_DIR)/$$(PERCENT).test,$$(wildcard $(TEST_DIR)/**/*.c));

report: $(DOC_DIR)/project-report.pdf;

clean: clean-bin clean-api-doc clean-report;


##### BINARIES GENERATION
.PRECIOUS: $(BIN_DIR)/%.o $(BIN_DIR)/%/
.PHONY: clean-bin

.SECONDEXPANSION:
$(BIN_DIR)/%.o: $$(patsubst $(BIN_DIR)/$$(PERCENT).o,$(SRC_DIR)/$$(PERCENT).c,$$@) | $$(@D)/
	$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@

.SECONDEXPANSION:
$(BIN_DIR)/%.test: $$(patsubst $(BIN_DIR)/$$(PERCENT).test,$(TEST_DIR)/$$(PERCENT).c,$$@) build | $$(@D)/
	$(CC) $(CFLAGS) $(IFLAGS) $(BIN_DIR)/**/*.o $< -o $@ $(LFLAGS)
	./$@

$(BIN_DIR)/%/:
	mkdir -p $(@D)

clean-bin:
	$(RM) -r $(BIN_DIR)/*


##### API DOC
.PHONY: api-doc clean-api-doc

api-doc:
	naturaldocs --rebuild --project $(DOC_DIR)/gen/ --output HTML $(DOC_DIR)/api/ \
	                      --input $(INCL_DIR) --input $(DOC_DIR)/topics/
	$(RM) $(DOC_DIR)/gen/Menu.txt

clean-api-doc:
	$(RM) -r $(DOC_DIR)/api/*


##### REPORT
.PRECIOUS: $(DOC_DIR)/%.pdf
.PHONY: clean-report

.SECONDEXPANSION:
$(DOC_DIR)/%.pdf: $$(patsubst $$(PERCENT).pdf,$$(PERCENT).md,$$@)
	pandoc --template $(DOC_DIR)/report-template.tex --number-sections --listings --output $@ $<

clean-report:
	$(RM) -r $(DOC_DIR)/project-report.pdf