-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
61 lines (44 loc) · 1.27 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
CC=gcc
CFLAGS=-g -Wall -lm -lGL -lGLU -lglut -lGLEW
MKDIR_P=mkdir -p
EXE=main
TEST_EXE=test_parser
SRC=src
BIN=bin
OBJ=build
SRCS=$(wildcard $(SRC)/*.c) $(wildcard $(SRC)/*/*.c)
OBJS=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS))
.PHONY: help
help: ## Show a help message
help:
@echo -e 'Usage: make [\033[36mtarget\033[0m]\ntargets:'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
sort | \
sed \
-e :a \
-e 's/^\([^:]\{1,10\}\):/\1 :/;ta' \
-e 's/^\([^:]*\): \+##/ \x1b[36m\1\x1b[0m/'
# sed -e :a \ Create a label "a"
# -e 's/^\([^:]\{1,9\}\):/\1 :/;ta' \ Loop through the string adding white space padding
# -e 's/^\([^:]*\): \+##/ \x1b[36m\1\x1b[0m/' Replace target with colored output
.PHONY: debug
debug: ## Build an executable to debug
debug: $(BIN)/$(EXE)
.PHONY: release
release: ## Build a release executable
release: CFLAGS=-O2 -DNDEBUG -lm -lGL -lGLU -lglut -lGLEW
release: clean
release: $(BIN)/$(EXE)
.PHONY: clean
clean: ## Clean all builded files
$(RM) -r $(BIN) $(OBJ)
$(OBJ)/%.o: $(SRC)/%.c $(OBJ)
@$(MKDIR_P) $(@D)
$(CC) $(CFLAGS) $(LDLIBS) -c $< -o $@
$(BIN)/$(EXE): $(OBJS) | $(BIN)
$(CC) $(CFLAGS) $(LDLIBS) $^ -o $@
# Directories
$(BIN):
$(MKDIR_P) $@
$(OBJ):
$(MKDIR_P) $@