blob: 85fb506f346009fd1f5d95d75e54751fcab1ff0e [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 \
Gabriel Oginskice62d6f2022-10-12 13:40:05 +000035 -lvlibapi \
Gabriel Oginski4e88e042022-06-29 12:54:30 +000036 -lsvm \
Gabriel Oginskice62d6f2022-10-12 13:40:05 +000037 -lvppapiclient
Gabriel Oginski4e88e042022-06-29 12:54:30 +000038
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
Fan Zhangad215f22023-03-01 14:45:46 +000057all: pull-swan install-swan $(TARGET)
Gabriel Oginski4e88e042022-06-29 12:54:30 +000058
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
Fan Zhangad215f22023-03-01 14:45:46 +000073
74install-swan:
75 @if ! [ -f "${SWANDIR}/configure" ]; then \
76 echo "SSWAN not downloaded, please run "make" or "make pull-swan" first." ; \
77 exit 1 ; \
78 fi
Renato Botelho do Couto893daca2024-06-05 18:11:46 +000079 cd ${SWANDIR} && $(MAKE) -j$(nproc)
80 cd ${SWANDIR} && sudo $(MAKE) install
Gabriel Oginski4e88e042022-06-29 12:54:30 +000081
82# check if VPP is installed
83ifneq ($(shell test "$(shell ldconfig -p | grep vppinfra.so | awk 'NR==1{print $$1;}')" && echo "yes"), yes)
84 $(info INFO: Not found installed VPP - checking if locally VPP exists)
85# check if VPPDIR exists
86ifneq ($(shell test -d $(VPPDIR) && echo "yes"), yes)
87 $(error ERROR: Not found installed VPP and locally VPP - please install or build)
88else
89# check if VPPLIBS exists
90ifneq ($(shell test -d $(VPPLIBS) && echo "yes"), yes)
91 $(error ERROR: directory $(VPPLIBS) - doesn't exists, please compile VPP before build this)
92else
93 $(info INFO: Found locally VPP)
94endif
95endif
96else
97 $(info INFO: Found installed VPP in version: $(VERSION_VPP))
98endif
99
100$(TARGET): $(OBJECTS)
101 gcc $(CFLAGS) -shared -DPIC $(OBJECTS) $(LDFLAGS) -Wl,-soname -Wl,$(TARGET) -o $@
102 cp $(TARGET) ${SWANDIR}
103
104%.o: %.c
105 gcc $(CFLAGS) $(CFLAGS_I) -c $< -o $@ $(LDFLAGS)
106
107install:
108 cp $(TARGET) $(SWANPLUGINS)/$(TARGET)
109 cp kernel-vpp.conf $(PLUGINCONF)
110
111clean:
Fan Zhangad215f22023-03-01 14:45:46 +0000112 rm -f ${SWANARCHIVE}/strongswan-${VERSION_SSWAN}.tar.gz
113 rm -rf ${SWANDIR}
Gabriel Oginski4e88e042022-06-29 12:54:30 +0000114 rm -f *.so *.o
115
Fan Zhangad215f22023-03-01 14:45:46 +0000116.PHONY: clean install all