package-ipkg.mk 8.4 KB

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