Skip to content

Commit b9902d7

Browse files
author
Randall C. O'Reilly
committed
add a -no-make flag, which prevents overwriting the generated Makefile when run from the Makefile. add extra -Wno-error -Wno-implicit-function-declaration CFLAGS to fix Xcode 12 and make actual errors more visible
1 parent 6d8fa23 commit b9902d7

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

bind/gen.go

+24-7
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ build:
356356
# this will fail but is needed to generate the .c file that then allows go build to work
357357
- $(PYTHON) build.py >/dev/null 2>&1
358358
# generate %[1]s_go.h from %[1]s.go -- unfortunately no way to build .h only
359-
$(GOBUILD) -buildmode=c-shared -o %[1]s_go$(LIBEXT) >/dev/null 2>&1
359+
$(GOBUILD) -buildmode=c-shared -o %[1]s_go$(LIBEXT)
360360
# use pybindgen to build the %[1]s.c file which are the CPython wrappers to cgo wrappers..
361361
# note: pip install pybindgen to get pybindgen if this fails
362362
$(PYTHON) build.py
@@ -457,6 +457,9 @@ var thePyGen *pyGen
457457
// before e.g., thePyGen is present.
458458
var NoWarn = false
459459

460+
// NoMake turns off generation of Makefiles
461+
var NoMake = false
462+
460463
// GenPyBind generates a .go file, build.py file to enable pybindgen to create python bindings,
461464
// and wrapper .py file(s) that are loaded as the interface to the package with shadow
462465
// python-side classes
@@ -538,11 +541,15 @@ func (g *pyGen) genPre() {
538541
g.gofile = &printer{buf: new(bytes.Buffer), indentEach: []byte("\t")}
539542
g.leakfile = &printer{buf: new(bytes.Buffer), indentEach: []byte("\t")}
540543
g.pybuild = &printer{buf: new(bytes.Buffer), indentEach: []byte("\t")}
541-
g.makefile = &printer{buf: new(bytes.Buffer), indentEach: []byte("\t")}
544+
if !NoMake {
545+
g.makefile = &printer{buf: new(bytes.Buffer), indentEach: []byte("\t")}
546+
}
542547
g.genGoPreamble()
543548
g.genLeaksPreamble()
544549
g.genPyBuildPreamble()
545-
g.genMakefile()
550+
if !NoMake {
551+
g.genMakefile()
552+
}
546553
oinit, err := os.Create(filepath.Join(g.odir, "__init__.py"))
547554
g.err.Add(err)
548555
err = oinit.Close()
@@ -562,11 +569,13 @@ func (g *pyGen) genOut() {
562569
g.pybuild.Printf("\nmod.generate(open('%v.c', 'w'))\n\n", g.outname)
563570
g.gofile.Printf("\n\n")
564571
g.genLeaksPostamble()
565-
g.makefile.Printf("\n\n")
566572
g.genPrintOut(g.outname+".go", g.gofile)
567573
g.genPrintOut("patch-leaks.go", g.leakfile)
568574
g.genPrintOut("build.py", g.pybuild)
569-
g.genPrintOut("Makefile", g.makefile)
575+
if !NoMake {
576+
g.makefile.Printf("\n\n")
577+
g.genPrintOut("Makefile", g.makefile)
578+
}
570579
}
571580

572581
func (g *pyGen) genPkgWrapOut() {
@@ -611,10 +620,12 @@ func (g *pyGen) genGoPreamble() {
611620
if err != nil {
612621
panic(err)
613622
}
623+
// this is critical to avoid pybindgen errors:
624+
exflags := " -Wno-error -Wno-implicit-function-declaration -Wno-int-conversion"
614625
pkgcfg := fmt.Sprintf(`
615626
#cgo CFLAGS: %s
616627
#cgo LDFLAGS: %s
617-
`, pycfg.cflags, pycfg.ldflags)
628+
`, pycfg.cflags+exflags, pycfg.ldflags)
618629

619630
return pkgcfg
620631
}()
@@ -688,7 +699,13 @@ func CmdStrToMakefile(cmdstr string) string {
688699
spidx := strings.Index(cmdstr[oidx:], " ")
689700
cmdstr = cmdstr[:oidx] + cmdstr[oidx+spidx+1:]
690701
}
691-
return cmdstr
702+
cmds := strings.Fields(cmdstr)
703+
ncmds := make([]string, 0, len(cmds)+1)
704+
ncmds = append(ncmds, cmds[:2]...)
705+
ncmds = append(ncmds, "-no-make")
706+
ncmds = append(ncmds, cmds[2:]...)
707+
708+
return strings.Join(ncmds, " ")
692709
}
693710

694711
func (g *pyGen) genMakefile() {

cmd_build.go

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ex:
3939
cmd.Flag.String("main", "", "code string to run in the go main() function in the cgo library")
4040
cmd.Flag.Bool("symbols", true, "include symbols in output")
4141
cmd.Flag.Bool("no-warn", false, "suppress warning messages, which may be expected")
42+
cmd.Flag.Bool("no-make", false, "do not generate a Makefile, e.g., when called from Makefile")
4243
return cmd
4344
}
4445

@@ -56,9 +57,11 @@ func gopyRunCmdBuild(cmdr *commander.Command, args []string) error {
5657
vm = cmdr.Flag.Lookup("vm").Value.Get().(string)
5758
symbols = cmdr.Flag.Lookup("symbols").Value.Get().(bool)
5859
nowarn = cmdr.Flag.Lookup("no-warn").Value.Get().(bool)
60+
nomake = cmdr.Flag.Lookup("no-make").Value.Get().(bool)
5961
)
6062

6163
bind.NoWarn = nowarn
64+
bind.NoMake = nomake
6265

6366
cmdstr := argStr()
6467

cmd_exe.go

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ex:
5353
cmd.Flag.String("desc", "", "short description of project (long comes from README.md)")
5454
cmd.Flag.String("url", "https://github.com/go-python/gopy", "home page for project")
5555
cmd.Flag.Bool("no-warn", false, "suppress warning messages, which may be expected")
56+
cmd.Flag.Bool("no-make", false, "do not generate a Makefile, e.g., when called from Makefile")
5657

5758
return cmd
5859
}
@@ -78,11 +79,13 @@ func gopyRunCmdExe(cmdr *commander.Command, args []string) error {
7879
desc = cmdr.Flag.Lookup("desc").Value.Get().(string)
7980
url = cmdr.Flag.Lookup("url").Value.Get().(string)
8081
nowarn = cmdr.Flag.Lookup("no-warn").Value.Get().(bool)
82+
nomake = cmdr.Flag.Lookup("no-make").Value.Get().(bool)
8183
)
8284

8385
cmdstr := argStr()
8486

8587
bind.NoWarn = nowarn
88+
bind.NoMake = nomake
8689

8790
if name == "" {
8891
path := args[0]

cmd_gen.go

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ex:
3333
cmd.Flag.String("name", "", "name of output package (otherwise name of first package is used)")
3434
cmd.Flag.String("main", "", "code string to run in the go main() function in the cgo library")
3535
cmd.Flag.Bool("no-warn", false, "suppress warning messages, which may be expected")
36+
cmd.Flag.Bool("no-make", false, "do not generate a Makefile, e.g., when called from Makefile")
3637
return cmd
3738
}
3839

@@ -53,13 +54,15 @@ func gopyRunCmdGen(cmdr *commander.Command, args []string) error {
5354
name = cmdr.Flag.Lookup("name").Value.Get().(string)
5455
mainstr = cmdr.Flag.Lookup("main").Value.Get().(string)
5556
nowarn = cmdr.Flag.Lookup("no-warn").Value.Get().(bool)
57+
nomake = cmdr.Flag.Lookup("no-make").Value.Get().(bool)
5658
)
5759

5860
if vm == "" {
5961
vm = "python"
6062
}
6163

6264
bind.NoWarn = nowarn
65+
bind.NoMake = nomake
6366

6467
for _, path := range args {
6568
pkg, err := newPackage(path)

cmd_pkg.go

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ ex:
5151
cmd.Flag.String("desc", "", "short description of project (long comes from README.md)")
5252
cmd.Flag.String("url", "https://github.com/go-python/gopy", "home page for project")
5353
cmd.Flag.Bool("no-warn", false, "suppress warning messages, which may be expected")
54+
cmd.Flag.Bool("no-make", false, "do not generate a Makefile, e.g., when called from Makefile")
5455

5556
return cmd
5657
}
@@ -76,11 +77,13 @@ func gopyRunCmdPkg(cmdr *commander.Command, args []string) error {
7677
desc = cmdr.Flag.Lookup("desc").Value.Get().(string)
7778
url = cmdr.Flag.Lookup("url").Value.Get().(string)
7879
nowarn = cmdr.Flag.Lookup("no-warn").Value.Get().(bool)
80+
nomake = cmdr.Flag.Lookup("no-make").Value.Get().(bool)
7981
)
8082

8183
cmdstr := argStr()
8284

8385
bind.NoWarn = nowarn
86+
bind.NoMake = nomake
8487

8588
if name == "" {
8689
path := args[0]

0 commit comments

Comments
 (0)