# Makefile for python interface for package pycymbal.
# File is generated by gopy. Do not edit.
# gopy gen -vm=python3 ./pycymbal

GOCMD=go
GOBUILD=$(GOCMD) build -mod=mod
GOIMPORTS=goimports
PYTHON=/opt/hostedtoolcache/Python/3.12.13/x64/bin/python3
LIBEXT=.so

# get the CC and flags used to build python:
GCC = $(shell $(GOCMD) env CC)
CFLAGS = -I/opt/hostedtoolcache/Python/3.12.13/x64/include/python3.12
LDFLAGS = -L/opt/hostedtoolcache/Python/3.12.13/x64/lib -lpython3.12 -ldl -lm

all: gen build

gen:
	gopy gen -no-make -vm=python3 ./pycymbal

build:
	# build target builds the generated files -- this is what gopy build does..
	# this will otherwise be built during go build and may be out of date
	- rm pycymbal.c
	# goimports is needed to ensure that the imports list is valid
	$(GOIMPORTS) -w pycymbal.go
	# generate pycymbal_go$(LIBEXT) from pycymbal.go -- the cgo wrappers to go functions
	$(GOBUILD) -buildmode=c-shared -o pycymbal_go$(LIBEXT) pycymbal.go
	# use pybindgen to build the pycymbal.c file which are the CPython wrappers to cgo wrappers..
	# note: pip install pybindgen to get pybindgen if this fails
	$(PYTHON) build.py
	# build the _pycymbal$(LIBEXT) library that contains the cgo and CPython wrappers
	# generated pycymbal.py python wrapper imports this c-code package
	
	$(GCC) pycymbal.c  pycymbal_go$(LIBEXT) -o _pycymbal$(LIBEXT) -Wl,-rpath,'$$ORIGIN' $(CFLAGS) $(LDFLAGS) -fPIC --shared -w
	


