2017-04-21 15:04:33 +00:00
|
|
|
# This requires GNU make, which is typically "gmake" on BSD systems
|
|
|
|
|
2023-04-21 19:12:43 +00:00
|
|
|
INCLUDES=-isystem ext -Iext/prometheus-cpp-lite-1.0/core/include -Iext/prometheus-cpp-lite-1.0/simpleapi/include
|
2014-11-04 19:20:38 +00:00
|
|
|
DEFS=
|
|
|
|
LIBS=
|
|
|
|
|
|
|
|
include objects.mk
|
2017-05-08 21:36:55 +00:00
|
|
|
ONE_OBJS+=osdep/BSDEthernetTap.o ext/http-parser/http_parser.o
|
2014-11-04 19:20:38 +00:00
|
|
|
|
2022-01-12 18:50:39 +00:00
|
|
|
ifeq ($(OSTYPE),FreeBSD)
|
|
|
|
# Auto-detect miniupnpc and nat-pmp as well and use ports libs if present,
|
|
|
|
# otherwise build into binary as done on Mac and Windows.
|
|
|
|
INCLUDES+=-I/usr/local/include
|
|
|
|
LIBS+=-L/usr/local/lib
|
|
|
|
ONE_OBJS+=osdep/PortMapper.o
|
|
|
|
override DEFS+=-DZT_USE_MINIUPNPC
|
|
|
|
MINIUPNPC_IS_NEW_ENOUGH=$(shell grep -sqr '.*define.*MINIUPNPC_VERSION.*"2..*"' /usr/local/include/miniupnpc/miniupnpc.h && echo 1)
|
|
|
|
ifeq ($(MINIUPNPC_IS_NEW_ENOUGH),1)
|
|
|
|
LIBS+=-lminiupnpc
|
|
|
|
override DEFS+=-DZT_USE_SYSTEM_MINIUPNPC
|
|
|
|
else
|
|
|
|
override DEFS+=-DMINIUPNP_STATICLIB -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -D_BSD_SOURCE -D_DEFAULT_SOURCE -DOS_STRING=\"FreeBSD/$(shell uname -r)\" -DMINIUPNPC_VERSION_STRING=\"2.0\" -DUPNP_VERSION_STRING=\"UPnP/1.1\" -DENABLE_STRNATPMPERR
|
|
|
|
ONE_OBJS+=ext/miniupnpc/connecthostport.o ext/miniupnpc/igd_desc_parse.o ext/miniupnpc/minisoap.o ext/miniupnpc/minissdpc.o ext/miniupnpc/miniupnpc.o ext/miniupnpc/miniwget.o ext/miniupnpc/minixml.o ext/miniupnpc/portlistingparse.o ext/miniupnpc/receivedata.o ext/miniupnpc/upnpcommands.o ext/miniupnpc/upnpdev.o ext/miniupnpc/upnperrors.o ext/miniupnpc/upnpreplyparse.o
|
|
|
|
endif
|
|
|
|
ifeq ($(wildcard /usr/local/include/natpmp.h),)
|
|
|
|
ONE_OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o
|
|
|
|
else
|
|
|
|
LIBS+=-lnatpmp
|
|
|
|
override DEFS+=-DZT_USE_SYSTEM_NATPMP
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2017-12-14 21:27:49 +00:00
|
|
|
# Build with address sanitization library for advanced debugging (clang)
|
|
|
|
ifeq ($(ZT_SANITIZE),1)
|
|
|
|
SANFLAGS+=-fsanitize=address -DASAN_OPTIONS=symbolize=1
|
|
|
|
endif
|
2014-11-04 19:20:38 +00:00
|
|
|
# "make debug" is a shortcut for this
|
|
|
|
ifeq ($(ZT_DEBUG),1)
|
2019-11-19 16:45:06 +00:00
|
|
|
CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
|
2015-07-03 18:18:19 +00:00
|
|
|
LDFLAGS+=
|
2014-11-04 19:20:38 +00:00
|
|
|
STRIP=echo
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_TRACE=1
|
2014-11-04 19:20:38 +00:00
|
|
|
# The following line enables optimization for the crypto code, since
|
|
|
|
# C25519 in particular is almost UNUSABLE in heavy testing without it.
|
2017-01-19 23:16:04 +00:00
|
|
|
node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
|
2014-11-04 19:20:38 +00:00
|
|
|
else
|
2015-07-03 18:18:19 +00:00
|
|
|
CFLAGS?=-O3 -fstack-protector
|
|
|
|
CFLAGS+=-Wall -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS)
|
|
|
|
LDFLAGS+=-pie -Wl,-z,relro,-z,now
|
2014-11-04 19:20:38 +00:00
|
|
|
STRIP=strip --strip-all
|
|
|
|
endif
|
|
|
|
|
2017-05-08 21:46:45 +00:00
|
|
|
ifeq ($(ZT_TRACE),1)
|
|
|
|
DEFS+=-DZT_TRACE
|
|
|
|
endif
|
|
|
|
|
2017-01-12 21:18:11 +00:00
|
|
|
# Determine system build architecture from compiler target
|
|
|
|
CC_MACH=$(shell $(CC) -dumpmachine | cut -d '-' -f 1)
|
2017-04-21 15:04:33 +00:00
|
|
|
ZT_ARCHITECTURE=999
|
2017-01-12 21:18:11 +00:00
|
|
|
ifeq ($(CC_MACH),x86_64)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=2
|
2017-04-21 15:04:33 +00:00
|
|
|
ZT_USE_X64_ASM_SALSA2012=1
|
2017-01-12 21:18:11 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),amd64)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=2
|
2017-04-21 15:04:33 +00:00
|
|
|
ZT_USE_X64_ASM_SALSA2012=1
|
2017-01-12 21:18:11 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),i386)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=1
|
2017-01-12 21:18:11 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),i686)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=1
|
2017-01-12 21:18:11 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),arm)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=3
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
ZT_USE_ARM32_NEON_ASM_SALSA2012=1
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),armel)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=3
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
ZT_USE_ARM32_NEON_ASM_SALSA2012=1
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),armhf)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=3
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
ZT_USE_ARM32_NEON_ASM_SALSA2012=1
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),armv6)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=3
|
2020-11-21 21:30:31 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING -DZT_NO_UNALIGNED_ACCESS
|
2017-04-21 15:04:33 +00:00
|
|
|
ZT_USE_ARM32_NEON_ASM_SALSA2012=1
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),armv6zk)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=3
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
ZT_USE_ARM32_NEON_ASM_SALSA2012=1
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),armv6kz)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=3
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
ZT_USE_ARM32_NEON_ASM_SALSA2012=1
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),armv7)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=3
|
2020-11-21 21:30:31 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING -DZT_AES_NO_ACCEL -DZT_NO_UNALIGNED_ACCESS
|
2017-04-21 15:04:33 +00:00
|
|
|
ZT_USE_ARM32_NEON_ASM_SALSA2012=1
|
2017-01-12 21:18:11 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),arm64)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=4
|
2020-11-07 22:16:03 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING -march=armv8-a+crypto
|
2017-01-12 21:18:11 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),aarch64)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=4
|
2020-11-07 22:16:03 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING -march=armv8-a+crypto
|
2017-04-21 15:04:33 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),mipsel)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=5
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),mips)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=5
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
2017-01-12 21:18:11 +00:00
|
|
|
endif
|
2017-04-21 15:04:33 +00:00
|
|
|
ifeq ($(CC_MACH),mips64)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=6
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
endif
|
|
|
|
ifeq ($(CC_MACH),mips64el)
|
2017-05-08 21:46:45 +00:00
|
|
|
ZT_ARCHITECTURE=6
|
2017-04-21 15:04:33 +00:00
|
|
|
override DEFS+=-DZT_NO_TYPE_PUNNING
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Fail if system architecture could not be determined
|
|
|
|
ifeq ($(ZT_ARCHITECTURE),999)
|
2022-12-05 21:33:00 +00:00
|
|
|
ERR=$(error FATAL: architecture could not be determined from $(CC) -dumpmachine: $(CC_MACH))
|
2017-04-21 15:04:33 +00:00
|
|
|
.PHONY: err
|
|
|
|
err: ; $(ERR)
|
|
|
|
endif
|
|
|
|
|
2017-04-21 15:09:18 +00:00
|
|
|
# Build faster crypto on some targets
|
|
|
|
ifeq ($(ZT_USE_X64_ASM_SALSA2012),1)
|
|
|
|
override DEFS+=-DZT_USE_X64_ASM_SALSA2012
|
2017-05-08 21:36:55 +00:00
|
|
|
override CORE_OBJS+=ext/x64-salsa2012-asm/salsa2012.o
|
2017-04-21 15:09:18 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(ZT_USE_ARM32_NEON_ASM_SALSA2012),1)
|
|
|
|
override DEFS+=-DZT_USE_ARM32_NEON_ASM_SALSA2012
|
2017-05-08 21:36:55 +00:00
|
|
|
override CORE_OBJS+=ext/arm32-neon-salsa2012-asm/salsa2012.o
|
2018-09-13 02:49:14 +00:00
|
|
|
override ASFLAGS+=-meabi=5
|
2020-11-07 22:16:03 +00:00
|
|
|
override LDFLAGS+=-Wl,-z,notext
|
2017-04-21 15:09:18 +00:00
|
|
|
endif
|
|
|
|
|
2017-04-21 15:42:45 +00:00
|
|
|
override DEFS+=-DZT_BUILD_PLATFORM=$(ZT_BUILD_PLATFORM) -DZT_BUILD_ARCHITECTURE=$(ZT_ARCHITECTURE) -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
|
2017-01-12 21:18:11 +00:00
|
|
|
|
2022-05-13 18:51:01 +00:00
|
|
|
CXXFLAGS+=$(CFLAGS) -std=c++17 #-D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_MATH -D_GLIBCXX_USE_C99_MATH_TR1
|
2014-11-04 19:20:38 +00:00
|
|
|
|
|
|
|
all: one
|
|
|
|
|
2017-05-08 21:36:55 +00:00
|
|
|
one: $(CORE_OBJS) $(ONE_OBJS) one.o
|
|
|
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(CORE_OBJS) $(ONE_OBJS) one.o $(LIBS)
|
2014-11-04 19:20:38 +00:00
|
|
|
$(STRIP) zerotier-one
|
|
|
|
ln -sf zerotier-one zerotier-idtool
|
2015-04-16 21:55:36 +00:00
|
|
|
ln -sf zerotier-one zerotier-cli
|
2014-11-04 19:20:38 +00:00
|
|
|
|
2017-05-08 21:36:55 +00:00
|
|
|
zerotier-one: one
|
|
|
|
|
|
|
|
zerotier-idtool: one
|
|
|
|
|
|
|
|
zerotier-cli: one
|
|
|
|
|
|
|
|
libzerotiercore.a: $(CORE_OBJS)
|
|
|
|
ar rcs libzerotiercore.a $(CORE_OBJS)
|
|
|
|
ranlib libzerotiercore.a
|
|
|
|
|
|
|
|
core: libzerotiercore.a
|
|
|
|
|
|
|
|
selftest: $(CORE_OBJS) $(ONE_OBJS) selftest.o
|
|
|
|
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(CORE_OBJS) $(ONE_OBJS) $(LIBS)
|
2014-11-04 19:20:38 +00:00
|
|
|
$(STRIP) zerotier-selftest
|
|
|
|
|
2017-05-08 21:36:55 +00:00
|
|
|
zerotier-selftest: selftest
|
|
|
|
|
2014-11-04 19:20:38 +00:00
|
|
|
clean:
|
2017-05-08 21:36:55 +00:00
|
|
|
rm -rf *.a *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o build-* zerotier-one zerotier-idtool zerotier-selftest zerotier-cli $(ONE_OBJS) $(CORE_OBJS)
|
2014-11-04 19:20:38 +00:00
|
|
|
|
|
|
|
debug: FORCE
|
2018-06-22 21:05:53 +00:00
|
|
|
$(MAKE) -j ZT_DEBUG=1
|
2014-11-04 19:20:38 +00:00
|
|
|
|
2017-01-19 23:15:31 +00:00
|
|
|
install: one
|
|
|
|
rm -f /usr/local/sbin/zerotier-one
|
|
|
|
cp zerotier-one /usr/local/sbin
|
|
|
|
ln -sf /usr/local/sbin/zerotier-one /usr/local/sbin/zerotier-cli
|
|
|
|
ln -sf /usr/local/sbin/zerotier-one /usr/local/bin/zerotier-idtool
|
|
|
|
|
|
|
|
uninstall: FORCE
|
|
|
|
rm -rf /usr/local/sbin/zerotier-one /usr/local/sbin/zerotier-cli /usr/local/bin/zerotier-idtool /var/db/zerotier-one/zerotier-one.port /var/db/zerotier-one/zerotier-one.pid /var/db/zerotier-one/iddb.d
|
|
|
|
|
2014-11-04 19:20:38 +00:00
|
|
|
FORCE:
|