include $(TOPDIR)/rules.mk

PKG_NAME:=skopeo
PKG_VERSION:=1.9.2
PKG_RELEASE:=$(AUTORELEASE)

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/containers/skopeo/archive/v$(PKG_VERSION)
PKG_HASH:=9a321ba75f213e5c46cba7f92073c2437137a56d3140c9ab6e723fb92890f9d0

PKG_LICENSE:=Apache-2.0
PKG_LICENSE_FILES:=LICENSE

HOST_BUILD_DEPENDS:=golang/host
HOST_BUILD_PARALLEL:=1

PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_PARALLEL:=1
PKG_USE_MIPS16:=0

GO_PKG:=github.com/containers/skopeo
GO_PKG_BUILD_PKG:=github.com/containers/skopeo/cmd/skopeo

include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk

GOLANG_PACKAGE_MK:=$(wildcard $(TOPDIR)/feeds/*/lang/golang/golang-package.mk)
GOLANG_HOST_PACKAGE_MK:=$(wildcard $(TOPDIR)/feeds/*/lang/golang/golang-host-build.mk)

# verify that there is only one single file returned
ifneq (1,$(words $(GOLANG_PACKAGE_MK)))
ifeq (0,$(words $(GOLANG_PACKAGE_MK)))
$(error did not find golang-package.mk in any feed)
else
$(error found multiple golang-package.mk files in the feeds)
endif
else
$(info found golang-package.mk at $(GOLANG_PACKAGE_MK))
endif

include $(GOLANG_PACKAGE_MK)
include $(GOLANG_HOST_PACKAGE_MK)

define Package/skopeo
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=Command line utility for container image management
  URL:=https://github.com/containers/skopeo
  DEPENDS:=$(GO_ARCH_DEPENDS)
endef

define Package/skopeo/description
  skopeo is a command line utility that performs various operations on container images and image repositories.
endef

define Package/skopeo/conffiles
/etc/containers/policy.json
endef

GO_PKG_TAGS=exclude_graphdriver_devicemapper,exclude_graphdriver_btrfs,containers_image_openpgp
GO_PKG_BUILD_VARS += GO111MODULE=auto

define Build/Compile
	$(call GoPackage/Build/Compile)
	$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
endef

define Package/skopeo/install
	$(call GoPackage/Package/Install/Bin,$(1))
	$(INSTALL_DIR) $(1)/etc/containers
	$(INSTALL_DATA) ./files/etc/containers/policy.json $(1)/etc/containers/policy.json
endef

$(eval $(call GoBinHostBuild))
$(eval $(call HostBuild))
$(eval $(call GoBinPackage,skopeo))
$(eval $(call BuildPackage,skopeo))
