1
0

package-ipkg.mk 9.4 KB

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