Browse Source

golang: Add support for setting gcflags/ldflags from package Makefile

This adds several variables for Go package Makefiles:
* GO_PKG_GCFLAGS - go tool compile arguments
* GO_PKG_LDFLAGS - go tool link arguments
* GO_PKG_LDFLAGS_X - go tool link -X definitions

Settings these will add the corresponding flags to the go install
command line. (Other command line arguments can still be added by
passing them as the first argument to GoPackage/Build/Compile.)

This also adds Go's runtime environment variables (GOGC, GOMAXPROCS,
GOTRACEBACK) to the unexport list.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
lilik-openwrt-22.03
Jeffery To 6 years ago
committed by Yousong Zhou
parent
commit
0d3ec704b0
2 changed files with 35 additions and 5 deletions
  1. +33
    -4
      lang/golang/golang-package.mk
  2. +2
    -1
      lang/golang/golang-values.mk

+ 33
- 4
lang/golang/golang-package.mk View File

@ -76,6 +76,28 @@ include $(GO_INCLUDE_DIR)/golang-values.mk
# not necessary.
#
# e.g. GO_PKG_GO_GENERATE:=1
#
#
# GO_PKG_GCFLAGS - list of arguments, default empty
#
# Additional go tool compile arguments to use when building targets.
#
# e.g. GO_PKG_GCFLAGS:=-N -l
#
#
# GO_PKG_LDFLAGS - list of arguments, default empty
#
# Additional go tool link arguments to use when building targets.
#
# e.g. GO_PKG_LDFLAGS:=-s -w
#
#
# GO_PKG_LDFLAGS_X - list of string variable definitions, default empty
#
# Each definition will be passed as the parameter to the -X go tool
# link argument, i.e. -ldflags "-X importpath.name=value"
#
# e.g. GO_PKG_LDFLAGS_X:=main.Version=$(PKG_VERSION) main.BuildStamp=$(SOURCE_DATE_EPOCH)
# Credit for this package build process (GoPackage/Build/Configure and
# GoPackage/Build/Compile) belong to Debian's dh-golang completely.
@ -247,18 +269,25 @@ define GoPackage/Build/Compile
if [ "$(GO_PKG_SOURCE_ONLY)" != 1 ]; then \
echo "Building targets" ; \
case $(GO_ARCH) in \
arm) installsuffix="-installsuffix v$(GO_ARM)" ;; \
mips|mipsle) installsuffix="-installsuffix $(GO_MIPS)" ;; \
mips64|mips64le) installsuffix="-installsuffix $(GO_MIPS64)" ;; \
arm) installsuffix="v$(GO_ARM)" ;; \
mips|mipsle) installsuffix="$(GO_MIPS)" ;; \
mips64|mips64le) installsuffix="$(GO_MIPS64)" ;; \
esac ; \
trimpath="all=-trimpath=$(GO_PKG_BUILD_DIR)" ; \
ldflags="all=-linkmode external -extldflags '$(TARGET_LDFLAGS)'" ; \
pkg_gcflags="$(GO_PKG_GCFLAGS)" ; \
pkg_ldflags="$(GO_PKG_LDFLAGS)" ; \
for def in $(GO_PKG_LDFLAGS_X); do \
pkg_ldflags="$$$$pkg_ldflags -X $$$$def" ; \
done ; \
go install \
$$$$installsuffix \
$$$${installsuffix:+-installsuffix $$$$installsuffix} \
-gcflags "$$$$trimpath" \
-asmflags "$$$$trimpath" \
-ldflags "$$$$ldflags" \
-v \
$$$${pkg_gcflags:+-gcflags "$$$$pkg_gcflags"} \
$$$${pkg_ldflags:+-ldflags "$$$$pkg_ldflags"} \
$(1) \
$$$$targets ; \
retval=$$$$? ; \


+ 2
- 1
lang/golang/golang-values.mk View File

@ -13,7 +13,8 @@ include $(GO_INCLUDE_DIR)/golang-version.mk
unexport \
GOARCH GOBIN GOCACHE GODEBUG GOFLAGS GOHOSTARCH GOOS GOPATH GORACE GOROOT GOTMPDIR GCCGO \
GOARCH GOBIN GOCACHE GOFLAGS GOHOSTARCH GOOS GOPATH GORACE GOROOT GOTMPDIR GCCGO \
GOGC GODEBUG GOMAXPROCS GOTRACEBACK \
CGO_ENABLED \
CGO_CFLAGS CGO_CFLAGS_ALLOW CGO_CFLAGS_DISALLOW \
CGO_CPPFLAGS CGO_CPPFLAGS_ALLOW CGO_CPPFLAGS_DISALLOW \


Loading…
Cancel
Save