-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
160 lines (126 loc) · 3.88 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
.PHONY: default all clean print
default: all
#########################################################
# 确定机器平台
#
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
TARGET_ARCH_ABI := x86_64
endif
ifeq ($(UNAME_M),aarch64)
TARGET_ARCH_ABI := arm64-v8a
endif
$(warning TARGET_ARCH_ABI=$(TARGET_ARCH_ABI))
#########################################################
# 确定gcc版本
#
GCC_VERSION = $(shell gcc -dumpversion)
#$(warning GCC_VERSION=$(GCC_VERSION))
#########################################################
# 确定-j数目
#
MAKE_PID := $(shell echo $$PPID)
JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))
JOBS := $(subst -j,,$(JOB_FLAG))
ifeq ($(JOBS),)
JOBS := 1
endif
#$(warning JOBS=$(JOBS))
#########################################################
CC := gcc
CXX := g++
CXXFLAGS +=
LDFLAGS +=
LIBS +=
AR := gcc-ar
ARFLAGS := rcs
glslangValidator := glslangValidator -Os
ObjectDir := obj
ifeq ($(TARGET_ARCH_ABI),x86_64)
ObjectDir := obj/x86_64
endif
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
ObjectDir := obj/arm64-v8a
endif
# for -D
CommonFlagsD :=
ifeq ($(TARGET_ARCH_ABI),x86_64)
CommonFlagsD +=
endif
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
CommonFlagsD +=
endif
CommonFlagsD +=
# for -I, -isystem
CommonFlagsI :=
# for compiler
O := -O0
CommonFlagsC := $(O) -std=c++20 -pipe -MMD -g -ggdb3 -fPIC -pthread
CommonLinkFlags := $(O) -pipe -MMD -g -ggdb3 -pthread -Wl,--no-undefined
CXX_ONLY := -std=c++20 -std=gnu++11 -std=gnu++17
C_ONLY := -std=gnu99
AllTargets :=
#######################################################################################################
#-------------------------------------------------------
# XXX
#-------------------------------------------------------
CommonFlags_XXX := \
$(CommonFlagsC) \
$(CommonFlagsD) \
$(CommonFlagsI) \
SourceDir_XXX := src
Source_XXX := \
aes.cpp
SourceMain_XXX := \
test.cpp \
test2.cpp \
test3.cpp \
test5_MyFile.cpp \
CXXFLAGS_XXX := \
$(CommonFlags_XXX) \
$(patsubst %, -I%, $(SourceDir_XXX)) \
CFLAGS_XXX := $(filter-out $(CXX_ONLY), $(CXXFLAGS_XXX)) #remove c++ only flags
LocalLib_XXX :=
ExtLib_XXX :=
#---------------------------------
Object_XXX := $(patsubst %.c, $(ObjectDir)/$(SourceDir_XXX)/%.o, $(Source_XXX))
Object_XXX := $(patsubst %.cpp, $(ObjectDir)/$(SourceDir_XXX)/%.o, $(Object_XXX))
Object_XXX := $(patsubst %.S, $(ObjectDir)/$(SourceDir_XXX)/%.o, $(Object_XXX))
ObjectMain_XXX := $(patsubst %.cpp, $(ObjectDir)/$(SourceDir_XXX)/%.o, $(SourceMain_XXX))
BinaryMain_XXX := $(patsubst %.cpp, $(ObjectDir)/$(SourceDir_XXX)/%, $(SourceMain_XXX))
AR_XXX := $(ObjectDir)/$(SourceDir_XXX)/libXXX.a
Depand_XXX := $(Object_XXX:.o=.d) $(ObjectMain_XXX:.o=.d)
# *.o <-- *.c
$(ObjectDir)/$(SourceDir_XXX)/%.o: $(SourceDir_XXX)/%.c
@printf "\n" && mkdir -p $(@D)
$(CC) $(CFLAGS_XXX) -c $< -o $@
# *.o <-- *.cpp
$(ObjectDir)/$(SourceDir_XXX)/%.o: $(SourceDir_XXX)/%.cpp
@printf "\n" && mkdir -p $(@D)
$(CXX) $(CXXFLAGS_XXX) -c $< -o $@
# *.o <-- *.S
$(ObjectDir)/$(SourceDir_XXX)/%.o: $(SourceDir_XXX)/%.S
@printf "\n" && mkdir -p $(@D)
$(CXX) $(CXXFLAGS_XXX) -c $< -o $@
# *.a <-- *.o
$(AR_XXX): $(Object_XXX)
@printf "\n" && mkdir -p $(@D)
$(AR) $(ARFLAGS) $@ $^
# binary <-- *.o *.a
$(ObjectDir)/$(SourceDir_XXX)/%: $(ObjectDir)/$(SourceDir_XXX)/%.o $(Object_XXX) $(LocalLib_XXX)
@printf "\n" && mkdir -p $(@D)
$(CXX) $(CXXFLAGS_XXX) -Wl,--start-group $^ $(ExtLib_XXX) -Wl,--end-group -o $@
@mkdir -p $(ObjectDir)/bin && ln -s -r -f $@ -t $(ObjectDir)/bin
.PHONY: XXX
XXX: $(Object_XXX) $(AR_XXX) $(ObjectMain_XXX) $(BinaryMain_XXX)
-include $(Depand_XXX)
AllTargets += XXX
#######################################################################################################
all: $(AllTargets)
# debug print
print:
@printf "JOBS=$(JOBS)\n"
@printf "Object_XXX=$(Object_XXX)\n"
@printf "ObjectMain_XXX=$(ObjectMain_XXX)\n"
clean:
rm -rf $(ObjectDir)/*