Skip to content

Commit

Permalink
Merge pull request #70 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 3.2.0
  • Loading branch information
andyone authored Sep 6, 2024
2 parents 201ee02 + f329bbd commit 894d794
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -111,8 +117,9 @@ 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.1.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 3.2.0\033[0m\n'

################################################################################
22 changes: 21 additions & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"
Expand Down Expand Up @@ -92,6 +93,7 @@ type Makefile struct {
Benchmark bool
Race bool
Strip bool
CGO bool
HasSubpackages bool
HasStableImports bool

Expand All @@ -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},
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -1148,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"
Expand Down Expand Up @@ -1184,6 +1189,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"
Expand All @@ -1203,6 +1212,16 @@ 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 += "else\n"
result += "export CGO_ENABLED=0\n"
result += "endif\n\n"
}

if m.ModUsed {
result += "COMPAT ?= 1.19\n"
}
Expand Down Expand Up @@ -1303,6 +1322,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")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=

0 comments on commit 894d794

Please sign in to comment.