make-linux.mk 3.1 KB

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