package.mk 9.8 KB

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