# NOTE: these are needed by the configure.in inside the packages folder
N2N_VERSION_SHORT = @N2N_VERSION_SHORT@
GIT_COMMITS = @GIT_COMMITS@
GIT_DESCRIBE = $( shell git describe --always --dirty)
########
export CC
export AR
CC = @CC@
AR = @AR@
#Ultrasparc64 users experiencing SIGBUS should try the following gcc options
#(thanks to Robert Gibbon)
PLATOPTS_SPARC64 = -mcpu= ultrasparc -pipe -fomit-frame-pointer -ffast-math -finline-functions -fweb -frename-registers -mapp-regs
export CFLAGS
export LDFLAGS
CFLAGS = @CFLAGS@ -I ./include
LDFLAGS = @LDFLAGS@ -L .
OPENSSL_CFLAGS = $( shell pkg-config openssl; echo $$ ?)
i f e q ( $( OPENSSL_CFLAGS ) , 0 )
CFLAGS += $( shell pkg-config --cflags-only-I openssl)
e n d i f
WARN = -Wall
CFLAGS += $( DEBUG) $( OPTIMIZATION) $( WARN) $( OPTIONS) $( PLATOPTS)
# Quick sanity check on our build environment
UNAME_S := $( shell uname -s)
i f n d e f U N A M E _ S
# This could happen if the Makefile is unable to run "uname", which can
# happen if the shell has a bad path (or is the wrong shell)
$( error Could not run uname command , cannot continue )
e n d i f
# Any compile environment that needs different flags, libraries, includes or
# other settings will get its own CONFIG_TARGET value. For cross compiling,
# this might be set externally to the Makefile, but if not set we try to
# set a reasonable default.
export CONFIG_TARGET
i f n d e f C O N F I G _ T A R G E T
i f e q ( $( shell uname -o ) , M s y s )
CONFIG_TARGET = mingw
e l s e i f e q ( $( shell uname -s ) , D a r w i n )
CONFIG_TARGET = darwin
e l s e i f e q ( $( shell uname ) , S u n O S )
CONFIG_TARGET = sunos
e l s e
CONFIG_TARGET = generic
e n d i f
e n d i f
export MKDIR
export INSTALL
export INSTALL_PROG
export INSTALL_DOC
export SBINDIR
MKDIR = mkdir -p
INSTALL = install
INSTALL_PROG = $( INSTALL) -m755
INSTALL_DOC = $( INSTALL) -m644
# DESTDIR set in debian make system
PREFIX ?= $( DESTDIR) /usr
i f e q ( $( CONFIG_TARGET ) , d a r w i n )
SBINDIR = $( PREFIX) /local/sbin
e l s e
SBINDIR = $( PREFIX) /sbin
e n d i f
MANDIR ?= $( PREFIX) /share/man
MAN1DIR = $( MANDIR) /man1
MAN7DIR = $( MANDIR) /man7
MAN8DIR = $( MANDIR) /man8
N2N_LIB = libn2n.a
N2N_OBJS = $( patsubst src/%.c, src/%.o, $( wildcard src/*.c) )
N2N_DEPS = $( wildcard include/*.h) $( wildcard src/*.c) Makefile
export LDLIBS
LDLIBS += -ln2n
LDLIBS += @N2N_LIBS@
#For OpenSolaris (Solaris too?)
i f e q ( $( CONFIG_TARGET ) , s u n o s )
LDLIBS += -lsocket -lnsl
e n d i f
i f e q ( $( CONFIG_TARGET ) , m i n g w )
CFLAGS += -I. -I./win32 -DWIN32
LDLIBS += $( abspath win32/n2n_win32.a)
LDLIBS += -lws2_32 -liphlpapi
N2N_DEPS += win32/n2n_win32.a
SUBDIRS += win32
e n d i f
APPS = edge
APPS += supernode
APPS += example_edge_embed_quick_edge_init
APPS += example_edge_embed
APPS += example_sn_embed
DOCS = edge.8.gz supernode.1.gz n2n.7.gz
SUBDIRS += tools
.PHONY : $( SUBDIRS )
.PHONY : steps build push all clean install test cover gcov build -dep
all : $( APPS ) $( DOCS ) $( SUBDIRS )
tools : $( N 2N_LIB )
$( MAKE) -C $@
win32 :
$( MAKE) -C $@
src/edge.o : $( N 2N_DEPS )
src/supernode.o : $( N 2N_DEPS )
src/example_edge_embed_quick_edge_init.o : $( N 2N_DEPS )
src/example_sn_embed.o : $( N 2N_DEPS )
src/example_edge_embed.o : $( N 2N_DEPS )
src/edge : $( N 2N_LIB )
src/supernode : $( N 2N_LIB )
src/example_edge_embed_quick_edge_init : $( N 2N_LIB )
src/example_sn_embed : $( N 2N_LIB )
src/example_edge_embed : $( N 2N_LIB )
% : src /%
cp $< $@
%.gz : %
gzip -c $< > $@
$(N2N_LIB) : $( N 2N_OBJS )
$( AR) rcs $( N2N_LIB) $( N2N_OBJS)
# $(RANLIB) $@
win32/n2n_win32.a : win 32
test : tools
tools/test_harness
# To generate coverage information, run configure with
# CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="--coverage"
# and run the desired tests. Ensure that package gcovr is installed
# and then run "make cover"
cover :
mkdir -p coverage
gcovr -s --html --html-details --output= coverage/index.html
# Use coverage data to generate gcov text report files.
# Unfortunately, these end up in the wrong directory due to the
# makefile layout
# The steps to use this are similar to the "make cover" above
gcov :
gcov $( N2N_OBJS)
$( MAKE) -C tools gcov
# This is the superset of all packages that might be needed.
# It is a convinent target to use during development or from a CI/CD system
build-dep :
i f e q ( $( CONFIG_TARGET ) , g e n e r i c )
sudo apt install build-essential autoconf libcap-dev libzstd-dev gcovr
e l s e i f e q ( $( CONFIG_TARGET ) , d a r w i n )
brew install automake gcovr
e l s e
echo Not attempting to install dependancies for system $( CONFIG_TARGET)
e n d i f
clean :
rm -rf $( N2N_OBJS) $( N2N_LIB) $( APPS) $( DOCS) coverage/ *.dSYM *~
rm -f tests/*.out src/*.gcno src/*.gcda
for dir in $( SUBDIRS) ; do $( MAKE) -C $$ dir clean; done
install : edge supernode edge .8.gz supernode .1.gz n 2n .7.gz
echo " MANDIR= $( MANDIR) "
$( MKDIR) $( SBINDIR) $( MAN1DIR) $( MAN7DIR) $( MAN8DIR)
$( INSTALL_PROG) supernode $( SBINDIR) /
$( INSTALL_PROG) edge $( SBINDIR) /
$( INSTALL_DOC) edge.8.gz $( MAN8DIR) /
$( INSTALL_DOC) supernode.1.gz $( MAN1DIR) /
$( INSTALL_DOC) n2n.7.gz $( MAN7DIR) /
$( MAKE) -C tools install SBINDIR = $( abspath $( SBINDIR) )
# Docker builder section
DOCKER_IMAGE_NAME = ntop/supernode
DOCKER_IMAGE_VERSION = $N2N_VERSION_SHORT
N2N_COMMIT_HASH = @GIT_REVISION@
default : steps
steps :
if [ " $( TARGET_ARCHITECTURE) " = "arm32v7" ] || [ " $( TARGET_ARCHITECTURE) " = "" ] ; then DOCKER_IMAGE_FILENAME = "Dockerfile.arm32v7" DOCKER_IMAGE_TAGNAME = $( DOCKER_IMAGE_NAME) :$( DOCKER_IMAGE_VERSION) -arm32v7 make build; fi
if [ " $( TARGET_ARCHITECTURE) " = "x86_64" ] || [ " $( TARGET_ARCHITECTURE) " = "" ] ; then DOCKER_IMAGE_FILENAME = "Dockerfile.x86_64" DOCKER_IMAGE_TAGNAME = $( DOCKER_IMAGE_NAME) :$( DOCKER_IMAGE_VERSION) -x86_64 make build; fi
build :
$( eval OS := $( shell uname -s) )
$( eval ARCHITECTURE := $( shell export DOCKER_IMAGE_TAGNAME = " $( DOCKER_IMAGE_TAGNAME) " ; echo $$ DOCKER_IMAGE_TAGNAME | grep -oe -.*) )
docker build --target builder --build-arg COMMIT_HASH = $( N2N_COMMIT_HASH) -t $( DOCKER_IMAGE_TAGNAME) -f image-platforms/$( DOCKER_IMAGE_FILENAME) .
docker container create --name builder $( DOCKER_IMAGE_TAGNAME)
if [ ! -d "./build" ] ; then mkdir ./build; fi
docker container cp builder:/usr/src/n2n/supernode ./build/supernode-$( OS) $( ARCHITECTURE)
docker container cp builder:/usr/src/n2n/edge ./build/edge-$( OS) $( ARCHITECTURE)
docker container rm -f builder
docker build --build-arg COMMIT_HASH = $( N2N_COMMIT_HASH) -t $( DOCKER_IMAGE_TAGNAME) -f image-platforms/$( DOCKER_IMAGE_FILENAME) .
docker tag $( DOCKER_IMAGE_TAGNAME) $( DOCKER_IMAGE_NAME) :latest$( ARCHITECTURE)
push :
if [ ! " $( TARGET_ARCHITECTURE) " = "" ] ; then \
docker push $( DOCKER_IMAGE_NAME) :$( DOCKER_IMAGE_VERSION) -$( TARGET_ARCHITECTURE) ; \
docker push $( DOCKER_IMAGE_NAME) :latest-$( TARGET_ARCHITECTURE) ; \
else \
echo "Please pass TARGET_ARCHITECTURE, see README.md." ; \
fi
# End Docker builder section