b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2006-2010 OpenWrt.org |
| 3 | # |
| 4 | # This is free software, licensed under the GNU General Public License v2. |
| 5 | # See /LICENSE for more information. |
| 6 | # |
| 7 | |
| 8 | curdir:=package |
| 9 | |
| 10 | include $(INCLUDE_DIR)/feeds.mk |
| 11 | include $(INCLUDE_DIR)/rootfs.mk |
| 12 | |
| 13 | -include $(TMP_DIR)/.packagedeps |
| 14 | package-y += kernel/linux |
| 15 | $(curdir)/autoremove:=1 |
| 16 | $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m)) |
| 17 | $(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m)) |
| 18 | $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m)) |
| 19 | ifdef CHECK_ALL |
| 20 | $(curdir)/builddirs-check:=$($(curdir)/builddirs) |
| 21 | $(curdir)/builddirs-download:=$($(curdir)/builddirs) |
| 22 | endif |
| 23 | ifneq ($(IGNORE_ERRORS),) |
| 24 | package-y-filter := $(package-y) |
| 25 | package-m-filter := $(filter-out $(package-y),$(package-m)) |
| 26 | package-n-filter := $(filter-out $(package-y) $(package-m),$(package-)) |
| 27 | package-ignore-errors := $(filter n m y,$(IGNORE_ERRORS)) |
| 28 | package-ignore-errors := $(if $(package-ignore-errors),$(package-ignore-errors),n m) |
| 29 | package-ignore-subdirs := $(sort $(foreach m,$(package-ignore-errors),$(package-$(m)-filter))) |
| 30 | $(curdir)/builddirs-ignore-download := $(package-ignore-subdirs) |
| 31 | $(curdir)/builddirs-ignore-compile := $(package-ignore-subdirs) |
| 32 | $(curdir)/builddirs-ignore-host-download := $(package-ignore-subdirs) |
| 33 | $(curdir)/builddirs-ignore-host-compile := $(package-ignore-subdirs) |
| 34 | endif |
| 35 | |
| 36 | PACKAGE_INSTALL_FILES:= \ |
| 37 | $(foreach pkg,$(sort $(package-y)), \ |
| 38 | $(foreach variant, \ |
| 39 | $(if $(strip $(package/$(pkg)/variants)), \ |
| 40 | $(package/$(pkg)/variants), \ |
| 41 | $(if $(package/$(pkg)/default-variant), \ |
| 42 | $(package/$(pkg)/default-variant), \ |
| 43 | default \ |
| 44 | ) \ |
| 45 | ), \ |
| 46 | $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \ |
| 47 | ) \ |
| 48 | ) |
| 49 | |
| 50 | $(curdir)/cleanup: $(TMP_DIR)/.build |
| 51 | rm -rf $(STAGING_DIR_ROOT) |
| 52 | |
| 53 | $(curdir)/merge: |
| 54 | rm -rf $(PACKAGE_DIR_ALL) |
| 55 | mkdir -p $(PACKAGE_DIR_ALL) |
| 56 | ifneq ($(CONFIG_USE_APK),) |
| 57 | -$(foreach pdir,$(PACKAGE_SUBDIRS),$(if $(wildcard $(pdir)/*.apk),ln -s $(pdir)/*.apk $(PACKAGE_DIR_ALL);)) |
| 58 | else |
| 59 | -$(foreach pdir,$(PACKAGE_SUBDIRS),$(if $(wildcard $(pdir)/*.ipk),ln -s $(pdir)/*.ipk $(PACKAGE_DIR_ALL);)) |
| 60 | endif |
| 61 | |
| 62 | $(BUILD_KEY_APK_SEC): |
| 63 | $(STAGING_DIR_HOST)/bin/openssl ecparam -name prime256v1 -genkey -noout -out $(BUILD_KEY_APK_SEC) |
| 64 | |
| 65 | $(BUILD_KEY_APK_PUB): $(BUILD_KEY_APK_SEC) |
| 66 | $(STAGING_DIR_HOST)/bin/openssl ec -in $(BUILD_KEY_APK_SEC) -pubout > $(BUILD_KEY_APK_PUB) |
| 67 | |
| 68 | $(curdir)/merge-index: $(curdir)/merge |
| 69 | ifneq ($(CONFIG_USE_APK),) |
| 70 | (cd $(PACKAGE_DIR_ALL) && $(STAGING_DIR_HOST)/bin/apk mkndx \ |
| 71 | --root $(TOPDIR) \ |
| 72 | --keys-dir $(TOPDIR) \ |
| 73 | --sign $(BUILD_KEY_APK_SEC) \ |
| 74 | --output packages.adb \ |
| 75 | *.apk; \ |
| 76 | ) |
| 77 | else |
| 78 | (cd $(PACKAGE_DIR_ALL) && $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages; ) |
| 79 | endif |
| 80 | |
| 81 | ifndef SDK |
| 82 | $(curdir)//compile = $(STAGING_DIR)/.prepared $(BIN_DIR) |
| 83 | ifneq ($(CONFIG_USE_APK),) |
| 84 | $(curdir)//compile += $(curdir)/system/apk/host/compile $(BUILD_KEY_APK_SEC) $(BUILD_KEY_APK_PUB) |
| 85 | else |
| 86 | $(curdir)/compile: $(curdir)/system/opkg/host/compile |
| 87 | endif |
| 88 | else |
| 89 | ifneq ($(CONFIG_USE_APK),) |
| 90 | $(curdir)//compile += $(BUILD_KEY_APK_SEC) $(BUILD_KEY_APK_PUB) |
| 91 | endif |
| 92 | endif |
| 93 | |
| 94 | $(curdir)/install: $(TMP_DIR)/.build $(curdir)/merge $(curdir)/merge-index |
| 95 | - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755 |
| 96 | rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG) |
| 97 | mkdir -p $(TARGET_DIR)/tmp |
| 98 | ifneq ($(CONFIG_USE_APK),) |
| 99 | $(file >$(TMP_DIR)/apk_install_list,\ |
| 100 | $(foreach pkg,$(shell cat $(PACKAGE_INSTALL_FILES) 2>/dev/null),$(pkg)$(call GetABISuffix,$(pkg)))) |
| 101 | $(call apk,$(TARGET_DIR)) add --initdb --no-scripts --arch $(ARCH_PACKAGES) \ |
| 102 | --repositories-file /dev/zero --repository file://$(PACKAGE_DIR_ALL)/packages.adb \ |
| 103 | $$(cat $(TMP_DIR)/apk_install_list) |
| 104 | else |
| 105 | $(file >$(TMP_DIR)/opkg_install_list,\ |
| 106 | $(call opkg_package_files,\ |
| 107 | $(foreach pkg,$(shell cat $(PACKAGE_INSTALL_FILES) 2>/dev/null),$(pkg)$(call GetABISuffix,$(pkg))))) |
| 108 | $(call opkg,$(TARGET_DIR)) install $$(cat $(TMP_DIR)/opkg_install_list) |
| 109 | @for file in $(PACKAGE_INSTALL_FILES); do \ |
| 110 | [ -s $$file.flags ] || continue; \ |
| 111 | for flag in `cat $$file.flags`; do \ |
| 112 | $(call opkg,$(TARGET_DIR)) flag $$flag `cat $$file`; \ |
| 113 | done; \ |
| 114 | done || true |
| 115 | endif |
| 116 | |
| 117 | $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG) |
| 118 | |
| 119 | $(call prepare_rootfs,$(TARGET_DIR),$(TOPDIR)/files) |
| 120 | |
| 121 | $(curdir)/index: FORCE |
| 122 | @echo Generating package index... |
| 123 | ifneq ($(CONFIG_USE_APK),) |
| 124 | @for d in $(PACKAGE_SUBDIRS); do \ |
| 125 | mkdir -p $$d; \ |
| 126 | cd $$d || continue; \ |
| 127 | ls *.apk >/dev/null 2>&1 || continue; \ |
| 128 | $(STAGING_DIR_HOST)/bin/apk mkndx \ |
| 129 | --root $(TOPDIR) \ |
| 130 | --keys-dir $(TOPDIR) \ |
| 131 | --sign $(BUILD_KEY_APK_SEC) \ |
| 132 | --output packages.adb \ |
| 133 | $$(ls *.apk | grep -v 'kernel\|libc'); \ |
| 134 | done |
| 135 | else |
| 136 | @for d in $(PACKAGE_SUBDIRS); do ( \ |
| 137 | mkdir -p $$d; \ |
| 138 | cd $$d || continue; \ |
| 139 | $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages.manifest; \ |
| 140 | grep -vE '^(Maintainer|LicenseFiles|Source|SourceName|Require|SourceDateEpoch)' Packages.manifest > Packages; \ |
| 141 | case "$$(((64 + $$(stat -L -c%s Packages)) % 128))" in 110|111) \ |
| 142 | $(call ERROR_MESSAGE,WARNING: Applying padding in $$d/Packages to workaround usign SHA-512 bug!); \ |
| 143 | { echo ""; echo ""; } >> Packages;; \ |
| 144 | esac; \ |
| 145 | echo -n '{"architecture": "$(ARCH_PACKAGES)", "packages":{' > index.json; \ |
| 146 | sed -n -e 's/^Package: \(.*\)$$/"\1":/p' -e 's/^Version: \(.*\)$$/"\1",/p' Packages | tr '\n' ' ' >> index.json; \ |
| 147 | echo '}}' >> index.json; \ |
| 148 | sed -i 's/, }}/}}/' index.json; \ |
| 149 | gzip -9nc Packages > Packages.gz; \ |
| 150 | ); done |
| 151 | ifdef CONFIG_SIGNED_PACKAGES |
| 152 | @echo Signing package index... |
| 153 | @for d in $(PACKAGE_SUBDIRS); do ( \ |
| 154 | [ -d $$d ] && \ |
| 155 | cd $$d || continue; \ |
| 156 | $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY); \ |
| 157 | ); done |
| 158 | endif |
| 159 | ifdef CONFIG_JSON_CYCLONEDX_SBOM |
| 160 | @echo Creating CycloneDX package SBOMs... |
| 161 | @for d in $(PACKAGE_SUBDIRS); do ( \ |
| 162 | [ -d $$d ] && \ |
| 163 | cd $$d || continue; \ |
| 164 | $(SCRIPT_DIR)/package-metadata.pl pkgcyclonedxsbom Packages.manifest > Packages.bom.cdx.json || true; \ |
| 165 | ); done |
| 166 | endif |
| 167 | endif |
| 168 | |
| 169 | $(curdir)/flags-install:= -j1 |
| 170 | |
| 171 | $(eval $(call stampfile,$(curdir),package,prereq,.config)) |
| 172 | $(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build)) |
| 173 | $(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build)) |
| 174 | $(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build)) |
| 175 | $(eval $(call stampfile,$(curdir),package,check,$(TMP_DIR)/.build)) |
| 176 | |
| 177 | $(eval $(call subdir,$(curdir))) |