make-linux.mk 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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=
  29. DEFS=
  30. LDLIBS?=
  31. include objects.mk
  32. OBJS+=osdep/LinuxEthernetTap.o
  33. # "make official" is a shortcut for this
  34. ifeq ($(ZT_OFFICIAL_RELEASE),1)
  35. DEFS+=-DZT_OFFICIAL_RELEASE
  36. ZT_USE_MINIUPNPC=1
  37. endif
  38. ifeq ($(ZT_USE_MINIUPNPC),1)
  39. DEFS+=-DZT_USE_MINIUPNPC
  40. LDLIBS+=ext/miniupnpc/libminiupnpc.a
  41. OBJS+=osdep/UPNPClient.o
  42. endif
  43. # Build with ZT_ENABLE_NETWORK_CONTROLLER=1 to build with the Sqlite network controller
  44. ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
  45. DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER
  46. LDLIBS+=-L/usr/local/lib -lsqlite3
  47. OBJS+=controller/SqliteNetworkController.o
  48. endif
  49. # Build with ZT_ENABLE_CLUSTER=1 to build with cluster support
  50. ifeq ($(ZT_ENABLE_CLUSTER),1)
  51. DEFS+=-DZT_ENABLE_CLUSTER
  52. endif
  53. # "make debug" is a shortcut for this
  54. ifeq ($(ZT_DEBUG),1)
  55. DEFS+=-DZT_TRACE
  56. CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  57. CXXFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  58. LDFLAGS=
  59. STRIP=echo
  60. # The following line enables optimization for the crypto code, since
  61. # C25519 in particular is almost UNUSABLE in -O0 even on a 3ghz box!
  62. ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  63. else
  64. CFLAGS?=-O3 -fstack-protector
  65. CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  66. CXXFLAGS?=-O3 -fstack-protector
  67. CXXFLAGS+=-Wall -fPIE -fvisibility=hidden -fno-rtti -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  68. LDFLAGS=-pie -Wl,-z,relro,-z,now
  69. STRIP=strip --strip-all
  70. endif
  71. ifeq ($(ZT_TRACE),1)
  72. DEFS+=-DZT_TRACE
  73. endif
  74. # Uncomment for gprof profile build
  75. #CFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  76. #CXXFLAGS=-Wall -g -pg -pthread $(INCLUDES) $(DEFS)
  77. #LDFLAGS=
  78. #STRIP=echo
  79. all: one
  80. one: $(OBJS) one.o
  81. ifeq ($(ZT_USE_MINIUPNPC),1)
  82. 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
  83. endif
  84. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) one.o $(LDLIBS)
  85. $(STRIP) zerotier-one
  86. ln -sf zerotier-one zerotier-idtool
  87. ln -sf zerotier-one zerotier-cli
  88. selftest: $(OBJS) selftest.o
  89. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS)
  90. $(STRIP) zerotier-selftest
  91. installer: one FORCE
  92. ./ext/installfiles/linux/buildinstaller.sh
  93. clean:
  94. rm -rf *.o 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
  95. cd ext/miniupnpc ; make clean
  96. debug: FORCE
  97. make ZT_DEBUG=1 one
  98. make ZT_DEBUG=1 selftest
  99. official: FORCE
  100. make -j 4 ZT_OFFICIAL_RELEASE=1
  101. make ZT_OFFICIAL_RELEASE=1 installer
  102. FORCE: