make-linux.mk 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # Automagically pick clang or gcc, with preference for clang
  2. # This is only done if we have not overridden these with an environment or CLI variable
  3. ifeq ($(origin CC),default)
  4. CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
  5. endif
  6. ifeq ($(origin CXX),default)
  7. CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
  8. endif
  9. INCLUDES?=
  10. DEFS?=-D_FORTIFY_SOURCE=2
  11. LDLIBS?=
  12. DESTDIR?=
  13. include objects.mk
  14. # Use bundled http-parser since distribution versions are NOT API-stable or compatible!
  15. # Trying to use dynamically linked libhttp-parser causes tons of compatibility problems.
  16. OBJS+=ext/http-parser/http_parser.o
  17. # Auto-detect miniupnpc and nat-pmp as well and use system libs if present,
  18. # otherwise build into binary as done on Mac and Windows.
  19. OBJS+=osdep/PortMapper.o
  20. DEFS+=-DZT_USE_MINIUPNPC
  21. MINIUPNPC_IS_NEW_ENOUGH=$(shell grep -sqr '.*define.*MINIUPNPC_VERSION.*"2.."' /usr/include/miniupnpc/miniupnpc.h && echo 1)
  22. ifeq ($(MINIUPNPC_IS_NEW_ENOUGH),1)
  23. DEFS+=-DZT_USE_SYSTEM_MINIUPNPC
  24. LDLIBS+=-lminiupnpc
  25. else
  26. DEFS+=-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=\"2.0\" -DUPNP_VERSION_STRING=\"UPnP/1.1\" -DENABLE_STRNATPMPERR
  27. 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
  28. endif
  29. ifeq ($(wildcard /usr/include/natpmp.h),)
  30. OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o
  31. else
  32. LDLIBS+=-lnatpmp
  33. DEFS+=-DZT_USE_SYSTEM_NATPMP
  34. endif
  35. ifeq ($(ZT_ENABLE_CLUSTER),1)
  36. DEFS+=-DZT_ENABLE_CLUSTER
  37. endif
  38. ifeq ($(ZT_SYNOLOGY), 1)
  39. DEFS+=-D__SYNOLOGY__
  40. endif
  41. ifeq ($(ZT_TRACE),1)
  42. DEFS+=-DZT_TRACE
  43. endif
  44. ifeq ($(ZT_RULES_ENGINE_DEBUGGING),1)
  45. DEFS+=-DZT_RULES_ENGINE_DEBUGGING
  46. endif
  47. ifeq ($(ZT_DEBUG),1)
  48. DEFS+=-DZT_TRACE
  49. override CFLAGS+=-Wall -g -O -pthread $(INCLUDES) $(DEFS)
  50. override CXXFLAGS+=-Wall -g -O -std=c++11 -pthread $(INCLUDES) $(DEFS)
  51. override LDFLAGS+=
  52. STRIP?=echo
  53. # The following line enables optimization for the crypto code, since
  54. # C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
  55. node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  56. else
  57. CFLAGS?=-O3 -fstack-protector
  58. override CFLAGS+=-Wall -fPIE -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  59. CXXFLAGS?=-O3 -fstack-protector
  60. override CXXFLAGS+=-Wall -Wno-unused-result -Wreorder -fPIE -std=c++11 -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  61. override LDFLAGS+=-pie -Wl,-z,relro,-z,now
  62. STRIP?=strip
  63. STRIP+=--strip-all
  64. endif
  65. # Uncomment for gprof profile build
  66. #CFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  67. #CXXFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  68. #LDFLAGS=
  69. #STRIP=echo
  70. # Determine system build architecture from compiler target
  71. CC_MACH=$(shell $(CC) -dumpmachine | cut -d '-' -f 1)
  72. ZT_ARCHITECTURE=0
  73. ifeq ($(CC_MACH),x86_64)
  74. ZT_ARCHITECTURE=2
  75. endif
  76. ifeq ($(CC_MACH),amd64)
  77. ZT_ARCHITECTURE=2
  78. endif
  79. ifeq ($(CC_MACH),i386)
  80. ZT_ARCHITECTURE=1
  81. endif
  82. ifeq ($(CC_MACH),i686)
  83. ZT_ARCHITECTURE=1
  84. endif
  85. ifeq ($(CC_MACH),arm)
  86. ZT_ARCHITECTURE=3
  87. endif
  88. ifeq ($(CC_MACH),arm64)
  89. ZT_ARCHITECTURE=4
  90. endif
  91. ifeq ($(CC_MACH),aarch64)
  92. ZT_ARCHITECTURE=4
  93. endif
  94. DEFS+=-DZT_BUILD_PLATFORM=1 -DZT_BUILD_ARCHITECTURE=$(ZT_ARCHITECTURE) -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
  95. # Define this to build a static binary, which is needed to make this runnable on a few ancient Linux distros
  96. ifeq ($(ZT_STATIC),1)
  97. override LDFLAGS+=-static
  98. endif
  99. all: one
  100. one: $(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o
  101. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o $(LDLIBS)
  102. $(STRIP) zerotier-one
  103. ln -sf zerotier-one zerotier-idtool
  104. ln -sf zerotier-one zerotier-cli
  105. selftest: $(OBJS) selftest.o
  106. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
  107. $(STRIP) zerotier-selftest
  108. manpages: FORCE
  109. cd doc ; ./build.sh
  110. doc: manpages
  111. clean: FORCE
  112. rm -rf *.so *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/miniupnpc/*.o ext/libnatpmp/*.o $(OBJS) zerotier-one zerotier-idtool zerotier-cli zerotier-selftest build-* ZeroTierOneInstaller-* *.deb *.rpm .depend debian/files debian/zerotier-one*.debhelper debian/zerotier-one.substvars debian/*.log debian/zerotier-one doc/node_modules
  113. distclean: clean
  114. realclean: distclean
  115. debug: FORCE
  116. make ZT_DEBUG=1 one
  117. make ZT_DEBUG=1 selftest
  118. # Note: keep the symlinks in /var/lib/zerotier-one to the binaries since these
  119. # provide backward compatibility with old releases where the binaries actually
  120. # lived here. Folks got scripts.
  121. install: FORCE
  122. mkdir -p $(DESTDIR)/usr/sbin
  123. rm -f $(DESTDIR)/usr/sbin/zerotier-one
  124. cp -f zerotier-one $(DESTDIR)/usr/sbin/zerotier-one
  125. rm -f $(DESTDIR)/usr/sbin/zerotier-cli
  126. rm -f $(DESTDIR)/usr/sbin/zerotier-idtool
  127. ln -s zerotier-one $(DESTDIR)/usr/sbin/zerotier-cli
  128. ln -s zerotier-one $(DESTDIR)/usr/sbin/zerotier-idtool
  129. mkdir -p $(DESTDIR)/var/lib/zerotier-one
  130. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-one
  131. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-cli
  132. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-idtool
  133. ln -s ../../../usr/sbin/zerotier-one $(DESTDIR)/var/lib/zerotier-one/zerotier-one
  134. ln -s ../../../usr/sbin/zerotier-one $(DESTDIR)/var/lib/zerotier-one/zerotier-cli
  135. ln -s ../../../usr/sbin/zerotier-one $(DESTDIR)/var/lib/zerotier-one/zerotier-idtool
  136. mkdir -p $(DESTDIR)/usr/share/man/man8
  137. rm -f $(DESTDIR)/usr/share/man/man8/zerotier-one.8.gz
  138. cat doc/zerotier-one.8 | gzip -9 >$(DESTDIR)/usr/share/man/man8/zerotier-one.8.gz
  139. mkdir -p $(DESTDIR)/usr/share/man/man1
  140. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-idtool.1.gz
  141. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-cli.1.gz
  142. cat doc/zerotier-cli.1 | gzip -9 >$(DESTDIR)/usr/share/man/man1/zerotier-cli.1.gz
  143. cat doc/zerotier-idtool.1 | gzip -9 >$(DESTDIR)/usr/share/man/man1/zerotier-idtool.1.gz
  144. # Uninstall preserves identity.public and identity.secret since the user might
  145. # want to save these. These are your ZeroTier address.
  146. uninstall: FORCE
  147. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-one
  148. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-cli
  149. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-idtool
  150. rm -f $(DESTDIR)/usr/sbin/zerotier-cli
  151. rm -f $(DESTDIR)/usr/sbin/zerotier-idtool
  152. rm -f $(DESTDIR)/usr/sbin/zerotier-one
  153. rm -rf $(DESTDIR)/var/lib/zerotier-one/iddb.d
  154. rm -rf $(DESTDIR)/var/lib/zerotier-one/updates.d
  155. rm -rf $(DESTDIR)/var/lib/zerotier-one/networks.d
  156. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-one.port
  157. rm -f $(DESTDIR)/usr/share/man/man8/zerotier-one.8.gz
  158. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-idtool.1.gz
  159. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-cli.1.gz
  160. # These are just for convenience for building Linux packages
  161. debian: FORCE
  162. debuild -I -i -us -uc -nc -b
  163. redhat: FORCE
  164. rpmbuild -ba zerotier-one.spec
  165. FORCE: