-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
common.mk
168 lines (163 loc) · 3.43 KB
/
common.mk
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
GCC_VER=$(shell $(PRE)$(CC) -dumpversion)
UNAME_S?=$(shell uname -s)
ARCH?=$(shell uname -m)
NASM_ELF_OPT=-felf64
ifeq ($(UNAME_S),Linux)
OS=Linux
endif
ifeq ($(findstring MINGW64,$(UNAME_S)),MINGW64)
OS=mingw64
CFLAGS+=-D__USE_MINGW_ANSI_STDIO=1
NASM_ELF_OPT=-fwin64
endif
ifeq ($(findstring CYGWIN,$(UNAME_S)),CYGWIN)
OS=cygwin
endif
ifeq ($(UNAME_S),Darwin)
ifeq ($(ARCH),x86_64)
OS=mac
else
OS=mac-m1
endif
LIB_SUF=dylib
NASM_ELF_OPT=-fmacho64
else
LIB_SUF=so
endif
ifeq ($(UNAME_S),OpenBSD)
OS=openbsd
CXX?=clang++
CFLAGS+=-I/usr/local/include
LDFLAGS+=-L/usr/local/lib
endif
ifeq ($(UNAME_S),FreeBSD)
OS=freebsd
CXX?=clang++
CFLAGS+=-I/usr/local/include
LDFLAGS+=-L/usr/local/lib
endif
ifneq ($(findstring $(ARCH),x86_64/amd64),)
CPU=x86-64
INTEL=1
ifeq ($(findstring $(OS),mingw64/cygwin),)
GCC_EXT=1
endif
BIT=64
BIT_OPT=-m64
#LOW_ASM_SRC=src/asm/low_x86-64.asm
#ASM=nasm -felf64
endif
ifneq ($(findstring $(ARCH),x86/i386/i686),)
CPU=x86
INTEL=1
BIT=32
BIT_OPT=-m32
#LOW_ASM_SRC=src/asm/low_x86.asm
endif
ifneq ($(findstring $(ARCH),armv7l/armv6l),)
CPU=arm
BIT=32
#LOW_ASM_SRC=src/asm/low_arm.s
endif
#ifeq ($(ARCH),aarch64)
ifneq ($(findstring $(ARCH),aarch64/arm64),)
CPU=aarch64
BIT=64
endif
ifeq ($(findstring $(OS),mac/mac-m1/mingw64/openbsd),)
LDFLAGS+=-lrt
endif
ifeq ($(ARCH),s390x)
CPU=systemz
BIT=64
endif
AR?=ar
ARFLAGS?=r
CP=cp -f
MKDIR=mkdir -p
RM=rm -rf
DEBUG?=0
ifeq ($(DEBUG),1)
ifeq ($(GCC_EXT),1)
SANITIZE_OPT?=-fsanitize=address
endif
endif
ifeq ($(DEBUG),2)
ifeq ($(GCC_EXT),1)
SANITIZE_OPT?=-fsanitize=memory -fsanitize-memory-track-origins=2
endif
endif
ifeq ($(DEBUG),3)
# no option
endif
ifeq ($(DEBUG),4)
ifeq ($(GCC_EXT),1)
SANITIZE_OPT?=-fsanitize=undefined -fno-sanitize-recover
endif
endif
CFLAGS+=$(SANITIZE_OPT)
LDFLAGS+=$(SANITIZE_OPT)
ifeq ($(DEBUG),0)
CFLAGS_OPT+=-fomit-frame-pointer -DNDEBUG -fno-stack-protector
ifeq ($(CXX),clang++)
CFLAGS_OPT+=-O3
else
CFLAGS_OPT+=-O3
endif
ifeq ($(MARCH),)
ifeq ($(INTEL),1)
# CFLAGS_OPT+=-march=native
endif
else
CFLAGS_OPT+=$(MARCH)
endif
endif
CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef
CFLAGS+=-g3
INC_OPT=-I include -I test
CFLAGS+=$(CFLAGS_WARN) $(BIT_OPT) $(INC_OPT)
DEBUG=0
CFLAGS_OPT_USER?=$(CFLAGS_OPT)
ifeq ($(DEBUG),0)
CFLAGS+=$(CFLAGS_OPT_USER)
endif
CFLAGS+=$(CFLAGS_USER)
ifneq ($(MCL_SIZEOF_UNIT),)
CFLAGS+=-DMCL_SIZEOF_UNIT=$(MCL_SIZEOF_UNIT)
endif
MCL_USE_GMP?=0
ifeq ($(MCL_USE_GMP),1)
CFLAGS+=-DMCL_USE_GMP=1
MCL_USE_GMP_LIB=1
endif
MCL_USE_GMP_LIB?=1
ifeq ($(MCL_USE_GMP_LIB),1)
GMP_LIB=-lgmp -lgmpxx
ifeq ($(UNAME_S),Darwin)
GMP_DIR?=/opt/homebrew/
endif
ifneq ($(GMP_DIR),)
CFLAGS+=-I$(GMP_DIR)/include
LDFLAGS+=-L$(GMP_DIR)/lib
endif
endif
ifeq ($(MCL_STATIC_CODE),1)
MCL_USE_XBYAK=0
MCL_MAX_BIT_SIZE=384
CFLAGS+=-DMCL_STATIC_CODE
CFLAGS+=-fno-exceptions -fno-rtti -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION
endif
ifeq ($(MCL_USE_OMP),1)
CFLAGS+=-DMCL_USE_OMP
ifneq ($(findstring $(OS),mac/mac-m1),)
CFLAGS+=-Xpreprocessor -fopenmp
LDFLAGS+=-lomp
else
CFLAGS+=-fopenmp
LDFLAGS+=-fopenmp
endif
endif
LDFLAGS+=$(GMP_LIB) $(BIT_OPT) $(LDFLAGS_USER)
# -fpic is better than -fPIC in exchange for restriction of a size of GOT
# https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
CFLAGS+=-fpic