From 1c75b9dca56f4879798d9c9a5b9c48428e117448 Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 2 Dec 2017 01:06:20 +0100 Subject: Add makefile and its doc Signed-off-by: pacien --- makefile | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 4 deletions(-) (limited to 'makefile') diff --git a/makefile b/makefile index 83f52fb..bc61f45 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,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 + + +##### UTILS +PERCENT := % + + +##### MAIN TARGETS +.PHONY: all test source api-doc report clean + +all: source test report; + +.SECONDEXPANSION: +source: $$(patsubst $(SRC_DIR)/$$(PERCENT).c,$(BIN_DIR)/$$(PERCENT).o,$$(wildcard $(SRC_DIR)/**/*.c)); + +.SECONDEXPANSION: +test: $$(patsubst $(TEST_DIR)/$$(PERCENT).c,$(BIN_DIR)/$$(PERCENT).test,$$(wildcard $(TEST_DIR)/**/*.c)) + $(foreach test,$(filter-out $<,$^),./$(test)) + +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,$$@) source | $$(@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: $(eval TMPDIR := $(shell mktemp -d)) - naturaldocs --project $(TMPDIR) --input include/ --input doc/topics/ --output HTML doc/api/ + naturaldocs --project $(TMPDIR) --input $(INCLUDE_DIR) --input $(DOC_DIR)/topics/ --output HTML $(DOC_DIR)/api/ $(RM) -r $(TMPDIR) -report: - pandoc --template doc/report-template.tex --number-sections --listings \ - --output doc/project-report.pdf doc/project-report.md +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 -- cgit v1.2.3