@@ -436,10 +436,10 @@ def Init():
436436
437437 `
438438
439- // 3 = gencmd, 4 = vm, 5 = libext 6 = extraGccArgs, 7 = CFLAGS, 8 = LDLFAGS ,
440- // 9 = windows special declspec hack, 10 = gopy version
439+ // 3 = gencmd, 4 = vm, 5 = libext, 6 = module file name ,
440+ // 7 = windows special declspec hack, 8 = gopy version
441441 MakefileTemplate = `# Makefile for python interface for package %[1]s.
442- # File is generated by gopy version %[10 ]s. Do not edit.
442+ # File is generated by gopy version %[8 ]s. Do not edit.
443443# %[2]s
444444
445445GOCMD=go
@@ -448,11 +448,6 @@ GOIMPORTS=goimports
448448PYTHON=%[4]s
449449LIBEXT=%[5]s
450450
451- # get the CC and flags used to build python:
452- GCC = $(shell $(GOCMD) env CC)
453- CFLAGS = %[7]s
454- LDFLAGS = %[8]s
455-
456451all: gen build
457452
458453gen:
@@ -464,20 +459,21 @@ build:
464459 - rm %[1]s.c
465460 # goimports is needed to ensure that the imports list is valid
466461 $(GOIMPORTS) -w %[1]s.go
467- # generate %[1]s_go$(LIBEXT) from %[1]s.go -- the cgo wrappers to go functions
462+ # build %[1]s.go -- the cgo wrappers to go functions -- once, only for the
463+ # %[1]s_go.h header it writes, which %[1]s.c includes
468464 $(GOBUILD) -buildmode=c-shared -o %[1]s_go$(LIBEXT) %[1]s.go
469- # use pybindgen to build the %[1]s.c file which are the CPython wrappers to cgo wrappers..
470- # note: pip install pybindgen to get pybindgen if this fails
471- $(PYTHON) build.py
472- # build the _%[1]s$(LIBEXT) library that contains the cgo and CPython wrappers
473- # generated %[1]s.py python wrapper imports this c-code package
474- %[9]s
475- $(GCC) %[1]s.c %[6]s %[1]s_go$(LIBEXT) -o _%[1]s$(LIBEXT) $(CFLAGS) $(LDFLAGS) -fPIC --shared -w
476-
465+ - rm %[1]s_go$(LIBEXT)
466+ # write %[1]s.c, the CPython wrappers to the cgo wrappers
467+ $(PYTHON) build.py%[7]s
468+ # build the module %[1]s.py imports: cgo compiles %[1]s.c into the same
469+ # shared library as the go code, so it depends on nothing but python
470+ $(GOBUILD) -buildmode=c-shared -o %[6]s .
471+
477472`
478473
479- // same argument positions as MakefileTemplate, though only 1-5 and 10 are used:
480- // cffi needs none of the CPython CFLAGS/LDFLAGS that building %[1]s.c would.
474+ // 1 = package name, 2 = gopy command, 3 = gencmd, 4 = vm, 5 = libext,
475+ // 10 = gopy version (6-9 are unused): cffi needs no %[1]s.c, and none of
476+ // the CPython flags that building one would.
481477 MakefileTemplateCFFI = `# Makefile for python interface for package %[1]s, using cffi.
482478# File is generated by gopy version %[10]s. Do not edit.
483479# %[2]s
@@ -896,10 +892,12 @@ func (g *pyGen) genMakefile() {
896892 } else {
897893 winhack := ""
898894 if WindowsOS {
899- winhack = fmt .Sprintf (`# windows-only sed hack here to fix pybindgen declaration of PyInit
900- sed -i "s/ PyInit_/ __declspec(dllexport) PyInit_/g" %s.c` , g .cfg .Name )
895+ winhack = fmt .Sprintf (`
896+ # windows-only sed hack here to fix pybindgen declaration of PyInit
897+ sed -i "s/ PyInit_/ __declspec(dllexport) PyInit_/g" %s.c` , g .cfg .Name )
901898 }
902- g .makefile .Printf (MakefileTemplate , g .cfg .Name , g .cfg .Cmd , gencmd , g .cfg .VM , g .libext , g .extraGccArgs , pycfg .CFlags , pycfg .LdFlags , winhack , g .cfg .Version )
899+ g .makefile .Printf (MakefileTemplate , g .cfg .Name , g .cfg .Cmd , gencmd , g .cfg .VM , g .libext ,
900+ ExtModuleName (g .cfg .Name , g .libext , pycfg ), winhack , g .cfg .Version )
903901 }
904902}
905903
0 commit comments