package.mk 9.7 KB

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