2019-07-06 14:40:16 +02:00
# NOTE: these are needed by the configure.in inside the packages folder
N2N_VERSION_SHORT = @N2N_VERSION_SHORT@
GIT_COMMITS = @GIT_COMMITS@
########
2021-10-05 21:07:15 +02:00
export CC
export AR
2020-06-21 22:26:27 +02:00
CC = @CC@
2021-02-16 12:31:23 +01:00
AR = @AR@
2016-10-23 10:46:15 +02:00
#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
2021-10-05 21:07:15 +02:00
export CFLAGS
export LDFLAGS
2020-06-21 22:26:27 +02:00
CFLAGS = @CFLAGS@ -I ./include
2021-09-16 14:49:04 +02:00
LDFLAGS = @LDFLAGS@ -L .
2016-10-23 10:46:15 +02:00
2018-10-09 17:28:09 +02:00
OPENSSL_CFLAGS = $( shell pkg-config openssl; echo $$ ?)
i f e q ( $( OPENSSL_CFLAGS ) , 0 )
2020-04-24 00:36:32 +02:00
CFLAGS += $( shell pkg-config --cflags-only-I openssl)
2018-10-09 17:28:09 +02:00
e n d i f
2016-10-23 10:46:15 +02:00
2021-09-15 18:23:45 +02:00
WARN = -Wall
2018-10-07 11:37:19 +02:00
CFLAGS += $( DEBUG) $( OPTIMIZATION) $( WARN) $( OPTIONS) $( PLATOPTS)
2016-10-23 10:46:15 +02:00
2021-10-05 21:07:15 +02:00
# 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
2016-10-23 10:46:15 +02:00
2021-10-05 21:07:15 +02:00
MKDIR = mkdir -p
INSTALL = install
2016-10-23 10:46:15 +02:00
INSTALL_PROG = $( INSTALL) -m755
INSTALL_DOC = $( INSTALL) -m644
# DESTDIR set in debian make system
PREFIX ?= $( DESTDIR) /usr
2021-10-05 21:07:15 +02:00
i f e q ( $( CONFIG_TARGET ) , d a r w i n )
2018-09-22 09:08:58 +02:00
SBINDIR = $( PREFIX) /local/sbin
e l s e
2016-10-23 10:46:15 +02:00
SBINDIR = $( PREFIX) /sbin
2018-09-22 09:08:58 +02:00
e n d i f
2016-10-23 10:46:15 +02:00
MANDIR ?= $( PREFIX) /share/man
MAN1DIR = $( MANDIR) /man1
MAN7DIR = $( MANDIR) /man7
MAN8DIR = $( MANDIR) /man8
2018-06-08 11:26:25 +02:00
N2N_LIB = libn2n.a
2020-06-21 22:26:27 +02:00
N2N_OBJS = $( patsubst src/%.c, src/%.o, $( wildcard src/*.c) )
2021-09-16 14:49:04 +02:00
N2N_DEPS = $( wildcard include/*.h) $( wildcard src/*.c) Makefile
2020-06-21 22:26:27 +02:00
2021-10-23 21:36:18 +02:00
# As source files pass the linter, they can be added here (If all the source
# is passing the linter tests, this can be refactored)
LINT_CCODE = \
include/edge_utils_win32.h \
include/n2n_define.h \
include/pearson.h \
include/speck.h \
src/edge_utils_win32.c \
src/example_edge_embed_quick_edge_init.c \
src/header_encryption.c \
src/sn_selection.c \
src/transform_cc20.c \
src/tuntap_linux.c \
src/wire.c \
tools/tests-compress.c \
tools/tests-elliptic.c \
tools/tests-hashing.c \
tools/tests-transform.c \
tools/tests-wire.c \
2021-10-05 21:07:15 +02:00
export LDLIBS
2021-10-23 21:36:18 +02:00
2021-09-16 14:49:04 +02:00
LDLIBS += -ln2n
LDLIBS += @N2N_LIBS@
2016-10-23 10:46:15 +02:00
#For OpenSolaris (Solaris too?)
2021-10-05 21:07:15 +02:00
i f e q ( $( CONFIG_TARGET ) , s u n o s )
2021-09-16 14:49:04 +02:00
LDLIBS += -lsocket -lnsl
2016-10-23 10:46:15 +02:00
e n d i f
2021-10-05 21:07:15 +02:00
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
2016-10-23 10:46:15 +02:00
APPS = edge
APPS += supernode
2020-03-16 15:03:03 +01:00
APPS += example_edge_embed_quick_edge_init
2018-06-08 08:19:06 +02:00
APPS += example_edge_embed
2020-03-16 15:03:03 +01:00
APPS += example_sn_embed
2016-10-23 10:46:15 +02:00
2018-06-20 20:23:28 +02:00
DOCS = edge.8.gz supernode.1.gz n2n.7.gz
2016-10-23 10:46:15 +02:00
2021-10-23 21:36:18 +02:00
# This is the superset of all packages that might be needed during the build.
# Mostly of use in automated build systems.
BUILD_DEP := \
autoconf \
build-essential \
flake8 \
gcovr \
libcap-dev \
libzstd-dev \
shellcheck \
uncrustify \
2021-10-24 21:52:21 +02:00
yamllint \
2021-10-23 21:36:18 +02:00
2021-10-05 21:07:15 +02:00
SUBDIRS += tools
2021-10-15 16:34:52 +02:00
COVERAGEDIR ?= coverage
2021-10-05 21:07:15 +02:00
.PHONY : $( SUBDIRS )
2021-10-23 21:36:18 +02:00
.PHONY : steps build push all clean distclean install test cover gcov build -dep
2021-10-24 21:52:21 +02:00
.PHONY : lint lint .python lint .ccode lint .shell lint .yaml
2021-10-23 21:36:18 +02:00
2021-10-05 21:07:15 +02:00
all : $( APPS ) $( DOCS ) $( SUBDIRS )
2019-09-21 16:12:43 +02:00
tools : $( N 2N_LIB )
$( MAKE) -C $@
2016-10-23 10:46:15 +02:00
2021-10-05 21:07:15 +02:00
win32 :
$( MAKE) -C $@
2021-09-16 14:49:04 +02:00
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 )
2016-10-23 10:46:15 +02:00
2021-09-16 14:49:04 +02:00
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 )
2019-09-20 02:13:07 +02:00
2021-09-16 14:49:04 +02:00
% : src /%
cp $< $@
2018-06-08 08:19:06 +02:00
2016-10-23 10:46:15 +02:00
%.gz : %
gzip -c $< > $@
$(N2N_LIB) : $( N 2N_OBJS )
2021-02-16 12:31:23 +01:00
$( AR) rcs $( N2N_LIB) $( N2N_OBJS)
2016-10-23 10:46:15 +02:00
# $(RANLIB) $@
2021-10-05 21:07:15 +02:00
win32/n2n_win32.a : win 32
2021-09-27 11:41:06 +02:00
test : tools
2021-10-23 21:36:18 +02:00
scripts/test_harness.sh
2021-10-24 21:52:21 +02:00
lint : lint .python lint .ccode lint .shell lint .yaml
2021-09-27 11:41:06 +02:00
2021-10-15 20:26:39 +02:00
lint.python :
2021-10-24 00:13:01 +02:00
flake8 scripts/n2n-ctl scripts/n2n-httpd
2021-10-15 20:26:39 +02:00
2021-10-23 21:36:18 +02:00
lint.ccode :
scripts/indent.sh $( LINT_CCODE)
lint.shell :
shellcheck scripts/*.sh
2021-10-24 21:52:21 +02:00
lint.yaml :
2021-10-25 12:22:01 +02:00
yamllint .
2021-10-24 21:52:21 +02:00
2021-09-27 11:41:06 +02:00
# 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 :
2021-10-15 16:34:52 +02:00
mkdir -p $( COVERAGEDIR)
gcovr -s --html --html-details --output= $( COVERAGEDIR) /index.html
2021-09-27 11:41:06 +02:00
# 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
2021-10-23 21:36:18 +02:00
# This is a convinent target to use during development or from a CI/CD system
2021-09-27 11:41:06 +02:00
build-dep :
2021-10-05 21:07:15 +02:00
i f e q ( $( CONFIG_TARGET ) , g e n e r i c )
2021-10-23 21:36:18 +02:00
sudo apt install $( BUILD_DEP)
2021-10-05 21:07:15 +02:00
e l s e i f e q ( $( CONFIG_TARGET ) , d a r w i n )
brew install automake gcovr
2021-09-29 13:06:02 +02:00
e l s e
2021-10-05 21:07:15 +02:00
echo Not attempting to install dependancies for system $( CONFIG_TARGET)
2021-09-29 13:06:02 +02:00
e n d i f
2021-09-27 11:41:06 +02:00
2016-10-23 10:46:15 +02:00
clean :
2021-10-15 16:34:52 +02:00
rm -rf $( N2N_OBJS) $( N2N_LIB) $( APPS) $( DOCS) $( COVERAGEDIR) / *.dSYM *~
2021-09-27 11:41:06 +02:00
rm -f tests/*.out src/*.gcno src/*.gcda
2021-10-05 21:07:15 +02:00
for dir in $( SUBDIRS) ; do $( MAKE) -C $$ dir clean; done
2016-10-23 10:46:15 +02:00
2021-10-23 21:36:18 +02:00
distclean :
rm -f tests/*.out src/*.gcno src/*.gcda src/*.indent src/*.unc-backup*
rm -rf autom4te.cache/
rm -f config.log config.status configure configure.ac Makefile tools/Makefile include/config.h include/config.h.in
rm -f doc/edge.8.gz doc/n2n.7.gz doc/supernode.1.gz
2021-11-01 11:17:08 +01:00
rm -f packages/debian/config.log packages/debian/config.status
rm -rf packages/debian/autom4te.cache/
rm -f packages/rpm/config.log packages/rpm/config.status
2021-10-23 21:36:18 +02:00
rm -f $( addprefix src/,$( APPS) )
2018-06-20 20:23:28 +02:00
install : edge supernode edge .8.gz supernode .1.gz n 2n .7.gz
2016-10-23 10:46:15 +02:00
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) /
2018-06-20 20:23:28 +02:00
$( INSTALL_DOC) n2n.7.gz $( MAN7DIR) /
2021-10-11 14:59:28 +02:00
$( MAKE) -C tools install SBINDIR = $( abspath $( SBINDIR) )
2018-08-17 14:25:35 +02:00
# Docker builder section
DOCKER_IMAGE_NAME = ntop/supernode
2019-07-06 14:40:16 +02:00
DOCKER_IMAGE_VERSION = $N2N_VERSION_SHORT
2019-07-06 12:30:33 +02:00
N2N_COMMIT_HASH = @GIT_REVISION@
2018-08-17 14:25:35 +02:00
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
2018-08-18 09:10:03 +02:00
# End Docker builder section