## START: Set by rpmautospec
## (rpmautospec version 0.2.5)
%define autorelease(e:s:pb:) %{?-p:0.}%{lua:
    release_number = 5;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{?dist}
## END: Set by rpmautospec

%global with_debug 1

%if 0%{?with_debug}
%global _find_debuginfo_dwz_opts %{nil}
%global _dwz_low_mem_die_limit 0
%else
%global debug_package   %{nil}
%endif

%if ! 0%{?gobuild:1}
%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 %{?**};
%endif

%global provider github
%global provider_tld com
%global project buildpacks
%global repo pack
# https://github.com/buildpacks/pack
%global import_path %{provider}.%{provider_tld}/%{project}/%{repo}
%global git0 https://%{import_path}

%global built_tag v0.23.0
%global built_tag_strip %(b=%{built_tag}; echo ${b:1})
%global gen_version %(b=%{built_tag_strip}; echo ${b/-/"~"})

Name: %{repo}
Version: %{gen_version}
Release: %autorelease
Summary: Convert code into runnable images
License: ASL 2.0 and BSD and ISC and MIT
URL: %{git0}
Source0: %{built_tag}-vendor.tar.gz
BuildRequires: golang
BuildRequires: go-rpm-macros
BuildRequires: git
BuildRequires: glib2-devel
BuildRequires: glibc-static
BuildRequires: make
Provides: %{name}cli = %{version}-%{release}
Provides: %{name}-cli = %{version}-%{release}
# awk '{print "Provides: bundled(golang("$1")) = "$2}' go.mod | sort | uniq | sed -e 's/-/_/g'
Provides: bundled(golang(github.com/Azure/go_ansiterm)) = v0.0.0_20210617225240_d185dfc1b5a1
Provides: bundled(golang(github.com/BurntSushi/toml)) = v1.0.0
Provides: bundled(golang(github.com/Masterminds/semver)) = v1.5.0
Provides: bundled(golang(github.com/Microsoft/go_winio)) = v0.5.1
Provides: bundled(golang(github.com/Microsoft/hcsshim)) = v0.8.23
Provides: bundled(golang(github.com/apex/log)) = v1.9.0
Provides: bundled(golang(github.com/bits_and_blooms/bitset)) = v1.2.0
Provides: bundled(golang(github.com/buildpacks/imgutil)) = v0.0.0_20211203200417_76206845baac
Provides: bundled(golang(github.com/buildpacks/lifecycle)) = v0.13.2
Provides: bundled(golang(github.com/containerd/containerd)) = v1.5.8
Provides: bundled(golang(github.com/containerd/stargz_snapshotter/estargz)) = v0.10.1
Provides: bundled(golang(github.com/docker/cli)) = v20.10.12+incompatible
Provides: bundled(golang(github.com/docker/distribution)) = v2.7.1+incompatible
Provides: bundled(golang(github.com/docker/docker)) = v20.10.12+incompatible
Provides: bundled(golang(github.com/docker/docker_credential_helpers)) = v0.6.4
Provides: bundled(golang(github.com/docker/go_connections)) = v0.4.0
Provides: bundled(golang(github.com/docker/go_units)) = v0.4.0
Provides: bundled(golang(github.com/dustin/go_humanize)) = v1.0.0
Provides: bundled(golang(github.com/emirpasic/gods)) = v1.12.0
Provides: bundled(golang(github.com/gdamore/encoding)) = v1.0.0
Provides: bundled(golang(github.com/gdamore/tcell/v2)) = v2.4.0
Provides: bundled(golang(github.com/ghodss/yaml)) = v1.0.0
Provides: bundled(golang(github.com/gogo/protobuf)) = v1.3.2
Provides: bundled(golang(github.com/golang/mock)) = v1.6.0
Provides: bundled(golang(github.com/golang/protobuf)) = v1.5.2
Provides: bundled(golang(github.com/google/go_cmp)) = v0.5.7
Provides: bundled(golang(github.com/google/go_containerregistry)) = v0.8.0
Provides: bundled(golang(github.com/google/go_github/v30)) = v30.1.0
Provides: bundled(golang(github.com/google/go_querystring)) = v1.0.0
Provides: bundled(golang(github.com/hectane/go_acl)) = v0.0.0_20190604041725_da78bae5fc95
Provides: bundled(golang(github.com/heroku/color)) = v0.0.6
Provides: bundled(golang(github.com/inconshreveable/mousetrap)) = v1.0.0
Provides: bundled(golang(github.com/jbenet/go_context)) = v0.0.0_20150711004518_d14ea06fba99
Provides: bundled(golang(github.com/kevinburke/ssh_config)) = v0.0.0_20190725054713_01f96b0aa0cd
Provides: bundled(golang(github.com/klauspost/compress)) = v1.13.6
Provides: bundled(golang(github.com/lucasb_eyer/go_colorful)) = v1.2.0
Provides: bundled(golang(github.com/mattn/go_colorable)) = v0.1.12
Provides: bundled(golang(github.com/mattn/go_isatty)) = v0.0.14
Provides: bundled(golang(github.com/mattn/go_runewidth)) = v0.0.10
Provides: bundled(golang(github.com/mitchellh/go_homedir)) = v1.1.0
Provides: bundled(golang(github.com/mitchellh/ioprogress)) = v0.0.0_20180201004757_6a23b12fa88e
Provides: bundled(golang(github.com/moby/sys/mount)) = v0.2.0
Provides: bundled(golang(github.com/moby/sys/mountinfo)) = v0.4.1
Provides: bundled(golang(github.com/moby/term)) = v0.0.0_20210619224110_3f7ff695adc6
Provides: bundled(golang(github.com/morikuni/aec)) = v1.0.0
Provides: bundled(golang(github.com/onsi/gomega)) = v1.18.0
Provides: bundled(golang(github.com/opencontainers/go_digest)) = v1.0.0
Provides: bundled(golang(github.com/opencontainers/image_spec)) = v1.0.2
Provides: bundled(golang(github.com/opencontainers/runc)) = v1.0.2
Provides: bundled(golang(github.com/opencontainers/selinux)) = v1.8.2
Provides: bundled(golang(github.com/pelletier/go_toml)) = v1.9.4
Provides: bundled(golang(github.com/pkg/errors)) = v0.9.1
Provides: bundled(golang(github.com/rivo/tview)) = v0.0.0_20210624165335_29d673af0ce2
Provides: bundled(golang(github.com/rivo/uniseg)) = v0.2.0
Provides: bundled(golang(github.com/sabhiram/go_gitignore)) = v0.0.0_20201211074657_223ce5d391b0
Provides: bundled(golang(github.com/sclevine/spec)) = v1.4.0
Provides: bundled(golang(github.com/sergi/go_diff)) = v1.1.0
Provides: bundled(golang(github.com/sirupsen/logrus)) = v1.8.1
Provides: bundled(golang(github.com/spf13/cobra)) = v1.3.0
Provides: bundled(golang(github.com/spf13/pflag)) = v1.0.5
Provides: bundled(golang(github.com/src_d/gcfg)) = v1.4.0
Provides: bundled(golang(github.com/vbatts/tar_split)) = v0.11.2
Provides: bundled(golang(github.com/xanzy/ssh_agent)) = v0.3.0
Provides: bundled(golang(golang.org/x/crypto)) = v0.0.0_20210817164053_32db794688a5
Provides: bundled(golang(golang.org/x/mod)) = v0.5.1
Provides: bundled(golang(golang.org/x/net)) = v0.0.0_20211216030914_fe4d6282115f
Provides: bundled(golang(golang.org/x/oauth2)) = v0.0.0_20211104180415_d3ed0bb246c8
Provides: bundled(golang(golang.org/x/sync)) = v0.0.0_20210220032951_036812b2e83c
Provides: bundled(golang(golang.org/x/sys)) = v0.0.0_20211216021012_1d35b9e2eb4e
Provides: bundled(golang(golang.org/x/term)) = v0.0.0_20210615171337_6886f2dfbf5b
Provides: bundled(golang(golang.org/x/text)) = v0.3.7
Provides: bundled(golang(google.golang.org/appengine)) = v1.6.7
Provides: bundled(golang(google.golang.org/genproto)) = v0.0.0_20211208223120_3a66f561d7aa
Provides: bundled(golang(google.golang.org/grpc)) = v1.43.0
Provides: bundled(golang(google.golang.org/protobuf)) = v1.27.1
Provides: bundled(golang(gopkg.in/natefinch/npipe.v2)) = v2.0.0_20160621034901_c1b8fa8bdcce
Provides: bundled(golang(gopkg.in/src_d/go_billy.v4)) = v4.3.2
Provides: bundled(golang(gopkg.in/src_d/go_git.v4)) = v4.13.1
Provides: bundled(golang(gopkg.in/warnings.v0)) = v0.1.2
Provides: bundled(golang(gopkg.in/yaml.v2)) = v2.4.0
Provides: bundled(golang(gopkg.in/yaml.v3)) = v3.0.0_20210107192922_496545a6307b

%description
%{name} is a CLI implementation of the Platform Interface Specification
for Cloud Native Buildpacks.

%prep
%autosetup -Sgit -n %{name}-%{built_tag_strip}-vendor

%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 CGO_CFLAGS="-O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -ffat-lto-objects -fexceptions -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
%ifarch x86_64
export CGO_CFLAGS+=" -m64 -mtune=generic -fcf-protection=full"
%endif
# These extra flags present in %%{optflags} have been skipped for now as they break the build
#export CGO_CFLAGS+=" -flto=auto -Wp,D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1"

%gobuild -o out/%{name} %{import_path}/cmd/%{name}

%install
export GOPATH=$(pwd)/_build:$(pwd):%{gopath}
make DESTDIR=%{buildroot} PREFIX=%{_prefix} install

#define license tag if not already defined
%{!?_licensedir:%global license %doc}

%files
%license LICENSE
%doc README.md
%{_bindir}/%{name}

%changelog
* Thu Jan 27 2022 Lokesh Mandvekar <lsm5@fedoraproject.org> 0.23.0-5
- switch to autospec and misc fixes

* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> 0.23.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Thu Dec 09 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.23.0-3
- pack-0.23.0-1

* Mon Dec 06 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.23.0-2
- pack-0.23.0-0.2.rc2

* Mon Nov 22 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.23.0-1
- pack-0.23.0-0.1.rc1

* Mon Nov 08 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.22.0-2
- pack-0.22.0-1

* Tue Nov 02 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.22.0-1
- pack-0.22.0-0.1.rc1

* Mon Sep 20 2021 Lokesh Mandvekar <lsm5@fedoraproject.org> 0.21.1-2
- pack-0.21.1-2

* Sat Sep 18 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.21.1-1
- pack-0.21.1-1

* Wed Sep 15 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.21.0-3
- pack-0.21.0-1

* Fri Sep 10 2021 RH Container Bot <rhcontainerbot@fedoraproject.org> 0.21.0-1
- pack-0.21.0-0.1.rc1

* Tue Jul 27 2021 Lokesh Mandvekar <lsm5@fedoraproject.org> 0.20.0-1
- pack-0.20.0-2