From 02a39814d30dc2a3b883daee9863905d0e25d3a6 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 5 Sep 2024 16:44:22 +0300 Subject: [PATCH 1/5] Add option '-C'/'--cgo' to force CGO usage --- cli/cli.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cli/cli.go b/cli/cli.go index 432e6ac..492e714 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -47,7 +47,7 @@ import ( // App info const ( APP = "GoMakeGen" - VER = "3.1.0" + VER = "3.2.0" DESC = "Utility for generating makefiles for Go applications" ) @@ -60,6 +60,7 @@ const ( OPT_STRIP = "S:strip" OPT_BENCHMARK = "B:benchmark" OPT_RACE = "R:race" + OPT_CGO = "C:cgo" OPT_NO_COLOR = "nc:no-color" OPT_HELP = "h:help" OPT_VER = "v:version" @@ -92,6 +93,7 @@ type Makefile struct { Benchmark bool Race bool Strip bool + CGO bool HasSubpackages bool HasStableImports bool @@ -111,6 +113,7 @@ var optMap = options.Map{ OPT_STRIP: {Type: options.BOOL}, OPT_BENCHMARK: {Type: options.BOOL}, OPT_RACE: {Type: options.BOOL}, + OPT_CGO: {Type: options.BOOL}, OPT_NO_COLOR: {Type: options.BOOL}, OPT_HELP: {Type: options.BOOL}, OPT_VER: {Type: options.MIXED}, @@ -264,6 +267,7 @@ func generateMakefile(sources []string, dir string) *Makefile { makefile.Benchmark = makefile.Benchmark || options.GetB(OPT_BENCHMARK) makefile.Race = makefile.Race || options.GetB(OPT_RACE) + makefile.CGO = makefile.CGO || options.GetB(OPT_CGO) makefile.Strip = makefile.Strip || options.GetB(OPT_STRIP) makefile.GlideUsed = makefile.GlideUsed || options.GetB(OPT_GLIDE) || fsutil.IsExist(dir+"/glide.yaml") makefile.DepUsed = makefile.DepUsed || options.GetB(OPT_DEP) || fsutil.IsExist(dir+"/Gopkg.toml") @@ -1184,6 +1188,10 @@ func (m *Makefile) getGenerationComment() string { result += fmt.Sprintf("--%s ", getOptionName(OPT_RACE)) } + if m.CGO { + result += fmt.Sprintf("--%s ", getOptionName(OPT_CGO)) + } + result += ".\n" result += "#\n" result += "# More info: https://kaos.sh/gomakegen\n\n" @@ -1203,6 +1211,14 @@ func (m *Makefile) getDefaultVariables() string { result += "export GOPROXY=https://proxy.golang.org/cached-only,direct\n" result += "endif\n\n" + if m.CGO { + result += "export CGO_ENABLED=1\n\n" + } else { + result += "ifdef CGO ## Enable CGO usage (Flag)\n" + result += "export CGO_ENABLED=1\n" + result += "endif\n\n" + } + if m.ModUsed { result += "COMPAT ?= 1.19\n" } @@ -1303,6 +1319,7 @@ func genUsage() *usage.Info { info.AddOption(OPT_STRIP, "Strip binaries") info.AddOption(OPT_BENCHMARK, "Add target to run benchmarks") info.AddOption(OPT_RACE, "Add target to test race conditions") + info.AddOption(OPT_CGO, "Enable CGO usage") info.AddOption(OPT_OUTPUT, "Output file {s-}(Makefile by default){!}", "file") info.AddOption(OPT_NO_COLOR, "Disable colors in output") info.AddOption(OPT_HELP, "Show this help message") From 655136cc3aadb32b77a4693f433ecd3e226b42b4 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 6 Sep 2024 14:52:10 +0300 Subject: [PATCH 2/5] Improve CGO env var export generation --- cli/cli.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/cli.go b/cli/cli.go index 492e714..0a813f3 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -1216,6 +1216,8 @@ func (m *Makefile) getDefaultVariables() string { } else { result += "ifdef CGO ## Enable CGO usage (Flag)\n" result += "export CGO_ENABLED=1\n" + result += "else\n" + result += "export CGO_ENABLED=0\n" result += "endif\n\n" } From 68cd125aca1ce5a6079f7fb08cced44103b8a1cb Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 6 Sep 2024 14:52:57 +0300 Subject: [PATCH 3/5] Regenerate Makefile with the latest version of gomakegen --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 081db21..623dd04 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ################################################################################ -# This Makefile generated by GoMakeGen 3.1.0 using next command: +# This Makefile generated by GoMakeGen 3.2.0 using next command: # gomakegen --mod --strip . # # More info: https://kaos.sh/gomakegen @@ -15,6 +15,12 @@ ifdef PROXY ## Force proxy usage for downloading dependencies (Flag) export GOPROXY=https://proxy.golang.org/cached-only,direct endif +ifdef CGO ## Enable CGO usage (Flag) +export CGO_ENABLED=1 +else +export CGO_ENABLED=0 +endif + COMPAT ?= 1.19 MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) @@ -113,6 +119,6 @@ help: ## Show this info | sed 's/ifdef //' \ | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 3.1.0\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 3.2.0\033[0m\n' ################################################################################ From 1854570f79a838cefe981331d94b3c37f898e379 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 6 Sep 2024 15:06:07 +0300 Subject: [PATCH 4/5] Add variables sorting in 'help' target output --- Makefile | 1 + cli/cli.go | 1 + 2 files changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 623dd04..45f75c8 100644 --- a/Makefile +++ b/Makefile @@ -117,6 +117,7 @@ help: ## Show this info @echo -e '\n\033[1mVariables:\033[0m\n' @grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \ | sed 's/ifdef //' \ + | sort -h \ | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}' @echo -e '' @echo -e '\033[90mGenerated by GoMakeGen 3.2.0\033[0m\n' diff --git a/cli/cli.go b/cli/cli.go index 0a813f3..8b2d753 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -1152,6 +1152,7 @@ func (m *Makefile) getHelpTarget() string { result += "\t@echo -e '\\n\\033[1mVariables:\\033[0m\\n'\n" result += "\t@grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \\\n" result += "\t\t| sed 's/ifdef //' \\\n" + result += "\t\t| sort -h \\\n" result += "\t\t| awk 'BEGIN {FS = \" .*?## \"}; {printf \" \\033[32m%-" + optionNameSize + "s\\033[0m %s\\n\", $$1, $$2}'\n" result += "\t@echo -e ''\n" result += "\t@echo -e '\\033[90mGenerated by GoMakeGen " + VER + "\\033[0m\\n'\n\n" From f329bbda83c48ef5046645dd5e36aee0de87d25c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 6 Sep 2024 15:14:41 +0300 Subject: [PATCH 5/5] Dependencies update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5f738d9..8c39fb3 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,5 @@ require github.com/essentialkaos/ek/v13 v13.3.5 require ( github.com/essentialkaos/depsy v1.3.0 // indirect - golang.org/x/sys v0.24.0 // indirect + golang.org/x/sys v0.25.0 // indirect ) diff --git a/go.sum b/go.sum index d14056a..6117cc7 100644 --- a/go.sum +++ b/go.sum @@ -10,5 +10,5 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=