build: create APK files parallel to IPK 21.02-staging-containers
authorPaul Spooren <mail@aparcar.org>
Sat, 3 Oct 2020 09:30:30 +0000 (23:30 -1000)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 20 Oct 2021 16:47:52 +0000 (17:47 +0100)
Create APK files based on the folder and control files of IPK packages.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
[included fix for host-build from Felix Fietkau]
Signed-off-by: Paul Spooren <mail@aparcar.org>
include/package-ipkg.mk
package/Makefile
package/base-files/Makefile
rules.mk
scripts/apk-make-index.sh [new file with mode: 0755]

index e972b7de0bb9d270f5b4c4e68363143777912459..5c31b1774f9557345aa5ec1934f859ca2888cb8d 100644 (file)
@@ -102,6 +102,7 @@ ifeq ($(DUMP),)
     ABIV_$(1):=$(call FormatABISuffix,$(1),$(ABI_VERSION))
     PDIR_$(1):=$(call FeedPackageDir,$(1))
     IPKG_$(1):=$$(PDIR_$(1))/$(1)$$(ABIV_$(1))_$(VERSION)_$(PKGARCH).ipk
+    APK_$(1):=$$(PDIR_$(1))/$(1)$$(ABIV_$(1))_$(VERSION)_$(PKGARCH).apk
     IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
     KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
 
@@ -200,7 +201,7 @@ $(_endef)
     $(PKG_INFO_DIR)/$(1).provides $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
        @rm -rf $$(IDIR_$(1)); \
                $$(call remove_ipkg_files,$(1),$$(call opkg_package_files,$(call gen_ipkg_wildcard,$(1))))
-       mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
+       mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1)) $(PKG_INFO_DIR)
        $(call Package/$(1)/install,$$(IDIR_$(1)))
        $(if $(Package/$(1)/install-overlay),mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/rootfs-overlay)
        $(call Package/$(1)/install-overlay,$$(IDIR_$(1))/rootfs-overlay)
@@ -226,6 +227,37 @@ $(_endef)
                ) || true \
        )
     endif
+
+    ifneq ($$(KEEP_$(1)),)
+               @( \
+                       keepfiles=""; \
+                       for x in $$(KEEP_$(1)); do \
+                               [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
+                       done; \
+                       [ -z "$$$$keepfiles" ] || { \
+                               mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
+                               for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
+                       }; \
+               )
+    endif
+
+       $(INSTALL_DIR) $$(PDIR_$(1))
+
+       $(FAKEROOT) apk mkpkg \
+         --info "name:$(1)" \
+         --info "version:$(VERSION)" \
+         --info "description:$()" \
+         --info "arch:$(PKGARCH)" \
+         --info "license:$(LICENSE)" \
+         --info "origin:$(SOURCE)" \
+         --info "maintainer:$(MAINTAINER)" \
+         $$(foreach dep,$$(Package/$(1)/DEPENDS),--info "depends:$$(subst $$(comma),,$$(dep))") \
+         --files "$$(IDIR_$(1))" \
+         --output "$$(APK_$(1))" \
+         --sign "$(BUILD_KEY_APK_SEC)"
+
+       mkdir -p $$(IDIR_$(1))/CONTROL
+
        (cd $$(IDIR_$(1))/CONTROL; \
                ( \
                        echo "$$$$CONTROL"; \
@@ -249,20 +281,6 @@ $(_endef)
                $($(1)_COMMANDS) \
        )
 
-    ifneq ($$(KEEP_$(1)),)
-               @( \
-                       keepfiles=""; \
-                       for x in $$(KEEP_$(1)); do \
-                               [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
-                       done; \
-                       [ -z "$$$$keepfiles" ] || { \
-                               mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
-                               for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
-                       }; \
-               )
-    endif
-
-       $(INSTALL_DIR) $$(PDIR_$(1))
        $(FAKEROOT) $(SCRIPT_DIR)/ipkg-build -m "$(FILE_MODES)" $$(IDIR_$(1)) $$(PDIR_$(1))
        @[ -f $$(IPKG_$(1)) ]
 
index ec503dc5273d43d6cec3699e50dd654f23ceda99..16fbfaf6842bff63ca59082395f52ef2d9806528 100644 (file)
@@ -60,6 +60,8 @@ $(curdir)/merge-index: $(curdir)/merge
 
 ifndef SDK
   $(curdir)/compile: $(curdir)/system/opkg/host/compile
+  $(curdir)/compile: $(curdir)/system/opkg/host/compile
+  $(patsubst %,$(curdir)/%/compile,$(filter-out %/apk/host,$($(curdir)/builddirs))): $(curdir)/feeds/packages/apk/host/compile
 endif
 
 $(curdir)/install: $(TMP_DIR)/.build $(curdir)/merge $(if $(CONFIG_TARGET_PER_DEVICE_ROOTFS),$(curdir)/merge-index)
@@ -84,6 +86,7 @@ $(curdir)/index: FORCE
        @for d in $(PACKAGE_SUBDIRS); do ( \
                mkdir -p $$d; \
                cd $$d || continue; \
+               $(SCRIPT_DIR)/apk-make-index.sh . 2>&1; \
                $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages.manifest; \
                grep -vE '^(Maintainer|LicenseFiles|Source|SourceName|Require|SourceDateEpoch)' Packages.manifest > Packages; \
                case "$$(((64 + $$(stat -L -c%s Packages)) % 128))" in 110|111) \
index 8a1ddf96f50b29324dc46cfc1501dbd351d6748b..9db48129812465a543538f5dfa1faad9d89e3fa9 100644 (file)
@@ -107,6 +107,10 @@ ifdef CONFIG_SIGNED_PACKAGES
        [ -s $(BUILD_KEY).ucert ] || \
                $(STAGING_DIR_HOST)/bin/ucert -I -c $(BUILD_KEY).ucert -p $(BUILD_KEY).pub -s $(BUILD_KEY)
 
+       [ -s $(BUILD_KEY_APK_SEC) -a -s $(BUILD_KEY_APK_PUB) ] || \
+               openssl ecparam -name prime256v1 -genkey -noout -out $(BUILD_KEY_APK_SEC); \
+               openssl ec -in $(BUILD_KEY_APK_SEC) -pubout > $(BUILD_KEY_APK_PUB)
+
   endef
 
 ifndef CONFIG_BUILDBOT
index f31d9bb113e25f83475177ca83125d98ba9346a6..de81b65d463973a25a3134c2790c503f759eeeea 100644 (file)
--- a/rules.mk
+++ b/rules.mk
@@ -258,6 +258,8 @@ else
 endif
 
 BUILD_KEY=$(TOPDIR)/key-build
+BUILD_KEY_APK_SEC=$(TOPDIR)/private-key.pem
+BUILD_KEY_APK_PUB=$(TOPDIR)/public-key.pem
 
 FAKEROOT:=$(STAGING_DIR_HOST)/bin/fakeroot
 
diff --git a/scripts/apk-make-index.sh b/scripts/apk-make-index.sh
new file mode 100755 (executable)
index 0000000..df1f1a2
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+set -e
+
+pkg_dir=$1
+
+if [ -z "$pkg_dir" ] || [ ! -d "$pkg_dir" ]; then
+       echo "Usage: apk-make-index <package_directory>" >&2
+       exit 1
+fi
+
+(
+       cd "$pkg_dir" || exit 1
+       GLOBIGNORE="kernel*:libc*"
+       set -- *.apk
+       if [ "$1" = '*.apk' ]; then
+               echo "No APK packages found"
+       fi
+       apk index --output APKINDEX.tar.gz "$@"
+       unset GLOBIGNORE
+)