-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
201 lines (168 loc) · 5.92 KB
/
Copy pathMakefile
File metadata and controls
201 lines (168 loc) · 5.92 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
FILC_ROOT := $(PWD)/tools/filc-0.674-linux-x86_64
FILC_BIN := $(FILC_ROOT)/build/bin
CXX := $(FILC_BIN)/clang++
CC := $(FILC_BIN)/clang
# ---------------------------------------------------------------------
# Build directories
# ---------------------------------------------------------------------
SRC_DIR := src
BUILD_DIR := build
BIN := encrypt-it
# ---------------------------------------------------------------------
# OpenSSL
# ---------------------------------------------------------------------
OPENSSL_INC_DIR = $(PWD)/build/fil-c/pizfix/include
OPENSSL_LIB_DIR = $(PWD)/build/fil-c/pizfix/lib
OPENSSL_INC = -I$(OPENSSL_INC_DIR)
OPENSSL_LIB = \
$(OPENSSL_LIB_DIR)/libcrypto.a \
$(OPENSSL_LIB_DIR)/libssl.a \
-ldl -pthread
# ---------------------------------------------------------------------
# Argon2
# ---------------------------------------------------------------------
ARGON2_BUILD_DIR = $(BUILD_DIR)/argon2
ARGON2_INC = -I$(BUILD_DIR)/phc-winner-argon2/include
ARGON2_LIBS = $(ARGON2_BUILD_DIR)/libargon2.a
# ---------------------------------------------------------------------
# fmtlog
# ---------------------------------------------------------------------
FMTLOG_INC =
FMTLOG_LIBS =
# ---------------------------------------------------------------------
# Compiler and Linker Flags
# ---------------------------------------------------------------------
CXXFLAGS := -std=c++17 -O2 -Wall -Wextra \
-I./src \
-I./src/include \
$(OPENSSL_INC) $(ARGON2_INC) $(FMTLOG_INC)
LDFLAGS := $(OPENSSL_LIB) $(ARGON2_LIBS) $(FMTLOG_LIBS)
# ---------------------------------------------------------------------
# Source files
# ---------------------------------------------------------------------
SRCS := $(shell find $(SRC_DIR) -name "*.cpp")
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
JOB_NUMBERS = -j1
THREAD_NUMBERS = -m1
# ---------------------------------------------------------------------
# Build Rules
# ---------------------------------------------------------------------
all: $(BIN)
$(BUILD_DIR)/%.cpp.o: %.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(BIN): $(OBJS)
$(CXX) $(OBJS) $(LDFLAGS) -o $@
@echo "Build complete: $(BIN)"
clean:
rm -f $(BIN)
find $(BUILD_DIR) -name "*.o" -delete
# ---------------------------------------------------------------------
# Dependency Downloads
# ---------------------------------------------------------------------
setup: cli11 toml fmtlog fil-c argon2 openssl
cli11:
@if [ ! -f src/include/CLI11.hpp ]; then \
echo "Downloading CLI11..."; \
echo "Note: This requires network access to GitHub"; \
mkdir -p src/include && \
cd src/include && \
wget https://github.com/CLIUtils/CLI11/releases/download/v2.6.1/CLI11.hpp && \
cd ..; \
else \
echo "CLI11 already downloaded"; \
fi
toml:
@if [ ! -f src/include/toml.hpp ]; then \
echo "Downloading toml11..."; \
echo "Note: This requires network access to GitHub"; \
mkdir -p src/include && \
cd src/include && \
wget https://raw.githubusercontent.com/marzer/tomlplusplus/master/toml.hpp && \
cd ..; \
else \
echo "toml11 already downloaded"; \
fi
fmtlog:
@if [ ! -f src/include/fmtlog.h ]; then \
echo "Downloading fmtlog..."; \
echo "Note: This requires network access to GitHub"; \
cd src/include/ && \
wget https://raw.githubusercontent.com/MengRao/fmtlog/master/fmtlog.h && \
cd ../..; \
else \
echo "fmtlog already downloaded"; \
fi
# ---------------------------------------------------------------------
# Argon2
# ---------------------------------------------------------------------
argon2:
@if [ ! -f $(ARGON2_LIBS) ]; then \
echo "Building Argon2 (pizlonated with fil-c)..."; \
mkdir -p $(BUILD_DIR); \
cd $(BUILD_DIR); \
if [ ! -d phc-winner-argon2 ]; then \
echo "Cloning Argon2 repository..."; \
git clone https://github.com/P-H-C/phc-winner-argon2.git; \
fi; \
cd phc-winner-argon2; \
$(MAKE) CC=$(CC) CXX=$(CXX); \
mkdir -p $(ARGON2_BUILD_DIR); \
cp libargon2.a $(ARGON2_BUILD_DIR)/; \
cp include/argon2.h $(PWD)/src/include/; \
else \
echo "Argon2 already built"; \
fi
@if [ ! -f src/include/argon2.h ]; then \
echo "Copying argon2 header..."; \
cp $(BUILD_DIR)/phc-winner-argon2/include/argon2.h src/include/; \
fi
# ---------------------------------------------------------------------
# OpenSSL
# ---------------------------------------------------------------------
openssl:
@if [ ! -d build/openssl ]; then \
echo "Setting up OpenSSL..."; \
echo "Note: This requires network access to GitHub"; \
mkdir -p build && \
cd build && \
git clone --depth 1 https://github.com/pizlonator/fil-c.git && \
cd fil-c/ && \
sed -i 's|zlib --prefix=|no-zlib --prefix=|' build_openssl.sh && \
sed -i "s|CC=\"\$$PWD/../../../build/bin/clang|CC=\"$(FILC_BIN)/clang|" build_openssl.sh && \
./build_openssl.sh && \
cd $(PWD); \
else \
echo "OpenSSL already installed"; \
fi
# ---------------------------------------------------------------------
# fil-c setup
# ---------------------------------------------------------------------
fil-c:
@if [ ! -d tools ]; then \
echo "Setting up fil-c..."; \
echo "Note: This requires network access to GitHub"; \
mkdir -p tools && \
cd tools && \
wget https://github.com/pizlonator/fil-c/releases/download/v0.674/filc-0.674-linux-x86_64.tar.xz && \
tar -xf filc-0.674-linux-x86_64.tar.xz && \
rm filc-0.674-linux-x86_64.tar.xz && \
cd filc-0.674-linux-x86_64 && \
./setup.sh && \
echo "fil-c setup complete"; \
echo "CPP TEST"; \
echo "#include <iostream>" > test.cpp && \
echo "int main() { return 0; }" >> test.cpp && \
./build/bin/clang++ test.cpp -o test && \
if [ -f test ]; then \
echo "fil-c test compilation succeeded"; \
rm test test.cpp; \
else \
echo "fil-c test compilation failed"; \
fi; \
cd ../..; \
else \
echo "fil-c already installed"; \
fi
# ---------------------------------------------------------------------
.PHONY: all clean cli11 toml fmtlog argon2 openssl fil-c