-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstaticlib
174 lines (160 loc) · 6.18 KB
/
staticlib
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
CXX:=g++
INSTALL_PREFIX=/usr/local/
EPI_HEADER_OUT:=build/include/extended-precision-integers/include/epi
HEADER_OUT:=build/include
LIB_OUT:=build/lib
LIB_OUTNAME:=libchacha20.a
CXXFLAGS:=-std=c++20 -Wall -Wextra
USERFLAGS:=-D_MAKE_LIB -D_HIDE_WARNING
TEST_OPTIMIZATION:=-g -Og
HEADER_PATHS:=-I./$(HEADER_OUT)
LIB_OPTIMIZATION:=-O2
LIB_PATHS:=-L./$(LIB_OUT)
LIBS:=-lchacha20
OS:=$(shell uname)
ifeq ($(OS), Linux)
TEST_OPTIMIZATION+=-fsanitize=address
endif
SRC:=tests
SRC_FILES:=$(wildcard $(SRC)/*.cpp)
OBJ:=$(patsubst $(SRC)/%.cpp,$(SRC)/%.out,$(SRC_FILES))
default:
ifeq ($(OS), Linux)
echo "creating build directory"
mkdir build
mkdir build/include
mkdir build/include/extended-precision-integers
mkdir build/include/extended-precision-integers/include
mkdir build/include/extended-precision-integers/include/epi
mkdir $(LIB_OUT)
echo "creating static lib"
echo "compiling ChaCha20..."
$(CXX) $(CXXFLAGS) -c ChaCha20-Poly1305.cpp $(LIB_OPTIMIZATION) $(USERFLAGS)
echo "compiling $(LIB_OUTNAME)..."
ar -r $(LIB_OUTNAME) ChaCha20-Poly1305.o
echo "build done : output -> $(LIB_OUTNAME)"
echo "moving files to build folder"
mv $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_OUTNAME) ./$(LIB_OUT)/
cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))ChaCha20-Poly1305.hpp ./$(HEADER_OUT)/
cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))extended-precision-integers/include/epi/epi.hpp ./$(EPI_HEADER_OUT)/
else
echo "creating build directory"
mkdir build
mkdir build/include
mkdir build/include/extended-precision-integers
mkdir build/include/extended-precision-integers/include
mkdir build/include/extended-precision-integers/include/epi
mkdir "$(LIB_OUT)"
echo "creating static lib"
echo "compiling ChaCha20..."
$(CXX) $(CXXFLAGS) -c ChaCha20-Poly1305.cpp $(LIB_OPTIMIZATION) $(USERFLAGS)
echo "compiling $(LIB_OUTNAME)..."
ar -r $(LIB_OUTNAME) ChaCha20.o
echo "build done : output -> $(LIB_OUTNAME)"
echo "moving files to build folder"
move "./$(LIB_OUTNAME)" "$(LIB_OUT)"
copy "./ChaCha20-Poly1305.hpp" "$(HEADER_OUT)"
copy "./extended-precision-integers/include/epi/epi.hpp" "$(EPI_HEADER_OUT)"
endif
cleanup:
ifeq ($(OS), Linux)
echo "removing objects..."
rm -rf build
rm *.o *.out
else
rmdir /S build
del *.o *.out *.exe
endif
build_test:
ifeq ($(OS), Linux)
echo "==============================="
echo ""
echo "running build test"
cp static-build.cpp build
$(CXX) $(CXXFLAGS) build/static-build.cpp -o build/static-build.out -I./$(HEADER_OUT)/ -L./$(LIB_OUT) $(LIBS)
./build/static-build.out
else
echo "==============================="
echo ""
echo "running build test"
copy static-build.cpp build
$(CXX) $(CXXFLAGS) build/static-build.cpp -o build/static-build.exe -I./$(HEADER_OUT)/ -L./$(LIB_OUT) $(LIBS)
build/static-build.exe
endif
# -------------------------- run test programs ---------------------------
static_test: $(OBJ)
echo "----------------------------------------------------"
echo "Running Initial Tests..."
./$(SRC)/QuarterRound_test.out
./$(SRC)/BlockFunction_test.out
./$(SRC)/Encryption_test.out
./$(SRC)/poly1305_mac_test.out
./$(SRC)/poly1305_keygen.out
./$(SRC)/chacha20_aead_enc_dec.out
echo "----------------------------------------------------"
echo "Running Additional Tests..."
./$(SRC)/BlockFunction_test1.out
./$(SRC)/BlockFunction_test2.out
./$(SRC)/BlockFunction_test3.out
./$(SRC)/BlockFunction_test4.out
./$(SRC)/BlockFunction_test5.out
./$(SRC)/ChaCha20Encryption_t1.out
./$(SRC)/ChaCha20Encryption_t2.out
./$(SRC)/ChaCha20Encryption_t3.out
./$(SRC)/Poly1305_mac_t1.out
./$(SRC)/Poly1305_mac_t2.out
./$(SRC)/Poly1305_mac_t3.out
./$(SRC)/Poly1305_mac_t4.out
./$(SRC)/Poly1305_mac_t5.out
./$(SRC)/Poly1305_mac_t6.out
./$(SRC)/Poly1305_mac_t7.out
./$(SRC)/Poly1305_mac_t8.out
./$(SRC)/Poly1305_mac_t9.out
./$(SRC)/Poly1305_mac_t10.out
./$(SRC)/Poly1305_mac_t11.out
./$(SRC)/Poly1305_keygen_t1.out
./$(SRC)/Poly1305_keygen_t2.out
./$(SRC)/Poly1305_keygen_t3.out
./$(SRC)/ChaCha20Poly1305_decrypt.out
./$(SRC)/ChaCha20Poly1305_decrypt_nonceV.out
# -------------------------- test program compilation ---------------------------
$(SRC)/%.out: $(SRC)/%.cpp
echo "compiling test program (static build) - compiler : $(CXX)"
$(CXX) $(CXXFLAGS) $(USERFLAGS) $(HEADER_PATHS) -o $@ $< $(LIB_PATHS) $(LIBS) $(TEST_OPTIMIZATION)
install:
ifeq ($(OS), Linux)
cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_OUT)/$(LIB_OUTNAME) $(INSTALL_PREFIX)lib
cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(HEADER_OUT)/ChaCha20-Poly1305.hpp $(INSTALL_PREFIX)include
mkdir "$(INSTALL_PREFIX)include/extended-precision-integers"
mkdir "$(INSTALL_PREFIX)include/extended-precision-integers/include"
mkdir "$(INSTALL_PREFIX)include/extended-precision-integers/include/epi"
cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(HEADER_OUT)/extended-precision-integers/include/epi/epi.hpp $(INSTALL_PREFIX)include/extended-precision-integers/include/epi
echo "$(LIB_OUTNAME) now installed to $(INSTALL_PREFIX)lib"
echo "ChaCha20-Poly1305.hpp now installed to $(INSTALL_PREFIX)include"
echo "epi.hpp now installed to $(INSTALL_PREFIX)include/extended-precision-integers/include/epi"
else
echo .
echo For Mingw64 in windows, please specify your mingw64 folder path with the INSTALL_PREFIX
echo eample:
echo .
echo mingw32-make -f staticlib install INSTALL_PREFIX=PATH\mingw64
echo .
copy build\lib\$(LIB_OUTNAME) "$(INSTALL_PREFIX)\lib"
copy build\include\ChaCha20-Poly1305.hpp "$(INSTALL_PREFIX)\include"
mkdir "$(INSTALL_PREFIX)\include\extended-precision-integers"
mkdir "$(INSTALL_PREFIX)\include\extended-precision-integers\include"
mkdir "$(INSTALL_PREFIX)\include\extended-precision-integers\include\epi"
copy build\include\extended-precision-integers\include\epi\epi.hpp "$(INSTALL_PREFIX)\include\extended-precision-integers\include\epi"
echo install success
endif
uninstall:
ifeq ($(OS), Linux)
rm $(INSTALL_PREFIX)lib/$(LIB_OUTNAME)
rm $(INSTALL_PREFIX)include/ChaCha20-Poly1305.hpp
rm $(INSTALL_PREFIX)include/extended-precision-integers/include/epi/epi.hpp
else
del "$(INSTALL_PREFIX)\lib\$(LIB_OUTNAME)"
del "$(INSTALL_PREFIX)\include\ChaCha20-Poly1305.hpp"
del "$(INSTALL_PREFIX)\include\extended-precision-integers\include\epi\epi.hpp"
echo uninstall success
endif