Repository navigation
Expand file tree
/
Copy pathMakefile1
More file actions
208 lines (184 loc) · 6.19 KB
/
Copy pathMakefile1
File metadata and controls
208 lines (184 loc) · 6.19 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#
# 'make' build executable file 'main'
# 'make clean' removes all .o and executable files
#
# define the Cpp compiler to use
CXX = g++
# define any compile-time flags
CXXFLAGS := -std=c++11 -Wall -Wextra -g -O0
# define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify
# their path using -Lpath, something like:
# LFLAGS = -lboost_filesystem-mgw12-mt-x64-1_75 -lboost_system-mgw12-mt-x64-1_75 -lws2_32 -lboost_thread-mgw12-mt-x64-1_75 -lboost_random-mgw12-mt-x64-1_75 -lboost_json-mgw12-mt-x64-1_75 -lboost_iostreams-mgw12-mt-x64-1_75 -lssl -lcrypto -lz
ifeq ($(OS), Windows_NT)
LFLAGS += -lboost_filesystem-mgw12-mt-x64-1_75
LFLAGS += -lboost_system-mgw12-mt-x64-1_75
LFLAGS += -lws2_32
LFLAGS += -lboost_thread-mgw12-mt-x64-1_75
LFLAGS += -lboost_random-mgw12-mt-x64-1_75
LFLAGS += -lboost_json-mgw12-mt-x64-1_75
LFLAGS += -lboost_iostreams-mgw12-mt-x64-1_75
LFLAGS += -lssl
LFLAGS += -lcrypto
LFLAGS += -lz
LIB := lib/windows/boost lib/windows/zlib lib/windows/openssl
INCLUDE := include
else
# 如果是在 Linux 上,设置对应的链接库
LFLAGS += -lboost_system
LFLAGS += -lboost_filesystem
LFLAGS += -lboost_thread
LFLAGS += -lboost_random
LFLAGS += -lboost_json
LFLAGS += -lboost_iostreams
LFLAGS += -lboost_stacktrace_basic
LFLAGS += -pthread
LFLAGS += -lssl
LFLAGS += -lcrypto
LFLAGS += -ldl
LFLAGS += -lz
# LFLAGS += -lzlibstatic
LIB := lib/linux/boost lib/linux/zlib lib/linux/openssl
INCLUDE := include
endif
# LFLAGS = -lboost_filesystem-mgw8-mt-sd-x64-1_75 -lboost_system-mgw8-mt-sd-x64-1_75 -lboost_thread-mgw8-mt-sd-x64-1_75 -lboost_random-mgw8-mt-sd-x64-1_75 -lboost_json-mgw8-mt-sd-x64-1_75 -lboost_iostreams-mgw8-mt-sd-x64-1_75 -lws2_32 -lssl -lcrypto -lz
# define output directory
OUTPUT := output
# define source directory
SRC := src
BUILD := build
# define include directory
# INCLUDE := include D:/Softwares/boost_1_75_0
# INCLUDE := include
# define lib directory
# LIB := lib\boost lib\zlib lib\openssl
# LIB := D:/Softwares/boost_1_75_0/lib64-msvc-14.1
OCI := oci_images
ifeq ($(OS),Windows_NT)
MAIN := main.exe
SOURCEDIRS := $(SRC) $(shell dir /s /b /ad $(SRC))
BUILDDIRS := $(subst $(SRC),$(BUILD),$(SOURCEDIRS))
INCLUDEDIRS := $(INCLUDE)
LIBDIRS := $(LIB)
FIXPATH = $(subst /,\,$1)
RM := del /q /f
RMDIR := rmdir /s /q
MD := mkdir
else
MAIN := main
SOURCEDIRS := $(shell find $(SRC) -type d)
BUILDDIRS := $(subst $(SRC),$(BUILD),$(SOURCEDIRS))
INCLUDEDIRS := $(INCLUDE)
LIBDIRS := $(LIB)
# INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
# LIBDIRS := $(shell find $(LIB) -type d)
FIXPATH = $1
RM = rm -f
RMDIR = rm -rf
MD := mkdir -p
endif
# define any directories containing header files other than /usr/include
INCLUDES := $(patsubst %,-I %, $(INCLUDEDIRS:%/=%))
# define the C libs
LIBS := $(patsubst %,-L %, $(LIBDIRS:%/=%))
# define the C source files
SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
# SOURCES := $(wildcard $(foreach dir,$(SOURCEDIRS),$(dir)/*.cpp))
# define the C object files
OBJECTS := $(SOURCES:.cpp=.o)
BUILDS := $(subst $(SRC),$(BUILD),$(OBJECTS))
# define the dependency output files.
DEPS := $(BUILDS:.o=.d)
# define the dependency output files
# DEPS := $(OBJECTS:.o=.d)
#
# The following part of the makefile is generic; it can be used to
# build any executable just by changing the definitions above and by
# deleting dependencies appended to the file from 'make depend'
#
OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))
# test程序的变量
LFLAGSTEST := $(LFLAGS)
INCLUDETEST := -I include
OUTPUTTEST := tests
OUTPUTMAINTEST := $(call FIXPATH,$(OUTPUTTEST)/$(MAIN))
SRCTEST := ./tests/sha356.cpp
LIBSTEST := $(LIB)
all: dirmk $(OUTPUT) $(MAIN)
# $(RM) $(call FIXPATH,$(OBJECTS))
# $(RM) $(call FIXPATH,$(DEPS))
@echo Executing 'all' complete!
$(OUTPUT):
$(MD) $(OUTPUT)
# $(MAIN): $(OBJECTS)
# $(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LIBS) $(LFLAGS)
$(MAIN): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(BUILDS) $(LIBS) $(LFLAGS)
# include all .d files
-include $(DEPS)
dirmk:
# @echo $(BUILDDIRS)
# $(MD) $(BUILDDIRS)
ifeq ($(OS),Windows_NT)
@for %%D in ($(BUILDDIRS)) do ( \
if not exist "%%D" ( \
echo Creating directory %%D & $(MD) "%%D" \
) \
)
else
@for D in $(BUILDDIRS); do \
if [ ! -d $$D ]; then \
echo "Creating directory $$D"; \
$(MD) $$D; \
fi; \
done
endif
test:
$(CXX) $(CXXFLAGS) $(INCLUDETEST) -o $(OUTPUTMAINTEST) $(SRCTEST) $(LIBSTEST) $(LFLAGSTEST)
# ./$(OUTPUTMAINTEST)
# this is a suffix replacement rule for building .o's and .d's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
# -MMD generates dependency output files same name as the .o file
# (see the gnu make manual section about automatic variables)
# .cpp.o:
# $(CXX) $(CXXFLAGS) $(INCLUDES) -c -MMD $< -o $@
%.o:%.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -MMD $< -o $(subst $(SRC),$(BUILD),$@)
.PHONY: clean
# clean:
# $(RM) $(OUTPUTMAIN)
# # $(RM) $(call FIXPATH,$(OBJECTS))
# # $(RM) $(call FIXPATH,$(DEPS))
# @echo "Deleting .o and .d files..."
# @for /R $(SOURCEDIRS) %%D in (.) do ( \
# if exist "%%D\*.o" ( \
# echo Deleting .o files in %%D... & del /Q "%%D\*.o" \
# ) \
# if exist "%%D\*.d" ( \
# echo Deleting .d files in %%D... & del /Q "%%D\*.d" \
# ) \
# )
# @echo Cleanup complete!
run: all
./$(OUTPUTMAIN)
@echo Executing 'run: all' complete!
cleanoci:
# $(RM) $(OCI)/*
ifeq ($(OS), Windows_NT)
# 在 Windows 上使用 del 和 rmdir 删除文件夹及内容
@echo Deleting folder on Windows...
@del /f /q $(OCI)\*.* || true
@rmdir /s /q $(OCI) || true
else
# 在类 Unix 系统上使用 rm -rf 删除文件夹及内容
@echo Deleting folder on Unix-like system...
@rm -rf $(OCI)
endif
@echo Cleanup OCI complete!
cleanbuild:
$(RM) $(OUTPUTMAIN)
# $(RM) $(call FIXPATH,$(BUILDS))
# $(RM) $(call FIXPATH,$(DEPS))
$(RMDIR) $(BUILD)
@echo Cleanup complete!