package.mk 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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)/host.mk
  34. include $(INCLUDE_DIR)/unpack.mk
  35. include $(INCLUDE_DIR)/depends.mk
  36. include $(INCLUDE_DIR)/quilt.mk
  37. find_library_dependencies = $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
  38. $(filter-out $(BUILD_PACKAGES),$(foreach dep, \
  39. $(filter-out @%, $(patsubst +%,%,$(1))), \
  40. $(if $(findstring :,$(dep)), \
  41. $(word 2,$(subst :,$(space),$(dep))), \
  42. $(dep) \
  43. ) \
  44. ))))
  45. PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
  46. STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
  47. PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
  48. ifneq ($(PREV_STAMP_PREPARED),)
  49. STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
  50. CONFIG_AUTOREBUILD:=
  51. else
  52. STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))$(call confvar,$(PKG_PREPARED_DEPENDS)))
  53. endif
  54. STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
  55. STAMP_CONFIGURED_WILDCARD=$(PKG_BUILD_DIR)/.configured_*
  56. STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
  57. STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
  58. STAGING_FILES_LIST:=$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
  59. define CleanStaging
  60. rm -f $(STAMP_INSTALLED)
  61. @-(\
  62. cd "$(STAGING_DIR)"; \
  63. if [ -f packages/$(STAGING_FILES_LIST) ]; then \
  64. cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
  65. fi; \
  66. )
  67. endef
  68. ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
  69. USE_GIT_TREE:=1
  70. QUILT:=1
  71. endif
  72. ifdef USE_SOURCE_DIR
  73. QUILT:=1
  74. endif
  75. ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
  76. QUILT:=1
  77. endif
  78. PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
  79. include $(INCLUDE_DIR)/package-defaults.mk
  80. include $(INCLUDE_DIR)/package-dumpinfo.mk
  81. include $(INCLUDE_DIR)/package-ipkg.mk
  82. include $(INCLUDE_DIR)/package-bin.mk
  83. include $(INCLUDE_DIR)/autotools.mk
  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); git checkout .)
  104. endef
  105. endif
  106. ifdef USE_SOURCE_DIR
  107. define Build/Prepare/Default
  108. rm -rf $(PKG_BUILD_DIR)
  109. $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
  110. ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
  111. touch $(PKG_BUILD_DIR)/.source_dir
  112. endef
  113. endif
  114. define Build/Exports/Default
  115. $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR)/usr/share/aclocal $$(STAGING_DIR)/usr/share/aclocal-* $$(STAGING_DIR)/host/share/aclocal $$(STAGING_DIR)/host/share/aclocal-*),-I $$(p))
  116. $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
  117. $(1) : export PATH=$$(TARGET_PATH_PKG)
  118. $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
  119. $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
  120. $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
  121. $(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache
  122. endef
  123. Build/Exports=$(Build/Exports/Default)
  124. define Build/CoreTargets
  125. $(if $(QUILT),$(Build/Quilt))
  126. $(call Build/Autoclean)
  127. download:
  128. $(foreach hook,$(Hooks/Download),
  129. $(call $(hook))$(sep)
  130. )
  131. $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
  132. $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
  133. @-rm -rf $(PKG_BUILD_DIR)
  134. @mkdir -p $(PKG_BUILD_DIR)
  135. $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
  136. $(Build/Prepare)
  137. $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
  138. touch $$@
  139. $(call Build/Exports,$(STAMP_CONFIGURED))
  140. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(STAMP_CONFIGURED_DEPENDS)
  141. $(CleanStaging)
  142. $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
  143. $(Build/Configure)
  144. $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
  145. rm -f $(STAMP_CONFIGURED_WILDCARD)
  146. touch $$@
  147. $(call Build/Exports,$(STAMP_BUILT))
  148. $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
  149. $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
  150. $(Build/Compile)
  151. $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
  152. $(Build/Install)
  153. $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
  154. touch $$@
  155. $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
  156. $(STAMP_INSTALLED): $(STAMP_BUILT)
  157. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  158. mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
  159. $(foreach hook,$(Hooks/InstallDev/Pre),\
  160. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  161. )
  162. $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
  163. $(foreach hook,$(Hooks/InstallDev/Post),\
  164. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  165. )
  166. if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
  167. $(SCRIPT_DIR)/clean-package.sh \
  168. "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
  169. "$(STAGING_DIR)"; \
  170. fi
  171. if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
  172. (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
  173. $(call locked, \
  174. mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
  175. $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
  176. ,staging-dir); \
  177. fi
  178. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  179. touch $$@
  180. ifdef Build/InstallDev
  181. compile: $(STAMP_INSTALLED)
  182. endif
  183. prepare: $(STAMP_PREPARED)
  184. configure: $(STAMP_CONFIGURED)
  185. dist: $(STAMP_CONFIGURED)
  186. distcheck: $(STAMP_CONFIGURED)
  187. endef
  188. define Build/DefaultTargets
  189. $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  190. $(if $(DUMP),,$(Build/CoreTargets))
  191. define Build/DefaultTargets
  192. endef
  193. endef
  194. define Build/IncludeOverlay
  195. $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_DIR_NAME).mk))
  196. define Build/IncludeOverlay
  197. endef
  198. endef
  199. define BuildPackage
  200. $(Build/IncludeOverlay)
  201. $(eval $(Package/Default))
  202. $(eval $(Package/$(1)))
  203. ifdef DESCRIPTION
  204. $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
  205. endif
  206. ifndef Package/$(1)/description
  207. define Package/$(1)/description
  208. $(TITLE)
  209. endef
  210. endif
  211. BUILD_PACKAGES += $(1)
  212. $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(DEPENDS)))
  213. $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
  214. ifeq ($($(FIELD)),)
  215. $$(error Package/$(1) is missing the $(FIELD) field)
  216. endif
  217. )
  218. $(if $(DUMP), \
  219. $(if $(CHECK),,$(Dumpinfo/Package)), \
  220. $(foreach target, \
  221. $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
  222. $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
  223. ), $(BuildTarget/$(target)) \
  224. ) \
  225. )
  226. $(if $(PKG_HOST_ONLY),,$(call Build/DefaultTargets,$(1)))
  227. endef
  228. define pkg_install_files
  229. $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
  230. endef
  231. define pkg_install_bin
  232. $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
  233. endef
  234. Build/Prepare=$(call Build/Prepare/Default,)
  235. Build/Configure=$(call Build/Configure/Default,)
  236. Build/Compile=$(call Build/Compile/Default,)
  237. Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
  238. Build/Dist=$(call Build/Dist/Default,)
  239. Build/DistCheck=$(call Build/DistCheck/Default,)
  240. .NOTPARALLEL:
  241. .PHONY: prepare-package-install
  242. prepare-package-install:
  243. @mkdir -p $(PKG_INFO_DIR)
  244. @touch $(PKG_INSTALL_STAMP).clean
  245. @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
  246. $(PACKAGE_DIR):
  247. mkdir -p $@
  248. dumpinfo:
  249. download:
  250. prepare:
  251. configure:
  252. compile: prepare-package-install
  253. install: compile
  254. clean: FORCE
  255. $(CleanStaging)
  256. $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
  257. $(Build/Clean)
  258. rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
  259. rm -rf $(PKG_BUILD_DIR)
  260. dist:
  261. $(Build/Dist)
  262. distcheck:
  263. $(Build/DistCheck)