package-ipkg.mk 7.8 KB

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