Gabriel Oginski | 4e88e04 | 2022-06-29 12:54:30 +0000 | [diff] [blame] | 1 | # the directory to the strongSwan sources |
| 2 | SWANDIR=${CURDIR}/../../../build-root/build-vpp-native/external/sswan |
| 3 | # location of config.h |
| 4 | CONFIGH=$(SWANDIR)/config.h |
| 5 | # default install prefix: /usr/local or /usr |
| 6 | PREFIX=/usr |
| 7 | # location of the installed strongSwan libraries |
| 8 | SWANLIBS=$(PREFIX)/lib/ipsec/ |
| 9 | # location of the strongSwan plugins |
| 10 | SWANPLUGINS=$(PREFIX)/lib/ipsec/plugins |
| 11 | # location of the strongSwan archive |
| 12 | SWANARCHIVE=${CURDIR}/../../../build/external/downloads |
| 13 | # default install configuration files: |
| 14 | PREFIX_SYS_CONF=/etc |
| 15 | # target location of the plugin config snippet: $(PREFIX)/etc/strongswan.d/charon/ or /etc/strongswan.d/charon/ |
| 16 | PLUGINCONF=$(PREFIX_SYS_CONF)/strongswan.d/charon/ |
| 17 | # location of the VPP libraries |
| 18 | VPPLIBS=$(CURDIR)/../../../build-root/install-vpp-native/vpp/lib/x86_64-linux-gnu |
| 19 | # the directory to the VPP sources |
| 20 | VPPDIR=../../../build-root/install-vpp-native/vpp/include |
| 21 | |
| 22 | TARGET=libstrongswan-kernel-vpp.so |
| 23 | |
| 24 | # tested only with 5.9.5 and 5.9.6 version of strongSwan |
| 25 | VERSION_SSWAN=5.9.6 |
| 26 | |
| 27 | CFLAGS=-O2 -g -Wall -Wextra -fpic |
| 28 | |
| 29 | CFLAGS_I=-include $(CONFIGH) \ |
| 30 | -I$(SWANDIR)/src/libstrongswan \ |
| 31 | -I$(SWANDIR)/src/libcharon |
| 32 | |
| 33 | LDFLAGS= -lvppinfra \ |
| 34 | -lvlibmemoryclient \ |
| 35 | -lvppapiclient \ |
| 36 | -lsvm \ |
| 37 | -lvlib |
| 38 | |
| 39 | VERSION_VPP=$(shell (dpkg -s vpp | grep Version) | grep -Po '(?<=Version: )\d\d.\d\d') |
| 40 | |
| 41 | # check if VPP is installed |
| 42 | ifneq ($(shell test "$(shell ldconfig -p | grep vppinfra.so | awk 'NR==1{print $$1;}')" && echo "yes"), yes) |
| 43 | # check if VPPDIR exists |
| 44 | ifeq ($(shell test -d $(VPPDIR) && echo "yes"), yes) |
| 45 | CFLAGS_I += -I$(VPPDIR) |
| 46 | endif |
| 47 | # check if VPPLIBS exists |
| 48 | ifeq ($(shell test -d $(VPPLIBS) && echo "yes"), yes) |
| 49 | LDFLAGS += -L$(VPPLIBS) |
| 50 | LDFLAGS += -Wl,-rpath=$(VPPLIBS) |
| 51 | endif |
| 52 | endif |
| 53 | |
| 54 | SOURCES=$(wildcard *.c) |
| 55 | OBJECTS=$(SOURCES:.c=.o) |
| 56 | |
| 57 | all: pull-swan $(TARGET) |
| 58 | |
| 59 | pull-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 |
| 77 | ifneq ($(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 |
| 80 | ifneq ($(shell test -d $(VPPDIR) && echo "yes"), yes) |
| 81 | $(error ERROR: Not found installed VPP and locally VPP - please install or build) |
| 82 | else |
| 83 | # check if VPPLIBS exists |
| 84 | ifneq ($(shell test -d $(VPPLIBS) && echo "yes"), yes) |
| 85 | $(error ERROR: directory $(VPPLIBS) - doesn't exists, please compile VPP before build this) |
| 86 | else |
| 87 | $(info INFO: Found locally VPP) |
| 88 | endif |
| 89 | endif |
| 90 | else |
| 91 | $(info INFO: Found installed VPP in version: $(VERSION_VPP)) |
| 92 | endif |
| 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 | |
| 101 | install: |
| 102 | cp $(TARGET) $(SWANPLUGINS)/$(TARGET) |
| 103 | cp kernel-vpp.conf $(PLUGINCONF) |
| 104 | |
| 105 | clean: |
| 106 | rm -f *.so *.o |
| 107 | |
| 108 | .PHONY: clean install all |