2018-03-17 17:32:35 +01:00
|
|
|
#
|
2020-07-16 05:55:15 +02:00
|
|
|
# Copyright (C) 2018-2020 Jeffery To
|
2018-03-17 17:32:35 +01:00
|
|
|
#
|
|
|
|
# This is free software, licensed under the GNU General Public License v2.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
#
|
|
|
|
|
|
|
|
ifeq ($(origin GO_INCLUDE_DIR),undefined)
|
|
|
|
GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
|
|
|
endif
|
|
|
|
|
|
|
|
include $(GO_INCLUDE_DIR)/golang-values.mk
|
|
|
|
|
|
|
|
|
|
|
|
# Variables (all optional, except GO_PKG) to be set in package
|
|
|
|
# Makefiles:
|
|
|
|
#
|
|
|
|
# GO_PKG (required) - name of Go package
|
|
|
|
#
|
|
|
|
# Go name of the package.
|
|
|
|
#
|
|
|
|
# e.g. GO_PKG:=golang.org/x/text
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_INSTALL_EXTRA - list of regular expressions, default empty
|
|
|
|
#
|
|
|
|
# Additional files/directories to install. By default, only these
|
|
|
|
# files are installed:
|
|
|
|
#
|
|
|
|
# * Files with one of these extensions:
|
2019-02-09 12:52:49 +01:00
|
|
|
# .go, .c, .cc, .cpp, .h, .hh, .hpp, .proto, .s
|
2018-03-17 17:32:35 +01:00
|
|
|
#
|
|
|
|
# * Files in any 'testdata' directory
|
|
|
|
#
|
2019-02-09 13:00:56 +01:00
|
|
|
# * go.mod and go.sum, in any directory
|
|
|
|
#
|
2018-03-17 17:32:35 +01:00
|
|
|
# e.g. GO_PKG_INSTALL_EXTRA:=example.toml marshal_test.toml
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_INSTALL_ALL - boolean (0 or 1), default false
|
|
|
|
#
|
|
|
|
# If true, install all files regardless of extension or directory.
|
|
|
|
#
|
|
|
|
# e.g. GO_PKG_INSTALL_ALL:=1
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_SOURCE_ONLY - boolean (0 or 1), default false
|
|
|
|
#
|
|
|
|
# If true, 'go install' will not be called. If the package does not
|
|
|
|
# (or should not) build any binaries, then specifying this option will
|
|
|
|
# save build time.
|
|
|
|
#
|
|
|
|
# e.g. GO_PKG_SOURCE_ONLY:=1
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_BUILD_PKG - list of build targets, default GO_PKG/...
|
|
|
|
#
|
|
|
|
# Build targets for compiling this Go package, i.e. arguments passed
|
2020-07-16 05:55:15 +02:00
|
|
|
# to 'go install'.
|
2018-03-17 17:32:35 +01:00
|
|
|
#
|
|
|
|
# e.g. GO_PKG_BUILD_PKG:=github.com/debian/ratt/cmd/...
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_EXCLUDES - list of regular expressions, default empty
|
|
|
|
#
|
|
|
|
# Patterns to exclude from the build targets expanded from
|
|
|
|
# GO_PKG_BUILD_PKG.
|
|
|
|
#
|
|
|
|
# e.g. GO_PKG_EXCLUDES:=examples/
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_GO_GENERATE - boolean (0 or 1), default false
|
|
|
|
#
|
|
|
|
# If true, 'go generate' will be called on all build targets (as
|
|
|
|
# determined by GO_PKG_BUILD_PKG and GO_PKG_EXCLUDES). This is usually
|
|
|
|
# not necessary.
|
|
|
|
#
|
|
|
|
# e.g. GO_PKG_GO_GENERATE:=1
|
2019-03-20 21:26:10 +01:00
|
|
|
#
|
|
|
|
#
|
2020-07-16 05:55:15 +02:00
|
|
|
# GO_PKG_GCFLAGS - list of options, default empty
|
2019-03-20 21:26:10 +01:00
|
|
|
#
|
2020-07-16 05:55:15 +02:00
|
|
|
# Additional go tool compile options to use when building targets.
|
2019-03-20 21:26:10 +01:00
|
|
|
#
|
|
|
|
# e.g. GO_PKG_GCFLAGS:=-N -l
|
|
|
|
#
|
|
|
|
#
|
2020-07-16 05:55:15 +02:00
|
|
|
# GO_PKG_LDFLAGS - list of options, default empty
|
2019-03-20 21:26:10 +01:00
|
|
|
#
|
2020-07-16 05:55:15 +02:00
|
|
|
# Additional go tool link options to use when building targets.
|
2019-03-20 21:26:10 +01:00
|
|
|
#
|
2020-05-12 13:54:14 +02:00
|
|
|
# Note that the OpenWrt build system has an option to strip binaries
|
|
|
|
# (enabled by default), so -s (Omit the symbol table and debug
|
|
|
|
# information) and -w (Omit the DWARF symbol table) flags are not
|
|
|
|
# necessary.
|
|
|
|
#
|
|
|
|
# e.g. GO_PKG_LDFLAGS:=-r dir1:dir2 -u
|
2019-03-20 21:26:10 +01:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_LDFLAGS_X - list of string variable definitions, default empty
|
|
|
|
#
|
|
|
|
# Each definition will be passed as the parameter to the -X go tool
|
2020-07-16 05:55:15 +02:00
|
|
|
# link option, i.e. -ldflags "-X importpath.name=value".
|
2019-03-20 21:26:10 +01:00
|
|
|
#
|
|
|
|
# e.g. GO_PKG_LDFLAGS_X:=main.Version=$(PKG_VERSION) main.BuildStamp=$(SOURCE_DATE_EPOCH)
|
2020-07-16 05:55:15 +02:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# GO_PKG_TAGS - list of build tags, default empty
|
|
|
|
#
|
|
|
|
# Build tags to consider satisfied during the build, passed as the
|
|
|
|
# parameter to the -tags option for 'go install'.
|
|
|
|
#
|
|
|
|
# e.g. GO_PKG_TAGS:=release,noupgrade
|
2018-03-17 17:32:35 +01:00
|
|
|
|
|
|
|
# Credit for this package build process (GoPackage/Build/Configure and
|
|
|
|
# GoPackage/Build/Compile) belong to Debian's dh-golang completely.
|
2019-02-09 12:52:49 +01:00
|
|
|
# https://salsa.debian.org/go-team/packages/dh-golang
|
2018-03-17 17:32:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
# for building packages, not user code
|
|
|
|
GO_PKG_PATH:=/usr/share/gocode
|
|
|
|
|
2020-01-07 18:22:05 +01:00
|
|
|
GO_PKG_BUILD_PKG?=$(strip $(GO_PKG))/...
|
2018-03-17 17:32:35 +01:00
|
|
|
|
|
|
|
GO_PKG_WORK_DIR_NAME:=.go_work
|
2020-08-23 22:59:05 +02:00
|
|
|
GO_PKG_BUILD_DIR=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)/build
|
2020-06-28 20:18:34 +02:00
|
|
|
GO_PKG_BUILD_BIN_DIR=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$(GO_OS_ARCH))
|
2018-03-17 17:32:35 +01:00
|
|
|
|
2020-06-28 20:18:34 +02:00
|
|
|
GO_PKG_BUILD_DEPENDS_SRC=$(STAGING_DIR)$(GO_PKG_PATH)/src
|
2018-03-17 17:32:35 +01:00
|
|
|
|
2020-01-15 12:36:09 +01:00
|
|
|
ifdef CONFIG_PKG_ASLR_PIE_ALL
|
2020-01-14 15:17:21 +01:00
|
|
|
ifeq ($(strip $(PKG_ASLR_PIE)),1)
|
|
|
|
ifeq ($(GO_TARGET_PIE_SUPPORTED),1)
|
|
|
|
GO_PKG_ENABLE_PIE:=1
|
2020-01-15 12:36:09 +01:00
|
|
|
else
|
|
|
|
$(warning PIE buildmode is not supported for $(GO_OS)/$(GO_ARCH))
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef CONFIG_PKG_ASLR_PIE_REGULAR
|
|
|
|
ifeq ($(strip $(PKG_ASLR_PIE_REGULAR)),1)
|
|
|
|
ifeq ($(GO_TARGET_PIE_SUPPORTED),1)
|
|
|
|
GO_PKG_ENABLE_PIE:=1
|
|
|
|
else
|
|
|
|
$(warning PIE buildmode is not supported for $(GO_OS)/$(GO_ARCH))
|
2020-01-14 15:17:21 +01:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-03-17 17:32:35 +01:00
|
|
|
# sstrip causes corrupted section header size
|
|
|
|
ifneq ($(CONFIG_USE_SSTRIP),)
|
|
|
|
ifneq ($(CONFIG_DEBUG),)
|
|
|
|
GO_PKG_STRIP_ARGS:=--strip-unneeded --remove-section=.comment --remove-section=.note
|
|
|
|
else
|
|
|
|
GO_PKG_STRIP_ARGS:=--strip-all
|
|
|
|
endif
|
|
|
|
STRIP:=$(TARGET_CROSS)strip $(GO_PKG_STRIP_ARGS)
|
|
|
|
endif
|
|
|
|
|
|
|
|
define GoPackage/GoSubMenu
|
|
|
|
SUBMENU:=Go
|
|
|
|
SECTION:=lang
|
|
|
|
CATEGORY:=Languages
|
|
|
|
endef
|
|
|
|
|
2020-05-12 18:05:18 +02:00
|
|
|
GO_PKG_TARGET_VARS= \
|
2020-08-28 20:07:34 +02:00
|
|
|
GOOS="$(GO_OS)" \
|
|
|
|
GOARCH="$(GO_ARCH)" \
|
|
|
|
GO386="$(GO_386)" \
|
|
|
|
GOARM="$(GO_ARM)" \
|
|
|
|
GOMIPS="$(GO_MIPS)" \
|
|
|
|
GOMIPS64="$(GO_MIPS64)" \
|
2018-03-17 17:32:35 +01:00
|
|
|
CGO_ENABLED=1 \
|
2020-08-28 20:07:34 +02:00
|
|
|
CC="$(TARGET_CC)" \
|
|
|
|
CXX="$(TARGET_CXX)" \
|
2018-03-17 17:32:35 +01:00
|
|
|
CGO_CFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CFLAGS))" \
|
|
|
|
CGO_CPPFLAGS="$(TARGET_CPPFLAGS)" \
|
2020-02-04 14:48:08 +01:00
|
|
|
CGO_CXXFLAGS="$(filter-out $(GO_CFLAGS_TO_REMOVE),$(TARGET_CXXFLAGS))" \
|
|
|
|
CGO_LDFLAGS="$(TARGET_LDFLAGS)"
|
|
|
|
|
2020-05-12 18:05:18 +02:00
|
|
|
GO_PKG_BUILD_VARS= \
|
2020-08-28 20:07:34 +02:00
|
|
|
GOPATH="$(GO_PKG_BUILD_DIR)" \
|
|
|
|
GOCACHE="$(GO_BUILD_CACHE_DIR)" \
|
|
|
|
GOMODCACHE="$(GO_MOD_CACHE_DIR)" \
|
2020-02-04 14:48:08 +01:00
|
|
|
GOENV=off
|
|
|
|
|
2020-05-12 18:05:18 +02:00
|
|
|
GO_PKG_DEFAULT_VARS= \
|
|
|
|
$(GO_PKG_TARGET_VARS) \
|
|
|
|
$(GO_PKG_BUILD_VARS)
|
|
|
|
|
|
|
|
GO_PKG_VARS=$(GO_PKG_DEFAULT_VARS)
|
2018-03-17 17:32:35 +01:00
|
|
|
|
2020-05-12 20:08:56 +02:00
|
|
|
GO_PKG_DEFAULT_LDFLAGS= \
|
|
|
|
-buildid '$(SOURCE_DATE_EPOCH)' \
|
|
|
|
-linkmode external \
|
|
|
|
-extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))'
|
|
|
|
|
|
|
|
GO_PKG_CUSTOM_LDFLAGS= \
|
|
|
|
$(GO_PKG_LDFLAGS) \
|
|
|
|
$(patsubst %,-X %,$(GO_PKG_LDFLAGS_X))
|
|
|
|
|
2020-06-28 20:18:34 +02:00
|
|
|
GO_PKG_INSTALL_ARGS= \
|
|
|
|
-v \
|
|
|
|
-trimpath \
|
|
|
|
-ldflags "all=$(GO_PKG_DEFAULT_LDFLAGS)" \
|
|
|
|
$(if $(filter $(GO_PKG_ENABLE_PIE),1),-buildmode pie) \
|
|
|
|
$(if $(filter $(GO_ARCH),arm),-installsuffix "v$(GO_ARM)") \
|
|
|
|
$(if $(filter $(GO_ARCH),mips mipsle),-installsuffix "$(GO_MIPS)") \
|
|
|
|
$(if $(filter $(GO_ARCH),mips64 mips64le),-installsuffix "$(GO_MIPS64)") \
|
|
|
|
$(if $(GO_PKG_GCFLAGS),-gcflags "$(GO_PKG_GCFLAGS)") \
|
2020-07-16 05:55:15 +02:00
|
|
|
$(if $(GO_PKG_CUSTOM_LDFLAGS),-ldflags "$(GO_PKG_CUSTOM_LDFLAGS) $(GO_PKG_DEFAULT_LDFLAGS)") \
|
|
|
|
$(if $(GO_PKG_TAGS),-tags "$(GO_PKG_TAGS)")
|
2020-05-12 20:08:56 +02:00
|
|
|
|
2018-03-17 17:32:35 +01:00
|
|
|
# false if directory does not exist
|
2020-08-28 20:07:34 +02:00
|
|
|
GoPackage/is_dir_not_empty=$$$$($(FIND) "$(1)" -maxdepth 0 -type d \! -empty 2>/dev/null)
|
2018-03-17 17:32:35 +01:00
|
|
|
|
|
|
|
GoPackage/has_binaries=$(call GoPackage/is_dir_not_empty,$(GO_PKG_BUILD_BIN_DIR))
|
|
|
|
|
|
|
|
define GoPackage/Build/Configure
|
|
|
|
( \
|
2020-08-28 20:07:34 +02:00
|
|
|
cd "$(PKG_BUILD_DIR)" ; \
|
2020-08-23 22:59:05 +02:00
|
|
|
mkdir -p \
|
2020-08-28 20:07:34 +02:00
|
|
|
"$(GO_PKG_BUILD_DIR)/bin" "$(GO_PKG_BUILD_DIR)/src" \
|
|
|
|
"$(GO_BUILD_CACHE_DIR)" "$(GO_MOD_CACHE_DIR)" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
\
|
2020-08-28 20:07:34 +02:00
|
|
|
files="$$$$($(FIND) ./ \
|
|
|
|
-type d -a \( -path "./.git" -o -path "./$(GO_PKG_WORK_DIR_NAME)" \) -prune -o \
|
2018-03-17 17:32:35 +01:00
|
|
|
\! -type d -print | \
|
2020-08-28 20:07:34 +02:00
|
|
|
sed 's|^\./||')" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
\
|
2020-01-07 18:22:05 +01:00
|
|
|
if [ "$(strip $(GO_PKG_INSTALL_ALL))" != 1 ]; then \
|
2020-08-28 20:07:34 +02:00
|
|
|
code="$$$$(echo "$$$$files" | grep '\.\(c\|cc\|cpp\|go\|h\|hh\|hpp\|proto\|s\)$$$$')" ; \
|
|
|
|
testdata="$$$$(echo "$$$$files" | grep '\(^\|/\)testdata/')" ; \
|
|
|
|
gomod="$$$$(echo "$$$$files" | grep '\(^\|/\)go\.\(mod\|sum\)$$$$')" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
\
|
|
|
|
for pattern in $(GO_PKG_INSTALL_EXTRA); do \
|
2020-08-28 20:07:34 +02:00
|
|
|
extra="$$$$(echo "$$$$extra"; echo "$$$$files" | grep "$$$$pattern")" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
done ; \
|
|
|
|
\
|
2020-08-28 20:07:34 +02:00
|
|
|
files="$$$$(echo "$$$$code"; echo "$$$$testdata"; echo "$$$$gomod"; echo "$$$$extra")" ; \
|
|
|
|
files="$$$$(echo "$$$$files" | grep -v '^[[:space:]]*$$$$' | sort -u)" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
fi ; \
|
|
|
|
\
|
2019-02-09 12:42:06 +01:00
|
|
|
IFS=$$$$'\n' ; \
|
|
|
|
\
|
2020-01-07 18:22:05 +01:00
|
|
|
echo "Copying files from $(PKG_BUILD_DIR) into $(GO_PKG_BUILD_DIR)/src/$(strip $(GO_PKG))" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
for file in $$$$files; do \
|
2020-08-28 20:07:34 +02:00
|
|
|
echo "$$$$file" ; \
|
|
|
|
dest="$(GO_PKG_BUILD_DIR)/src/$(strip $(GO_PKG))/$$$$file" ; \
|
|
|
|
mkdir -p "$$$$(dirname "$$$$dest")" ; \
|
|
|
|
$(CP) "$$$$file" "$$$$dest" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
done ; \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
\
|
|
|
|
link_contents() { \
|
2020-08-28 20:07:34 +02:00
|
|
|
local src="$$$$1" ; \
|
|
|
|
local dest="$$$$2" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
local dirs dir base ; \
|
|
|
|
\
|
2020-08-28 20:07:34 +02:00
|
|
|
if [ -n "$$$$($(FIND) "$$$$src" -mindepth 1 -maxdepth 1 -name "*.go" \! -type d)" ]; then \
|
2018-03-17 17:32:35 +01:00
|
|
|
echo "$$$$src is already a Go library" ; \
|
|
|
|
return 1 ; \
|
|
|
|
fi ; \
|
|
|
|
\
|
2020-08-28 20:07:34 +02:00
|
|
|
dirs="$$$$($(FIND) "$$$$src" -mindepth 1 -maxdepth 1 -type d)" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
for dir in $$$$dirs; do \
|
2020-08-28 20:07:34 +02:00
|
|
|
base="$$$$(basename "$$$$dir")" ; \
|
|
|
|
if [ -d "$$$$dest/$$$$base" ]; then \
|
|
|
|
case "$$$$dir" in \
|
2020-01-07 18:22:05 +01:00
|
|
|
*$(GO_PKG_PATH)/src/$(strip $(GO_PKG))) \
|
|
|
|
echo "$(strip $(GO_PKG)) is already installed. Please check for circular dependencies." ;; \
|
2018-03-17 17:32:35 +01:00
|
|
|
*) \
|
2020-08-28 20:07:34 +02:00
|
|
|
link_contents "$$$$src/$$$$base" "$$$$dest/$$$$base" ;; \
|
2018-03-17 17:32:35 +01:00
|
|
|
esac ; \
|
|
|
|
else \
|
|
|
|
echo "...$$$${src#$(GO_PKG_BUILD_DEPENDS_SRC)}/$$$$base" ; \
|
2020-08-28 20:07:34 +02:00
|
|
|
$(LN) "$$$$src/$$$$base" "$$$$dest/$$$$base" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
fi ; \
|
|
|
|
done ; \
|
|
|
|
} ; \
|
|
|
|
\
|
2020-01-07 18:22:05 +01:00
|
|
|
if [ "$(strip $(GO_PKG_SOURCE_ONLY))" != 1 ]; then \
|
2020-08-28 20:07:34 +02:00
|
|
|
if [ -d "$(GO_PKG_BUILD_DEPENDS_SRC)" ]; then \
|
2018-03-17 17:32:35 +01:00
|
|
|
echo "Symlinking directories from $(GO_PKG_BUILD_DEPENDS_SRC) into $(GO_PKG_BUILD_DIR)/src" ; \
|
2020-08-28 20:07:34 +02:00
|
|
|
link_contents "$(GO_PKG_BUILD_DEPENDS_SRC)" "$(GO_PKG_BUILD_DIR)/src" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
else \
|
|
|
|
echo "$(GO_PKG_BUILD_DEPENDS_SRC) does not exist, skipping symlinks" ; \
|
|
|
|
fi ; \
|
|
|
|
else \
|
|
|
|
echo "Not building binaries, skipping symlinks" ; \
|
|
|
|
fi ; \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
2018-06-26 21:05:11 +02:00
|
|
|
# $(1) additional arguments for go command line (optional)
|
2018-03-17 17:32:35 +01:00
|
|
|
define GoPackage/Build/Compile
|
|
|
|
( \
|
2020-08-28 20:07:34 +02:00
|
|
|
cd "$(GO_PKG_BUILD_DIR)" ; \
|
2020-05-12 18:05:18 +02:00
|
|
|
export $(GO_PKG_VARS) ; \
|
2020-08-18 23:39:41 +02:00
|
|
|
if [ -f "$(PKG_BUILD_DIR)/go.mod" ] ; then \
|
|
|
|
modargs="$(GO_MOD_ARGS)" ; \
|
|
|
|
fi ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
\
|
2018-12-11 21:23:47 +01:00
|
|
|
echo "Finding targets" ; \
|
2020-08-28 20:07:34 +02:00
|
|
|
targets="$$$$(go list $$$$modargs $(GO_PKG_BUILD_PKG))" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
for pattern in $(GO_PKG_EXCLUDES); do \
|
2020-08-28 20:07:34 +02:00
|
|
|
targets="$$$$(echo "$$$$targets" | grep -v "$$$$pattern")" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
done ; \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
\
|
2020-01-07 18:22:05 +01:00
|
|
|
if [ "$(strip $(GO_PKG_GO_GENERATE))" = 1 ]; then \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo "Calling go generate" ; \
|
2018-06-26 21:05:11 +02:00
|
|
|
go generate -v $(1) $$$$targets ; \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
fi ; \
|
|
|
|
\
|
2020-01-07 18:22:05 +01:00
|
|
|
if [ "$(strip $(GO_PKG_SOURCE_ONLY))" != 1 ]; then \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo "Building targets" ; \
|
2020-08-18 23:39:41 +02:00
|
|
|
go install $(GO_PKG_INSTALL_ARGS) $$$$modargs $(1) $$$$targets ; \
|
2020-08-28 20:07:34 +02:00
|
|
|
retval="$$$$?" ; \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
\
|
|
|
|
if [ "$$$$retval" -eq 0 ] && [ -z "$(call GoPackage/has_binaries)" ]; then \
|
|
|
|
echo "No binaries were generated, consider adding GO_PKG_SOURCE_ONLY:=1 to Makefile" ; \
|
2018-12-11 21:23:47 +01:00
|
|
|
echo ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
fi ; \
|
2018-12-11 21:23:47 +01:00
|
|
|
\
|
2020-08-18 23:39:41 +02:00
|
|
|
if [ "$$$$retval" -ne 0 ]; then \
|
|
|
|
$(call Go/CacheCleanup) ; \
|
|
|
|
fi ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
fi ; \
|
2020-08-28 20:07:34 +02:00
|
|
|
exit "$$$$retval" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
|
|
|
define GoPackage/Build/InstallDev
|
|
|
|
$(call GoPackage/Package/Install/Src,$(1))
|
|
|
|
endef
|
|
|
|
|
|
|
|
define GoPackage/Package/Install/Bin
|
|
|
|
if [ -n "$(call GoPackage/has_binaries)" ]; then \
|
2020-08-28 20:07:34 +02:00
|
|
|
$(INSTALL_DIR) "$(1)/usr/bin" ; \
|
|
|
|
$(INSTALL_BIN) "$(GO_PKG_BUILD_BIN_DIR)"/* "$(1)/usr/bin/" ; \
|
2018-03-17 17:32:35 +01:00
|
|
|
fi
|
|
|
|
endef
|
|
|
|
|
|
|
|
define GoPackage/Package/Install/Src
|
2020-08-28 20:07:34 +02:00
|
|
|
dir="$$$$(dirname "$(GO_PKG)")" ; \
|
|
|
|
$(INSTALL_DIR) "$(1)$(GO_PKG_PATH)/src/$$$$dir" ; \
|
|
|
|
$(CP) "$(GO_PKG_BUILD_DIR)/src/$(strip $(GO_PKG))" "$(1)$(GO_PKG_PATH)/src/$$$$dir/"
|
2018-03-17 17:32:35 +01:00
|
|
|
endef
|
|
|
|
|
|
|
|
define GoPackage/Package/Install
|
|
|
|
$(call GoPackage/Package/Install/Bin,$(1))
|
|
|
|
$(call GoPackage/Package/Install/Src,$(1))
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
2020-01-07 18:22:05 +01:00
|
|
|
ifneq ($(strip $(GO_PKG)),)
|
2018-03-17 17:32:35 +01:00
|
|
|
Build/Configure=$(call GoPackage/Build/Configure)
|
|
|
|
Build/Compile=$(call GoPackage/Build/Compile)
|
2020-08-18 23:39:41 +02:00
|
|
|
Hooks/Compile/Post+=Go/CacheCleanup
|
2018-03-17 17:32:35 +01:00
|
|
|
Build/InstallDev=$(call GoPackage/Build/InstallDev,$(1))
|
|
|
|
endif
|
|
|
|
|
|
|
|
define GoPackage
|
|
|
|
ifndef Package/$(1)/install
|
|
|
|
Package/$(1)/install=$$(call GoPackage/Package/Install,$$(1))
|
|
|
|
endif
|
|
|
|
endef
|
|
|
|
|
|
|
|
define GoBinPackage
|
|
|
|
ifndef Package/$(1)/install
|
|
|
|
Package/$(1)/install=$$(call GoPackage/Package/Install/Bin,$$(1))
|
|
|
|
endif
|
|
|
|
endef
|
|
|
|
|
|
|
|
define GoSrcPackage
|
|
|
|
ifndef Package/$(1)/install
|
|
|
|
Package/$(1)/install=$$(call GoPackage/Package/Install/Src,$$(1))
|
|
|
|
endif
|
|
|
|
endef
|
2020-08-23 22:59:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Deprecated variables - these will be removed after the next OpenWrt release
|
|
|
|
GO_PKG_WORK_DIR=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)
|
|
|
|
GO_PKG_CACHE_DIR=$(GO_BUILD_CACHE_DIR)
|
|
|
|
GoPackage/Environment=$(GO_PKG_VARS)
|
|
|
|
# End of deprecated variables
|