-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
58 lines (41 loc) · 1.23 KB
/
Makefile
File metadata and controls
58 lines (41 loc) · 1.23 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
CC=clang
TARGET_EXEC ?= ${name}
BUILD_DIR ?= ./build/${TARGET_EXEC}
SRC_DIRS ?= $(addprefix ./src/,${TARGET_EXEC} cystring multi-stack hanoi)
SRCS := $(shell find $(SRC_DIRS) -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
ifeq ($(origin CPPFLAGS), undefined)
CPPFLAGS += -std=c17 # Use the the C17 Standard
# From feature_test_macros(7):
# (Since glibc 2.10) The value 200809L or
# greater additionally exposes definitions
# corresponding to the POSIX.1-2008 base
# specification (excluding the XSI extension).
CPPFLAGS += -D_POSIX_C_SOURCE=200809L
# Uncomment to enable debugging
CPPFLAGS += -g
## Uncomment to save intermediate files during compilation
#CPPFLAGS += -save-temps
CPPFLAGS += $(INC_FLAGS)
CPPFLAGS += -MMD
CPPFLAGS += -MP
endif
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
# assembly
$(BUILD_DIR)/%.s.o: %.s
$(MKDIR_P) $(dir $@)
$(AS) $(ASFLAGS) -c $< -o $@
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
clang-format --verbose -i -style=Google $<
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEPS)
MKDIR_P ?= mkdir -p