From d198229fe38ab8384a17d82a2b41d54dc52404da Mon Sep 17 00:00:00 2001 From: saces Date: Fri, 13 Feb 2026 14:46:36 +0100 Subject: [PATCH] add build parameters --- pygomx-module/Makefile | 42 ++++++++++++++++++++++++++++++++++++-- pygomx-module/build_ffi.py | 12 ++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/pygomx-module/Makefile b/pygomx-module/Makefile index ad9c9c7..64db8f2 100644 --- a/pygomx-module/Makefile +++ b/pygomx-module/Makefile @@ -1,16 +1,54 @@ +# set some defaults + +# one of static, shared +ifndef BUILD_MODE + BUILD_MODE = static +endif + +# one of none, colm, goolm, vodozemac +ifndef OLM_FLAVOUR + OLM_FLAVOUR = colm +endif + + +# calculate configuration matrix + +ifeq ($(BUILD_MODE),static) + build_mode_name=c-archive + build_mode_ext=a +else ifeq ($(BUILD_MODE),shared) + build_mode_name=c-shared + build_mode_ext=so +else + $(error unknown BUILD_MODE $(BUILD_MODE)) +endif + +link_list = + +ifeq ($(BUILD_MODE),static) + ifeq ($(OLM_FLAVOUR),colm) + link_list += olm + endif +endif + + SOURCE_GO=$(shell find ../libmxclient/ -iname "*.go") +ifndef GO_OUTDIR + GO_OUTDIR = ../pygomx-module +endif + .PHONY: all: _pygomx.o libmxclient.h mkdir -p build/lib cp *.so build/lib _pygomx.o: libmxclient.h build_ffi.py - python3 build_ffi.py + python3 build_ffi.py $(link_list) libmxclient.h: ../libmxclient/go.mod ../libmxclient/go.sum $(SOURCE_GO) cd ../libmxclient/ && \ - CGO_ENABLED=1 go build -buildmode=c-archive -o ../pygomx-module/libmxclient.a . + CGO_ENABLED=1 go build -buildmode=$(build_mode_name) -o $(GO_OUTDIR)/libmxclient.$(build_mode_ext) . .PHONY: clean: diff --git a/pygomx-module/build_ffi.py b/pygomx-module/build_ffi.py index 1c88497..308043e 100644 --- a/pygomx-module/build_ffi.py +++ b/pygomx-module/build_ffi.py @@ -1,6 +1,16 @@ #!/usr/bin/python +import sys from cffi import FFI +lib_list = [ + "mxclient", +] + +if len(sys.argv) > 1: + lib_list += sys.argv[1:] + +print(f"liblist: {lib_list}") + ffibuilder = FFI() ffibuilder.set_source( @@ -8,7 +18,7 @@ ffibuilder.set_source( source=""" //passed to the real C compiler #include "libmxclient.h" """, - libraries=["mxclient", "olm"], + libraries=lib_list, library_dirs=["."], include_dirs=["."], )