make-bsd.mk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # This requires GNU make, which is typically "gmake" on BSD systems
  2. INCLUDES=
  3. DEFS=
  4. LIBS=
  5. include objects.mk
  6. OBJS+=osdep/BSDEthernetTap.o ext/http-parser/http_parser.o
  7. # Build with ZT_ENABLE_CLUSTER=1 to build with cluster support
  8. ifeq ($(ZT_ENABLE_CLUSTER),1)
  9. DEFS+=-DZT_ENABLE_CLUSTER
  10. endif
  11. # "make debug" is a shortcut for this
  12. ifeq ($(ZT_DEBUG),1)
  13. DEFS+=-DZT_TRACE
  14. CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
  15. LDFLAGS+=
  16. STRIP=echo
  17. # The following line enables optimization for the crypto code, since
  18. # C25519 in particular is almost UNUSABLE in heavy testing without it.
  19. node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS)
  20. else
  21. CFLAGS?=-O3 -fstack-protector
  22. CFLAGS+=-Wall -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS)
  23. LDFLAGS+=-pie -Wl,-z,relro,-z,now
  24. STRIP=strip --strip-all
  25. endif
  26. # Determine system build architecture from compiler target
  27. CC_MACH=$(shell $(CC) -dumpmachine | cut -d '-' -f 1)
  28. ZT_ARCHITECTURE=999
  29. ifeq ($(CC_MACH),x86_64)
  30. ZT_ARCHITECTURE=2
  31. ZT_USE_X64_ASM_SALSA2012=1
  32. endif
  33. ifeq ($(CC_MACH),amd64)
  34. ZT_ARCHITECTURE=2
  35. ZT_USE_X64_ASM_SALSA2012=1
  36. endif
  37. ifeq ($(CC_MACH),i386)
  38. ZT_ARCHITECTURE=1
  39. endif
  40. ifeq ($(CC_MACH),i686)
  41. ZT_ARCHITECTURE=1
  42. endif
  43. ifeq ($(CC_MACH),arm)
  44. ZT_ARCHITECTURE=3
  45. override DEFS+=-DZT_NO_TYPE_PUNNING
  46. ZT_USE_ARM32_NEON_ASM_SALSA2012=1
  47. endif
  48. ifeq ($(CC_MACH),armel)
  49. ZT_ARCHITECTURE=3
  50. override DEFS+=-DZT_NO_TYPE_PUNNING
  51. ZT_USE_ARM32_NEON_ASM_SALSA2012=1
  52. endif
  53. ifeq ($(CC_MACH),armhf)
  54. ZT_ARCHITECTURE=3
  55. override DEFS+=-DZT_NO_TYPE_PUNNING
  56. ZT_USE_ARM32_NEON_ASM_SALSA2012=1
  57. endif
  58. ifeq ($(CC_MACH),armv6)
  59. ZT_ARCHITECTURE=3
  60. override DEFS+=-DZT_NO_TYPE_PUNNING
  61. ZT_USE_ARM32_NEON_ASM_SALSA2012=1
  62. endif
  63. ifeq ($(CC_MACH),armv6zk)
  64. ZT_ARCHITECTURE=3
  65. override DEFS+=-DZT_NO_TYPE_PUNNING
  66. ZT_USE_ARM32_NEON_ASM_SALSA2012=1
  67. endif
  68. ifeq ($(CC_MACH),armv6kz)
  69. ZT_ARCHITECTURE=3
  70. override DEFS+=-DZT_NO_TYPE_PUNNING
  71. ZT_USE_ARM32_NEON_ASM_SALSA2012=1
  72. endif
  73. ifeq ($(CC_MACH),armv7)
  74. ZT_ARCHITECTURE=3
  75. override DEFS+=-DZT_NO_TYPE_PUNNING
  76. ZT_USE_ARM32_NEON_ASM_SALSA2012=1
  77. endif
  78. ifeq ($(CC_MACH),arm64)
  79. ZT_ARCHITECTURE=4
  80. override DEFS+=-DZT_NO_TYPE_PUNNING
  81. endif
  82. ifeq ($(CC_MACH),aarch64)
  83. ZT_ARCHITECTURE=4
  84. override DEFS+=-DZT_NO_TYPE_PUNNING
  85. endif
  86. ifeq ($(CC_MACH),mipsel)
  87. ZT_ARCHITECTURE=5
  88. override DEFS+=-DZT_NO_TYPE_PUNNING
  89. endif
  90. ifeq ($(CC_MACH),mips)
  91. ZT_ARCHITECTURE=5
  92. override DEFS+=-DZT_NO_TYPE_PUNNING
  93. endif
  94. ifeq ($(CC_MACH),mips64)
  95. ZT_ARCHITECTURE=6
  96. override DEFS+=-DZT_NO_TYPE_PUNNING
  97. endif
  98. ifeq ($(CC_MACH),mips64el)
  99. ZT_ARCHITECTURE=6
  100. override DEFS+=-DZT_NO_TYPE_PUNNING
  101. endif
  102. # Fail if system architecture could not be determined
  103. ifeq ($(ZT_ARCHITECTURE),999)
  104. ERR=$(error FATAL: architecture could not be determined from $(CC) -dumpmachine: $CC_MACH)
  105. .PHONY: err
  106. err: ; $(ERR)
  107. endif
  108. # Build faster crypto on some targets
  109. ifeq ($(ZT_USE_X64_ASM_SALSA2012),1)
  110. override DEFS+=-DZT_USE_X64_ASM_SALSA2012
  111. override OBJS+=ext/x64-salsa2012-asm/salsa2012.o
  112. endif
  113. ifeq ($(ZT_USE_ARM32_NEON_ASM_SALSA2012),1)
  114. override DEFS+=-DZT_USE_ARM32_NEON_ASM_SALSA2012
  115. override OBJS+=ext/arm32-neon-salsa2012-asm/salsa2012.o
  116. endif
  117. override DEFS+=-DZT_BUILD_PLATFORM=$(ZT_BUILD_PLATFORM) -DZT_BUILD_ARCHITECTURE=$(ZT_ARCHITECTURE) -DZT_SOFTWARE_UPDATE_DEFAULT="\"disable\""
  118. CXXFLAGS+=$(CFLAGS) -fno-rtti -std=c++11 #-D_GLIBCXX_USE_C99 -D_GLIBCXX_USE_C99_MATH -D_GLIBCXX_USE_C99_MATH_TR1
  119. all: one
  120. one: $(OBJS) service/OneService.o one.o
  121. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one $(OBJS) service/OneService.o one.o $(LIBS)
  122. $(STRIP) zerotier-one
  123. ln -sf zerotier-one zerotier-idtool
  124. ln -sf zerotier-one zerotier-cli
  125. selftest: $(OBJS) selftest.o
  126. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LIBS)
  127. $(STRIP) zerotier-selftest
  128. clean:
  129. rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o build-* zerotier-one zerotier-idtool zerotier-selftest zerotier-cli ZeroTierOneInstaller-* $(OBJS)
  130. debug: FORCE
  131. make -j 4 ZT_DEBUG=1
  132. install: one
  133. rm -f /usr/local/sbin/zerotier-one
  134. cp zerotier-one /usr/local/sbin
  135. ln -sf /usr/local/sbin/zerotier-one /usr/local/sbin/zerotier-cli
  136. ln -sf /usr/local/sbin/zerotier-one /usr/local/bin/zerotier-idtool
  137. uninstall: FORCE
  138. rm -rf /usr/local/sbin/zerotier-one /usr/local/sbin/zerotier-cli /usr/local/bin/zerotier-idtool /var/db/zerotier-one/zerotier-one.port /var/db/zerotier-one/zerotier-one.pid /var/db/zerotier-one/iddb.d
  139. FORCE: