make-linux.mk 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 $(CC) -dumpmachine | cut -d '-' -f 1)
  28. INCLUDES=-Iext/lwip/src/include -Iext/lwip/src/include/ipv4 -Iext/lwip/src/include/ipv6
  29. DEFS=-DZT_ENABLE_NETCON
  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. LDLIBS+=ext/miniupnpc/libminiupnpc.a
  42. OBJS+=osdep/UPNPClient.o
  43. endif
  44. # Build with ZT_ENABLE_NETWORK_CONTROLLER=1 to build with the Sqlite network controller
  45. ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
  46. DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER
  47. LDLIBS+=-L/usr/local/lib -lsqlite3
  48. OBJS+=controller/SqliteNetworkController.o
  49. endif
  50. # Build with ZT_ENABLE_CLUSTER=1 to build with cluster support
  51. ifeq ($(ZT_ENABLE_CLUSTER),1)
  52. DEFS+=-DZT_ENABLE_CLUSTER
  53. endif
  54. # "make debug" is a shortcut for this
  55. ifeq ($(ZT_DEBUG),1)
  56. DEFS+=-DZT_TRACE
  57. CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  58. CXXFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  59. LDFLAGS=-ldl
  60. STRIP=echo
  61. # The following line enables optimization for the crypto code, since
  62. # C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
  63. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  64. else
  65. CFLAGS?=-O3 -fstack-protector
  66. CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  67. CXXFLAGS?=-O3 -fstack-protector
  68. CXXFLAGS+=-Wall -Wreorder -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  69. LDFLAGS=-ldl -pie -Wl,-z,relro,-z,now
  70. STRIP=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
  81. one: $(OBJS) one.o
  82. ifeq ($(ZT_USE_MINIUPNPC),1)
  83. cd ext/miniupnpc ; make clean ; make 'CFLAGS=-O2 -fstack-protector -fPIE -fno-common -DMINIUPNPC_SET_SOCKET_TIMEOUT -DMINIUPNPC_GET_SRC_ADDR -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600' -j 2 libminiupnpc.a
  84. endif
  85. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LDLIBS)
  86. $(STRIP) zerotier-one
  87. ln -sf zerotier-one zerotier-idtool
  88. ln -sf zerotier-one zerotier-cli
  89. selftest: $(OBJS) selftest.o
  90. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
  91. $(STRIP) zerotier-selftest
  92. installer: one FORCE
  93. ./ext/installfiles/linux/buildinstaller.sh
  94. clean:
  95. find ./ -type f -name '*.o' -delete
  96. find netcon/ -type f -name '*.so' -delete
  97. find netcon/ -type f -name '*.1.0' -delete
  98. find netcon/ -type f -name 'zerotier-one' -delete
  99. find netcon/ -type f -name 'zerotier-cli' -delete
  100. find netcon/docker-test -name "zerotier-intercept" -type f -delete
  101. rm -rf zerotier-one zerotier-idtool zerotier-cli zerotier-selftest zerotier-netcon build-* ZeroTierOneInstaller-* *.deb *.rpm *.pkg *.tgz
  102. cd ext/miniupnpc ; make clean
  103. debug: FORCE
  104. make ZT_DEBUG=1 one
  105. make ZT_DEBUG=1 selftest
  106. official: FORCE
  107. make -j 4 ZT_OFFICIAL_RELEASE=1
  108. make ZT_OFFICIAL_RELEASE=1 installer
  109. FORCE: