-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (71 loc) · 1.92 KB
/
Copy pathMakefile
File metadata and controls
88 lines (71 loc) · 1.92 KB
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
CC = gcc
DEBUG_FLAGS = -g -DDEBUG
OPT_FLAGS = -O2 # -flto -march=native
CFLAGS_EXTRA =
CFLAGS = -Wall -Wextra -pedantic -std=c11 $(DEBUG_FLAGS) $(OPT_FLAGS) $(CFLAGS_EXTRA)
OPT_LD_FLAGS = # -flto
LDFLAGS = $(OPT_LD_FLAGS)
TARGET = gradeviewer
BUILD_DIR = build
rebuild = 0
test = 0
ausan = 0
arg1 =
arg2 =
arg3 =
ifneq ($(rebuild),0)
CLEAN_DEPENDENCY = clean
endif
ifneq ($(test),0)
CFLAGS += -DRUN_TESTS
TARGET := gradeviewer_tests
endif
ifneq ($(ausan),0)
CFLAGS += -DDEBUG -g -fsanitize=address,undefined
LDFLAGS += -fsanitize=address,undefined
endif
# Platform detection
ifeq ($(OS),Windows_NT)
TARGET := gradeviewer.exe
RM = del /Q /F
RMDIR = rmdir /S /Q
MKDIR = if not exist "$(subst /,\,$1)" mkdir "$(subst /,\,$1)"
FIX_PATH = $(subst /,\,$1)
SRCS := $(sort $(shell dir /s /b src\*.c 2>nul))
NULL_DEVICE = nul
else
RM = rm -f
RMDIR = rm -rf
MKDIR = mkdir -p $1
FIX_PATH = $1
SRCS := $(sort $(shell find src -type f -name '*.c' 2>/dev/null))
NULL_DEVICE = /dev/null
endif
OBJS = $(SRCS:%.c=$(BUILD_DIR)/%.o)
# Builds normally
all: $(CLEAN_DEPENDENCY) $(BUILD_DIR)/$(TARGET)
run: all
ifeq ($(OS),Windows_NT)
$(call FIX_PATH,$(BUILD_DIR)/$(TARGET))
else
./$(BUILD_DIR)/$(TARGET) $(arg1) $(arg2) $(arg3)
endif
profile: CFLAGS := $(CFLAGS) -g -DDEBUG
profile: all
valgrind --tool=callgrind --dump-instr=yes ./$(BUILD_DIR)/$(TARGET) $(arg1) $(arg2) $(arg3)
valgrind: CFLAGS := $(CFLAGS) -g -DDEBUG
valgrind: all
valgrind --leak-check=full --show-leak-kinds=all --main-stacksize=1000000 ./$(BUILD_DIR)/$(TARGET) $(arg1) $(arg2) $(arg3)
$(BUILD_DIR)/$(TARGET): $(OBJS)
$(call MKDIR,$(dir $@))
$(CC) $(OBJS) $(LDFLAGS) -o $@
$(BUILD_DIR)/%.o: %.c
$(call MKDIR,$(dir $@))
$(CC) $(CFLAGS) -c $< -o $@
clean:
ifeq ($(OS),Windows_NT)
$(RMDIR) $(call FIX_PATH,$(BUILD_DIR)) 2>$(NULL_DEVICE) || echo Clean complete
else
$(RMDIR) $(BUILD_DIR)
endif
.PHONY: all clean build run valgrind