blob: cb642c8669fbea1323e5977eaddec63c57c085cf [file] [log] [blame]
Gabriel Oginski4e88e042022-06-29 12:54:30 +00001# the directory to the strongSwan sources
2SWANDIR=${CURDIR}/../../../build-root/build-vpp-native/external/sswan
3# location of config.h
4CONFIGH=$(SWANDIR)/config.h
5# default install prefix: /usr/local or /usr
6PREFIX=/usr
7# location of the installed strongSwan libraries
8SWANLIBS=$(PREFIX)/lib/ipsec/
9# location of the strongSwan plugins
10SWANPLUGINS=$(PREFIX)/lib/ipsec/plugins
11# location of the strongSwan archive
12SWANARCHIVE=${CURDIR}/../../../build/external/downloads
13# default install configuration files:
14PREFIX_SYS_CONF=/etc
15# target location of the plugin config snippet: $(PREFIX)/etc/strongswan.d/charon/ or /etc/strongswan.d/charon/
16PLUGINCONF=$(PREFIX_SYS_CONF)/strongswan.d/charon/
17# location of the VPP libraries
18VPPLIBS=$(CURDIR)/../../../build-root/install-vpp-native/vpp/lib/x86_64-linux-gnu
19# the directory to the VPP sources
20VPPDIR=../../../build-root/install-vpp-native/vpp/include
21
22TARGET=libstrongswan-kernel-vpp.so
23
24# tested only with 5.9.5 and 5.9.6 version of strongSwan
25VERSION_SSWAN=5.9.6
26
27CFLAGS=-O2 -g -Wall -Wextra -fpic
28
29CFLAGS_I=-include $(CONFIGH) \
30 -I$(SWANDIR)/src/libstrongswan \
31 -I$(SWANDIR)/src/libcharon
32
33LDFLAGS= -lvppinfra \
34 -lvlibmemoryclient \
35 -lvppapiclient \
36 -lsvm \
37 -lvlib
38
39VERSION_VPP=$(shell (dpkg -s vpp | grep Version) | grep -Po '(?<=Version: )\d\d.\d\d')
40
41# check if VPP is installed
42ifneq ($(shell test "$(shell ldconfig -p | grep vppinfra.so | awk 'NR==1{print $$1;}')" && echo "yes"), yes)
43# check if VPPDIR exists
44ifeq ($(shell test -d $(VPPDIR) && echo "yes"), yes)
45 CFLAGS_I += -I$(VPPDIR)
46endif
47# check if VPPLIBS exists
48ifeq ($(shell test -d $(VPPLIBS) && echo "yes"), yes)
49 LDFLAGS += -L$(VPPLIBS)
50 LDFLAGS += -Wl,-rpath=$(VPPLIBS)
51endif
52endif
53
54SOURCES=$(wildcard *.c)
55OBJECTS=$(SOURCES:.c=.o)
56
57all: pull-swan $(TARGET)
58
59pull-swan:
60 @if [ -d "${SWANDIR}" ]; then \
61 rm -rf ${SWANDIR} ; \
62 fi
63 @if ! [ -f "${SWANARCHIVE}/strongswan-${VERSION_SSWAN}.tar.gz" ]; then \
64 curl -o ${SWANARCHIVE}/strongswan-${VERSION_SSWAN}.tar.gz -LO https://github.com/strongswan/strongswan/archive/${VERSION_SSWAN}.tar.gz; \
65 fi
66 @if ! [ -d "${CURDIR}/../../../build-root/build-vpp-native/external/" ]; then \
67 mkdir ${CURDIR}/../../../build-root/build-vpp-native/external; \
68 fi
69 tar -zxof ${SWANARCHIVE}/strongswan-${VERSION_SSWAN}.tar.gz -C ${CURDIR}/../../../build-root/build-vpp-native/external/
70 mv ${CURDIR}/../../../build-root/build-vpp-native/external/strongswan-${VERSION_SSWAN} ${SWANDIR}
71 cd ${SWANDIR} && ./autogen.sh
72 cd ${SWANDIR} && ./configure --prefix=${PREFIX} --sysconfdir=${PREFIX_SYS_CONF} --enable-libipsec --enable-systemd --enable-swanctl --disable-gmp --enable-openssl
73 cd ${SWANDIR} && make -j$(nproc)
74# cd ${SWANDIR} && sudo make install
75
76# check if VPP is installed
77ifneq ($(shell test "$(shell ldconfig -p | grep vppinfra.so | awk 'NR==1{print $$1;}')" && echo "yes"), yes)
78 $(info INFO: Not found installed VPP - checking if locally VPP exists)
79# check if VPPDIR exists
80ifneq ($(shell test -d $(VPPDIR) && echo "yes"), yes)
81 $(error ERROR: Not found installed VPP and locally VPP - please install or build)
82else
83# check if VPPLIBS exists
84ifneq ($(shell test -d $(VPPLIBS) && echo "yes"), yes)
85 $(error ERROR: directory $(VPPLIBS) - doesn't exists, please compile VPP before build this)
86else
87 $(info INFO: Found locally VPP)
88endif
89endif
90else
91 $(info INFO: Found installed VPP in version: $(VERSION_VPP))
92endif
93
94$(TARGET): $(OBJECTS)
95 gcc $(CFLAGS) -shared -DPIC $(OBJECTS) $(LDFLAGS) -Wl,-soname -Wl,$(TARGET) -o $@
96 cp $(TARGET) ${SWANDIR}
97
98%.o: %.c
99 gcc $(CFLAGS) $(CFLAGS_I) -c $< -o $@ $(LDFLAGS)
100
101install:
102 cp $(TARGET) $(SWANPLUGINS)/$(TARGET)
103 cp kernel-vpp.conf $(PLUGINCONF)
104
105clean:
106 rm -f *.so *.o
107
108.PHONY: clean install all