-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Makefile.onelib
223 lines (196 loc) · 7.9 KB
/
Makefile.onelib
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
# This Makefile is to build one bls384_256.a which contains libmcl.a for convenience.
BLS_DIR?=./
OUT_DIR?=./
MCL_DIR?=$(BLS_DIR)/mcl
include $(MCL_DIR)/common.mk
#ETH_CFLAGS=-DBLS_ETH
UNIT?=$(shell expr $(BIT) / 8)
THIS_FILE := $(realpath $(firstword $(MAKEFILE_LIST)))
MIN_CFLAGS=-O3 -fno-exceptions -fno-threadsafe-statics -fno-rtti -fno-stack-protector -DNDEBUG -DMCL_DONT_USE_OPENSSL -DMCL_SIZEOF_UNIT=$(UNIT) -DMCL_MAX_BIT_SIZE=384 -DCYBOZU_DONT_USE_EXCEPTION -DCYBOZU_DONT_USE_STRING -D_FORTIFY_SOURCE=0 -I$(BLS_DIR)/include -I$(MCL_DIR)/include $(ETH_CFLAGS) $(CFLAGS_USER)
MIN_CFLAGS+=-std=c++03
OBJ_DIR=obj
OBJS=$(OBJ_DIR)/bls_c384_256.o $(OBJ_DIR)/fp.o
ifeq ($(OS),mingw64)
_OS=windows
else
MIN_CFLAGS+=-fpic
endif
ifeq ($(OS),Linux)
_OS=linux
endif
ifeq ($(OS),mac)
_OS=darwin
endif
ifeq ($(OS),mac-m1)
_OS=darwin
endif
ifeq ($(OS),openbsd)
_OS=openbsd
endif
ifeq ($(OS),freebsd)
_OS=freebsd
endif
BASE_OBJ=$(MCL_DIR)/$(OBJ_DIR)/base$(BIT).o
BINT_OBJ=$(MCL_DIR)/$(OBJ_DIR)/bint$(BIT).o
ifeq ($(CPU),x86-64)
_ARCH=amd64
ifneq ($(UNAME_S),Darwin)
MCL_MSM?=1
endif
endif
ifeq ($(CPU),aarch64)
_ARCH=arm64
endif
ifeq ($(CPU),arm)
_ARCH=arm
endif
ifeq ($(CPU),systemz)
_ARCH=s390x
endif
ifeq ($(UNAME_S),Darwin)
ifeq ($(CLANG_TARGET),)
CLANG_TARGET?=$(ARCH)-apple-macos
endif
endif
ifneq ($(CLANG_TARGET),)
MIN_CFLAGS+=-target $(CLANG_TARGET)
ASFLAGS+=-target $(CLANG_TARGET)
endif
OBJS+=$(BINT_OBJ)
ifeq ($(findstring $(OS),mingw64/cygwin),)
MCL_USE_LLVM?=1
else
MCL_USE_LLVM=0
endif
ifeq ($(MCL_USE_LLVM),1)
MIN_CFLAGS+=-DMCL_USE_LLVM=1
OBJS+=$(BASE_OBJ)
endif
ifeq ($(MCL_MSM),1)
ifeq ($(CPU),x86-64)
MSM=msm_avx
endif
MIN_CFLAGS+=-DMCL_MSM=1
MSM_OBJ=$(MCL_DIR)/$(OBJ_DIR)/$(MSM).o
OBJS+=$(MSM_OBJ)
endif
LIB_DIR?=$(OUT_DIR)/bls/lib/$(_OS)/$(_ARCH)
STATIC_LIB=$(LIB_DIR)/libbls384_256.a
SHARED_LIB=$(LIB_DIR)/libbls384_256.$(LIB_SUF)
TARGET=$(STATIC_LIB)
ifeq ($(BLS_LIB_SHARED),1)
TARGET+=$(SHARED_LIB)
endif
ifneq ($(findstring $(OS),mac/mingw64),)
# MIN_LDFLAGS+=-lstdc++
endif
ifeq ($(OS),mingw64)
MIN_LDFLAGS+=-Wl,--out-implib,$(STATIC_LIB)
endif
all: $(TARGET)
ifeq ($(CPU)$(ETH_CFLAGS),x86-64-DBLS_ETH)
ifeq ($(_OS),windows)
MCL_STATIC_CODE?=0
else
MCL_STATIC_CODE?=1
endif
endif
ifeq ($(MCL_STATIC_CODE),1)
MIN_CFLAGS+=-DMCL_STATIC_CODE -DMCL_DONT_USE_XBYAK
OBJS+=$(MCL_DIR)/$(OBJ_DIR)/static_code.o
$(MCL_DIR)/$(OBJ_DIR)/static_code.o:
$(MAKE) -C $(MCL_DIR) $(OBJ_DIR)/static_code.o
endif
$(STATIC_LIB): $(OBJS)
-mkdir -p $(LIB_DIR)
$(AR) $(ARFLAGS) $(STATIC_LIB) $(OBJS)
$(SHARED_LIB): $(OBJS) $(STATIC_LIB)
$(PRE)$(CXX) -shared -o $@ $(OBJS) $(MIN_LDFLAGS)
$(OBJ_DIR)/fp.o: $(MCL_DIR)/src/fp.cpp
$(CXX) -c $< -o $@ $(MIN_CFLAGS)
$(OBJ_DIR)/bls_c384_256.o: $(BLS_DIR)/src/bls_c384_256.cpp
$(CXX) -c $< -o $@ $(MIN_CFLAGS)
$(BINT_OBJ):
$(MAKE) -C $(MCL_DIR) obj/bint$(BIT).o CPU=$(CPU) OS=$(OS) BIT=$(BIT)
$(BASE_OBJ):
$(MAKE) -C $(MCL_DIR) obj/base$(BIT).o CPU=$(CPU) OS=$(OS) BIT=$(BIT)
$(MSM_OBJ): $(MCL_DIR)/src/$(MSM).cpp
$(CXX) -c $< -o $@ $(MIN_CFLAGS) -mavx512f -mavx512ifma -std=c++11
ANDROID_TARGET=armeabi-v7a arm64-v8a x86_64
NDK_BUILD?=ndk-build
android: $(BASE_LL)
@$(NDK_BUILD) -C $(BLS_DIR)/android/jni NDK_DEBUG=0 BLS_LIB_SHARED=$(BLS_LIB_SHARED) ETH_CFLAGS=$(ETH_CFLAGS)
@for target in $(ANDROID_TARGET); do \
mkdir -p $(OUT_DIR)/bls/lib/android/$$target; \
cp $(BLS_DIR)/android/obj/local/$$target/libbls384_256.a $(OUT_DIR)/bls/lib/android/$$target/; \
done
# ios
XCODEPATH=$(shell xcode-select -p)
IOS_CLANG=$(XCODEPATH)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
IOS_AR=${XCODEPATH}/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar
PLATFORM?="iPhoneOS"
IOS_MIN_VERSION?=7.0
IOS_CFLAGS=-fembed-bitcode -fno-common -DPIC -fPIC -Dmcl_EXPORTS
IOS_CFLAGS+=-fno-exceptions -fno-rtti -fno-threadsafe-statics -fno-stack-protector -DCYBOZU_DONT_USE_EXCEPTION -DCYBOZU_DONT_USE_STRING
IOS_CFLAGS+=-DMCL_DONT_USE_XBYAK -DMCL_USE_LLVM=1 -std=c++03 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -O3 -DNDEBUG $(ETH_CFLAGS)
IOS_CFLAGS+=-I $(MCL_DIR)/include -I $(BLS_DIR)/include
IOS_LDFLAGS=-dynamiclib -Wl,-flat_namespace -Wl,-undefined -Wl,suppress
CURVE_BIT?=384_256
IOS_LIB=libbls$(CURVE_BIT).a
IOS_LIBS=ios/armv7/$(IOS_LIB) ios/arm64/$(IOS_LIB) iossimulator/x86_64/$(IOS_LIB) iossimulator/i386/$(IOS_LIB)
SIMULATOR_LIBS= iossimulator/arm64/$(IOS_LIB) iossimulator/x86_64/$(IOS_LIB) iossimulator/i386/$(IOS_LIB)
ios: ios_simulator
$(MAKE) -f $(THIS_FILE) each_ios OUTDIR="ios" MINVERSION="-mios-version-min" PLATFORM="iPhoneOS" ARCH=armv7 BIT=32 UNIT=4
$(MAKE) -f $(THIS_FILE) each_ios OUTDIR="ios" MINVERSION="-mios-version-min" PLATFORM="iPhoneOS" ARCH=arm64 BIT=64 UNIT=8
@echo $(IOS_LIBS)
@mkdir -p $(OUT_DIR)/bls/lib/ios
lipo $(IOS_LIBS) -create -output $(OUT_DIR)/bls/lib/ios/$(IOS_LIB)
ios_simulator:
$(MAKE) -f $(THIS_FILE) each_ios OUTDIR="iossimulator" MINVERSION="-mios-simulator-version-min" PLATFORM="iPhoneSimulator" ARCH=arm64 BIT=64 UNIT=8
$(MAKE) -f $(THIS_FILE) each_ios OUTDIR="iossimulator" MINVERSION="-mios-simulator-version-min" PLATFORM="iPhoneSimulator" ARCH=x86_64 BIT=64 UNIT=8
$(MAKE) -f $(THIS_FILE) each_ios OUTDIR="iossimulator" MINVERSION="-mios-simulator-version-min" PLATFORM="iPhoneSimulator" ARCH=i386 BIT=32 UNIT=4
@echo $(SIMULATOR_LIBS)
@mkdir -p $(OUT_DIR)/bls/lib/iossimulator
lipo $(SIMULATOR_LIBS) -create -output $(OUT_DIR)/bls/lib/iossimulator/$(IOS_LIB)
each_ios: $(BASE_LL)
@echo "Building $(PLATFORM) $(ARCH) BIT=$(BIT) UNIT=$(UNIT)"
$(eval IOS_CFLAGS=$(IOS_CFLAGS) -DMCL_SIZEOF_UNIT=$(UNIT))
@echo IOS_CFLAGS=$(IOS_CFLAGS)
$(eval IOS_OUTDIR=$(OUTDIR)/$(ARCH))
$(eval IOS_SDK_PATH=$(XCODEPATH)/Platforms/$(PLATFORM).platform/Developer/SDKs/$(PLATFORM).sdk)
$(eval IOS_COMMON=-arch $(ARCH) -isysroot $(IOS_SDK_PATH) $(MINVERSION)=$(IOS_MIN_VERSION))
@mkdir -p $(IOS_OUTDIR)
$(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/fp.cpp -o $(IOS_OUTDIR)/fp.o
$(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/base$(BIT).ll -o $(IOS_OUTDIR)/base$(BIT).o
$(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(BLS_DIR)/src/bls_c$(CURVE_BIT).cpp -o $(IOS_OUTDIR)/bls_c$(CURVE_BIT).o
ifeq ($(ARCH),x86_64)
@echo compile bint-x64-amd64.S
$(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/asm/bint-x64-amd64.S -o $(IOS_OUTDIR)/bint64.o
else
@echo compile bint$(BIT).ll
$(IOS_CLANG) $(IOS_COMMON) $(IOS_CFLAGS) -c $(MCL_DIR)/src/bint$(BIT).ll -o $(IOS_OUTDIR)/bint$(BIT).o
endif
ar cru $(IOS_OUTDIR)/$(IOS_LIB) $(IOS_OUTDIR)/fp.o $(IOS_OUTDIR)/base$(BIT).o $(IOS_OUTDIR)/bls_c$(CURVE_BIT).o $(IOS_OUTDIR)/bint$(BIT).o
ranlib $(IOS_OUTDIR)/$(IOS_LIB)
# cross compile
#Try a compiler option `-isystem <include directory>` if you have trouble with including standard heder file.
# make -f Makefile.onelib build_aarch64 CXX=clang++ LLVM_VER=-18 build_aarch64
# aarch64-linux-gnu-gcc-13 sample/minsample.c bls/lib/linux/arm64/libbls384_256.a -I include/ -I mcl/include/
# env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/ ./a.out
build_aarch64:
$(MAKE) -f $(THIS_FILE) ARCH=aarch64 CLANG_TARGET=aarch64
# $(CXX) -target aarch64 test/bls_c384_256_test.cpp -I ./include -I mcl/include bls/lib/linux/arm64/libbls384_256.a
build_i686:
$(MAKE) -f $(THIS_FILE) ARCH=x86 CLANG_TARGET=i686
# g++ -m32 test/bls_c384_256_test.cpp -I ./include -I mcl/include bls/lib/linux/libbls384_256.a
#make -f Makefile.onelib ARCH=mipsisa32r6el CLANG_TARGET=mipsisa32r6el BIT=32 CXX=clang++-17
#mipsisa32r6el-linux-gnu-gcc-13 sample/minsample.c -I include/ -I mcl/include/ bls/lib/linux/libbls384_256.a
#env QEMU_LD_PREFIX=/usr/mipsisa32r6el-linux-gnu/ ./a.out
# for mingw64
# make -f Makefile.onelib CXX=x86_64-w64-mingw32-g++ MCL_USE_LLVM=0 OS=mingw64 LIB_DIR=./
# x86_64-w64-mingw32-g++ -o pairing.exe -I mcl/include/ mcl/sample/pairing.cpp -DMCL_MAX_BIT_SIZE=384 libbls384_256.a
clean:
$(MAKE) -C $(MCL_DIR) clean
$(MAKE) -C $(BLS_DIR) clean
$(RM) -rf obj/*.o android/obj/* bls/lib/android/*
.PHONY: android ios ios_simulator each_ios clean