\!/ KyuuKazami \!/

Path : /proc/self/root/usr/lib/rpm/macros.d/
Upload :
Current File : //proc/self/root/usr/lib/rpm/macros.d/macros.go-srpm

# Copyright © 2015-2019 Jakub Cajka <jcajka@redhat.com>,
#                       Jan Chaloupka <jchaloup@redhat.com>,
#                       Nicolas Mailhot <nim@fedoraproject.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
# This file contains macros for building projects in golang for packages
# with golang compiler or gcc-go compiler based on an architecture.
# Golang is primarly for primary architectures, gcc-go for secondary.
#
# This file provides only macros and must not use any other package except
# redhat-rpm-macros.
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Define arches for PA and SA
%golang_arches   i386 i486 i586 i686 pentium3 pentium4 athlon geode x86_64 armv3l armv4b armv4l armv4tl armv5tel armv5tejl armv6l armv7l armv7hl armv7hnl aarch64 ppc64le s390x
%gccgo_arches    %{mips}
%go_arches       %{golang_arches} %{gccgo_arches}

# Where to set GOPATH for builds
%gopath          /usr/share/gocode

# Define go_compilers macro to signal go-compiler package is available
%go_compiler     1

# Sanitize a Go import path that can then serve as rpm package name
# Mandatory parameter: a Go import path (without flag)
# Optional parameters:
#  – “-c <compatid>” a compat identifier, used to distinguish the package
#                    from the primary package tracking the project recommended
#                    version. For example: a (different) major version, a
#                    specific shortened commit, etc
%gorpmname(c:) %{lua:
local go = require "fedora.srpm.go"
print(go.rpmname("%1", "%{-c*}"))
}

# Map Go information to rpm metadata. This macro will compute default spec
# variable values.
#
# The following spec variable MUST be set before calling the macro:
#
#   goipath   the packaged Go project import path
#
# The following spec variables SHOULD be set before calling the macro:
#
#   forgeurl  the project url on the forge,
#             if it can not be deduced from goipath
#   Version   if applicable, set it with Version: <version>
#   tag       if applicable
#   commit    if applicable
#   date      if applicable (to override the mtime of the Source archive)
#
#  Use -z for multiple calls to the macro
#
# The macro will attempt to compute and set the following variables if they are
# not already set by the packager:
#
#   goname         an rpm-compatible package name derived from goipath
#   gosource       an URL that can be used as SourceX: value
#   gourl          an URL that can be used as URL: value
#
# It will delegate processing to the forgemeta macro for:
#
#   forgesource    an URL that can be used as SourceX: value
#   forgesetupargs the correct arguments to pass to %setup for this source
#                  used by %forgesetup and %forgeautosetup
#   archivename    the source archive filename, without extentions
#   archiveext     the source archive filename extensions, without leading dot
#   archiveurl     the url that can be used to download the source archive,
#                  without renaming
#   topdir         the source archive top directory (can be empty)
#   extractdir     the source directory created inside %{_builddir} after using
#                  %%forgesetup, %forgeautosetup or %{forgesetupargs}
#   repo           the repository name
#   owner          the repository owner (if used by another computed variable)
#   shortcommit    the commit hash clamping used by the forge, if any
#   scm            the scm type, when packaging code snapshots: commits or tags
#   distprefix     the prefix that needs adding to dist to trace non-release packaging
#
# Most of the computed variables are both overridable and optional.
#
# Optional parameters:
#   -a          process all sources in one go, instead of using separate -z calls
#   -z <number> suffix all the read and written variable names with <number>
#               for example read     goipath<number>, version<number>…
#                       and generate goname<number>, archiveurl<number>…
#               The macro assumes that null or nil suffix is used for the primary
#               package source.
#   -s  Silently ignore problems in forgeurl, use it if it can be parsed,
#       ignore it otherwise.
#   -v  Be verbose and print every spec variable the macro sets.
#   -i  Print some info about the state of spec variables the macro may use or
#       set at the end of the processing.
%gometa(az:svi) %{lua:
print(           "BuildRequires: go-rpm-macros\\n")
print(rpm.expand("ExclusiveArch: %{go_arches}\\n"))
local      fedora =  require "fedora.common"
local          go =  require "fedora.srpm.go"
local     verbose =  rpm.expand("%{-v}") ~= ""
local informative =  rpm.expand("%{-i}") ~= ""
local      silent =  rpm.expand("%{-s}") ~= ""
local  processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
if processall then
  for _,s in pairs(fedora.getsuffixes("goipath")) do
    go.meta(s,verbose,informative,silent)
  end
else
  go.meta(rpm.expand("%{-z*}"),verbose,informative,silent)
end
}

# Create %package sections for every known kind of go subpackage. Arguments:
# -v                  be verbose
%gopkg(av) %{expand:
%godevelpkg -a %{-v}
%goaltpkg   -a %{-v}
}

# Create a %package section for a golang-*-devel subpackage. Arguments:
# -z <number>         read the zth block of definitions, for example
#                     %{goipaths<number>}
# -a                  process all blocks in one go, instead of using separate
#                     -z calls
# -v                  be verbose
%godevelpkg(z:av) %{lua:
local         go =  require "fedora.srpm.go"
local     suffix =  rpm.expand("%{-z*}")
local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
local    verbose = (rpm.expand("%{-v}") ~= "")
go.pkg("devel", suffix, processall, verbose)
}

# Create a %package section for a compat-golang-*-devel subpackage. Arguments:
# -z <number>         read the zth block of definitions, for example
#                     %{goaltipaths<number>}
# -a                  process all blocks in one go, instead of using separate
#                     -z calls
# -v                  be verbose
%goaltpkg(z:av) %{lua:
local         go =  require "fedora.srpm.go"
local     suffix =  rpm.expand("%{-z*}")
local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
local    verbose = (rpm.expand("%{-v}") ~= "")
go.pkg("alt", suffix, processall, verbose)
}

# Create %files sections for every known kind of Go subpackage. Arguments:
# -v                  be verbose
%gopkgfiles(av) %{expand:
%godevelfiles -a %{-v}
%goaltfiles   -a %{-v}
}

# Create a %files section for a golang-*-devel subpackage. Arguments:
# -z <number>         read the zth block of definitions, for example
#                     %{goipaths<number>}
# -a                  process all blocks in one go, instead of using separate
#                     -z calls
# -v                  be verbose
%godevelfiles(z:av) %{lua:
local         go =  require "fedora.srpm.go"
local     suffix =  rpm.expand("%{-z*}")
local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
local    verbose = (rpm.expand("%{-v}") ~= "")
go.files("devel", suffix, processall, verbose)
}

# Create a %files section for a compat-golang-*-devel subpackage. Arguments:
# -z <number>         read the zth block of definitions, for example
#                     %{goaltipaths<number>}
# -a                  process all blocks in one go, instead of using separate
#                     -z calls
# -v                  be verbose
%goaltfiles(z:av) %{lua:
local         go =  require "fedora.srpm.go"
local     suffix =  rpm.expand("%{-z*}")
local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
local    verbose = (rpm.expand("%{-v}") ~= "")
go.files("alt", suffix, processall, verbose)
}

@KyuuKazami