2011-05-19 20:17:10 +02:00
|
|
|
# Macros for Go module building.
|
|
|
|
#
|
2012-05-09 17:04:39 +02:00
|
|
|
# Copyright: (c) 2011 Sascha Peilicke <saschpe@gmx.de>
|
|
|
|
# Copyright: (c) 2012 Graham Anderson <graham@andtech.eu>
|
2015-03-30 17:23:46 +02:00
|
|
|
# Copyright: (c) 2015 SUSE Linux GmbH
|
2011-05-19 20:17:10 +02:00
|
|
|
#
|
|
|
|
|
2013-10-18 15:05:09 +02:00
|
|
|
%go_ver %(LC_ALL=C rpm -q --qf '%%{epoch}:%%{version}\\n' go | sed -e 's/(none)://' -e 's/ 0:/ /' | grep -v "is not")
|
2012-05-10 06:13:33 +02:00
|
|
|
%go_arch GOARCH
|
2013-06-13 10:58:59 +02:00
|
|
|
%go_build_ver %(go version | sed 's/^go version //' | sed 's:\/::g' | tr -d ' ' | cut -c 1-7 )
|
2011-05-19 20:17:10 +02:00
|
|
|
|
2012-05-09 17:04:39 +02:00
|
|
|
%go_dir %{_libdir}/go
|
|
|
|
%go_sitedir %{_libdir}/go/pkg
|
|
|
|
%go_sitearch %{_libdir}/go/pkg/linux_%{go_arch}
|
|
|
|
%go_contribdir %{_libdir}/go/contrib/pkg/linux_%{go_arch}
|
2014-09-26 16:25:10 +02:00
|
|
|
%go_contribsrcdir %{_datadir}/go/contrib/src/
|
2013-10-18 16:20:11 +02:00
|
|
|
%go_tooldir %{_datadir}/go/pkg/tool/linux_%{go_arch}
|
2011-05-19 20:17:10 +02:00
|
|
|
|
2013-08-13 12:03:17 +02:00
|
|
|
%go_exclusivearch \
|
2013-08-13 09:25:05 +02:00
|
|
|
ExclusiveArch: %ix86 x86_64 %arm
|
|
|
|
|
2013-08-13 12:03:17 +02:00
|
|
|
%go_requires \
|
|
|
|
ExclusiveArch: %ix86 x86_64 %arm \
|
2013-08-13 16:10:17 +02:00
|
|
|
Requires: go >= %go_build_ver
|
2011-05-19 20:17:10 +02:00
|
|
|
|
2011-05-19 20:23:17 +02:00
|
|
|
%go_provides \
|
2011-05-21 14:19:45 +02:00
|
|
|
Provides: %{name}-devel = %{version} \
|
|
|
|
Provides: %{name}-devel-static = %{version}
|
2011-05-19 20:17:10 +02:00
|
|
|
|
2014-09-15 16:28:16 +02:00
|
|
|
%go_recommends \
|
|
|
|
%if 0%{?suse_version} >= 1100 \
|
|
|
|
Recommends: %{name}-doc \
|
|
|
|
%endif
|
|
|
|
|
2012-03-07 13:05:43 +01:00
|
|
|
# Prepare the expected Go package build environement.
|
|
|
|
# We need a $GOPATH: go help gopath
|
|
|
|
# We need a valid importpath: go help packages
|
|
|
|
%goprep() \
|
2015-04-08 11:01:18 +02:00
|
|
|
# *.a files in golang doesn't contain debuginfo right now, \
|
|
|
|
# so extract a debug package will cause \
|
|
|
|
# "Failed to write file: invalid section alignment" \
|
|
|
|
# and we don't need to bother stripping them. \
|
2015-03-30 17:23:46 +02:00
|
|
|
%global debug_package %{nil} \
|
|
|
|
%global __strip /bin/true \
|
2012-01-28 17:28:41 +01:00
|
|
|
export GOPATH=%{_builddir}/go \
|
2012-03-07 13:05:43 +01:00
|
|
|
if [ %# -eq 0 ]; then \
|
|
|
|
echo "goprep: please specify a valid importpath, see: go help packages" \
|
|
|
|
exit 1 \
|
|
|
|
else \
|
|
|
|
export IMPORTPATH=%1 \
|
|
|
|
fi \
|
|
|
|
# create the importpath and move the package there \
|
2013-08-13 16:10:17 +02:00
|
|
|
pkg_dir=$(basename $PWD) \
|
2013-08-13 13:17:59 +02:00
|
|
|
cd %{_builddir} \
|
2013-08-13 16:10:17 +02:00
|
|
|
mkdir -p $GOPATH/src/$IMPORTPATH \
|
|
|
|
(shopt -s dotglob; mv -- ${pkg_dir}/* $GOPATH/src/$IMPORTPATH) \
|
|
|
|
# now link the old location to the new (for compatibility) \
|
|
|
|
rmdir ${pkg_dir} \
|
|
|
|
ln -s $GOPATH/src/$IMPORTPATH ${pkg_dir} \
|
|
|
|
cd ${pkg_dir} \
|
2013-10-30 17:00:01 +01:00
|
|
|
# we'll be installing packages/binaries/tools, make the targ dirs \
|
2012-05-09 17:04:39 +02:00
|
|
|
install -d %{buildroot}%{go_contribdir} \
|
2013-10-30 17:00:01 +01:00
|
|
|
install -d %{buildroot}%{go_tooldir} \
|
2012-01-25 04:57:43 +01:00
|
|
|
install -d %{buildroot}%{_bindir} \
|
2012-03-07 13:05:43 +01:00
|
|
|
%{nil}
|
|
|
|
|
|
|
|
# %%gobuild macro actually performs the command "go install", but the go
|
|
|
|
# toolchain will install to the $GOPATH which allows us then customise the final
|
|
|
|
# install for the distro default locations.
|
|
|
|
#
|
|
|
|
# gobuild accepts zero or more arguments. Each argument corresponds to
|
|
|
|
# a modifier of the importpath. If no arguments are passed, this is equivalent
|
|
|
|
# to the following go install statement:
|
|
|
|
#
|
|
|
|
# go install [importpath]
|
|
|
|
#
|
|
|
|
# Only the first or last arguement may be ONLY the wildcard argument "..."
|
|
|
|
# if the wildcard argument is passed then the importpath expands to all packages
|
|
|
|
# and binaries underneath it. If the argument contains only the wildcard no further
|
|
|
|
# arguments are considered.
|
|
|
|
#
|
|
|
|
# If no wildcard argument is passed, go install will be invoked on each $arg
|
|
|
|
# subdirectory under the importpath.
|
|
|
|
#
|
|
|
|
# Valid importpath modifier examples:
|
|
|
|
#
|
|
|
|
# example: %gobuild ...
|
|
|
|
# command: go install importpath...
|
|
|
|
#
|
|
|
|
# example: %gobuild /...
|
|
|
|
# command: go install importpath/... (All subdirs NOT including importpath)
|
|
|
|
#
|
|
|
|
# example: %gobuild foo...
|
|
|
|
# command: go install importpath/foo... (All subdirs INCLUDING foo)
|
|
|
|
#
|
|
|
|
# example: %gobuild foo ... (same as foo...)
|
|
|
|
# command: go install importpath/foo... (All subdirs INCLUDING foo)
|
|
|
|
#
|
|
|
|
# example: %gobuild foo/...
|
|
|
|
# commands: go install importpath/foo/... (All subdirs NOT including foo)
|
|
|
|
#
|
|
|
|
# example: %gobuild foo bar
|
|
|
|
# commands: go install importpath/foo
|
|
|
|
# go install importpath/bar
|
|
|
|
#
|
|
|
|
# example: %gobuild foo ... bar
|
|
|
|
# commands: go install importpath/foo... (bar is ignored)
|
|
|
|
#
|
|
|
|
# example: %gobuild foo bar... baz
|
|
|
|
# commands: go install importpath/foo
|
|
|
|
# go install importpath/bar...
|
|
|
|
# go install importpath/baz
|
|
|
|
#
|
|
|
|
# See: go help install, go help packages
|
|
|
|
%gobuild() \
|
2012-08-16 19:23:45 +02:00
|
|
|
export BUILDFLAGS="-s -v -p 4 -x" \
|
2012-05-10 05:45:06 +02:00
|
|
|
export GOPATH=%{_builddir}/go:%{_libdir}/go/contrib \
|
2012-03-30 17:22:52 +02:00
|
|
|
export GOBIN=%{_builddir}/go/bin \
|
2012-03-07 13:05:43 +01:00
|
|
|
MOD="" \
|
|
|
|
if [ %# -gt 0 ]; then \
|
|
|
|
for mod in %*; do \
|
|
|
|
if [ $mod == "..." ]; then \
|
|
|
|
MOD=$MOD... \
|
|
|
|
go install $BUILDFLAGS $IMPORTPATH$MOD \
|
|
|
|
break \
|
|
|
|
else \
|
|
|
|
MOD=/$mod \
|
|
|
|
go install $BUILDFLAGS $IMPORTPATH$MOD \
|
|
|
|
fi \
|
|
|
|
done \
|
2012-01-25 04:57:43 +01:00
|
|
|
else \
|
2012-03-07 13:05:43 +01:00
|
|
|
go install $BUILDFLAGS $IMPORTPATH \
|
|
|
|
fi \
|
|
|
|
%{nil}
|
|
|
|
|
|
|
|
# Install all compiled packages and binaries to the buildroot
|
|
|
|
%goinstall() \
|
|
|
|
export GOPATH=%{_builddir}/go \
|
2012-05-09 17:04:39 +02:00
|
|
|
install -d %{buildroot}%{go_contribdir} \
|
2012-03-07 13:05:43 +01:00
|
|
|
TMPPKG=%{_builddir}/go/pkg \
|
|
|
|
if [ "$(ls -A $TMPPKG)" ]; then \
|
2012-05-09 17:04:39 +02:00
|
|
|
cp -ar %{_builddir}/go/pkg/linux_%{go_arch}/* %{buildroot}%{go_contribdir} \
|
2012-01-25 04:57:43 +01:00
|
|
|
fi \
|
2012-02-04 11:55:47 +01:00
|
|
|
TMPBIN=%{_builddir}/go/bin \
|
|
|
|
if [ "$(ls -A $TMPBIN)" ]; then \
|
|
|
|
install -m755 $TMPBIN/* %{buildroot}%{_bindir} \
|
|
|
|
fi \
|
2012-01-25 04:57:43 +01:00
|
|
|
%{nil}
|
|
|
|
|
2012-03-07 13:05:43 +01:00
|
|
|
%gofix() \
|
|
|
|
export GOPATH=%{_builddir}/go \
|
|
|
|
if [ %# -eq 0 ]; then \
|
|
|
|
echo "gofix: please specify a valid importpath, see: go help fix" \
|
|
|
|
exit 1 \
|
2012-01-25 04:57:43 +01:00
|
|
|
else \
|
2012-07-17 02:07:47 +02:00
|
|
|
go fix %1... \
|
2012-01-25 04:57:43 +01:00
|
|
|
fi \
|
|
|
|
%{nil}
|
2012-02-04 11:55:47 +01:00
|
|
|
|
2012-03-07 13:05:43 +01:00
|
|
|
%gotest() \
|
2012-05-10 05:45:06 +02:00
|
|
|
export GOPATH=%{_builddir}/go:%{_libdir}/go/contrib \
|
2012-03-07 13:05:43 +01:00
|
|
|
if [ %# -eq 0 ]; then \
|
|
|
|
echo "gotest: please specify a valid importpath, see: go help test" \
|
|
|
|
exit 1 \
|
2012-02-04 11:55:47 +01:00
|
|
|
else \
|
2012-07-11 14:36:49 +02:00
|
|
|
go test -x %1... \
|
2012-02-04 11:55:47 +01:00
|
|
|
fi \
|
2012-03-10 19:49:47 +01:00
|
|
|
%{nil}
|
2012-04-02 20:30:40 +02:00
|
|
|
|
|
|
|
%godoc() \
|
2012-05-09 17:04:39 +02:00
|
|
|
install -d %{buildroot}%{go_contribsrcdir} \
|
2012-04-02 20:30:40 +02:00
|
|
|
cd %{_builddir}/go/src \
|
2012-05-09 17:04:39 +02:00
|
|
|
find . -name *.go -exec install -Dm644 \{\} %{buildroot}%{go_contribsrcdir}/\{\} \\; \
|
2012-04-02 20:30:40 +02:00
|
|
|
%{nil}
|
|
|
|
|
2014-09-15 16:28:16 +02:00
|
|
|
# Template for doc sub-package
|
|
|
|
%godoc_package(n:r:) \
|
|
|
|
%package %{-n:-n %{-n*}-}doc \
|
|
|
|
Summary: API documention for package %{name} \
|
|
|
|
Group: Documentation/Other \
|
|
|
|
Requires: %{-n:%{-n*}}%{!-n:%{name}} = %{version} \
|
|
|
|
%{-r:Requires: %{-r*}} \
|
|
|
|
%description %{-n:-n %{-n*}-}doc \
|
|
|
|
This package provides API, examples and documentation \
|
2015-03-20 14:27:49 +01:00
|
|
|
for package %{name}.\
|
|
|
|
%{nil}
|
|
|
|
|