make-mac.mk 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ifeq ($(origin CC),default)
  2. CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
  3. endif
  4. ifeq ($(origin CXX),default)
  5. CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
  6. endif
  7. INCLUDES=
  8. DEFS=
  9. LIBS=
  10. ARCH_FLAGS=-arch x86_64
  11. include objects.mk
  12. OBJS+=osdep/OSXEthernetTap.o
  13. # Disable codesign since open source users will not have ZeroTier's certs
  14. CODESIGN=echo
  15. PRODUCTSIGN=echo
  16. CODESIGN_APP_CERT=
  17. CODESIGN_INSTALLER_CERT=
  18. # Build with libminiupnpc by default for Mac
  19. ZT_USE_MINIUPNPC?=1
  20. # For internal use only -- signs everything with ZeroTier's developer cert
  21. ifeq ($(ZT_OFFICIAL_RELEASE),1)
  22. DEFS+=-DZT_OFFICIAL_RELEASE -DZT_AUTO_UPDATE
  23. ZT_USE_MINIUPNPC=1
  24. CODESIGN=codesign
  25. PRODUCTSIGN=productsign
  26. CODESIGN_APP_CERT="Developer ID Application: ZeroTier Networks LLC (8ZD9JUCZ4V)"
  27. CODESIGN_INSTALLER_CERT="Developer ID Installer: ZeroTier Networks LLC (8ZD9JUCZ4V)"
  28. endif
  29. # Build with ZT_ENABLE_CLUSTER=1 to build with cluster support
  30. ifeq ($(ZT_ENABLE_CLUSTER),1)
  31. DEFS+=-DZT_ENABLE_CLUSTER
  32. endif
  33. ifeq ($(ZT_AUTO_UPDATE),1)
  34. DEFS+=-DZT_AUTO_UPDATE
  35. endif
  36. ifeq ($(ZT_USE_MINIUPNPC),1)
  37. DEFS+=-DMACOSX -DZT_USE_MINIUPNPC -DMINIUPNP_STATICLIB -D_DARWIN_C_SOURCE -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -D_BSD_SOURCE -D_DEFAULT_SOURCE -DOS_STRING=\"Darwin/15.0.0\" -DMINIUPNPC_VERSION_STRING=\"1.9\" -DUPNP_VERSION_STRING=\"UPnP/1.1\" -DENABLE_STRNATPMPERR
  38. 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
  39. endif
  40. # Build with ZT_ENABLE_NETWORK_CONTROLLER=1 to build with the Sqlite network controller
  41. ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
  42. DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER
  43. LIBS+=-L/usr/local/lib -lsqlite3
  44. OBJS+=controller/SqliteNetworkController.o
  45. endif
  46. # Debug mode -- dump trace output, build binary with -g
  47. ifeq ($(ZT_DEBUG),1)
  48. DEFS+=-DZT_TRACE
  49. CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  50. STRIP=echo
  51. # The following line enables optimization for the crypto code, since
  52. # C25519 in particular is almost UNUSABLE in heavy testing without it.
  53. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  54. else
  55. CFLAGS?=-Ofast -fstack-protector
  56. CFLAGS+=$(ARCH_FLAGS) -Wall -flto -fPIE -pthread -mmacosx-version-min=10.7 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
  57. STRIP=strip
  58. endif
  59. CXXFLAGS=$(CFLAGS) -fno-rtti
  60. all: one
  61. one: $(OBJS) service/OneService.o one.o
  62. $(CXX) $(CXXFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o $(LIBS)
  63. $(STRIP) zerotier-one
  64. ln -sf zerotier-one zerotier-idtool
  65. ln -sf zerotier-one zerotier-cli
  66. $(CODESIGN) -f -s $(CODESIGN_APP_CERT) zerotier-one
  67. $(CODESIGN) -vvv zerotier-one
  68. netcon: $(OBJS)
  69. rm -f *.o
  70. # Need to selectively rebuild one.cpp and OneService.cpp with ZT_SERVICE_NETCON and ZT_ONE_NO_ROOT_CHECK defined, and also NetconEthernetTap
  71. $(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
  72. # Build netcon/liblwip.so which must be placed in ZT home for zerotier-netcon-service to work
  73. cd netcon ; make -f make-liblwip.mk
  74. # Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility
  75. cd netcon ; gcc -O2 -Wall -std=c99 -fPIC -fno-common -dynamiclib -flat_namespace -DVERBOSE -D_GNU_SOURCE -DNETCON_INTERCEPT -I. -nostdlib -shared -o libzerotierintercept.so Intercept.c RPC.c -ldl
  76. cp netcon/libzerotierintercept.so libzerotierintercept.so
  77. ln -sf zerotier-netcon-service zerotier-cli
  78. ln -sf zerotier-netcon-service zerotier-idtool
  79. selftest: $(OBJS) selftest.o
  80. $(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LIBS)
  81. $(STRIP) zerotier-selftest
  82. # Requires Packages: http://s.sudre.free.fr/Software/Packages/about.html
  83. mac-dist-pkg: FORCE
  84. packagesbuild "ext/installfiles/mac/ZeroTier One.pkgproj"
  85. rm -f "ZeroTier One Signed.pkg"
  86. $(PRODUCTSIGN) --sign $(CODESIGN_INSTALLER_CERT) "ZeroTier One.pkg" "ZeroTier One Signed.pkg"
  87. if [ -f "ZeroTier One Signed.pkg" ]; then mv -f "ZeroTier One Signed.pkg" "ZeroTier One.pkg"; fi
  88. # For internal use only
  89. official: FORCE
  90. make ZT_OFFICIAL_RELEASE=1 clean
  91. make -j 4 ZT_OFFICIAL_RELEASE=1
  92. make ZT_OFFICIAL_RELEASE=1 mac-dist-pkg
  93. clean:
  94. rm -rf netcon/*.so *.dSYM build-* *.pkg *.dmg *.o node/*.o controller/*.o service/*.o osdep/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o $(OBJS) zerotier-one zerotier-idtool zerotier-selftest zerotier-cli ZeroTierOneInstaller-* mkworld
  95. # For those building from source -- installs signed binary tap driver in system ZT home
  96. install-mac-tap: FORCE
  97. mkdir -p /Library/Application\ Support/ZeroTier/One
  98. rm -rf /Library/Application\ Support/ZeroTier/One/tap.kext
  99. cp -R ext/bin/tap-mac/tap.kext /Library/Application\ Support/ZeroTier/One
  100. chown -R root:wheel /Library/Application\ Support/ZeroTier/One/tap.kext
  101. FORCE: