make-linux.mk 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #
  2. # Makefile for ZeroTier One on Linux
  3. #
  4. # This is confirmed to work on distributions newer than CentOS 6 (the
  5. # one used for reference builds) and on 32 and 64 bit x86 and ARM
  6. # machines. It should also work on other 'normal' machines and recent
  7. # distributions. Editing might be required for tiny devices or weird
  8. # distros.
  9. #
  10. # Targets
  11. # one: zerotier-one and symlinks (cli and idtool)
  12. # all: builds 'one'
  13. # selftest: zerotier-selftest
  14. # debug: builds 'one' and 'selftest' with tracing and debug flags
  15. # installer: ZeroTierOneInstaller-... and packages (if possible)
  16. # official: builds 'one' and 'installer'
  17. # clean: removes all built files, objects, other trash
  18. #
  19. GENERATED_FILES :=
  20. DOC_DIR = doc
  21. # Automagically pick clang or gcc, with preference for clang
  22. # This is only done if we have not overridden these with an environment or CLI variable
  23. ifeq ($(origin CC),default)
  24. CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
  25. endif
  26. ifeq ($(origin CXX),default)
  27. CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
  28. endif
  29. #UNAME_M=$(shell $(CC) -dumpmachine | cut -d '-' -f 1)
  30. INCLUDES?=
  31. DEFS?=
  32. LDLIBS?=
  33. include objects.mk
  34. # "make official" is a shortcut for this
  35. ifeq ($(ZT_OFFICIAL_RELEASE),1)
  36. DEFS+=-DZT_OFFICIAL_RELEASE
  37. ZT_USE_MINIUPNPC=1
  38. endif
  39. ifeq ($(ZT_USE_MINIUPNPC),1)
  40. DEFS+=-DZT_USE_MINIUPNPC -DMINIUPNP_STATICLIB -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -DOS_STRING=\"Linux\" -DMINIUPNPC_VERSION_STRING=\"1.9\" -DUPNP_VERSION_STRING=\"UPnP/1.1\" -DENABLE_STRNATPMPERR
  41. OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o 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 osdep/PortMapper.o
  42. endif
  43. # Build with ZT_ENABLE_NETWORK_CONTROLLER=1 to build with the Sqlite network controller
  44. ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
  45. DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER
  46. LDLIBS+=-L/usr/local/lib -lsqlite3
  47. OBJS+=controller/SqliteNetworkController.o
  48. endif
  49. # Build with ZT_ENABLE_CLUSTER=1 to build with cluster support
  50. ifeq ($(ZT_ENABLE_CLUSTER),1)
  51. DEFS+=-DZT_ENABLE_CLUSTER
  52. endif
  53. # "make debug" is a shortcut for this
  54. ifeq ($(ZT_DEBUG),1)
  55. DEFS+=-DZT_TRACE
  56. CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  57. CXXFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  58. LDFLAGS=-ldl
  59. STRIP?=echo
  60. # The following line enables optimization for the crypto code, since
  61. # C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
  62. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  63. else
  64. CFLAGS?=-O3 -fstack-protector
  65. CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  66. CXXFLAGS?=-O3 -fstack-protector
  67. CXXFLAGS+=-Wall -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  68. LDFLAGS=-ldl -pie -Wl,-z,relro,-z,now
  69. STRIP?=strip
  70. STRIP+=--strip-all
  71. endif
  72. ifeq ($(ZT_TRACE),1)
  73. DEFS+=-DZT_TRACE
  74. endif
  75. # Uncomment for gprof profile build
  76. #CFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  77. #CXXFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  78. #LDFLAGS=
  79. #STRIP=echo
  80. all: one doc
  81. one: $(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o
  82. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o $(LDLIBS)
  83. $(STRIP) zerotier-one
  84. ln -sf zerotier-one zerotier-idtool
  85. ln -sf zerotier-one zerotier-cli
  86. netcon: $(OBJS)
  87. rm -f *.o
  88. # Need to selectively rebuild one.cpp and OneService.cpp with ZT_SERVICE_NETCON and ZT_ONE_NO_ROOT_CHECK defined, and also NetconEthernetTap
  89. $(CXX) $(CXXFLAGS) $(LDFLAGS) -DZT_SERVICE_NETCON -DZT_ONE_NO_ROOT_CHECK -Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6 -o zerotier-netcon-service $(OBJS) service/OneService.cpp netcon/NetconEthernetTap.cpp one.cpp -x c netcon/RPC.c $(LDLIBS) -ldl
  90. # Build netcon/liblwip.so which must be placed in ZT home for zerotier-netcon-service to work
  91. cd netcon ; make -f make-liblwip.mk
  92. # Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility
  93. cd netcon ; gcc -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DNETCON_INTERCEPT -I. -nostdlib -shared -o libzerotierintercept.so Intercept.c RPC.c -ldl
  94. cp netcon/libzerotierintercept.so libzerotierintercept.so
  95. ln -sf zerotier-netcon-service zerotier-cli
  96. ln -sf zerotier-netcon-service zerotier-idtool
  97. selftest: $(OBJS) selftest.o
  98. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
  99. $(STRIP) zerotier-selftest
  100. installer: one FORCE
  101. ./ext/installfiles/linux/buildinstaller.sh
  102. clean: FORCE
  103. rm -rf ${GENERATED_FILES} *.so *.o netcon/*.a node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o ext/miniupnpc/*.o ext/libnatpmp/*.o $(OBJS) zerotier-one zerotier-idtool zerotier-cli zerotier-selftest zerotier-netcon-service build-* ZeroTierOneInstaller-* *.deb *.rpm .depend netcon/.depend
  104. find netcon -type f \( -name '*.o' -o -name '*.so' -o -name '*.1.0' -o -name 'zerotier-one' -o -name 'zerotier-cli' -o -name 'zerotier-netcon-service' \) -delete
  105. find netcon/docker-test -name "zerotier-intercept" -type f -delete
  106. debug: FORCE
  107. make ZT_DEBUG=1 one
  108. make ZT_DEBUG=1 selftest
  109. official: FORCE
  110. make ZT_OFFICIAL_RELEASE=1 clean
  111. make -j 4 ZT_OFFICIAL_RELEASE=1 one
  112. make ZT_OFFICIAL_RELEASE=1 installer
  113. include ${DOC_DIR}/module.mk
  114. FORCE: