package.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #
  2. # Copyright (C) 2006-2008 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. __package_mk:=1
  8. all: $(if $(DUMP),dumpinfo,$(if $(CHECK),check,compile))
  9. include $(INCLUDE_DIR)/download.mk
  10. PKG_BUILD_DIR ?= $(BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
  11. PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
  12. PKG_BUILD_PARALLEL ?=
  13. PKG_USE_MIPS16 ?= 1
  14. PKG_IREMAP ?= 1
  15. MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
  16. ifeq ($(strip $(PKG_BUILD_PARALLEL)),0)
  17. PKG_JOBS?=-j1
  18. else
  19. PKG_JOBS?=$(if $(PKG_BUILD_PARALLEL),$(MAKE_J),-j1)
  20. endif
  21. ifdef CONFIG_USE_MIPS16
  22. ifeq ($(strip $(PKG_USE_MIPS16)),1)
  23. TARGET_ASFLAGS_DEFAULT = $(filter-out -mips16 -minterlink-mips16,$(TARGET_CFLAGS))
  24. TARGET_CFLAGS += -mips16 -minterlink-mips16
  25. endif
  26. endif
  27. ifeq ($(strip $(PKG_IREMAP)),1)
  28. IREMAP_CFLAGS = $(call iremap,$(PKG_BUILD_DIR),$(notdir $(PKG_BUILD_DIR)))
  29. TARGET_CFLAGS += $(IREMAP_CFLAGS)
  30. endif
  31. include $(INCLUDE_DIR)/hardening.mk
  32. include $(INCLUDE_DIR)/prereq.mk
  33. include $(INCLUDE_DIR)/unpack.mk
  34. include $(INCLUDE_DIR)/depends.mk
  35. ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
  36. USE_GIT_TREE:=1
  37. QUILT:=1
  38. endif
  39. ifdef USE_SOURCE_DIR
  40. QUILT:=1
  41. endif
  42. ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
  43. QUILT:=1
  44. endif
  45. include $(INCLUDE_DIR)/quilt.mk
  46. find_library_dependencies = $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
  47. $(filter-out $(BUILD_PACKAGES),$(foreach dep, \
  48. $(filter-out @%, $(patsubst +%,%,$(1))), \
  49. $(if $(findstring :,$(dep)), \
  50. $(word 2,$(subst :,$(space),$(dep))), \
  51. $(dep) \
  52. ) \
  53. ))))
  54. PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
  55. STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
  56. PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
  57. ifneq ($(PREV_STAMP_PREPARED),)
  58. STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
  59. CONFIG_AUTOREBUILD:=
  60. else
  61. STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(PKG_PREPARED_DEPENDS)))
  62. endif
  63. STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
  64. STAMP_CONFIGURED_WILDCARD=$(PKG_BUILD_DIR)/.configured_*
  65. STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
  66. STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
  67. STAGING_FILES_LIST:=$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
  68. define CleanStaging
  69. rm -f $(STAMP_INSTALLED)
  70. @-(\
  71. cd "$(STAGING_DIR)"; \
  72. if [ -f packages/$(STAGING_FILES_LIST) ]; then \
  73. cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
  74. fi; \
  75. )
  76. endef
  77. PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
  78. include $(INCLUDE_DIR)/package-defaults.mk
  79. include $(INCLUDE_DIR)/package-dumpinfo.mk
  80. include $(INCLUDE_DIR)/package-ipkg.mk
  81. include $(INCLUDE_DIR)/package-bin.mk
  82. include $(INCLUDE_DIR)/autotools.mk
  83. _pkg_target:=$(if $(QUILT),,.)
  84. override MAKEFLAGS=
  85. CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
  86. CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
  87. SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
  88. PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
  89. unexport QUIET CONFIG_SITE
  90. ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
  91. ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
  92. define Build/Autoclean
  93. $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
  94. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
  95. $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
  96. endef
  97. endif
  98. endif
  99. ifdef USE_GIT_TREE
  100. define Build/Prepare/Default
  101. mkdir -p $(PKG_BUILD_DIR)
  102. ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
  103. ( cd $(PKG_BUILD_DIR); \
  104. git checkout .; \
  105. git submodule update --recursive; \
  106. git submodule foreach git config --unset core.worktree; \
  107. git submodule foreach git checkout .; \
  108. )
  109. endef
  110. endif
  111. ifdef USE_SOURCE_DIR
  112. define Build/Prepare/Default
  113. rm -rf $(PKG_BUILD_DIR)
  114. $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
  115. ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
  116. touch $(PKG_BUILD_DIR)/.source_dir
  117. endef
  118. endif
  119. define Build/Exports/Default
  120. $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR)/usr/share/aclocal $$(STAGING_DIR)/usr/share/aclocal-* $$(STAGING_DIR_HOSTPKG)/share/aclocal $$(STAGING_DIR_HOSTPKG)/share/aclocal-* $$(STAGING_DIR)/host/share/aclocal $$(STAGING_DIR)/host/share/aclocal-*),-I $$(p))
  121. $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
  122. $(1) : export PATH=$$(TARGET_PATH_PKG)
  123. $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
  124. $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
  125. $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
  126. $(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache
  127. endef
  128. Build/Exports=$(Build/Exports/Default)
  129. define Build/CoreTargets
  130. STAMP_PREPARED:=$$(STAMP_PREPARED)
  131. STAMP_CONFIGURED:=$$(STAMP_CONFIGURED)
  132. $(if $(QUILT),$(Build/Quilt))
  133. $(call Build/Autoclean)
  134. $(call DefaultTargets)
  135. download:
  136. $(foreach hook,$(Hooks/Download),
  137. $(call $(hook))$(sep)
  138. )
  139. $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
  140. $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
  141. @-rm -rf $(PKG_BUILD_DIR)
  142. @mkdir -p $(PKG_BUILD_DIR)
  143. touch $$@_check
  144. $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
  145. $(Build/Prepare)
  146. $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
  147. touch $$@
  148. $(call Build/Exports,$(STAMP_CONFIGURED))
  149. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(STAMP_CONFIGURED_DEPENDS)
  150. rm -f $(STAMP_CONFIGURED_WILDCARD)
  151. $(CleanStaging)
  152. $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
  153. $(Build/Configure)
  154. $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
  155. touch $$@
  156. $(call Build/Exports,$(STAMP_BUILT))
  157. $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
  158. rm -f $$@
  159. touch $$@_check
  160. $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
  161. $(Build/Compile)
  162. $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
  163. $(Build/Install)
  164. $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
  165. touch $$@
  166. $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
  167. $(STAMP_INSTALLED): $(STAMP_BUILT)
  168. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  169. mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
  170. $(foreach hook,$(Hooks/InstallDev/Pre),\
  171. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  172. )
  173. $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
  174. $(foreach hook,$(Hooks/InstallDev/Post),\
  175. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  176. )
  177. if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
  178. $(SCRIPT_DIR)/clean-package.sh \
  179. "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
  180. "$(STAGING_DIR)"; \
  181. fi
  182. if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
  183. (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
  184. $(call locked, \
  185. mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
  186. $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
  187. ,staging-dir); \
  188. fi
  189. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  190. touch $$@
  191. ifdef Build/InstallDev
  192. $(_pkg_target)compile: $(STAMP_INSTALLED)
  193. endif
  194. $(_pkg_target)prepare: $(STAMP_PREPARED)
  195. $(_pkg_target)configure: $(STAMP_CONFIGURED)
  196. $(_pkg_target)dist: $(STAMP_CONFIGURED)
  197. $(_pkg_target)distcheck: $(STAMP_CONFIGURED)
  198. ifneq ($(CONFIG_AUTOREMOVE),)
  199. compile:
  200. -touch -r $(PKG_BUILD_DIR)/.built $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null
  201. $(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | \
  202. $(XARGS) rm -rf
  203. endif
  204. endef
  205. define Build/DefaultTargets
  206. $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  207. $(if $(DUMP),,$(Build/CoreTargets))
  208. define Build/DefaultTargets
  209. endef
  210. endef
  211. define BuildPackage
  212. $(eval $(Package/Default))
  213. $(eval $(Package/$(1)))
  214. ifdef DESCRIPTION
  215. $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
  216. endif
  217. ifndef Package/$(1)/description
  218. define Package/$(1)/description
  219. $(TITLE)
  220. endef
  221. endif
  222. BUILD_PACKAGES += $(1)
  223. $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(DEPENDS)))
  224. $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
  225. ifeq ($($(FIELD)),)
  226. $$(error Package/$(1) is missing the $(FIELD) field)
  227. endif
  228. )
  229. $(if $(DUMP), \
  230. $(if $(CHECK),,$(Dumpinfo/Package)), \
  231. $(foreach target, \
  232. $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
  233. $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
  234. ), $(BuildTarget/$(target)) \
  235. ) \
  236. )
  237. $(if $(PKG_HOST_ONLY),,$(call Build/DefaultTargets,$(1)))
  238. endef
  239. define pkg_install_files
  240. $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
  241. endef
  242. define pkg_install_bin
  243. $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
  244. endef
  245. Build/Prepare=$(call Build/Prepare/Default,)
  246. Build/Configure=$(call Build/Configure/Default,)
  247. Build/Compile=$(call Build/Compile/Default,)
  248. Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
  249. Build/Dist=$(call Build/Dist/Default,)
  250. Build/DistCheck=$(call Build/DistCheck/Default,)
  251. .NOTPARALLEL:
  252. .PHONY: prepare-package-install
  253. prepare-package-install:
  254. @mkdir -p $(PKG_INFO_DIR)
  255. @rm -f $(PKG_INSTALL_STAMP)
  256. @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
  257. $(PACKAGE_DIR):
  258. mkdir -p $@
  259. compile:
  260. .install: .compile
  261. install: compile
  262. force-clean-build: FORCE
  263. rm -rf $(PKG_BUILD_DIR)
  264. clean-build: $(if $(wildcard $(PKG_BUILD_DIR)/.autoremove),force-clean-build)
  265. clean: force-clean-build
  266. $(CleanStaging)
  267. $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
  268. $(Build/Clean)
  269. rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
  270. dist:
  271. $(Build/Dist)
  272. distcheck:
  273. $(Build/DistCheck)