-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
51 lines (36 loc) · 1.16 KB
/
Copy pathMakefile
File metadata and controls
51 lines (36 loc) · 1.16 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
TARGET_EXEC := diec
TARGET_LIB := libdiec.so
# NOTE: This Makefile uses implicit gnumake rules and flags for c/cpp compilation
# Program for compiling C programs; default cc
CC := clang
# NOTE: CPP =/= C++ here
# Extra flags to give to the C preprocessor
CPPFLAGS := -MMD -MP
# Extra flags to give to the C compiler
CFLAGS := -std=c99 -Wall -Werror -include-pch
TESTFLAGS := -g -Og
BUILD_DIR := build
SRC_DIR := src
TEST_DIR := tests
SRCS := $(wildcard $(SRC_DIR)/*)
TESTS := $(wildcard $(TEST_DIR)/*)
SRC_OBJS := $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
TEST_OBJS := $(TESTS:$(TEST_DIR)/%.c=$(BUILD_DIR)/%.o)
DEPS := $(SRC_OBJS:.o=.d) $(TEST_OBJS:.o=.d)
all: test $(TARGET_EXEC) $(TARGET_LIB)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(TARGET_EXEC): $(SRC_OBJS)
$(CC) -o $@ $^
$(TARGET_LIB): $(SRC_OBJS)
$(CC) -shared -fPIC -o $@ $^
test: $(TEST_OBJS)
$(CC) $(TESTFLAGS) -o $@ $^
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
$(BUILD_DIR)/%.o: $(TEST_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) $(TESTFLAGS) -o $@ -c $<
clean:
rm -rf $(BUILD_DIR) $(TARGET_EXEC) $(TARGET_LIB) test
-include $(DEPS)
.PHONY: all clean test