From 1bd5a1ebcd6fb99b6a1c723514a8bf354486a443 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 4 Nov 2014 11:20:38 -0800 Subject: [PATCH] Make selftest build and run on FreeBSD 10 with gmake --- Makefile | 5 +++ make-freebsd.mk | 88 ++++++++++++++++++++++++++++++++++++++++++++ node/Constants.hpp | 15 ++++++++ node/InetAddress.h | 0 node/InetAddress.hpp | 1 + 5 files changed, 109 insertions(+) create mode 100644 make-freebsd.mk create mode 100644 node/InetAddress.h diff --git a/Makefile b/Makefile index ac50884cd..bc0942609 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,8 @@ endif ifeq ($(OSTYPE),Linux) include make-linux.mk endif + +ifeq ($(OSTYPE),FreeBSD) + include make-freebsd.mk +endif + diff --git a/make-freebsd.mk b/make-freebsd.mk new file mode 100644 index 000000000..744999723 --- /dev/null +++ b/make-freebsd.mk @@ -0,0 +1,88 @@ +CC=cc +CXX=c++ + +INCLUDES= +DEFS= +LIBS= + +include objects.mk +OBJS+= +TESTNET_OBJS=testnet/SimNet.o testnet/SimNetSocketManager.o testnet/TestEthernetTap.o testnet/TestEthernetTapFactory.o testnet/TestRoutingTable.o + +# Enable SSE-optimized Salsa20 on x86 and x86_64 machines +MACHINE=$(shell uname -m) +ifeq ($(MACHINE),x86_64) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),amd64) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),i686) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),i586) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),i386) + DEFS+=-DZT_SALSA20_SSE +endif +ifeq ($(MACHINE),x86) + DEFS+=-DZT_SALSA20_SSE +endif + +# "make official" is a shortcut for this +ifeq ($(ZT_OFFICIAL_RELEASE),1) + ZT_AUTO_UPDATE=1 + DEFS+=-DZT_OFFICIAL_RELEASE +endif +ifeq ($(ZT_AUTO_UPDATE),1) + DEFS+=-DZT_AUTO_UPDATE +endif + +# "make debug" is a shortcut for this +ifeq ($(ZT_DEBUG),1) +# DEFS+=-DZT_TRACE -DZT_LOG_STDOUT + CFLAGS=-Wall -g -pthread $(INCLUDES) $(DEFS) + LDFLAGS= + STRIP=echo + # The following line enables optimization for the crypto code, since + # C25519 in particular is almost UNUSABLE in heavy testing without it. +ext/lz4/lz4.o node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g -pthread $(INCLUDES) $(DEFS) +else + CFLAGS=-Wall -O3 -fPIE -fvisibility=hidden -fstack-protector -pthread $(INCLUDES) -DNDEBUG $(DEFS) + LDFLAGS=-pie -Wl,-z,relro,-z,now + STRIP=strip --strip-all +endif + +CXXFLAGS=$(CFLAGS) -fno-rtti + +all: one + +one: $(OBJS) main.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-one main.o $(OBJS) $(LIBS) + $(STRIP) zerotier-one + ln -sf zerotier-one zerotier-cli + ln -sf zerotier-one zerotier-idtool + +selftest: $(OBJS) selftest.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LIBS) + $(STRIP) zerotier-selftest + +testnet: $(TESTNET_OBJS) $(OBJS) testnet.o + $(CXX) $(CXXFLAGS) -o zerotier-testnet testnet.o $(OBJS) $(TESTNET_OBJS) $(LIBS) + $(STRIP) zerotier-testnet + +installer: one FORCE + ./buildinstaller.sh + +clean: + rm -rf $(OBJS) $(TESTNET_OBJS) node/*.o osnet/*.o control/*.o testnet/*.o *.o zerotier-* build-* ZeroTierOneInstaller-* + +debug: FORCE + make -j 4 ZT_DEBUG=1 + +official: FORCE + make -j 4 ZT_OFFICIAL_RELEASE=1 + ./buildinstaller.sh + +FORCE: diff --git a/node/Constants.hpp b/node/Constants.hpp index 83c98e0fc..82d254594 100644 --- a/node/Constants.hpp +++ b/node/Constants.hpp @@ -58,6 +58,21 @@ #include #endif +#ifdef __FreeBSD__ +#ifndef __UNIX_LIKE__ +#define __UNIX_LIKE__ +#endif +#ifndef __BSD__ +#define __BSD__ +#endif +#include +#ifndef __BYTE_ORDER +#define __BYTE_ORDER _BYTE_ORDER +#define __LITTLE_ENDIAN _LITTLE_ENDIAN +#define __BIG_ENDIAN _BIG_ENDIAN +#endif +#endif + // TODO: Android is what? Linux technically, but does it define it? #ifdef __APPLE__ diff --git a/node/InetAddress.h b/node/InetAddress.h new file mode 100644 index 000000000..e69de29bb diff --git a/node/InetAddress.hpp b/node/InetAddress.hpp index 0ddb2cd43..06da9de66 100644 --- a/node/InetAddress.hpp +++ b/node/InetAddress.hpp @@ -45,6 +45,7 @@ #else #include #include +#include #endif namespace ZeroTier {