summaryrefslogtreecommitdiff
path: root/makefile
blob: b4cc66a538a2ee995e79e5b6930e41a32bfb165e (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##### 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 $(DOC_DIR)/commits.log;

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

archive: upem-c-morphing-adam-pacien.tar.gz;


##### 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 $(DOC_DIR)/commits.log
.PHONY: clean-report

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

$(DOC_DIR)/commits.log:
	git log > $@

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


##### ARCHIVE
.PRECIOUS: upem-c-morphing-adam-pacien.tar.gz
.PHONY: clean-archive

upem-c-morphing-adam-pacien.tar.gz: build check clean report
	touch $@
	tar --exclude-vcs --exclude=./$@ -zcvf ./$@ .

clean-archive:
	$(RM) upem-c-morphing-adam-pacien.tar.gz