From dece2c13dbaa9c8c451b5403d809abd84c9b07c0 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 7 Jan 2021 21:19:35 +0100 Subject: [PATCH] Here is an example python extension using code generation (synth_shed) --- gen/examples/ext/synth_shed/Makefile | 38 +++++++++++++++++++ gen/examples/ext/synth_shed/Makefile.conf | 18 +++++++++ .../synth_shed/gen}/Makefile | 3 +- .../synth_shed/gen}/config.json | 2 +- gen/examples/ext/synth_shed/synth_shed.cc | 14 +++++++ gen/examples/synth_shed/Makefile.conf | 5 --- 6 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 gen/examples/ext/synth_shed/Makefile create mode 100644 gen/examples/ext/synth_shed/Makefile.conf rename gen/examples/{synth_shed => ext/synth_shed/gen}/Makefile (91%) rename gen/examples/{synth_shed => ext/synth_shed/gen}/config.json (82%) create mode 100644 gen/examples/ext/synth_shed/synth_shed.cc delete mode 100644 gen/examples/synth_shed/Makefile.conf diff --git a/gen/examples/ext/synth_shed/Makefile b/gen/examples/ext/synth_shed/Makefile new file mode 100644 index 0000000..88c143e --- /dev/null +++ b/gen/examples/ext/synth_shed/Makefile @@ -0,0 +1,38 @@ +include Makefile.conf + +TARGET_MODULE=synth_shed.so +# C++ +CXX=clang +CXXFLAGS+=-std=c++11 -g + +# Sources +SRCS+=$(wildcard *.cc) +OBJS+=$(SRCS:.cc=.o) + +#Compile +CXXFLAGS+=$(INCLUDES) -I$(PREFIX)/include + +#Link +LDFLAGS+=-undefined dynamic_lookup $(LIBS_PATH) $(LIBS) + + +$(info -----BUILD INFO----) +$(info SRCS $(SRCS)) +$(info OBJS $(OBJS)) + +.PHONY: all gen module clean + +all: gen module + +gen: + $(MAKE) -C gen + +module: $(TARGET_MODULE) + +$(TARGET_MODULE) : $(OBJS) + $(CXX) $(LDFLAGS) -o $@ $^ + +clean: + $(MAKE) -C gen clean + rm -f $(TARGET_MODULE) + rm -f $(OBJS) diff --git a/gen/examples/ext/synth_shed/Makefile.conf b/gen/examples/ext/synth_shed/Makefile.conf new file mode 100644 index 0000000..04a970a --- /dev/null +++ b/gen/examples/ext/synth_shed/Makefile.conf @@ -0,0 +1,18 @@ +# pyBind11 +PREFIX=/Users/heck/local-default + +# YML2 +YML2_PATH=$(HOME)/src/pepbase/default/yml2 +YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS) +YML2_OPTS=--encoding=utf8 + +# GEN-CID +GEN_CID_DIR=../../../../gen_cid/ + +# C Python headers +INCLUDES+=-I/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 + +# example lib +INCLUDES+=-I../../lib/synth_shed +LIBS+=-lsynth_shed +LIBS_PATH+=-L../../lib/synth_shed/ diff --git a/gen/examples/synth_shed/Makefile b/gen/examples/ext/synth_shed/gen/Makefile similarity index 91% rename from gen/examples/synth_shed/Makefile rename to gen/examples/ext/synth_shed/gen/Makefile index b456855..f0bce30 100644 --- a/gen/examples/synth_shed/Makefile +++ b/gen/examples/ext/synth_shed/gen/Makefile @@ -1,9 +1,8 @@ -include Makefile.conf +include ../Makefile.conf YML2_FILE=py_module.yml2 CC_FILE=py_module.cc - .PHONY = yml cc all: yml cc diff --git a/gen/examples/synth_shed/config.json b/gen/examples/ext/synth_shed/gen/config.json similarity index 82% rename from gen/examples/synth_shed/config.json rename to gen/examples/ext/synth_shed/gen/config.json index 0f53e81..eb53bb5 100644 --- a/gen/examples/synth_shed/config.json +++ b/gen/examples/ext/synth_shed/gen/config.json @@ -1,6 +1,6 @@ { "module_name": "synth_shed", - "header_filename": "../../src/synth_shed/synth_shed.h", + "header_filename": "../../../../examples/lib/synth_shed/synth_shed.h", "libclang_path": "/opt/local/libexec/llvm-9.0/lib/libclang.dylib", "variables": [ ], diff --git a/gen/examples/ext/synth_shed/synth_shed.cc b/gen/examples/ext/synth_shed/synth_shed.cc new file mode 100644 index 0000000..640f72c --- /dev/null +++ b/gen/examples/ext/synth_shed/synth_shed.cc @@ -0,0 +1,14 @@ +#include +#include +#include +#include +#include "synth_shed.h" + +using namespace std; + +PYBIND11_MODULE(synth_shed, m) { + #include "gen/py_module.cc" + + +} + diff --git a/gen/examples/synth_shed/Makefile.conf b/gen/examples/synth_shed/Makefile.conf deleted file mode 100644 index 00bfd37..0000000 --- a/gen/examples/synth_shed/Makefile.conf +++ /dev/null @@ -1,5 +0,0 @@ -YML2_PATH=$(HOME)/src/pepbase/default/yml2 -YML2_PROC=$(YML2_PATH)/yml2proc $(YML2_OPTS) -YML2_OPTS=--encoding=utf8 - -GEN_CID_DIR=../../gen_cid/