package-ipkg.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2006-2020 OpenWrt.org
  4. ifndef DUMP
  5. include $(INCLUDE_DIR)/feeds.mk
  6. endif
  7. IPKG_REMOVE:= \
  8. $(SCRIPT_DIR)/ipkg-remove
  9. IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
  10. # Generates a make statement to return a wildcard for candidate ipkg files
  11. # 1: package name
  12. define gen_ipkg_wildcard
  13. $(1)$$(if $$(filter -%,$$(ABIV_$(1))),,[^a-z-])*
  14. endef
  15. # 1: package name
  16. # 2: candidate ipk files
  17. define remove_ipkg_files
  18. $(if $(strip $(2)),$(IPKG_REMOVE) $(1) $(2))
  19. endef
  20. # 1: package name
  21. # 2: variable name
  22. # 3: variable suffix
  23. # 4: file is a script
  24. define BuildIPKGVariable
  25. ifdef Package/$(1)/$(2)
  26. $$(IPKG_$(1)) : VAR_$(2)$(3)=$$(Package/$(1)/$(2))
  27. $(call shexport,Package/$(1)/$(2))
  28. $(1)_COMMANDS += echo "$$$$$$$$$(call shvar,Package/$(1)/$(2))" > $(2)$(3); $(if $(4),chmod 0755 $(2)$(3);)
  29. endif
  30. endef
  31. PARENL :=(
  32. PARENR :=)
  33. dep_split=$(subst :,$(space),$(1))
  34. dep_rem=$(subst !,,$(subst $(strip $(PARENL)),,$(subst $(strip $(PARENR)),,$(word 1,$(call dep_split,$(1))))))
  35. dep_and=dep_and_res:=$$(and $(subst $(space),$(comma),$(foreach cond,$(subst &&, ,$(1)),$$(CONFIG_$(cond)))))
  36. dep_confvar=$(strip $(foreach cond,$(subst ||, ,$(call dep_rem,$(1))),$(eval $(call dep_and,$(cond)))$(dep_and_res)))
  37. dep_pos=$(if $(call dep_confvar,$(1)),$(call dep_val,$(1)))
  38. dep_neg=$(if $(call dep_confvar,$(1)),,$(call dep_val,$(1)))
  39. dep_if=$(if $(findstring !,$(1)),$(call dep_neg,$(1)),$(call dep_pos,$(1)))
  40. dep_val=$(word 2,$(call dep_split,$(1)))
  41. strip_deps=$(strip $(subst +,,$(filter-out @%,$(1))))
  42. filter_deps=$(foreach dep,$(call strip_deps,$(1)),$(if $(findstring :,$(dep)),$(call dep_if,$(dep)),$(dep)))
  43. define AddDependency
  44. $$(if $(1),$$(if $(2),$$(foreach pkg,$(1),$$(IPKG_$$(pkg))): $$(foreach pkg,$(2),$$(IPKG_$$(pkg)))))
  45. endef
  46. define FixupReverseDependencies
  47. DEPS := $$(filter %:$(1),$$(IDEPEND))
  48. DEPS := $$(patsubst %:$(1),%,$$(DEPS))
  49. DEPS := $$(filter $$(DEPS),$$(IPKGS))
  50. $(call AddDependency,$$(DEPS),$(1))
  51. endef
  52. define FixupDependencies
  53. DEPS := $$(filter $(1):%,$$(IDEPEND))
  54. DEPS := $$(patsubst $(1):%,%,$$(DEPS))
  55. DEPS := $$(filter $$(DEPS),$$(IPKGS))
  56. $(call AddDependency,$(1),$$(DEPS))
  57. endef
  58. ifneq ($(PKG_NAME),toolchain)
  59. define CheckDependencies
  60. @( \
  61. rm -f $(PKG_INFO_DIR)/$(1).missing; \
  62. ( \
  63. export \
  64. READELF=$(TARGET_CROSS)readelf \
  65. OBJCOPY=$(TARGET_CROSS)objcopy \
  66. XARGS="$(XARGS)"; \
  67. $(SCRIPT_DIR)/gen-dependencies.sh "$$(IDIR_$(1))"; \
  68. ) | while read FILE; do \
  69. grep -qxF "$$$$FILE" $(PKG_INFO_DIR)/$(1).provides || \
  70. echo "$$$$FILE" >> $(PKG_INFO_DIR)/$(1).missing; \
  71. done; \
  72. if [ -f "$(PKG_INFO_DIR)/$(1).missing" ]; then \
  73. echo "Package $(1) is missing dependencies for the following libraries:" >&2; \
  74. cat "$(PKG_INFO_DIR)/$(1).missing" >&2; \
  75. false; \
  76. fi; \
  77. )
  78. endef
  79. endif
  80. _addsep=$(word 1,$(1))$(foreach w,$(wordlist 2,$(words $(1)),$(1)),$(strip $(2) $(w)))
  81. _cleansep=$(subst $(space)$(2)$(space),$(2)$(space),$(1))
  82. mergelist=$(call _cleansep,$(call _addsep,$(1),$(comma)),$(comma))
  83. addfield=$(if $(strip $(2)),$(1): $(2))
  84. _define=define
  85. _endef=endef
  86. ifeq ($(DUMP),)
  87. define BuildTarget/ipkg
  88. ABIV_$(1):=$(call FormatABISuffix,$(1),$(ABI_VERSION))
  89. PDIR_$(1):=$(call FeedPackageDir,$(1))
  90. IPKG_$(1):=$$(PDIR_$(1))/$(1)$$(ABIV_$(1))_$(VERSION)_$(PKGARCH).ipk
  91. IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
  92. KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
  93. TARGET_VARIANT:=$$(if $(ALL_VARIANTS),$$(if $$(VARIANT),$$(filter-out *,$$(VARIANT)),$(firstword $(ALL_VARIANTS))))
  94. ifeq ($(BUILD_VARIANT),$$(if $$(TARGET_VARIANT),$$(TARGET_VARIANT),$(BUILD_VARIANT)))
  95. do_install=
  96. ifdef Package/$(1)/install
  97. do_install=yes
  98. endif
  99. ifdef Package/$(1)/install-overlay
  100. do_install=yes
  101. endif
  102. ifdef do_install
  103. ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
  104. IPKGS += $(1)
  105. $(_pkg_target)compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
  106. prepare-package-install: $$(IPKG_$(1))
  107. compile: $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
  108. else
  109. $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
  110. endif
  111. .PHONY: $(PKG_INSTALL_STAMP).$(1)
  112. ifeq ($(CONFIG_PACKAGE_$(1)),y)
  113. compile: $(PKG_INSTALL_STAMP).$(1)
  114. endif
  115. $(PKG_INSTALL_STAMP).$(1): prepare-package-install
  116. echo "$(1)" >> $(PKG_INSTALL_STAMP)
  117. else
  118. $(if $(CONFIG_PACKAGE_$(1)),$$(warning WARNING: skipping $(1) -- package has no install section))
  119. endif
  120. endif
  121. DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
  122. IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
  123. IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
  124. $(FixupDependencies)
  125. $(FixupReverseDependencies)
  126. $(eval $(call BuildIPKGVariable,$(1),conffiles))
  127. $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
  128. $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
  129. $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
  130. $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
  131. $(PKG_BUILD_DIR)/.pkgdir/$(1).installed : export PATH=$$(TARGET_PATH_PKG)
  132. $(PKG_BUILD_DIR)/.pkgdir/$(1).installed: $(STAMP_BUILT)
  133. rm -rf $$@ $(PKG_BUILD_DIR)/.pkgdir/$(1)
  134. mkdir -p $(PKG_BUILD_DIR)/.pkgdir/$(1)
  135. $(call Package/$(1)/install,$(PKG_BUILD_DIR)/.pkgdir/$(1))
  136. $(call Package/$(1)/install_lib,$(PKG_BUILD_DIR)/.pkgdir/$(1))
  137. touch $$@
  138. $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(PKG_BUILD_DIR)/.pkgdir/$(1).installed
  139. mkdir -p $(STAGING_DIR_ROOT)/stamp
  140. $(if $(ABI_VERSION),echo '$(ABI_VERSION)' | cmp -s - $(PKG_INFO_DIR)/$(1).version || { \
  141. echo '$(ABI_VERSION)' > $(PKG_INFO_DIR)/$(1).version; \
  142. $(foreach pkg,$(filter-out $(1),$(PROVIDES)), \
  143. cp $(PKG_INFO_DIR)/$(1).version $(PKG_INFO_DIR)/$(pkg).version; \
  144. ) \
  145. } )
  146. $(call locked,$(CP) $(PKG_BUILD_DIR)/.pkgdir/$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
  147. touch $$@
  148. Package/$(1)/DEPENDS := $$(call mergelist,$$(foreach dep,$$(filter-out @%,$$(IDEPEND_$(1))),$$(dep)$$(call GetABISuffix,$$(dep))))
  149. ifneq ($$(EXTRA_DEPENDS),)
  150. Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
  151. endif
  152. $(_define) Package/$(1)/CONTROL
  153. Package: $(1)$$(ABIV_$(1))
  154. Version: $(VERSION)
  155. $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
  156. )$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
  157. )$$(call addfield,Provides,$$(call mergelist,$$(filter-out $(1)$$(ABIV_$(1)),$(PROVIDES)$$(if $$(ABIV_$(1)), $(1) $(foreach provide,$(PROVIDES),$(provide)$$(ABIV_$(1))))))
  158. )$$(call addfield,Alternatives,$$(call mergelist,$(ALTERNATIVES))
  159. )$$(call addfield,Source,$(SOURCE)
  160. )$$(call addfield,SourceName,$(1)
  161. )$$(call addfield,License,$(LICENSE)
  162. )$$(call addfield,LicenseFiles,$(LICENSE_FILES)
  163. )$$(call addfield,Section,$(SECTION)
  164. )$$(call addfield,Require-User,$(USERID)
  165. )$$(call addfield,SourceDateEpoch,$(PKG_SOURCE_DATE_EPOCH)
  166. )$$(if $$(ABIV_$(1)),ABIVersion: $$(ABIV_$(1))
  167. )$(if $(PKG_CPE_ID),CPE-ID: $(PKG_CPE_ID)
  168. )$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
  169. )$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
  170. )$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
  171. )Architecture: $(PKGARCH)
  172. Installed-Size: 0
  173. $(_endef)
  174. $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
  175. $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
  176. $$(IPKG_$(1)) : export PATH=$$(TARGET_PATH_PKG)
  177. $$(IPKG_$(1)) : export PKG_SOURCE_DATE_EPOCH:=$(PKG_SOURCE_DATE_EPOCH)
  178. $(PKG_INFO_DIR)/$(1).provides $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
  179. @rm -rf $$(IDIR_$(1)); \
  180. $$(call remove_ipkg_files,$(1),$$(call opkg_package_files,$(call gen_ipkg_wildcard,$(1))))
  181. mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
  182. $(call Package/$(1)/install,$$(IDIR_$(1)))
  183. $(if $(Package/$(1)/install-overlay),mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/rootfs-overlay)
  184. $(call Package/$(1)/install-overlay,$$(IDIR_$(1))/rootfs-overlay)
  185. -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
  186. @( \
  187. find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
  188. for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
  189. if [ -f "$$$$file" ]; then \
  190. cat $$$$file; \
  191. fi; \
  192. done; $(Package/$(1)/extra_provides) \
  193. ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
  194. $(if $(PROVIDES),@for pkg in $(filter-out $(1),$(PROVIDES)); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
  195. $(CheckDependencies)
  196. $(RSTRIP) $$(IDIR_$(1))
  197. ifneq ($$(CONFIG_IPK_FILES_CHECKSUMS),)
  198. (cd $$(IDIR_$(1)); \
  199. ( \
  200. find . -type f \! -path ./CONTROL/\* -exec $(MKHASH) sha256 -n \{\} \; 2> /dev/null | \
  201. sed 's|\([[:blank:]]\)\./| \1/|' > $$(IDIR_$(1))/CONTROL/files-sha256sum \
  202. ) || true \
  203. )
  204. endif
  205. (cd $$(IDIR_$(1))/CONTROL; \
  206. ( \
  207. echo "$$$$CONTROL"; \
  208. printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
  209. ) > control; \
  210. chmod 644 control; \
  211. ( \
  212. echo "#!/bin/sh"; \
  213. echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
  214. echo "[ -s "\$$$${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; \
  215. echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
  216. echo "default_postinst \$$$$0 \$$$$@"; \
  217. ) > postinst; \
  218. ( \
  219. echo "#!/bin/sh"; \
  220. echo "[ -s "\$$$${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; \
  221. echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
  222. echo "default_prerm \$$$$0 \$$$$@"; \
  223. ) > prerm; \
  224. chmod 0755 postinst prerm; \
  225. $($(1)_COMMANDS) \
  226. )
  227. ifneq ($$(KEEP_$(1)),)
  228. @( \
  229. keepfiles=""; \
  230. for x in $$(KEEP_$(1)); do \
  231. [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
  232. done; \
  233. [ -z "$$$$keepfiles" ] || { \
  234. mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
  235. for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
  236. }; \
  237. )
  238. endif
  239. $(INSTALL_DIR) $$(PDIR_$(1))
  240. $(FAKEROOT) $(STAGING_DIR_HOST)/bin/bash $(SCRIPT_DIR)/ipkg-build -m "$(FILE_MODES)" $$(IDIR_$(1)) $$(PDIR_$(1))
  241. @[ -f $$(IPKG_$(1)) ]
  242. $(1)-clean:
  243. $$(call remove_ipkg_files,$(1),$$(call opkg_package_files,$(call gen_ipkg_wildcard,$(1))))
  244. clean: $(1)-clean
  245. endef
  246. endif