File go-md2man.spec of Package go-md2man

%define realname go-md2man
%define realver  2.0.7
%define srcext   tar.gz

%define numcpus  %(/usr/bin/getconf _NPROCESSORS_ONLN)

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       MIT
Group:         Development/Tools/Doc Generators
URL:           https://github.com/cpuguy83/go-md2man
Summary:       Markdown into roff (man pages) converter

# Build-time parameters
BuildRequires: go
Source0:       https://codeload.github.com/cpuguy83/go-md2man/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# cd go-md2man; go mod vendor -v && tar -Jcvf ../vendor.tar.xz vendor && rm -rf vendor; cd ..
Source1:       vendor.tar.xz

%description
Converts markdown into roff (man pages).

Uses blackfriday to process markdown into man pages.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a1

# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS="%{optflags}  %{?gcc_lto}"
_LDFLAGS="-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}"
# Set go build variables
export GOPATH=$(pwd -P)/gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS"
export CGO_CXXFLAGS="$_CFLAGS"
export CGO_LDFLAGS="$_LDFLAGS"
# Build binary
go build \
    -a -v -mod=vendor -buildmode=pie -trimpath \
    -gcflags=all="-c=$(nproc) -dwarf=false" \
    -ldflags=all="-s -w -linkmode=external '-extldflags=$_LDFLAGS'" \
    -o bin/go-md2man
# Build manpage
bin/go-md2man -in go-md2man.1.md -out go-md2man.1

# Install built stuff
%install
%{__install} -D -m0755 bin/go-md2man %{buildroot}%{_bindir}/go-md2man
%{__install} -D -m0644 go-md2man.1   %{buildroot}%{_mandir}/man1/go-md2man.1

# Files list
%files
%defattr(-,root,root)
%license LICENSE.md
%doc README.md
%{_bindir}/go-md2man
%doc %{_mandir}/man1/go-md2man.1*

%changelog
openSUSE Build Service is sponsored by