1
0

package.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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)/$(if $(BUILD_VARIANT),$(PKG_NAME)-$(BUILD_VARIANT)/)$(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 ($(wildcard $(TOPDIR)/git-src/$(PKG_NAME)/.git),)
  36. USE_GIT_SRC_CHECKOUT:=1
  37. QUILT:=1
  38. endif
  39. ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
  40. USE_GIT_TREE:=1
  41. QUILT:=1
  42. endif
  43. ifdef USE_SOURCE_DIR
  44. QUILT:=1
  45. endif
  46. ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
  47. QUILT:=1
  48. endif
  49. include $(INCLUDE_DIR)/quilt.mk
  50. find_library_dependencies = \
  51. $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
  52. $(sort $(foreach dep4, \
  53. $(sort $(foreach dep3, \
  54. $(sort $(foreach dep2, \
  55. $(sort $(foreach dep1, \
  56. $(sort $(foreach dep0, \
  57. $(Package/$(1)/depends), \
  58. $(Package/$(dep0)/depends) $(dep0) \
  59. )), \
  60. $(Package/$(dep1)/depends) $(dep1) \
  61. )), \
  62. $(Package/$(dep2)/depends) $(dep2) \
  63. )), \
  64. $(Package/$(dep3)/depends) $(dep3) \
  65. )), \
  66. $(Package/$(dep4)/depends) $(dep4) \
  67. )), \
  68. ))
  69. PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
  70. STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
  71. PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
  72. ifneq ($(PREV_STAMP_PREPARED),)
  73. STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
  74. CONFIG_AUTOREBUILD:=
  75. else
  76. STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(PKG_PREPARED_DEPENDS)))
  77. endif
  78. STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
  79. STAMP_CONFIGURED_WILDCARD=$(PKG_BUILD_DIR)/.configured_*
  80. STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
  81. STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
  82. STAGING_FILES_LIST:=$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
  83. define CleanStaging
  84. rm -f $(STAMP_INSTALLED)
  85. @-(\
  86. if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
  87. $(SCRIPT_DIR)/clean-package.sh \
  88. "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
  89. "$(STAGING_DIR)"; \
  90. fi; \
  91. )
  92. endef
  93. PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
  94. include $(INCLUDE_DIR)/package-defaults.mk
  95. include $(INCLUDE_DIR)/package-dumpinfo.mk
  96. include $(INCLUDE_DIR)/package-ipkg.mk
  97. include $(INCLUDE_DIR)/package-bin.mk
  98. include $(INCLUDE_DIR)/autotools.mk
  99. _pkg_target:=$(if $(QUILT),,.)
  100. override MAKEFLAGS=
  101. CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
  102. CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
  103. SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
  104. PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
  105. unexport QUIET CONFIG_SITE
  106. ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
  107. ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
  108. define Build/Autoclean
  109. $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
  110. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
  111. $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
  112. endef
  113. endif
  114. endif
  115. ifdef USE_GIT_SRC_CHECKOUT
  116. define Build/Prepare/Default
  117. mkdir -p $(PKG_BUILD_DIR)
  118. ln -s $(TOPDIR)/git-src/$(PKG_NAME)/.git $(PKG_BUILD_DIR)/.git
  119. ( cd $(PKG_BUILD_DIR); \
  120. git checkout .; \
  121. git submodule update --recursive; \
  122. git submodule foreach git config --unset core.worktree; \
  123. git submodule foreach git checkout .; \
  124. )
  125. endef
  126. endif
  127. ifdef USE_GIT_TREE
  128. define Build/Prepare/Default
  129. mkdir -p $(PKG_BUILD_DIR)
  130. ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
  131. ( cd $(PKG_BUILD_DIR); \
  132. git checkout .; \
  133. git submodule update --recursive; \
  134. git submodule foreach git config --unset core.worktree; \
  135. git submodule foreach git checkout .; \
  136. )
  137. endef
  138. endif
  139. ifdef USE_SOURCE_DIR
  140. define Build/Prepare/Default
  141. rm -rf $(PKG_BUILD_DIR)
  142. $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
  143. ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
  144. touch $(PKG_BUILD_DIR)/.source_dir
  145. endef
  146. endif
  147. define Build/Exports/Default
  148. $(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))
  149. $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
  150. $(1) : export PATH=$$(TARGET_PATH_PKG)
  151. $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
  152. $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
  153. $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
  154. $(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache)
  155. endef
  156. Build/Exports=$(Build/Exports/Default)
  157. define Build/CoreTargets
  158. STAMP_PREPARED:=$$(STAMP_PREPARED)
  159. STAMP_CONFIGURED:=$$(STAMP_CONFIGURED)
  160. $(if $(QUILT),$(Build/Quilt))
  161. $(call Build/Autoclean)
  162. $(call DefaultTargets)
  163. download:
  164. $(foreach hook,$(Hooks/Download),
  165. $(call $(hook))$(sep)
  166. )
  167. $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
  168. $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
  169. @-rm -rf $(PKG_BUILD_DIR)
  170. @mkdir -p $(PKG_BUILD_DIR)
  171. touch $$@_check
  172. $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
  173. $(Build/Prepare)
  174. $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
  175. touch $$@
  176. $(call Build/Exports,$(STAMP_CONFIGURED))
  177. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(STAMP_CONFIGURED_DEPENDS)
  178. rm -f $(STAMP_CONFIGURED_WILDCARD)
  179. $(CleanStaging)
  180. $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
  181. $(Build/Configure)
  182. $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
  183. touch $$@
  184. $(call Build/Exports,$(STAMP_BUILT))
  185. $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
  186. rm -f $$@
  187. touch $$@_check
  188. $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
  189. $(Build/Compile)
  190. $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
  191. $(Build/Install)
  192. $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
  193. touch $$@
  194. $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
  195. $(STAMP_INSTALLED): $(STAMP_BUILT)
  196. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  197. mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
  198. $(foreach hook,$(Hooks/InstallDev/Pre),\
  199. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  200. )
  201. $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
  202. $(foreach hook,$(Hooks/InstallDev/Post),\
  203. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  204. )
  205. if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
  206. $(SCRIPT_DIR)/clean-package.sh \
  207. "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
  208. "$(STAGING_DIR)"; \
  209. fi
  210. if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
  211. (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
  212. $(call locked, \
  213. mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
  214. $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
  215. ,staging-dir); \
  216. fi
  217. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  218. touch $$@
  219. ifdef Build/InstallDev
  220. $(_pkg_target)compile: $(STAMP_INSTALLED)
  221. endif
  222. $(_pkg_target)prepare: $(STAMP_PREPARED)
  223. $(_pkg_target)configure: $(STAMP_CONFIGURED)
  224. $(_pkg_target)dist: $(STAMP_CONFIGURED)
  225. $(_pkg_target)distcheck: $(STAMP_CONFIGURED)
  226. ifneq ($(CONFIG_AUTOREMOVE),)
  227. compile:
  228. -touch -r $(PKG_BUILD_DIR)/.built $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null
  229. $(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | \
  230. $(XARGS) rm -rf
  231. endif
  232. endef
  233. define Build/DefaultTargets
  234. $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE)$(USE_GIT_SRC_CHECKOUT),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  235. $(if $(DUMP),,$(Build/CoreTargets))
  236. define Build/DefaultTargets
  237. endef
  238. endef
  239. define BuildPackage
  240. $(eval $(Package/Default))
  241. $(eval $(Package/$(1)))
  242. ifdef DESCRIPTION
  243. $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
  244. endif
  245. ifndef Package/$(1)/description
  246. define Package/$(1)/description
  247. $(TITLE)
  248. endef
  249. endif
  250. BUILD_PACKAGES += $(1)
  251. $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(1)))
  252. $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
  253. ifeq ($($(FIELD)),)
  254. $$(error Package/$(1) is missing the $(FIELD) field)
  255. endif
  256. )
  257. $(if $(DUMP), \
  258. $(if $(CHECK),,$(Dumpinfo/Package)), \
  259. $(foreach target, \
  260. $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
  261. $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
  262. ), $(BuildTarget/$(target)) \
  263. ) \
  264. )
  265. $(if $(PKG_HOST_ONLY),,$(call Build/DefaultTargets,$(1)))
  266. endef
  267. define pkg_install_files
  268. $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
  269. endef
  270. define pkg_install_bin
  271. $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
  272. endef
  273. Build/Prepare=$(call Build/Prepare/Default,)
  274. Build/Configure=$(call Build/Configure/Default,)
  275. Build/Compile=$(call Build/Compile/Default,)
  276. Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
  277. Build/Dist=$(call Build/Dist/Default,)
  278. Build/DistCheck=$(call Build/DistCheck/Default,)
  279. .NOTPARALLEL:
  280. .PHONY: prepare-package-install
  281. prepare-package-install:
  282. @mkdir -p $(PKG_INFO_DIR)
  283. @rm -f $(PKG_INSTALL_STAMP)
  284. @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
  285. $(PACKAGE_DIR):
  286. mkdir -p $@
  287. compile:
  288. .install: .compile
  289. install: compile
  290. force-clean-build: FORCE
  291. rm -rf $(PKG_BUILD_DIR)
  292. clean-build: $(if $(wildcard $(PKG_BUILD_DIR)/.autoremove),force-clean-build)
  293. clean: force-clean-build
  294. $(CleanStaging)
  295. $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
  296. $(Build/Clean)
  297. rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
  298. dist:
  299. $(Build/Dist)
  300. distcheck:
  301. $(Build/DistCheck)