make-linux.mk 3.0 KB

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