package-ipkg.mk 8.4 KB

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