make-linux.mk 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. # Used to auto-detect these and use them if dev headers were present, but stopped
  15. # since it caused too many damn problems. The http-parser library in particular
  16. # is basically broken between versions. Fark the Debian policies about including
  17. # libraries. It's better if things work.
  18. #ifeq ($(wildcard /usr/include/http_parser.h),)
  19. # OBJS+=ext/http-parser/http_parser.o
  20. #else
  21. # LDLIBS+=-lhttp_parser
  22. # DEFS+=-DZT_USE_SYSTEM_HTTP_PARSER
  23. #endif
  24. OBJS+=ext/http-parser/http_parser.o
  25. # Auto-detect miniupnpc and nat-pmp as well and use system libs if present,
  26. # otherwise build into binary as done on Mac and Windows.
  27. OBJS+=osdep/PortMapper.o
  28. DEFS+=-DZT_USE_MINIUPNPC
  29. MINIUPNPC_IS_NEW_ENOUGH=$(shell grep -sqr '.*define.*MINIUPNPC_VERSION.*"2.."' /usr/include/miniupnpc/miniupnpc.h && echo 1)
  30. ifeq ($(MINIUPNPC_IS_NEW_ENOUGH),1)
  31. DEFS+=-DZT_USE_SYSTEM_MINIUPNPC
  32. LDLIBS+=-lminiupnpc
  33. else
  34. 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
  35. 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
  36. endif
  37. ifeq ($(wildcard /usr/include/natpmp.h),)
  38. OBJS+=ext/libnatpmp/natpmp.o ext/libnatpmp/getgateway.o
  39. else
  40. LDLIBS+=-lnatpmp
  41. DEFS+=-DZT_USE_SYSTEM_NATPMP
  42. endif
  43. ifeq ($(ZT_ENABLE_CLUSTER),1)
  44. DEFS+=-DZT_ENABLE_CLUSTER
  45. endif
  46. ifeq ($(ZT_TRACE),1)
  47. DEFS+=-DZT_TRACE
  48. endif
  49. ifeq ($(ZT_RULES_ENGINE_DEBUGGING),1)
  50. DEFS+=-DZT_RULES_ENGINE_DEBUGGING
  51. endif
  52. ifeq ($(ZT_DEBUG),1)
  53. DEFS+=-DZT_TRACE
  54. override CFLAGS+=-Wall -g -O -pthread $(INCLUDES) $(DEFS)
  55. override CXXFLAGS+=-Wall -g -O -std=c++11 -pthread $(INCLUDES) $(DEFS)
  56. override LDFLAGS+=
  57. STRIP?=echo
  58. # The following line enables optimization for the crypto code, since
  59. # C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
  60. node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  61. else
  62. CFLAGS?=-O3 -fstack-protector
  63. override CFLAGS+=-Wall -fPIE -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  64. CXXFLAGS?=-O3 -fstack-protector
  65. override CXXFLAGS+=-Wall -Wno-unused-result -Wreorder -fPIE -std=c++11 -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  66. override LDFLAGS+=-pie -Wl,-z,relro,-z,now
  67. STRIP?=strip
  68. STRIP+=--strip-all
  69. endif
  70. # Uncomment for gprof profile build
  71. #CFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  72. #CXXFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  73. #LDFLAGS=
  74. #STRIP=echo
  75. # Determine system build architecture from compiler target
  76. CC_MACH=$(shell $(CC) -dumpmachine | cut -d '-' -f 1)
  77. ZT_ARCHITECTURE=0
  78. ifeq ($(CC_MACH),x86_64)
  79. ZT_ARCHITECTURE=2
  80. endif
  81. ifeq ($(CC_MACH),amd64)
  82. ZT_ARCHITECTURE=2
  83. endif
  84. ifeq ($(CC_MACH),i386)
  85. ZT_ARCHITECTURE=1
  86. endif
  87. ifeq ($(CC_MACH),i686)
  88. ZT_ARCHITECTURE=1
  89. endif
  90. ifeq ($(CC_MACH),arm)
  91. ZT_ARCHITECTURE=3
  92. endif
  93. ifeq ($(CC_MACH),arm64)
  94. ZT_ARCHITECTURE=4
  95. endif
  96. ifeq ($(CC_MACH),aarch64)
  97. ZT_ARCHITECTURE=4
  98. endif
  99. DEFS+=-DZT_BUILD_PLATFORM=1 -DZT_BUILD_ARCHITECTURE=$(ZT_ARCHITECTURE) -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
  100. all: one
  101. one: $(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o osdep/LinuxDropPrivileges.o
  102. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o osdep/LinuxEthernetTap.o osdep/LinuxDropPrivileges.o $(LDLIBS)
  103. $(STRIP) zerotier-one
  104. ln -sf zerotier-one zerotier-idtool
  105. ln -sf zerotier-one zerotier-cli
  106. selftest: $(OBJS) selftest.o
  107. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
  108. $(STRIP) zerotier-selftest
  109. manpages: FORCE
  110. cd doc ; ./build.sh
  111. doc: manpages
  112. clean: FORCE
  113. 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
  114. distclean: clean
  115. realclean: distclean
  116. debug: FORCE
  117. make ZT_DEBUG=1 one
  118. make ZT_DEBUG=1 selftest
  119. # Note: keep the symlinks in /var/lib/zerotier-one to the binaries since these
  120. # provide backward compatibility with old releases where the binaries actually
  121. # lived here. Folks got scripts.
  122. install: FORCE
  123. mkdir -p $(DESTDIR)/usr/sbin
  124. rm -f $(DESTDIR)/usr/sbin/zerotier-one
  125. cp -f zerotier-one $(DESTDIR)/usr/sbin/zerotier-one
  126. rm -f $(DESTDIR)/usr/sbin/zerotier-cli
  127. rm -f $(DESTDIR)/usr/sbin/zerotier-idtool
  128. ln -s zerotier-one $(DESTDIR)/usr/sbin/zerotier-cli
  129. ln -s zerotier-one $(DESTDIR)/usr/sbin/zerotier-idtool
  130. mkdir -p $(DESTDIR)/var/lib/zerotier-one
  131. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-one
  132. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-cli
  133. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-idtool
  134. ln -s ../../../usr/sbin/zerotier-one $(DESTDIR)/var/lib/zerotier-one/zerotier-one
  135. ln -s ../../../usr/sbin/zerotier-one $(DESTDIR)/var/lib/zerotier-one/zerotier-cli
  136. ln -s ../../../usr/sbin/zerotier-one $(DESTDIR)/var/lib/zerotier-one/zerotier-idtool
  137. mkdir -p $(DESTDIR)/usr/share/man/man8
  138. rm -f $(DESTDIR)/usr/share/man/man8/zerotier-one.8.gz
  139. cat doc/zerotier-one.8 | gzip -9 >$(DESTDIR)/usr/share/man/man8/zerotier-one.8.gz
  140. mkdir -p $(DESTDIR)/usr/share/man/man1
  141. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-idtool.1.gz
  142. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-cli.1.gz
  143. cat doc/zerotier-cli.1 | gzip -9 >$(DESTDIR)/usr/share/man/man1/zerotier-cli.1.gz
  144. cat doc/zerotier-idtool.1 | gzip -9 >$(DESTDIR)/usr/share/man/man1/zerotier-idtool.1.gz
  145. # Uninstall preserves identity.public and identity.secret since the user might
  146. # want to save these. These are your ZeroTier address.
  147. uninstall: FORCE
  148. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-one
  149. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-cli
  150. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-idtool
  151. rm -f $(DESTDIR)/usr/sbin/zerotier-cli
  152. rm -f $(DESTDIR)/usr/sbin/zerotier-idtool
  153. rm -f $(DESTDIR)/usr/sbin/zerotier-one
  154. rm -rf $(DESTDIR)/var/lib/zerotier-one/iddb.d
  155. rm -rf $(DESTDIR)/var/lib/zerotier-one/updates.d
  156. rm -rf $(DESTDIR)/var/lib/zerotier-one/networks.d
  157. rm -f $(DESTDIR)/var/lib/zerotier-one/zerotier-one.port
  158. rm -f $(DESTDIR)/usr/share/man/man8/zerotier-one.8.gz
  159. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-idtool.1.gz
  160. rm -f $(DESTDIR)/usr/share/man/man1/zerotier-cli.1.gz
  161. # These are just for convenience for building Linux packages
  162. debian: distclean
  163. debuild -I -i -us -uc
  164. redhat: distclean
  165. rpmbuild -ba zerotier-one.spec
  166. FORCE: