-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (50 loc) · 1.25 KB
/
Makefile
File metadata and controls
69 lines (50 loc) · 1.25 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
# TODO: Add multiple OS support
NAME := fix_point
BIN_DIR := bin
OBJ_DIR := obj
DATA_DIR := data
TESTS_DIR := tests
TABLE_DIR := lib/table
SCRIPTS := scripts
DIRS := $(BIN_DIR) $(OBJ_DIR) $(BUILD_DIR) $(DATA_DIR)
CC := clang
CFLAGS := -std=gnu17 -D _GNU_SOURCE -D __STDC_WANT_LIB_EXT1__ -Wall -Wextra -pedantic
LDFLAGS := -lm
dbg ?= 0
ifeq ($(dbg), 1)
CFLAGS += -g -O0
else
CFLAGS += -O3
endif
SRC_DIR := src
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:src/%.c=obj/%.o)
TARGET := $(BIN_DIR)/$(NAME).out
TEST := $(BIN_DIR)/$(NAME)_test.out
$(DIRS):
mkdir -p $@
$(OBJ): obj/%.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS)
$(TARGET): $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $@
$(TEST): $(OBJ)
$(CC) $(CFLAGS) $(filter-out obj/main.o, $(OBJ)) $(TESTS_DIR)/*.c -lcunit -o $@ $(LDFLAGS)
all: build $(TARGET)
build: $(DIRS)
run: all
@./$(TARGET)
check: all
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose $(TARGET)
test: build $(TEST)
@./$(TEST)
setup:
@sudo apt install -y valgrind
@sudo apt install -y build-essential
@sudo apt install -y libcunit1 libcunit1-doc libcunit1-dev
@sudo apt update
@sudo apt upgrade -y
@sudo apt autoremove -y
@sudo apt autoclean -y
clean:
rm -rf $(DIRS)
.PHONY: all setup build run clean