-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (56 loc) · 1.8 KB
/
Makefile
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
# starter makefile, based on: https://www.partow.net/programming/makefile/index.html
CXX := clang
SRC_EXT := c
CXXFLAGS := -pedantic-errors -Wall -Wextra
LDFLAGS := -lm -lgmp
BUILD := ./build
DOC_DIR := ./doc
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/apps
TARGET := pi
INCLUDE := -Iinclude/
SRC := $(shell find src -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
TEST_SRC := $(shell find src test -not -path src/main.c -a -name '*.$(SRC_EXT)' | sort -k 1nr | cut -f2-)
OBJECTS := $(SRC:%.$(SRC_EXT)=$(OBJ_DIR)/%.o)
DEPENDENCIES := $(OBJECTS:.o=.d)
ifeq ($(OS),Windows_NT)
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -L$(shell brew --prefix gmp)/lib
INCLUDE += -I$(shell brew --prefix gmp)/include
endif
endif
all: build $(APP_DIR)/$(TARGET)
$(OBJ_DIR)/%.o: %.$(SRC_EXT)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -MMD -o $@
$(APP_DIR)/$(TARGET): $(OBJECTS)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS)
-include $(DEPENDENCIES)
.PHONY: all build clean debug release info doc
build:
@mkdir -p $(APP_DIR)
@mkdir -p $(OBJ_DIR)
debug: CXXFLAGS += -DDEBUG -g
debug: all
release: CXXFLAGS += -O3 -Werror
release: all
clean:
-@rm -rvf $(OBJ_DIR)/*
-@rm -rvf $(APP_DIR)/*
info:
@echo "[*] Application dir: ${APP_DIR} "
@echo "[*] Object dir: ${OBJ_DIR} "
@echo "[*] Sources: ${SRC} "
@echo "[*] Tests: ${TEST_SRC} "
@echo "[*] Objects: ${OBJECTS} "
@echo "[*] Dependencies: ${DEPENDENCIES}"
run:
@$(APP_DIR)/$(TARGET)
test: $(TEST_SRC) $(SRC)
$(CXX) $(CXXFLAGS) $(INCLUDE) -o $(APP_DIR)/test $(TEST_SRC) $(LDFLAGS)
@$(APP_DIR)/test
doc:
pandoc $(DOC_DIR)/documentation.md -o $(BUILD)/documentation.pdf --resource-path $(DOC_DIR) --citeproc --number-sections