# # Makefile for ZeroTier One on Linux # # This is confirmed to work on distributions newer than CentOS 6 (the # one used for reference builds) and on 32 and 64 bit x86 and ARM # machines. It should also work on other 'normal' machines and recent # distributions. Editing might be required for tiny devices or weird # distros. # # Targets # one: zerotier-one and symlinks (cli and idtool) # doc: builds manpages, requires rst2man somewhere in PATH # all: builds 'one' # selftest: zerotier-selftest # debug: builds 'one' and 'selftest' with tracing and debug flags # installer: builds installers and packages (RPM/DEB/etc.) if possible # official: cleans and then builds 'one', 'installer', and 'doc' # clean: removes all built files, objects, other trash # GENERATED_FILES := DOC_DIR = doc # Automagically pick clang or gcc, with preference for clang # This is only done if we have not overridden these with an environment or CLI variable ifeq ($(origin CC),default) CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi) endif ifeq ($(origin CXX),default) CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi) endif #UNAME_M=$(shell $(CC) -dumpmachine | cut -d '-' -f 1) INCLUDES?= DEFS?= LDLIBS?= include objects.mk ifeq ($(ZT_DEBUG),1) DEFS+=-DZT_TRACE CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) CXXFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS) LDFLAGS=-ldl STRIP?=echo # The following line enables optimization for the crypto code, since # C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box! ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) else CFLAGS?=-O3 -fstack-protector CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS) CXXFLAGS?=-O3 -fstack-protector CXXFLAGS+=-Wall -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS) LDFLAGS=-ldl -pie -Wl,-z,relro,-z,now STRIP?=strip STRIP+=--strip-all endif ifeq ($(ZT_TRACE),1) DEFS+=-DZT_TRACE endif # Debug output for Network Containers # Specific levels can be controlled in netcon/common.inc.c ifeq ($(SDK_DEBUG),1) DEFS+=-DSDK_DEBUG endif # Uncomment for gprof profile build #CFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS) #CXXFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS) #LDFLAGS= #STRIP=echo all: shared_lib check linux_shared_lib: $(OBJS) rm -f *.o $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEFS) -DZT_SDK -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -Izerotierone/osdep -Izerotierone/node -Isrc -o build/zerotier-sdk-service $(OBJS) zerotierone/service/OneService.cpp src/SDK_EthernetTap.cpp src/SDK_Proxy.cpp zerotierone/one.cpp -x c src/SDK_RPC.c $(LDLIBS) -ldl # Build liblwip.so which must be placed in ZT home for zerotier-netcon-service to work make -f make-liblwip.mk # Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility cd src ; gcc $(DEFS) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -I. -I../zerotierone/node -nostdlib -shared -o libztintercept.so SDK_Sockets.c SDK_Intercept.c SDK_Debug.c SDK_RPC.c -ldl mkdir -p build/linux_shared_lib cp src/libztintercept.so build/linux_shared_lib/libztintercept.so ln -sf zerotier-sdk-service zerotier-cli ln -sf zerotier-sdk-service zerotier-idtool check: ./check.sh build/lwip/liblwip.so ./check.sh build/linux_shared_lib/libztintercept.so clean: rm -rf ${GENERATED_FILES} rm -rf zerotier-cli zerotier-idtool rm -rf build/* find . -type f -name '*.a' -delete find . -type f -name '*.o' -delete find . -type f -name '*.so' -delete find . -type f -name '*.o.d' -delete # Remove junk generated by Android builds cd integrations/Android/proj; ./gradlew clean rm -rf integrations/Android/proj/.gradle rm -rf integrations/Android/proj/.idea rm -rf integrations/Android/proj/build