-
Notifications
You must be signed in to change notification settings - Fork 4
/
static
171 lines (155 loc) · 5.52 KB
/
static
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
CC := g++
INSTALL_PREFIX=/usr/local/
LIB_NAME:=apa
LIB_SRC=integer.cpp
LIB_OBJ=integer.o
LIB_OUT:=build/lib
LIB_HEADER_OUT:=build/include
LIB_OUTNAME:=lib$(LIB_NAME).a
CXXFLAGS := -Wall -Wextra
USERFLAGS := -D_MAKE_LIB
TEST_OPTIMIZATION := -g -Og
HEADER_PATHS := -I./$(LIB_HEADER_OUT)/APA
LIB_OPTIMIZATION := -O2
LIB_PATHS := -L./$(LIB_OUT)
LIBS := -l$(LIB_NAME)
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))
.PHONY: build_move build_compile cleanup static_test install uninstall release
build_move: build_compile
@echo "moving files to build folder"
ifeq ($(OS), Linux)
@mv $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_OUTNAME) ./$(LIB_OUT)/
@mkdir $(LIB_HEADER_OUT)/APA
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))integer.hpp ./$(LIB_HEADER_OUT)/APA/
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))bint.hpp ./$(LIB_HEADER_OUT)/APA/
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))config.hpp ./$(LIB_HEADER_OUT)/APA/
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))math.hpp ./$(LIB_HEADER_OUT)/APA/
else
@move "./$(LIB_OUTNAME)" "$(LIB_OUT)"
@mkdir $(LIB_HEADER_OUT)/APA
@copy "./integer.hpp" "$(LIB_HEADER_OUT)"\APA
@copy "./bint.hpp" "$(LIB_HEADER_OUT)"\APA
@copy "./config.hpp" "$(LIB_HEADER_OUT)"\APA
@copy "./math.hpp" "$(LIB_HEADER_OUT)"\APA
endif
build_compile:
@echo "Compiler : $(CC)"
@echo "OS : $(OS)"
@echo "------------------------------------------"
@echo "creating build directory"
@mkdir build
@mkdir $(LIB_HEADER_OUT)
@mkdir $(LIB_OUT)
@echo "creating static lib"
@echo "compiling integer..."
@$(CC) -c integer.cpp $(LIB_OPTIMIZATION)
@echo "compiling bint..."
@$(CC) -c bint.cpp $(LIB_OPTIMIZATION)
@echo "compiling math..."
@$(CC) -c math.cpp $(LIB_OPTIMIZATION)
@echo "compiling $(LIB_OUTNAME)..."
@ar -r $(LIB_OUTNAME) integer.o bint.o math.o
@echo "build done : output -> $(LIB_OUTNAME)"
cleanup:
@echo "removing objects..."
ifeq ($(OS), Linux)
@rm -rf build
@rm *.o *.out
else
rmdir /S build
del *.o *.out *.exe
endif
# -------------------------- run test programs ---------------------------
static_test: $(OBJ)
@echo OS : $(OS)
@echo LIMB : Base2_$(BASE2_RAISED_BY)
@echo "----------------------------------------------------"
@echo "Running Initial Tests..."
@./$(SRC)/integer_constructor.out
@./$(SRC)/integer_swap.out
@./$(SRC)/integer_add.out
@./$(SRC)/integer_add_assign.out
@./$(SRC)/integer_sub.out
@./$(SRC)/integer_sub_assign.out
@./$(SRC)/integer_mul.out
@./$(SRC)/integer_bitwise_logic.out
@./$(SRC)/integer_relational.out
@./$(SRC)/integer_logical.out
@./$(SRC)/integer_shifts.out
@./$(SRC)/integer_div.out
@./$(SRC)/integer_base_print.out
@./$(SRC)/integer_bases.out
@./$(SRC)/integer_access.out
@./$(SRC)/bint_construct.out
@./$(SRC)/bint_logical.out
@./$(SRC)/bint_add.out
@./$(SRC)/bint_add_assign.out
@./$(SRC)/bint_sub.out
@./$(SRC)/bint_sub_assign.out
@./$(SRC)/bint_mul.out
@./$(SRC)/bint_div.out
@./$(SRC)/bint_bitwise_logic.out
@./$(SRC)/bint_shifts.out
@./$(SRC)/bint_methods.out
@./$(SRC)/bint_karatsuba.out
@./$(SRC)/bint_error_handling.out
@./$(SRC)/bint_literal_assign.out
# -------------------------- test program compilation ---------------------------
$(SRC)/%.out: $(SRC)/%.cpp
@echo "compiling test program (static build) - compiler : $(CC)"
@$(CC) $(CXXFLAGS) $(USERFLAGS) $(HEADER_PATHS) -o $@ $< $(LIB_PATHS) $(LIBS) $(TEST_OPTIMIZATION)
install:
ifeq ($(OS), Linux)
@mkdir $(INSTALL_PREFIX)include/APA
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_HEADER_OUT)/APA/integer.hpp $(INSTALL_PREFIX)include/APA
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_HEADER_OUT)/APA/bint.hpp $(INSTALL_PREFIX)include/APA
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_HEADER_OUT)/APA/config.hpp $(INSTALL_PREFIX)include/APA
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_HEADER_OUT)/APA/math.hpp $(INSTALL_PREFIX)include/APA
@cp $(dir $(abspath $(lastword $(MAKEFILE_LIST))))$(LIB_OUT)/$(LIB_OUTNAME) $(INSTALL_PREFIX)lib
@echo "$(LIB_OUTNAME) now installed to $(INSTALL_PREFIX)lib"
@echo "headers are installed to $(INSTALL_PREFIX)include"
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 .
mkdir $(INSTALL_PREFIX)\include\APA
copy build\include\APA\integer.hpp "$(INSTALL_PREFIX)\include\APA
copy build\include\APA\bint.hpp "$(INSTALL_PREFIX)\include\APA
copy build\include\APA\config.hpp "$(INSTALL_PREFIX)\include\APA
copy build\include\APA\math.hpp "$(INSTALL_PREFIX)\include\APA
copy build\lib\$(LIB_OUTNAME) "$(INSTALL_PREFIX)\lib"
@echo install success
endif
uninstall:
ifeq ($(OS), Linux)
@rm $(INSTALL_PREFIX)lib/$(LIB_OUTNAME)
@rm $(INSTALL_PREFIX)include/APA/integer.hpp
@rm $(INSTALL_PREFIX)include/APA/bint.hpp
@rm $(INSTALL_PREFIX)include/APA/config.hpp
@rm $(INSTALL_PREFIX)include/APA/math.hpp
@rm -r $(INSTALL_PREFIX)include/APA
else
del "$(INSTALL_PREFIX)\lib\$(LIB_OUTNAME)"
del "$(INSTALL_PREFIX)\include\APA\integer.hpp"
del "$(INSTALL_PREFIX)\include\APA\bint.hpp"
del "$(INSTALL_PREFIX)\include\APA\config.hpp"
del "$(INSTALL_PREFIX)\include\APA\math.hpp"
rmdir $(INSTALL_PREFIX)\include\APA
echo uninstall success
endif
release: build
@echo "Bundling static library"
ifeq ($(OS), Linux)
tar -czvf apa-linux-release-v0.4.6.tar.gz build
else
zip -r apa-windows-release-v0.4.6.zip build
endif