-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile
100 lines (69 loc) · 2.24 KB
/
Makefile
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
89
90
91
92
93
94
95
96
97
98
99
TARGET = navmesh
OBJ_PATH = bin
PREFIX_BIN =
CC = gcc
CPP = g++ -std=c++17
INCLUDES += -I./ -I./libs/freeglut_mingw/include
LIB_DIRS = -lfreeglut -lopengl32 -lglu32 -L".\libs\freeglut_mingw\lib\x64"
G = -g
CFLAGS :=-Wall -Wno-unknown-pragmas $(G)
LINKFLAGS =
SRCDIR =./src
C_SRCDIR = $(SRCDIR)
C_SOURCES = $(foreach d,$(C_SRCDIR),$(wildcard $(d)/*.c) )
C_OBJS = $(patsubst %.c, $(OBJ_PATH)/%.o, $(C_SOURCES))
C_DEPEND = $(patsubst %.c, $(OBJ_PATH)/%.d, $(C_SOURCES))
CC_SRCDIR = $(SRCDIR)
CC_SOURCES = $(foreach d,$(CC_SRCDIR),$(wildcard $(d)/*.cc) )
CC_OBJS = $(patsubst %.cc, $(OBJ_PATH)/%.o, $(CC_SOURCES))
CC_DEPEND = $(patsubst %.cc, $(OBJ_PATH)/%.d, $(CC_SOURCES))
CPP_SRCDIR = $(SRCDIR)
CPP_SOURCES = $(foreach d,$(CPP_SRCDIR),$(wildcard $(d)/*.cpp) )
CPP_OBJS = $(patsubst %.cpp, $(OBJ_PATH)/%.o, $(CPP_SOURCES))
CPP_DEPEND = $(patsubst %.cpp, $(OBJ_PATH)/%.d, $(CPP_SOURCES))
default: compile
init:
$(foreach d,$(SRCDIR), mkdir -p $(OBJ_PATH)/$(d);)
$(C_OBJS):$(OBJ_PATH)/%.o:%.c
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
$(CC_OBJS):$(OBJ_PATH)/%.o:%.cc
$(CPP) -c $(CFLAGS) $(INCLUDES) $< -o $@
$(CPP_OBJS):$(OBJ_PATH)/%.o:%.cpp
$(CPP) -c $(CFLAGS) $(INCLUDES) $< -o $@
test:
@echo "C_SOURCES: $(C_SOURCES)"
@echo "C_OBJS: $(C_OBJS)"
@echo "CPP_SOURCES: $(CPP_SOURCES)"
@echo "CPP_OBJS: $(CPP_OBJS)"
@echo "CC_SOURCES: $(CC_SOURCES)"
@echo "CC_OBJS: $(CC_OBJS)"
compile:$(C_OBJS) $(CC_OBJS) $(CPP_OBJS)
$(CPP) $^ -o bin/$(TARGET) $(LINKFLAGS) ${LIB_DIRS}
cp .\libs\freeglut_mingw\bin\x64\freeglut.dll ./bin/freeglut.dll
clean:
rm -rf $(OBJ_PATH)
cleand:
find ./bin -name *.d | xargs rm -rf
cleanall:subdirs_clean
rm -rf $(OBJ_PATH)
rm -f $(TARGET)
install: $(TARGET)
cp $(TARGET) $(PREFIX_BIN)
uninstall:
rm -f $(PREFIX_BIN)/$(TARGET)
rebuild: clean init compile
ifeq ($(MAKECMDGOALS),)
include $(CPP_DEPEND) init
endif
# $* 不带后缀的target
# $< target
# $@ depend
# $$xx 变量要用两个$$表示
# $$$$ 进程号
# sed中的变量用 '"包围, 's,\('"$$BASESRC"'\)\.o[ :]*,\bin\/$*.o $@ : ,g'
$(CPP_DEPEND):$(OBJ_PATH)/%.d:%.cpp
@BASESRC=`basename $*`;\
set -e; rm -f $@; \
$(CPP) $(INCLUDES) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\('"$$BASESRC"'\)\.o[ :]*,\bin\/$*.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$