-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
253 lines (209 loc) · 8.94 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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# author: Brando
# date: 7/29/22
#
include external/libs/makefiles/libpaths.mk
include external/libs/makefiles/platforms.mk
include external/libs/bflibc/makefiles/uuid.mk
.SECONDEXPANSION:
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
PLATFORM = linux
PACKAGE_MODE = package-linux
endif
ifeq ($(UNAME_S),Darwin)
PLATFORM = macos
PACKAGE_MODE = package-macos
endif
CONFIG = release
BIN_PATH = bin
CPPLINKS = -lpthread -lncurses $(BF_LIB_C_UUID_FLAGS) -ldl
CPPSTD = -std=c++20
PACKAGE_NAME = chat
MAIN_FILE = src/main.cpp
ifeq ($(UNAME_S),Darwin)
LIBRARIES = external/bin/openssl-uni/libssl.a external/bin/openssl-uni/libcrypto.a
else
LIBRARIES = external/openssl/libssl.a external/openssl/libcrypto.a
endif
# used to make universal binaries
MACOS_TARGET_X86_64 = x86_64-apple-macos10--12
MACOS_TARGET_ARM64 = arm64-apple-macos11
### macOS Variables
IDENTITY =
TEAMID =
EMAIL =
PW =
FILES = \
interface cipher cipherasymmetric ciphersymmetric \
log user inputbuffer office \
chatroom message chatroomserver packet \
agent agentclient agentserver sealedpacket \
chatroomclient interfaceserver interfaceclient command \
permissions exception \
chat
### Release settings
ifeq ($(CONFIG), release) # ($(CONFIG), ???)
CPPFLAGS += -Isrc/ \
-Iexternal/libs/$(BF_LIB_RPATH_RELEASE) \
$(CPPSTD)
BIN_NAME = chat
BUILD_PATH = build/release
LIBRARIES += external/libs/$(BF_LIB_RPATH_RELEASE_NET)
ifeq ($(UNAME_S),Darwin)
OBJECTS_MACOS_TARGET_X86_64 = $(patsubst %, $(BUILD_PATH)/%.$(MACOS_TARGET_X86_64), $(FILES))
OBJECTS_MACOS_TARGET_ARM64 = $(patsubst %, $(BUILD_PATH)/%.$(MACOS_TARGET_ARM64), $(FILES))
OBJECTS_MACOS_TARGETS = $(OBJECTS_MACOS_TARGET_X86_64) $(OBJECTS_MACOS_TARGET_ARM64)
BIN_MACOS_TARGETS = $(BIN_PATH)/$(BIN_NAME).$(MACOS_TARGET_X86_64) $(BIN_PATH)/$(BIN_NAME).$(MACOS_TARGET_ARM64)
else # ($(UNAME_S),Darwin)
OBJECTS = $(patsubst %, $(BUILD_PATH)/%.o, $(FILES))
endif # ($(UNAME_S),Darwin)
### Debug settings
else ifeq ($(CONFIG), debug) # ($(CONFIG), ???)
ADDR_SANITIZER = -fsanitize=address
CPPFLAGS += -DDEBUG -g -Isrc/ \
-Iexternal/libs/$(BF_LIB_RPATH_DEBUG) \
$(ADDR_SANITIZER) $(CPPSTD)
BIN_NAME = chat-debug
BUILD_PATH = build/debug
LIBRARIES += external/libs/$(BF_LIB_RPATH_DEBUG_NET)
ifeq ($(UNAME_S),Darwin)
OBJECTS_MACOS_TARGET_X86_64 = $(patsubst %, $(BUILD_PATH)/%.$(MACOS_TARGET_X86_64), $(FILES))
OBJECTS_MACOS_TARGET_ARM64 = $(patsubst %, $(BUILD_PATH)/%.$(MACOS_TARGET_ARM64), $(FILES))
OBJECTS_MACOS_TARGETS = $(OBJECTS_MACOS_TARGET_X86_64) $(OBJECTS_MACOS_TARGET_ARM64)
BIN_MACOS_TARGETS = $(BIN_PATH)/$(BIN_NAME).$(MACOS_TARGET_X86_64) $(BIN_PATH)/$(BIN_NAME).$(MACOS_TARGET_ARM64)
else # ($(UNAME_S),Darwin)
D_OBJECTS = $(patsubst %, $(BUILD_PATH)/%.o, $(FILES))
endif # ($(UNAME_S),Darwin)
### Test settings
else ifeq ($(CONFIG), test) # ($(CONFIG), ???)
ADDR_SANITIZER = -fsanitize=address
CPPFLAGS += -DDEBUG -DTESTING -g -Isrc/ \
-Iexternal/libs/$(BF_LIB_RPATH_DEBUG) \
$(ADDR_SANITIZER) $(CPPSTD)
BIN_NAME = chat-test
BUILD_PATH = build/test
MAIN_FILE = testbench/tests.cpp
LIBRARIES += external/libs/$(BF_LIB_RPATH_DEBUG_NET)
BIN_PREREQS := $(wildcard testbench/*.hpp)
ifeq ($(UNAME_S),Darwin)
MAIN_OBJECT_MACOS_TARGET_X86_64 = $(BUILD_PATH)/tests.$(MACOS_TARGET_X86_64)
MAIN_OBJECT_MACOS_TARGET_ARM64 = $(BUILD_PATH)/tests.$(MACOS_TARGET_ARM64)
MAIN_OBJECT_MACOS_TARGETS = $(MAIN_OBJECT_MACOS_TARGET_X86_64) $(MAIN_OBJECT_MACOS_TARGET_ARM64)
OBJECTS_MACOS_TARGET_X86_64 = $(patsubst %, $(BUILD_PATH)/%.$(MACOS_TARGET_X86_64), $(FILES))
OBJECTS_MACOS_TARGET_ARM64 = $(patsubst %, $(BUILD_PATH)/%.$(MACOS_TARGET_ARM64), $(FILES))
OBJECTS_MACOS_TARGETS = $(OBJECTS_MACOS_TARGET_X86_64) $(OBJECTS_MACOS_TARGET_ARM64)
BIN_MACOS_TARGETS = $(BIN_PATH)/$(BIN_NAME).$(MACOS_TARGET_X86_64) $(BIN_PATH)/$(BIN_NAME).$(MACOS_TARGET_ARM64)
else
MAIN_OBJECT = $(BUILD_PATH)/tests.o
OBJECTS = $(patsubst %, $(BUILD_PATH)/%.o, $(FILES))
endif
endif # ($(CONFIG), ???)
.PRECIOUS: \
$(R_BUILD_PATH)/%.$(MACOS_TARGET_X86_64) $(R_BUILD_PATH)/%.$(MACOS_TARGET_ARM64) \
$(D_BUILD_PATH)/%.$(MACOS_TARGET_X86_64) $(D_BUILD_PATH)/%.$(MACOS_TARGET_ARM64) \
$(T_BUILD_PATH)/%.$(MACOS_TARGET_X86_64) $(T_BUILD_PATH)/%.$(MACOS_TARGET_ARM64)
build: setup dependencies $(BIN_PATH)/$(BIN_NAME)
run:
./$(BIN_PATH)/$(BIN_NAME)
help:
@echo "Usage:"
@echo " make [target] variables"
@echo ""
@echo "Target(s):"
@echo " clean cleans build and bin folder"
@echo " build builds release verions"
@echo " package compresses build"
@echo " dependecies builds all dependencies in the external directory"
@echo " clean-dependecies builds all dependencies in the external directory"
@echo " clean-all cleans local and dependency builds"
@echo ""
@echo "Variable(s):"
@echo " CONFIG use this to change the build config. Accepts \"release\" (default), \"debug\", or \"test\""
@echo " IDENTITY (macos only) \"Developer ID Application\" common name"
@echo " TEAMID (macos only) Organizational Unit"
@echo " EMAIL (macos only) Developer account email"
@echo " PW (macos only) Developer account password"
@echo ""
@echo "Example(s):"
@echo " Build for release for macOS distribution"
@echo " make clean build codesign package notarize staple IDENTITY=\"\" TEAMID=\"\" EMAIL=\"\" PW=\"\""
@echo " Build for release for Linux distribution"
@echo " make clean build package"
SETUP_DIRS = $(BIN_PATH) $(BUILD_PATH)
setup: $(SETUP_DIRS)
$(SETUP_DIRS):
mkdir -p $@
clean-all: clean clean-dependencies
clean:
rm -rfv $(BUILD_PATH)
rm -rfv $(BIN_PATH)
rm -rfv $(PACKAGE_NAME)
### Main build
ifeq ($(UNAME_S),Darwin)
$(BIN_PATH)/$(BIN_NAME): $(BIN_MACOS_TARGETS)
lipo -create -output $@ $^
$(BIN_MACOS_TARGETS): $(MAIN_FILE) $(OBJECTS_MACOS_TARGETS) $(BIN_PREREQS)
g++ -o $@ $< $(wildcard $(BUILD_PATH)/*$(suffix $@)) $(CPPFLAGS) $(CPPLINKS) $(LIBRARIES) -target $(subst --,.,$(subst .,,$(suffix $@)))
$(BUILD_PATH)/%.o: $(BUILD_PATH)/%.$(MACOS_TARGET_X86_64) $(BUILD_PATH)/%.$(MACOS_TARGET_ARM64)
lipo -create -output $@ $^
$(OBJECTS_MACOS_TARGETS): $$(subst $(BUILD_PATH), src, $$(subst $$(suffix $$@),, $$@)).cpp $$(subst $(BUILD_PATH), src, $$(subst $$(suffix $$@),, $$@)).hpp src/*.h
g++ -c -o $@ $< $(CPPFLAGS) -target $(subst --,.,$(subst .,,$(suffix $@)))
else # ($(UNAME_S),Darwin)
$(BIN_PATH)/$(BIN_NAME): $(MAIN_FILE) $(OBJECTS)
g++ -o $@ $^ $(LIBRARIES) $(CPPFLAGS) $(CPPLINKS)
$(BUILD_PATH)/%.o: src/%.cpp src/%.hpp src/*.h
g++ -c $< -o $@ $(CPPFLAGS)
endif
### Packaging
package: $(PACKAGE_MODE)
package-linux: $(PACKAGE_NAME) $(PACKAGE_NAME)/$(BIN_NAME)
zip -r $(BIN_PATH)/$(PACKAGE_NAME)-$(PLATFORM).zip $(PACKAGE_NAME)
tar vczf $(BIN_PATH)/$(PACKAGE_NAME)-$(PLATFORM).tar.gz $(PACKAGE_NAME)
package-macos: $(PACKAGE_NAME) $(PACKAGE_NAME)/$(BIN_NAME)
hdiutil create -fs HFS+ -volname Chat -srcfolder $(PACKAGE_NAME) $(BIN_PATH)/$(PACKAGE_NAME)-$(PLATFORM).dmg
$(PACKAGE_NAME):
mkdir -p $@
$(PACKAGE_NAME)/$(BIN_NAME): $(BIN_PATH)/$(BIN_NAME)
@cp -afv $< $(PACKAGE_NAME)
codesign:
codesign -s "$(IDENTITY)" --options=runtime --timestamp $(BIN_PATH)/$(BIN_NAME)
notarize:
xcrun notarytool submit --apple-id "$(EMAIL)" --password "$(PW)" --team-id "$(TEAMID)" --wait $(BIN_PATH)/$(PACKAGE_NAME)-$(PLATFORM).dmg
staple:
xcrun stapler staple $(BIN_PATH)/$(PACKAGE_NAME)-$(PLATFORM).dmg
### Dependencies
dependencies: libs openssl
clean-dependencies:
cd external/libs && make clean
cd external/openssl && make clean
rm -rfv external/bin
libs: external/libs/$(BF_LIB_RPATH_RELEASE_NET) external/libs/$(BF_LIB_RPATH_DEBUG_NET)
external/libs/$(BF_LIB_RPATH_RELEASE_NET):
cd external/libs && make clean all
external/libs/$(BF_LIB_RPATH_DEBUG_NET):
cd external/libs && make clean all
ifeq ($(UNAME_S),Darwin)
SETUP_OPENSSL_DIRS = external/bin/openssl-arm external/bin/openssl-intel external/bin/openssl-uni
setup-openssl: $(SETUP_OPENSSL_DIRS)
$(SETUP_OPENSSL_DIRS):
mkdir -p $@
openssl: setup-openssl external/bin/openssl-uni/libssl.a external/bin/openssl-uni/libcrypto.a
external/bin/openssl-uni/libssl.a: external/bin/openssl-arm/libssl.a external/bin/openssl-intel/libssl.a
lipo -create $^ -output $@
external/bin/openssl-uni/libcrypto.a: external/bin/openssl-arm/libcrypto.a external/bin/openssl-intel/libcrypto.a
lipo -create $^ -output $@
external/bin/openssl-arm/libssl.a:
cd external/bin/openssl-arm && ../../openssl/Configure darwin64-arm64 CPPFLAGS="-target arm64-apple-macos11" && make
external/bin/openssl-arm/libcrypto.a:
cd external/bin/openssl-arm && ../../openssl/Configure darwin64-arm64 CPPFLAGS="-target arm64-apple-macos11" && make
external/bin/openssl-intel/libssl.a:
cd external/bin/openssl-intel && ../../openssl/Configure darwin64-x86_64 CPPFLAGS="-target x86_64-apple-macos10.12" && make
external/bin/openssl-intel/libcrypto.a:
cd external/bin/openssl-intel && ../../openssl/Configure darwin64-x86_64 CPPFLAGS="-target x86_64-apple-macos10.12" && make
else # ($(UNAME_S),???)
openssl: external/openssl/libssl.a external/openssl/libcrypto.a
external/openssl/libssl.a:
cd external/openssl && ./Configure && make
external/openssl/libcrypto.a:
cd external/openssl && ./Configure && make
endif # ($(UNAME_S),???)