-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.mk
73 lines (57 loc) · 1.98 KB
/
default.mk
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
.PHONY: all
.SUFFIXES:
MAKEFLAGS+=" -r -j 4"
MY_CFLAGS = -Wall -Wextra -pedantic -Werror -std=gnu99 -ftabstop=1 -I ../include $(CFLAGS)
MY_CXXFLAGS = -Wall -Weffc++ -Wextra -pedantic -std=c++20 -ftabstop=1 -g -I ../include $(CXXFLAGS)
MY_LDFLAGS = $(LDFLAGS)
BUILD_DIR=build
EXE_DIR=$(BUILD_DIR)/EXE
OBJ_DIR=$(BUILD_DIR)/OBJ
DEPS_DIR=$(BUILD_DIR)/DEPS
DIRS+=$(EXE_DIR) $(OBJ_DIR)
CPPSOURCES+=$(shell find * -type f -name "*.c++")
CSOURCES+=$(shell find * -type f -name "*.c")
OBJECTS+=$(CPPSOURCES:%.c++=$(OBJ_DIR)/%.o)
OBJECTS+=$(CSOURCES:%.c=$(OBJ_DIR)/%.o)
.PRECIOUS: $(OBJECTS)
EXES+=$(filter-out $(IGNORE_EXES),$(CPPSOURCES:%.c++=$(EXE_DIR)/%))
EXES+=$(filter-out $(IGNORE_EXES),$(CSOURCES:%.c=$(EXE_DIR)/%))
all: $(EXES)
# include all the dependency files, if any exist
EXISTING_DEP_FILES = $(shell [ -d $(DEPS_DIR) ] && find $(DEPS_DIR) -name '*.d')
ifneq (,$(EXISTING_DEP_FILES))
include $(EXISTING_DEP_FILES)
endif
define cpp_to_obj
@mkdir -p $(dir $@)
@mkdir -p $(DEPS_DIR)/$(dir $*)
$(CXX) -c '$(abspath $<)' -o $@ $(MY_CXXFLAGS)
@$(CXX) -MM $< -MF $(DEPS_DIR)/$<.d.tmp $(MY_CXXFLAGS)
@sed -e 's|.*:|$@:|' < $(DEPS_DIR)/$<.d.tmp > $(DEPS_DIR)/$<.d
@sed -e 's/.*://' -e 's/\\$$//' < $(DEPS_DIR)/$<.d.tmp| fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $(DEPS_DIR)/$<.d
@rm -f $(DEPS_DIR)/$<.d.tmp
endef
$(OBJ_DIR)/%.o: %.c++
$(cpp_to_obj)
$(OBJ_DIR)/%.o: ../%.c++
$(cpp_to_obj)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(dir $@)
@mkdir -p $(DEPS_DIR)/$(dir $*)
$(CC) -c '$(abspath $<)' -o $@ $(MY_CFLAGS)
@$(CC) -MM $< -MF $(DEPS_DIR)/$<.d.tmp $(MY_CFLAGS)
@sed -e 's|.*:|$@:|' < $(DEPS_DIR)/$<.d.tmp > $(DEPS_DIR)/$<.d
@sed -e 's/.*://' -e 's/\\$$//' < $(DEPS_DIR)/$<.d.tmp| fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $(DEPS_DIR)/$<.d
@rm -f $(DEPS_DIR)/$<.d.tmp
$(EXE_DIR)/%: $(OBJ_DIR)/%.o
@mkdir -p $(dir $@)
$(CXX) $^ -o $@ $(MY_LDFLAGS)
run__%: $(EXE_DIR)/%
$(RUN_UNDER) "$<" $(RUN_ARGS)
run__%: $(EXE_DIR)/tests/%
$(RUN_UNDER) "$<" $(RUN_ARGS)
clean:
rm -f $(EXES)
rm -f $(OBJECTS)