-
Notifications
You must be signed in to change notification settings - Fork 16
/
portablelib.mk
278 lines (205 loc) · 6.36 KB
/
portablelib.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# Common fragment for people using this library
# Usage in your GNUmakefile:
#
# - define PORTABLE to path to this top level directory
# - include $(PORTABLE)/portablelib.mk
ifeq ($(PORTABLE),)
junk := $(error ** Please define PORTABLE before including this makefile **)
endif
ifeq ($(os),)
os := $(shell uname -s | tr '[A-Z]' '[a-z]')
endif
_mach := $(shell uname -m)
mach_x86_64 := amd64
mach_aarch64 := aarch64
mach_arm := arm
ifneq ($(mach_$(_mach)),)
machine := $(mach_$(_mach))
else
machine := $(_mach)
endif
all_win32_objs += gettimeofday.o truncate.o ndir.o \
ftruncate.o sleep.o basename.o dirname.o glob.o \
winmmap.o errno.o fsync.o inetutils.o \
socketpair.o
win32_vpath += $(PORTABLE)/src/win32
win32_incdirs += $(PORTABLE)/inc/win32
win32_defs += -DWIN32 -D_WIN32 -DWINVER=0x0501
win32_tests +=
win32_LDFLAGS +=
win32_ldlibs += -lwsock32
all_posix_objs = daemon.o
#all_posix_objs += resolve.o
all_posix_objs += c_resolve.o work.o job.o
posix_vpath += $(PORTABLE)/src/posix
posix_incdirs +=
posix_defs +=
posix_tests +=
posix_ldlibs +=
posix_LDFLAGS +=
linux_ldlibs += -lsodium
linux_defs += -D_GNU_SOURCE=1
darwin_incdirs += /opt/local/include
darwin_ldlibs += /opt/local/lib/libsodium.a
openbsd_incdirs += /usr/local/include
openbsd_ldlibs += -L/usr/local/lib -lsodium -lpthread
DragonFly_incdirs += /usr/local/include /usr/local/include/ncurses
DragonFly_ldlibs += -L/usr/local/lib -lsodium -lpthread
posix_oses = linux darwin solaris openbsd freebsd netbsd dragonfly
# Helper for Posix OSes
ifneq ($(findstring $(os),$(posix_oses)),)
$(os)_vpath += $(posix_vpath)
$(os)_incdirs += $(PORTABLE)/inc/$(os) $(posix_incdirs)
$(os)_defs += $(posix_defs)
$(os)_LDFLAGS += $(posix_LDFLAGS)
$(os)_ldlibs += $(posix_ldlibs)
endif
# Default objs for linux
linux_defobjs = $(all_posix_objs) linux_cpu.o \
arc4random.o
darwin_defobjs = $(all_posix_objs) darwin_cpu.o darwin_sem.o
win32_defobjs = $(all_win32_objs) win32_rand.o
openbsd_defobjs = $(all_posix_objs) openbsd_cpu.o
# DragonFly BSD supports linux's sched_{get/set}affinity()
dragonfly_defobjs = $(all_posix_objs) nofdatasync.o linux_cpu.o
# Add posix_entropy.o if your posix platform doesn't have
# getentropy(2)
#timerobjs = timer.o timer_int.o ctimer.o
hashfunc_objs = cityhash.o fasthash.o fnvhash.o \
frand.o hsieh_hash.o murmur3_hash.o \
romu-rand.o xoroshiro.o xorshift.o \
siphash24.o xxhash.o yorrike.o \
hashtab_objs = bloom.o bloom_marshal.o \
fast-ht.o hashtab.o hashtab_iter.o \
xorfilter.o xorfilter_marshal.o \
baseobjs = mempool.o dirname.o fts.o splitargs.o \
escape.o unescape.o mmap.o sysexception.o syserror.o \
getopt_long.o error.o str2hex.o \
b64_encode.o b64_decode.o humanize.o strtosize.o \
cmutex.o arena.o memmgr.o hexdump.o \
strunquote.o readpass.o uuid.o ulid.o \
mkdirhier.o parse-ip.o strcopy.o \
gstring.o gstring_var.o freadline.o rotatefile.o \
strsplit.o strsplit_csv.o strtrim.o \
pack.o progbar.o \
$(hashfunc_objs) $(hashtab_objs) \
$($(os)_objs)
default-libobjs = $(baseobjs) $($(os)_defobjs)
# Only assign if top level GNUmakefile hasn't done anything
libobjs ?= $(default-libobjs)
# Do this in the beginning so that VPATH etc. gets initialized
INCDIRS = $($(os)_incdirs)
VPATH = $($(os)_vpath)
psrc = $(PORTABLE)/src
INCDIRS += $(psrc) $(psrc)/hashtable $(PORTABLE)/inc
VPATH += $(psrc) $(psrc)/hashtable $(psrc)/hashfunc $(psrc)/prng
INCS = $(addprefix -I,$(INCDIRS))
DEFS = -D__$(os)__=1 -D__$(machine)__=1 $($(os)_defs)
# Cross compiling Win32 binaries on Linux. Way cool :-)
ifneq ($(CROSS),)
mingw_ok = $(shell if $(CROSS)gcc -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "yes"; else echo "no"; fi;)
ifeq ($(mingw_ok),yes)
CROSSPATH := $(CROSS)
os := win32
else
# Check for debian cross compiler
mingw_ok = $(shell if i586-mingw32msvc-gcc -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "yes"; else echo "no"; fi;)
ifeq ($(mingw_ok),yes)
CROSSPATH := i586-mingw32msvc-
os := win32
else
junk := $(error ** $(CROSS) Cross compiler is not available!)
endif
endif
else
ifneq ($(cyg-cross),)
CROSSPATH := $(cyg-cross)
endif
endif
ifeq ($(os),win32)
exe := .exe
WIN32 := 1
endif
# Aux tools we need
TOOLSDIR = $(PORTABLE)/tools
DEPWEED = $(TOOLSDIR)/depweed.py
MKGETOPT = $(TOOLSDIR)/mkgetopt.py
WARNINGS = -Wall -Wextra -Wpointer-arith -Wshadow
#EXTRA_WARNINGS = -Wsign-compare -Wconversion -Wsign-conversion
LDFLAGS += $(EXTRA_WARNINGS)
win32_CFLAGS += -mno-cygwin -mwin32 -mthreads
sanitize = -fsanitize=address \
-fsanitize=leak -fsanitize=bounds -fsanitize=signed-integer-overflow
linux_CC = gcc
linux_CXX = g++
linux_LD = g++
linux_CFLAGS += $(sanitize)
linux_CXXFLAGS += $(sanitize)
linux_LDFLAGS += $(sanitize)
linux_CXXFLAGS += -std=c++17
linux_ldlibs += -lpthread
openbsd_CXX = clang++
openbsd_CC = clang
openbsd_LD = clang++
openbsd_CXXFLAGS += -std=c++17
darwin_CC = clang
darwin_CXX = clang++
darwin_LD = clang++
darwin_SANITIZE = -fsanitize=undefined -fsanitize=address -fsanitize=bounds -fsanitize=signed-integer-overflow
darwin_CXXFLAGS += -std=c++17 $(darwin_SANITIZE)
darwin_CFLAGS += $(darwin_SANITIZE)
darwin_LDFLAGS += $(darwin_SANITIZE)
ARFLAGS = rv
CFLAGS += $($(os)_CFLAGS) $(WARNINGS) $(EXTRA_WARNINGS) $(INCS) $(DEFS)
LDFLAGS += $($(os)_LDFLAGS)
CXXFLAGS += $(CFLAGS) $($(os)_CXXFLAGS)
# XXX Can use better optimization on newer CPUs
linux_OFLAGS = -D_FORTIFY_SOURCE=2 -mharden-sls=all
openbsd_OFLAGS =
darwin_OFLAGS =
ifeq ($(RELEASE),1)
OPTIMIZE := 1
endif
ifeq ($(OPTIMIZE),1)
# FORTIFY_SOURCE is a no-op when not optimizing
CFLAGS += -O3 $($(os)_OFLAGS) $(OFLAGS) \
-g -Wuninitialized -D__MAKE_OPTIMIZE__=1
LDFLAGS += -g
buildtype := rel
# Strip the final executable
define strip-cmd
#$(CROSSPATH)strip $@
true
endef
#CFLAGS += -ffunction-sections -fdata-sections
ifneq ($(STATIC),)
LDFLAGS += -Bstatic
endif
else
CFLAGS += -g
LDFLAGS += -g
buildtype := dbg
# no-op
define strip-cmd
true
endef
endif
ifneq ($($(os)_CC),)
CC := $($(os)_CC)
else
CC = $(CROSSPATH)gcc
endif
ifneq ($($(os)_CXX),)
CXX := $($(os)_CXX)
else
CXX = $(CROSSPATH)g++
endif
ifneq ($($(os)_LD),)
LD := $($(os)_LD)
else
LD = $(CXX)
endif
# Tools we need
AR = $(CROSSPATH)ar
RANLIB = $(CROSSPATH)ranlib
# vim: ft=make:sw=4:ts=4:noexpandtab:notextmode:tw=72: