diff --git a/bind/gen.go b/bind/gen.go index 05fd70e..4d4d243 100644 --- a/bind/gen.go +++ b/bind/gen.go @@ -52,7 +52,9 @@ package main %[3]s // #define Py_LIMITED_API // need full API for PyRun* #include +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L) typedef uint8_t bool; +#endif // static inline is trick for avoiding need for extra .c file // the following are used for build value -- switch on reflect.Kind // or the types equivalent @@ -410,7 +412,7 @@ build: $(GOIMPORTS) -w %[1]s.go # this will otherwise be built during go build and may be out of date - rm %[1]s.c - echo "typedef uint8_t bool;" > %[1]s_go.h + printf "#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L)\ntypedef uint8_t bool;\n#endif\n" > %[1]s_go.h # this will fail but is needed to generate the .c file that then allows go build to work - $(PYTHON) build.py >/dev/null 2>&1 # generate %[1]s_go.h from %[1]s.go -- unfortunately no way to build .h only diff --git a/cmd_build.go b/cmd_build.go index 6c63dff..24b0191 100644 --- a/cmd_build.go +++ b/cmd_build.go @@ -125,7 +125,7 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error { if mode == bind.ModeExe { of, err := os.Create(buildname + ".h") // overwrite existing - fmt.Fprintf(of, "typedef uint8_t bool;\n") + fmt.Fprintf(of, "#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 202311L)\ntypedef uint8_t bool;\n#endif\n") of.Close() fmt.Printf("%v build.py # will fail, but needed to generate .c file\n", cfg.VM)