From b503900b1456e8bd4b60d1deb0ef7cc3665676f1 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sun, 4 Apr 2021 21:59:14 +0200 Subject: First step of cleaning up the Makefile.in hell. The goal is to get rid of the Makefile.in's (replace it with Automake Makefile.am's) as they duplicate lot's of text. That decreases readability and is in general a bad design pattern. It seems appropriate to use Automake for an Autoconf based project. Currently achieved: * using libtool to build the core library (+libtool's semantic versioning) * out-of-source builds should work right now * introducing Automake based Makefile in src/ * removed some (maybe) unused GIT ignored files * provide some small python fixes Signed-off-by: Toni Uhlig --- python/Makefile.in | 33 ++++++++++++++++++++------------- python/ndpi_example.py | 2 ++ python/ndpi_typestruct.py | 11 +++++++++-- 3 files changed, 31 insertions(+), 15 deletions(-) (limited to 'python') diff --git a/python/Makefile.in b/python/Makefile.in index a3bcd5da3..1a5929bec 100644 --- a/python/Makefile.in +++ b/python/Makefile.in @@ -1,26 +1,33 @@ CC=@CC@ -CFLAGS=-I. -I../src/include -I./src/lib/third_party/include @CFLAGS@ @CUSTOM_NDPI@ -shared -#LIBNDPI=../src/lib/libndpi.so.@NDPI_VERSION_SHORT@ -LIBNDPI=../src/lib/libndpi.a -LDFLAGS=$(CFILE) $(LIBNDPI) -lpcap @LIBS@ @ADDITIONAL_LIBS@ -SHARE = -soname,ndpi_wrap + +BUILD_SRC=../src +ROOT_SRC=@srcdir@/../src +ROOT_PYTHON=@srcdir@ + +PYTHON_EXEC?=python +CFLAGS=-I$(ROOT_PYTHON) -I$(ROOT_SRC)/include -I$(BUILD_SRC)/include -I$(ROOT_SRC)/lib/third_party/include \ + @CFLAGS@ @CUSTOM_NDPI@ -shared +LIBNDPI=$(BUILD_SRC)/.libs/libndpi.a +LDFLAGS=$(LIBNDPI) -lpcap @LIBS@ +SHARE=-soname,ndpi_wrap SO=ndpi_wrap.so -OBJS = ndpi_wrap.o -CFILE = ndpi_wrap.c -PIC = -fPIC -PREFIX?=/usr/local +CFILE=$(ROOT_PYTHON)/ndpi_wrap.c +PIC=-fPIC -DPIC +PREFIX?=@prefix@ .PHONY: all UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Darwin)#do something for linux - SHARE=-install_name,ndpiReader.so +ifeq ($(UNAME_S),Darwin) +SHARE=-install_name,ndpiReader.so endif all: $(SO) $(SO): $(CFILE) $(LIBNDPI) Makefile - $(CC) $(CFLAGS) -Wl,$(SHARE) -o $@ $(PIC) $(LDFLAGS) -# ln -s $(LIBNDPI) . + $(CC) $(CFLAGS) -Wl,$(SHARE) $(CFILE) -o $@ $(PIC) $(LDFLAGS) + +example: $(SO) + env NDPI_WRAP="$(realpath ./ndpi_wrap.so)" $(PYTHON_EXEC) $(ROOT_PYTHON)/ndpi_example.py clean: /bin/rm -f $(SO) diff --git a/python/ndpi_example.py b/python/ndpi_example.py index d134d3947..7b932941d 100755 --- a/python/ndpi_example.py +++ b/python/ndpi_example.py @@ -100,6 +100,8 @@ lista = [] # used to avoid impropriate memory deallocation from python # check ndpi version if ndpi.ndpi_get_api_version() != ndpi.ndpi_wrap_get_api_version(): print("nDPI Library version mismatch: please make sure this code and the nDPI library are in sync\n") + print("libnDPI api version..: " + str(ndpi.ndpi_get_api_version())) + print("NDPI_WRAP api version: " + str(ndpi.ndpi_wrap_get_api_version())) sys.exit(-1) # create data structure of ndpi diff --git a/python/ndpi_typestruct.py b/python/ndpi_typestruct.py index 1944a5f3c..4ccd15818 100644 --- a/python/ndpi_typestruct.py +++ b/python/ndpi_typestruct.py @@ -21,7 +21,14 @@ If not, see . from ctypes import CDLL, Structure, c_uint16, c_int, c_ulong, c_uint32, CFUNCTYPE, c_void_p, POINTER, c_char_p, c_uint8 from ctypes import c_char, c_uint, c_int16, c_longlong, c_size_t, Union, c_ubyte, c_uint64, c_int32, c_ushort, cast from os.path import abspath, dirname -ndpi = CDLL(dirname(abspath(__file__)) + '/ndpi_wrap.so') + +try: + ndpi = CDLL(dirname(abspath(__file__)) + '/ndpi_wrap.so') +except OSError: + from os import getenv + if getenv('NDPI_WRAP') is None: + raise RuntimeError('Environment variable NDPI_WRAP not set and default path does not exist: ' + dirname(abspath(__file__)) + '/ndpi_wrap.so') + ndpi = CDLL(getenv('NDPI_WRAP')) # ----------------------------------------------- Structures ----------------------------------------------------------- @@ -94,7 +101,7 @@ class NDPIProtoDefaultsT(Structure): _fields_ = [ ("protoName", c_char_p), ("protoCategory", c_uint), - ("subprotocols", c_uint16_p), + ("subprotocols", POINTER(c_uint16)), ("subprotocol_count", c_uint32), ("protoId", c_uint16), ("protoIdx", c_uint16), -- cgit v1.2.3