package-ipkg.mk 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. ifdef Package/$(1)/install
  87. ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
  88. IPKGS += $(1)
  89. compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
  90. ifneq ($(ABI_VERSION),)
  91. compile: $(PKG_INFO_DIR)/$(1).version
  92. endif
  93. else
  94. $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
  95. endif
  96. .PHONY: $(PKG_INSTALL_STAMP).$(1)
  97. compile: $(PKG_INSTALL_STAMP).$(1)
  98. $(PKG_INSTALL_STAMP).$(1):
  99. if [ -f $(PKG_INSTALL_STAMP).clean ]; then \
  100. rm -f \
  101. $(PKG_INSTALL_STAMP) \
  102. $(PKG_INSTALL_STAMP).clean; \
  103. fi
  104. ifeq ($(CONFIG_PACKAGE_$(1)),y)
  105. echo "$(1)" >> $(PKG_INSTALL_STAMP)
  106. endif
  107. endif
  108. endif
  109. DEPENDS:=$(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
  110. IDEPEND_$(1):=$$(call filter_deps,$$(DEPENDS))
  111. IDEPEND += $$(patsubst %,$(1):%,$$(IDEPEND_$(1)))
  112. $(FixupDependencies)
  113. $(FixupReverseDependencies)
  114. $(eval $(call BuildIPKGVariable,$(1),conffiles))
  115. $(eval $(call BuildIPKGVariable,$(1),preinst,,1))
  116. $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg,1))
  117. $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg,1))
  118. $(eval $(call BuildIPKGVariable,$(1),postrm,,1))
  119. $(STAGING_DIR_ROOT)/stamp/.$(1)_installed : export PATH=$$(TARGET_PATH_PKG)
  120. $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
  121. rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
  122. mkdir -p $(STAGING_DIR_ROOT)/stamp $(STAGING_DIR_ROOT)/tmp-$(1)
  123. $(call Package/$(1)/install,$(STAGING_DIR_ROOT)/tmp-$(1))
  124. $(call Package/$(1)/install_lib,$(STAGING_DIR_ROOT)/tmp-$(1))
  125. $(call locked,$(CP) $(STAGING_DIR_ROOT)/tmp-$(1)/. $(STAGING_DIR_ROOT)/,root-copy)
  126. rm -rf $(STAGING_DIR_ROOT)/tmp-$(1)
  127. touch $$@
  128. $(PKG_INFO_DIR)/$(1).version: $$(IPKG_$(1))
  129. echo '$(ABI_VERSION)' | cmp -s - $$@ || \
  130. echo '$(ABI_VERSION)' > $$@
  131. Package/$(1)/DEPENDS := $$(call mergelist,$$(filter-out @%,$$(IDEPEND_$(1))))
  132. ifneq ($$(EXTRA_DEPENDS),)
  133. Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
  134. endif
  135. $(_define) Package/$(1)/CONTROL
  136. Package: $(1)
  137. Version: $(VERSION)
  138. $$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
  139. )$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
  140. )$$(call addfield,Provides,$$(call mergelist,$(PROVIDES))
  141. )$$(call addfield,Source,$(SOURCE)
  142. )$$(call addfield,License,$$(PKG_LICENSE)
  143. )$$(call addfield,LicenseFiles,$$(PKG_LICENSE_FILES)
  144. )$$(call addfield,Section,$(SECTION)
  145. )$$(call addfield,Require-User,$(USERID)
  146. )$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
  147. )$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
  148. )$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
  149. )Architecture: $(PKGARCH)
  150. Installed-Size: 0
  151. $(_endef)
  152. $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
  153. $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
  154. $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
  155. $$(IPKG_$(1)) : export PATH=$$(TARGET_PATH_PKG)
  156. $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
  157. @rm -rf $$(IDIR_$(1)) $$(call opkg_package_files,$(1))
  158. mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
  159. $(call Package/$(1)/install,$$(IDIR_$(1)))
  160. -find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
  161. @( \
  162. find $$(IDIR_$(1)) -name lib\*.so\* -or -name \*.ko | awk -F/ '{ print $$$$NF }'; \
  163. for file in $$(patsubst %,$(PKG_INFO_DIR)/%.provides,$$(IDEPEND_$(1))); do \
  164. if [ -f "$$$$file" ]; then \
  165. cat $$$$file; \
  166. fi; \
  167. done; $(Package/$(1)/extra_provides) \
  168. ) | sort -u > $(PKG_INFO_DIR)/$(1).provides
  169. $(if $(PROVIDES),@for pkg in $(PROVIDES); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
  170. $(CheckDependencies)
  171. $(RSTRIP) $$(IDIR_$(1))
  172. (cd $$(IDIR_$(1))/CONTROL; \
  173. ( \
  174. echo "$$$$CONTROL"; \
  175. printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
  176. ) > control; \
  177. chmod 644 control; \
  178. ( \
  179. echo "#!/bin/sh"; \
  180. echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
  181. echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
  182. echo "default_postinst \$$$$0 \$$$$@"; \
  183. ) > postinst; \
  184. ( \
  185. echo "#!/bin/sh"; \
  186. echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
  187. echo "default_prerm \$$$$0 \$$$$@"; \
  188. ) > prerm; \
  189. chmod 0755 postinst prerm; \
  190. $($(1)_COMMANDS) \
  191. )
  192. ifneq ($$(KEEP_$(1)),)
  193. @( \
  194. keepfiles=""; \
  195. for x in $$(KEEP_$(1)); do \
  196. [ -f "$$(IDIR_$(1))/$$$$x" ] || keepfiles="$$$${keepfiles:+$$$$keepfiles }$$$$x"; \
  197. done; \
  198. [ -z "$$$$keepfiles" ] || { \
  199. mkdir -p $$(IDIR_$(1))/lib/upgrade/keep.d; \
  200. for x in $$$$keepfiles; do echo $$$$x >> $$(IDIR_$(1))/lib/upgrade/keep.d/$(1); done; \
  201. }; \
  202. )
  203. endif
  204. $(INSTALL_DIR) $$(PDIR_$(1))
  205. $(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
  206. @[ -f $$(IPKG_$(1)) ]
  207. $(1)-clean:
  208. $$(if $$(call opkg_package_files,$(1)),rm -f $$(call opkg_package_files,$(1)))
  209. clean: $(1)-clean
  210. endef
  211. endif