This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangyang-libzt/make-linux.mk

196 lines
6.8 KiB
Makefile
Raw Normal View History

# Automagically pick clang or gcc, with preference for clang
# This is only done if we have not overridden these with an environment or CLI variable
ifeq ($(origin CC),default)
CC=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
endif
ifeq ($(origin CXX),default)
CXX=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
endif
2017-04-14 17:23:28 -07:00
##############################################################################
## VARIABLES ##
##############################################################################
2017-04-14 17:23:28 -07:00
include objects.mk
2017-04-21 14:56:42 -07:00
OSTYPE = $(shell uname -s | tr '[A-Z]' '[a-z]')
2017-04-14 17:23:28 -07:00
# Target output filenames
STATIC_LIB_NAME = libzt.a
PICO_LIB_NAME = libpicotcp.a
#
STATIC_LIB = $(BUILD)/$(STATIC_LIB_NAME)
2017-04-21 14:56:42 -07:00
PICO_DIR = ext/picotcp
PICO_LIB = $(PICO_DIR)/build/lib/$(PICO_LIB_NAME)
#
TEST_BUILD_DIR = $(BUILD)/test
2017-04-14 17:23:28 -07:00
UNIT_TEST_SRC_DIR = test/unit
DUMB_TEST_SRC_DIR = test/dumb
##############################################################################
## General Configuration ##
##############################################################################
# Debug output for ZeroTier service
ifeq ($(ZT_DEBUG),1)
DEFS+=-DZT_TRACE
CFLAGS+=-Wall -g -pthread $(INCLUDES) $(DEFS)
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
2017-05-01 18:14:10 -07:00
CFLAGS?=-O3 -fstack-protector
2017-04-14 17:23:28 -07:00
CFLAGS+=-Wall -fPIE -fvisibility=hidden -pthread $(INCLUDES) $(DEFS)
#CFLAGS+=$(ARCH_FLAGS) -Wall -flto -fPIC -pthread -mmacosx-version-min=10.7 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
STRIP=strip
endif
CXXFLAGS=$(CFLAGS) -Wno-format -fno-rtti -std=c++11 -DZT_SDK
INCLUDES+= -Iext \
-I$(ZTO)/osdep \
-I$(ZTO)/node \
-I$(ZTO)/service \
-I$(ZTO)/include \
-I../$(ZTO)/osdep \
-I../$(ZTO)/node \
-I../$(ZTO)/service \
-I. \
-Isrc \
-Iinclude \
-Iext/picotcp/include \
-Iext/picotcp/build/include
2017-04-21 14:56:42 -07:00
COMMON_LIBS = -lpthread
2017-04-14 17:23:28 -07:00
##############################################################################
## User Build Flags ##
##############################################################################
# Debug option, prints filenames, lines, functions, arguments, etc
# Also enables debug symbols for debugging with tools like gdb, etc
ifeq ($(SDK_DEBUG),1)
SDK_FLAGS+=-DSDK_PICOTCP
CXXFLAGS+=-g
INCLUDES+= -I$(PICOTCP_DIR)/include \
-I$(PICOTCP_DIR)/build/include \
-Isrc/stack_drivers/picotcp
endif
##############################################################################
## Stack Configuration ##
##############################################################################
# Stack config flags
ifeq ($(SDK_PICOTCP),1)
SDK_FLAGS+=-DSDK_PICOTCP
INCLUDES+= -I$(PICOTCP_DIR)/include \
-I$(PICOTCP_DIR)/build/include \
-Isrc/stack_drivers/picotcp
endif
ifeq ($(SDK_IPV4),1)
SDK_FLAGS+=-DSDK_IPV4
endif
ifeq ($(SDK_IPV6),1)
SDK_FLAGS+=-DSDK_IPV6
endif
##############################################################################
## Files ##
##############################################################################
STACK_DRIVER_FILES:=src/picoTCP.cpp
TAP_FILES:=src/SocketTap.cpp \
src/ZeroTierSDK.cpp \
2017-04-21 14:56:42 -07:00
src/Utilities.cpp
2017-04-14 17:23:28 -07:00
SDK_OBJS+= SocketTap.o \
picoTCP.o \
ZeroTierSDK.o \
2017-04-21 14:56:42 -07:00
Utilities.o
2017-04-14 17:23:28 -07:00
PICO_OBJS+= ext/picotcp/build/lib/pico_device.o \
ext/picotcp/build/lib/pico_frame.o \
ext/picotcp/build/lib/pico_md5.o \
ext/picotcp/build/lib/pico_protocol.o \
ext/picotcp/build/lib/pico_socket_multicast.o \
ext/picotcp/build/lib/pico_socket.o \
ext/picotcp/build/lib/pico_stack.o \
ext/picotcp/build/lib/pico_tree.o
all:
2017-04-14 17:23:28 -07:00
tests: dumb_tests unit_tests
##############################################################################
## User-Space Stack ##
##############################################################################
picotcp:
2017-04-21 14:56:42 -07:00
cd $(PICO_DIR); make lib ARCH=shared IPV4=1 IPV6=1
2017-04-14 17:23:28 -07:00
##############################################################################
## Static Libraries ##
##############################################################################
static_lib: picotcp $(ZTO_OBJS)
2017-04-21 14:56:42 -07:00
@mkdir -p $(BUILD)
2017-04-14 17:23:28 -07:00
$(CXX) $(CXXFLAGS) $(SDK_FLAGS) $(TAP_FILES) $(STACK_DRIVER_FILES) -c -DSDK_STATIC
2017-04-21 14:56:42 -07:00
#libtool --mode=link $(STATIC_LIB) $(ZTO_OBJS) $(SDK_OBJS) $(PICO_LIB)
ar rcs -o $(STATIC_LIB) ext/picotcp/build/modules/*.o $(PICO_OBJS) $(ZTO_OBJS) $(SDK_OBJS)
2017-04-14 17:23:28 -07:00
jni_static_lib: picotcp $(ZTO_OBJS)
##############################################################################
## Unit Tests ##
##############################################################################
2017-04-21 14:56:42 -07:00
UNIT_TEST_SRC_FILES := $(wildcard $(UNIT_TEST_SRC_DIR)/*.cpp)
UNIT_TEST_OBJ_FILES := $(addprefix $(TEST_BUILD_DIR)/,$(notdir $(UNIT_TEST_SRC_FILES:.cpp=)))
UNIT_TEST_INCLUDES := -Iinclude
UNIT_TEST_LIBS := -L$(BUILD) -lzt $(COMMON_LIBS)
2017-04-14 17:23:28 -07:00
2017-04-21 14:56:42 -07:00
$(TEST_BUILD_DIR)/%: $(UNIT_TEST_SRC_DIR)/%.cpp
2017-04-14 17:23:28 -07:00
@mkdir -p $(TEST_BUILD_DIR)
@-$(CXX) $(UNIT_TEST_INCLUDES) -o $@ $< $(UNIT_TEST_LIBS)
@-./check.sh $@
unit_tests: $(UNIT_TEST_OBJ_FILES)
##############################################################################
## Non-ZT Client/Server Tests ##
##############################################################################
2017-04-21 14:56:42 -07:00
DUMB_TEST_SRC_FILES := $(wildcard $(DUMB_TEST_SRC_DIR)/*.cpp)
DUMB_TEST_OBJ_FILES := $(addprefix $(TEST_BUILD_DIR)/,$(notdir $(DUMB_TEST_SRC_FILES:.cpp=)))
2017-04-14 17:23:28 -07:00
2017-04-21 14:56:42 -07:00
$(TEST_BUILD_DIR)/%: $(DUMB_TEST_SRC_DIR)/%.cpp
2017-04-14 17:23:28 -07:00
@mkdir -p $(TEST_BUILD_DIR)
@-$(CC) -o $@ $<
@-./check.sh $@
dumb_tests: $(DUMB_TEST_OBJ_FILES)
##############################################################################
## Misc ##
##############################################################################
2017-04-21 14:56:42 -07:00
# Cleans only current $(OSTYPE)
2017-04-14 17:23:28 -07:00
clean:
-rm -rf $(BUILD)/*
2017-04-21 14:56:42 -07:00
-find $(PICO_DIR) -type f \( -name '*.o' -o -name '*.so' -o -name '*.a' \) -delete
-find . -type f \( -name '*.o' -o -name '*.so' -o -name '*.o.d' -o -name '*.out' -o -name '*.log' -o -name '*.dSYM' \) -delete
# Clean everything
nuke:
-rm -rf $(BUILD)/*
-find . -type f \( -name '*.o' -o -name '*.so' -o -name '*.a' -o -name '*.o.d' -o -name '*.out' -o -name '*.log' -o -name '*.dSYM' \) -delete
2017-04-14 17:23:28 -07:00
check:
-./check.sh $(PICO_LIB)
-./check.sh $(STATIC_LIB)