vpp-swan: improve Makefile
[vpp.git] / extras / strongswan / vpp_sswan / Makefile
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         -lvlibapi \
36         -lsvm \
37         -lvppapiclient
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 install-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
74 install-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
79         cd ${SWANDIR} && make -j$(nproc)
80         cd ${SWANDIR} && sudo make install
81
82 # check if VPP is installed
83 ifneq ($(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
86 ifneq ($(shell test -d $(VPPDIR) && echo "yes"), yes)
87         $(error ERROR: Not found installed VPP and locally VPP - please install or build)
88 else
89 # check if VPPLIBS exists
90 ifneq ($(shell test -d $(VPPLIBS) && echo "yes"), yes)
91         $(error ERROR: directory $(VPPLIBS) - doesn't exists, please compile VPP before build this)
92 else
93         $(info INFO: Found locally VPP)
94 endif
95 endif
96 else
97         $(info INFO: Found installed VPP in version: $(VERSION_VPP))
98 endif
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
107 install:
108         cp $(TARGET) $(SWANPLUGINS)/$(TARGET)
109         cp kernel-vpp.conf $(PLUGINCONF)
110
111 clean:
112         rm -f ${SWANARCHIVE}/strongswan-${VERSION_SSWAN}.tar.gz
113         rm -rf ${SWANDIR}
114         rm -f *.so *.o
115
116 .PHONY: clean install all