%global with_bundled 1
%global with_debug 1
%global _find_debuginfo_dwz_opts %{nil}
%global _dwz_low_mem_die_limit 0
%define gobuild(o:) GO111MODULE=off go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '" -a -v -x %{?**};
%ifarch ppc64
%define gobuild(o:) GO111MODULE=off go build -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '" -a -v -x %{?**};
%endif
%define provider github
%define provider_tld com
%define project containers
%define repo buildah
# https://github.com/containers/buildah
%define import_path %{provider}.%{provider_tld}/%{project}/%{repo}
%define git0 https://%{import_path}


Name: %{repo}
Version: 1.14.8
%define commit0 155ce56a2cd2d5608cf43c998f1728af5e7a499b
%define built_tag v%{version}
Release: 1%{?dist}
Summary: A command line tool used for creating OCI Images
License: ASL 2.0
URL: https://%{name}.io
%define download_url https://github.com/containers/%{name}/archive/%{built_tag}.tar.gz
Source: %{download_url}
BuildRequires: golang
BuildRequires: git
BuildRequires: glib2-devel
BuildRequires: glibc-static
BuildRequires: go-md2man
BuildRequires: gpgme-devel
BuildRequires: libassuan-devel
BuildRequires: make
Requires: containers-common
BuildRequires: btrfs-progs-devel
BuildRequires: device-mapper-devel
BuildRequires: ostree-devel
BuildRequires: libseccomp-static
Requires: container-selinux
Requires: slirp4netns >= 0.3-0
Requires: fuse-overlayfs
BuildRequires: libseccomp-devel
Requires: libseccomp
Requires: container-selinux
Requires: runc
%define shortcommit0 %(c=%{commit0}; echo ${c:0:7})
%define built_tag_strip %(b=%{built_tag}; echo ${b:1})


%description
The %{name} package provides a command line tool which can be used to
* create a working container from scratch
or
* create a working container from an image as a starting point
* mount/umount a working container's root file system for manipulation
* save container's root file system layer to create a new image
* delete a working container or an image


%package tests
Summary: Tests for %{name}
Requires: %{name} = %{version}-%{release}
Requires: bats
Requires: bzip2
Requires: podman
Requires: golang
Requires: jq
%description tests
%{summary}
This package contains system tests for %{name}


%prep
%autosetup -Sgit -n %{name}-%{built_tag_strip}
sed -i 's/GOMD2MAN =/GOMD2MAN ?=/' docs/Makefile
sed -i '/docs install/d' Makefile


%build
mkdir _build
pushd _build
mkdir -p src/%{provider}.%{provider_tld}/%{project}
ln -s $(dirs +1 -l) src/%{import_path}
popd
mv vendor src
export GOPATH=$(pwd)/_build:$(pwd)
export BUILDTAGS='seccomp selinux'
export GO111MODULE=off
%ifarch ppc64
export CGO_ENABLED=1
%endif
%gobuild -o %{name} %{import_path}/cmd/%{name}
%gobuild -o imgtype %{import_path}/tests/imgtype
GOMD2MAN=go-md2man %{__make} -C docs
%ifarch ppc64
unset CGO_ENABLED
%endif

%install
export GOPATH=$(pwd)/_build:$(pwd):%{gopath}
make DESTDIR=%{buildroot} PREFIX=%{_prefix} install install.completions
make DESTDIR=%{buildroot} PREFIX=%{_prefix} -C docs install
install -d -p %{buildroot}/%{_datadir}/%{name}/test/system
cp -pav tests/. %{buildroot}/%{_datadir}/%{name}/test/system
cp imgtype %{buildroot}/%{_bindir}/%{name}-imgtype
#define license tag if not already defined
%{!?_licensedir:%global license %doc}


%files
%license LICENSE
%doc README.md
%{_bindir}/%{name}
%{_mandir}/man1/%{name}*
%dir %{_datadir}/bash-completion
%dir %{_datadir}/bash-completion/completions
%{_datadir}/bash-completion/completions/%{name}


%files tests
%license LICENSE
%{_bindir}/%{name}-imgtype
%{_datadir}/%{name}/test


%changelog
