# Makefile for python interface for package poly.
# File is generated by gopy. Do not edit.
# gopy pkg -vm=python3 github.com/bebop/poly

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

# get the CC and flags used to build python:
GCC = $(shell $(GOCMD) env CC)
CFLAGS = "-I/opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/include/python3.13"
LDFLAGS = "-L/opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/lib" "-lpython3.13" -ldl  -framework CoreFoundation 

all: gen build

gen:
	gopy pkg -no-make -vm=python3 github.com/bebop/poly

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 poly.c
	# goimports is needed to ensure that the imports list is valid
	$(GOIMPORTS) -w poly.go
	# generate poly_go$(LIBEXT) from poly.go -- the cgo wrappers to go functions
	$(GOBUILD) -buildmode=c-shared -o poly_go$(LIBEXT) poly.go
	# use pybindgen to build the poly.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 _poly$(LIBEXT) library that contains the cgo and CPython wrappers
	# generated poly.py python wrapper imports this c-code package
	
	$(GCC) poly.c -dynamiclib poly_go$(LIBEXT) -o _poly$(LIBEXT) $(CFLAGS) $(LDFLAGS) -fPIC --shared -w
	


