forked from zeutro/openabe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
162 lines (145 loc) · 5.09 KB
/
Makefile.common
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
# Shared Makefile for openabe build from the source
CC ?= g++
CXX ?= g++
LDLIBS ?= -lgtest -lpthread
DEPS_INSTALL_ZROOT = $(ZROOT)/deps/root
OABE_LIB_ROOT = $(ZROOT)/root/lib
INCLUDE_ROOT = $(ZROOT)/root/include
LOCAL_LIB_ROOT ?= /usr/local/lib
LOCAL_INCLUDE ?= /usr/local/include
LOCAL_INSTALL_BIN ?= /usr/local/bin
# Include locations
# Dependencies (C/C++)
CCFLAGS = -I$(DEPS_INSTALL_ZROOT)/include
CXXFLAGS := -I$(DEPS_INSTALL_ZROOT)/include
# Local includes (for generated headers from bison/flex)
CXXFLAGS += -I$(ZROOT)/src
# Common includes (C/C++)
CCFLAGS += -I$(INCLUDE_ROOT) -I$(LOCAL_INCLUDE)
CXXFLAGS += -I$(INCLUDE_ROOT) -I$(LOCAL_INCLUDE)
RELIC_LIB = -lrelic -lrelic_ec
RELIC_LIB_STATIC = -lrelic_s -lrelic_s_ec
GMP_LIB = -lgmp
SSL_LIB = -lssl
CRYPTO_LIB = -lcrypto
RELIC_G =
# commit: 1e3f62a3823f7e3db9d403f724fd9d66f5b04cf8 (as of 7/18/17)
OPENSSL_VERSION := 1.1.1-dev
# Set flags for C++ 11
OLD_GPP = $(shell g++ --version | grep -q 4.6 && echo 1)
ifeq ($(OLD_GPP), 1)
CXX11FLAGS = -std=c++0x
CXXFLAGS += $(CXX11FLAGS)
else
CXX11FLAGS = -std=c++11
CXXFLAGS += $(CXX11FLAGS)
endif
# Set shared lib extension for each OS
DEPS_PACKAGES = $(if $(USE_DEPS),$(USE_DEPS),relic openssl gtest)
ADD_CFLAGS :=
OS_CXXFLAGS :=
WITH_BP :=
ifeq ($(OS), Windows_NT)
RELIC_OS := WINDOWS
# NOTE: relic build still broken for MINGW
DEPS_PACKAGES = openssl
WITH_BP := "with-bp"
OPENSSL_VERSION := 1.1.1-dev-bp
COMPILER_VARS := -G "MinGW Makefiles" -DSEED=WCGR
CMAKE_VARS := -DCMAKE_MAKE_PROGRAM=/mingw64/bin/mingw32-make -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++.exe CMAKE_INCLUDE_PATH="/usr/local/include" CMAKE_LIBRARY_PATH="/usr/local/lib"
SHLIB := dll
GTESTEXT := $(SHLIB)
# No need to set -fPIC for windows as all code is position independent by default.
CXXFLAGS += -DGTEST_USE_OWN_TR1_TUPLE=0 -I/usr/local/include/ -I/usr/include
SHFLAGS := -nostartfiles
OPENSSL_CONFIG := Configure mingw64 shared
# needed for static libs
OS_OBJS += /mingw64/x86_64-w64-mingw32/lib/dllcrt1.o
# for network func
OS_LIBS += -lwsock32 -lws2_32
#ADD_FLAGS :=
else
OS_NAME = $(shell uname -s)
ifeq ($(OS_NAME), Linux)
RELIC_OS = LINUX
SHFLAGS = -shared
SHLIB = so
GTESTEXT = $(SHLIB).0
ifneq (,$(filter $(OS_FAMILY), fedora redhat))
OS_CXXFLAGS += -I/usr/include
ifeq ($(OS_FAMILY), redhat)
OS_CXXFLAGS += -DOS_REDHAT_LINUX
else
OS_CXXFLAGS += -DOS_FEDORA_LINUX
endif
endif
CXXFLAGS += -fPIC -DGTEST_USE_OWN_TR1_TUPLE=0 $(OS_CXXFLAGS)
CCFLAGS += -fPIC
OPENSSL_CONFIG = config shared
ADD_CFLAGS += -Wno-implicit-function-declaration
endif
ifeq ($(OS_NAME), Darwin)
RELIC_OS = MACOSX
SHFLAGS = -dynamiclib -current_version 1.0 -compatibility_version 1.0
SHLIB = dylib
GTESTEXT = 0.$(SHLIB)
# pull in headers installed via brew (for gmp/relic/openssl)
CCFLAGS += -fPIC
CXXFLAGS += -I$(LOCAL_INCLUDE) $(OS_CXXFLAGS)
# include the clang C++ standard library (as a result, enable TR1_TUPLE flag)
CXXFLAGS += -stdlib=libc++ -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-deprecated
# (Option to use GMP with OpenSSL?): -DOPENSSL_USE_GMP -lgmp
OPENSSL_CONFIG := Configure darwin64-x86_64-cc shared
ADD_CFLAGS += -Wno-implicit-function-declaration -Wno-macro-redefined
endif
# TODO: add check for ARM, etc
endif
PTHREAD_LIB = -lpthread
# Other flags
CXXFLAGS += -pthread
# Warnings/errors, for now turn off one warning as this makes ztk unusable
CXXFLAGS += -Wall
# Avoid integer overflow issues with these flags
# -Wtype-limits
CXXFLAGS += -fstrict-overflow -Wsign-compare
# Add debug symbols (we must remove these in a production build)
CXXFLAGS += -g -O2
# uncomment to enable Address sanitizer
#CXXFLAGS += -fsanitize=address -ggdb
# uncomment to switch to afl-fuzz
# CC="afl-gcc" # for linux
# CXX="afl-g++"
# CC="afl-clang" # for mac
# CXX="afl-clang++"
LDFLAGS += -L$(DEPS_INSTALL_ZROOT)/lib -L$(OABE_LIB_ROOT) -L$(LOCAL_LIB_ROOT)
# Zeutro Math library config: RELIC vs OPENSSL
# Look for environment variable ZML_LIB=with_openssl
OPENSSL_ZML = -DSSL_LIB_INIT
ifeq ($(ZML_LIB), with_openssl)
# openssl-only build for math ops
OPENSSL_ZML += -DBP_WITH_OPENSSL
CXXFLAGS += $(OPENSSL_ZML)
CCFLAGS += -g -O2 $(OPENSSL_ZML)
else
# relic-only build for math ops
CXXFLAGS += $(OPENSSL_ZML)
CCFLAGS += -g -O2 $(OPENSSL_ZML) $(ADD_CFLAGS)
OABELDLIBS = $(RELIC_LIB_STATIC)
OABELDSHLIBS = $(RELIC_LIB)
endif
# remaining deps
OABELDLIBS += $(SSL_LIB) $(CRYPTO_LIB) $(GMP_LIB)
OABELDSHLIBS += $(SSL_LIB) $(CRYPTO_LIB) $(GMP_LIB)
SHLIB_PATH = $(LDFLAGS)
.DEFAULT_GOAL = all
define COMMON_LIB_template
$(1): $(1)($$($(1)_OBJS))
mkdir -p $(OABE_LIB_ROOT)
cp $$@ $(OABE_LIB_ROOT)
mkdir -p $(INCLUDE_ROOT)
-cp -r include/* $(INCLUDE_ROOT)
endef
# COMMON_LIBS, and the objects they use must be defined *before* this
# file is included!
$(foreach library, $(COMMON_LIBS), \
$(eval $(call COMMON_LIB_template,$(library))))