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>
|
2011-05-19 20:17:10 +02:00
|
|
|
#
|
|
|
|
|
2011-05-23 12:33:44 +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-05-15 05:38:25 +02:00
|
|
|
%go_build_ver %(go version | sed 's/^go version //' | sed 's:\/::g' | tr -d ' ' | cut -c 1-5 )
|
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}
|
|
|
|
%go_contribsrcdir %{_datadir}/go/contrib/src/pkg
|
2011-05-19 20:17:10 +02:00
|
|
|
|
2012-03-10 19:49:47 +01:00
|
|
|
%go_requires Requires: go-devel = %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
|
|
|
|
2011-06-30 11:18:52 +02:00
|
|
|
%go_disable_brp_strip_static_archive \
|
2012-08-18 08:08:24 +02:00
|
|
|
%undefine __os_install_post \
|
2011-06-30 11:18:52 +02:00
|
|
|
%define __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib/rpm/[^/]*/?brp-strip-static-archive %{__strip}!!g')
|
|
|
|
|
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() \
|
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 \
|
|
|
|
mkdir -p $GOPATH/src/$IMPORTPATH && mv ./* $GOPATH/src/$IMPORTPATH \
|
|
|
|
# now link the old location to the new (for compatibility) \
|
|
|
|
cd %{_builddir} && rmdir %{_builddir}/%(basename %1) \
|
|
|
|
ln -s $GOPATH/src/$IMPORTPATH %{_builddir}/%(basename %1) \
|
|
|
|
# we'll be installing packages/binaries, make the targ dirs \
|
2012-05-09 17:04:39 +02:00
|
|
|
install -d %{buildroot}%{go_contribdir} \
|
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-08-20 10:14:10 +02:00
|
|
|
%go_disable_brp_strip_static_archive \
|
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}
|
|
|
|
|