@@ -46,7 +46,7 @@ File is generated by gopy. Do not edit.
46
46
package main
47
47
48
48
/*
49
- #cgo pkg-config: %[3]s
49
+ %[3]s
50
50
// #define Py_LIMITED_API // need full API for PyRun*
51
51
#include <Python.h>
52
52
typedef uint8_t bool;
@@ -268,13 +268,12 @@ GOCMD=go
268
268
GOBUILD=$(GOCMD) build
269
269
GOIMPORTS=goimports
270
270
PYTHON=%[4]s
271
- PYTHON_CFG=$(PYTHON)-config
272
271
LIBEXT=%[5]s
273
272
274
273
# get the CC and flags used to build python:
275
274
GCC = $(shell $(GOCMD) env CC)
276
- CFLAGS = $(shell $(PYTHON_CFG) --cflags)
277
- LDFLAGS = $(shell $(PYTHON_CFG) --ldflags)
275
+ CFLAGS = %[7]s
276
+ LDFLAGS = %[8]s
278
277
279
278
all: gen build
280
279
@@ -294,7 +293,7 @@ build:
294
293
$(PYTHON) build.py
295
294
# build the _%[1]s$(LIBEXT) library that contains the cgo and CPython wrappers
296
295
# generated %[1]s.py python wrapper imports this c-code package
297
- $(GCC) %[1]s.c %[6]s %[1]s_go$(LIBEXT) -o _%[1]s$(LIBEXT) $(CFLAGS) $(LDFLAGS) -w
296
+ $(GCC) %[1]s.c %[6]s %[1]s_go$(LIBEXT) -o _%[1]s$(LIBEXT) $(CFLAGS) $(LDFLAGS) -fPIC --shared - w
298
297
299
298
`
300
299
@@ -307,13 +306,12 @@ GOCMD=go
307
306
GOBUILD=$(GOCMD) build
308
307
GOIMPORTS=goimports
309
308
PYTHON=%[4]s
310
- PYTHON_CFG=$(PYTHON)-config
311
309
LIBEXT=%[5]s
310
+ CFLAGS = %[6]s
311
+ LDFLAGS = %[7]s
312
312
313
313
# get the flags used to build python:
314
314
GCC = $(shell $(GOCMD) env CC)
315
- CFLAGS = $(shell $(PYTHON_CFG) --cflags)
316
- LDFLAGS = $(shell $(PYTHON_CFG) --ldflags)
317
315
318
316
all: gen build
319
317
@@ -476,9 +474,19 @@ func (g *pyGen) genGoPreamble() {
476
474
for pi , _ := range current .imports {
477
475
pkgimport += fmt .Sprintf ("\n \t %q" , pi )
478
476
}
479
- pypath , pyonly := filepath .Split (g .vm )
480
- pyroot , _ := filepath .Split (filepath .Clean (pypath ))
481
- libcfg := filepath .Join (filepath .Join (filepath .Join (pyroot , "lib" ), "pkgconfig" ), pyonly + ".pc" )
477
+ libcfg := func () string {
478
+ pycfg , err := getPythonConfig (g .vm )
479
+ if err != nil {
480
+ panic (err )
481
+ }
482
+ pkgcfg := fmt .Sprintf (`
483
+ #cgo CFLAGS: %s
484
+ #cgo LDFLAGS: %s
485
+ ` , pycfg .cflags , pycfg .ldflags )
486
+
487
+ return pkgcfg
488
+ }()
489
+
482
490
if g .mode == ModeExe && g .mainstr == "" {
483
491
g .mainstr = "GoPyMainRun()" // default is just to run main
484
492
}
@@ -549,10 +557,16 @@ func CmdStrToMakefile(cmdstr string) string {
549
557
func (g * pyGen ) genMakefile () {
550
558
gencmd := strings .Replace (g .cmdstr , "gopy build" , "gopy gen" , 1 )
551
559
gencmd = CmdStrToMakefile (gencmd )
560
+
561
+ pycfg , err := getPythonConfig (g .vm )
562
+ if err != nil {
563
+ panic (err )
564
+ }
565
+
552
566
if g .mode == ModeExe {
553
- g .makefile .Printf (MakefileExeTemplate , g .outname , g .cmdstr , gencmd , g .vm , g .libext )
567
+ g .makefile .Printf (MakefileExeTemplate , g .outname , g .cmdstr , gencmd , g .vm , g .libext , pycfg . cflags , pycfg . ldflags )
554
568
} else {
555
- g .makefile .Printf (MakefileTemplate , g .outname , g .cmdstr , gencmd , g .vm , g .libext , g .extraGccArgs )
569
+ g .makefile .Printf (MakefileTemplate , g .outname , g .cmdstr , gencmd , g .vm , g .libext , g .extraGccArgs , pycfg . cflags , pycfg . ldflags )
556
570
}
557
571
}
558
572
0 commit comments