make-linux.mk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. # Automagically pick clang or gcc, with preference for clang
  20. # This is only done if we have not overridden these with an environment or CLI variable
  21. ifeq ($(origin CC),default)
  22. CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
  23. endif
  24. ifeq ($(origin CXX),default)
  25. CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
  26. endif
  27. UNAME_M=$(shell uname -m)
  28. INCLUDES=-Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6
  29. DEFS=-DZT_ENABLE_NETCON #-DVERBOSE
  30. CXXFLAGS+=-Wc++11-compat-deprecated-writable-strings -Wformat
  31. LDLIBS?=
  32. include objects.mk
  33. OBJS+=osdep/LinuxEthernetTap.o netcon/NetconEthernetTap.o osdep/Arp.o netcon/NetconUtilities.o
  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
  41. ifeq ($(UNAME_M),armv6l)
  42. MINIUPNPC_LIB=ext/bin/miniupnpc/linux-arm32/libminiupnpc.a
  43. endif
  44. ifeq ($(UNAME_M),armv7l)
  45. MINIUPNPC_LIB=ext/bin/miniupnpc/linux-arm32/libminiupnpc.a
  46. endif
  47. ifeq ($(UNAME_M),x86_64)
  48. MINIUPNPC_LIB=ext/bin/miniupnpc/linux-x64/libminiupnpc.a
  49. endif
  50. ifeq ($(UNAME_M),i386)
  51. MINIUPNPC_LIB=ext/bin/miniupnpc/linux-x86/libminiupnpc.a
  52. endif
  53. ifeq ($(UNAME_M),i686)
  54. MINIUPNPC_LIB=ext/bin/miniupnpc/linux-x86/libminiupnpc.a
  55. endif
  56. MINIUPNPC_LIB?=-lminiupnpc
  57. LDLIBS+=$(MINIUPNPC_LIB)
  58. OBJS+=osdep/UPNPClient.o
  59. endif
  60. # Build with ZT_ENABLE_NETWORK_CONTROLLER=1 to build with the Sqlite network controller
  61. ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
  62. DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER
  63. LDLIBS+=-L/usr/local/lib -lsqlite3
  64. OBJS+=controller/SqliteNetworkController.o
  65. endif
  66. # "make debug" is a shortcut for this
  67. ifeq ($(ZT_DEBUG),1)
  68. DEFS+=-DZT_TRACE
  69. CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  70. CXXFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  71. LDFLAGS=-ldl
  72. STRIP=echo
  73. # The following line enables optimization for the crypto code, since
  74. # C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
  75. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  76. else
  77. CFLAGS?=-O3 -fstack-protector
  78. CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  79. CXXFLAGS?=-O3 -fstack-protector
  80. CXXFLAGS+=-Wall -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  81. LDFLAGS=-ldl -pie -Wl,-z,relro,-z,now
  82. STRIP=strip --strip-all
  83. endif
  84. # Uncomment for gprof profile build
  85. #CFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  86. #CXXFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  87. #LDFLAGS=
  88. #STRIP=echo
  89. all: one
  90. one: $(OBJS) one.o
  91. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LDLIBS)
  92. $(STRIP) zerotier-one
  93. ln -sf zerotier-one zerotier-idtool
  94. ln -sf zerotier-one zerotier-cli
  95. selftest: $(OBJS) selftest.o
  96. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
  97. $(STRIP) zerotier-selftest
  98. installer: one FORCE
  99. ./ext/installfiles/linux/buildinstaller.sh
  100. clean:
  101. rm -rf *.o
  102. find netcon/ -name "*.1.0" -type f -delete
  103. find netcon/ -name "*.so" -type f -delete
  104. find netcon/ -name "zerotier-one" -type f -delete
  105. find netcon/ -name "zerotier-cli" -type f -delete
  106. find netcon/docker-test -name "zerotier-intercept" -type f -delete
  107. rm -rf netcon/*.o netcon/*.so netcon/*.1.0
  108. rm -rf node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o zerotier-one zerotier-idtool zerotier-cli zerotier-selftest build-* ZeroTierOneInstaller-* *.deb *.rpm
  109. debug: FORCE
  110. make ZT_DEBUG=1 one
  111. make ZT_DEBUG=1 selftest
  112. official: FORCE
  113. make -j 4 ZT_OFFICIAL_RELEASE=1
  114. make ZT_OFFICIAL_RELEASE=1 installer
  115. FORCE: