-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
62 lines (49 loc) · 1.44 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
TARGET:=#ProjectNameMarker
SOURCES:=./sources
INCLUDES:=./includes
TESTS:=./tests
ifeq ($(MAKECMDGOALS),build)
BUILD:=./build
else ifeq ($(MAKECMDGOALS),dbg)
BUILD:=./build/dbg
else ifeq ($(MAKECMDGOALS),test)
BUILD:=./build/test
else ifeq ($(MAKECMDGOALS),testdbg)
BUILD:=./build/testdbg
else
BUILD:=./build
endif
CC:=gcc
CFLAGS:=-std=c11 -I$(INCLUDES)
CFILES:=$(shell find $(SOURCES) -printf '%P ' -name '*.c')
OFILES:=$(patsubst %.c,$(BUILD)/%.o,$(CFILES))
TCFILES:=$(shell find $(TESTS) -printf '%P ' -name '*.c')
TOFILES:=$(patsubst %.c,$(BUILD)/%.o,$(TCFILES))
.PHONY: build dbg test testdbg clean mkdir
.DEFAULT_GOAL:=build
build: CFLAGS+=-O2
build: mkdir $(OFILES)
$(CC) $(CFLAGS) $(OFILES) -o $(TARGET).exe
dbg: CFLAGS+=-O0 -ggdb -D DEBUG
dbg: mkdir $(OFILES)
$(CC) $(CFLAGS) $(OFILES) -o $(TARGET).dbg.exe
test: CFLAGS+=-I$(INCLUDES)/unity
test: build $(TOFILES)
$(CC) $(CFLAGS) $(TOFILES) $(filter-out $(BUILD)/main.o,$(OFILES)) -o $(TARGET).test
./$(TARGET).test
testdbg: CFLAGS+=-I$(INCLUDES)/unity -O0 -ggdb -D DEBUG
testdbg: dbg $(TOFILES)
$(CC) $(CFLAGS) $(TOFILES) $(filter-out $(BUILD)/main.o,$(OFILES)) -o $(TARGET).dbg.test
./$(TARGET).dbg.test
mkdir:
mkdir -p $(BUILD)
clean:
rm -rf $(BUILD)
rm -f $(TARGET).exe
rm -f $(TARGET).test
rm -f $(TARGET).dbg.exe
rm -f $(TARGET).dbg.test
$(OFILES): $(BUILD)/%.o: $(SOURCES)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(TOFILES): $(BUILD)/%.o: $(TESTS)/%.c
$(CC) $(CFLAGS) -c $< -o $@