package.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. $(DL_DIR)/$(FILE): FORCE
  164. download:
  165. $(foreach hook,$(Hooks/Download),
  166. $(call $(hook))$(sep)
  167. )
  168. $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
  169. $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
  170. @-rm -rf $(PKG_BUILD_DIR)
  171. @mkdir -p $(PKG_BUILD_DIR)
  172. touch $$@_check
  173. $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
  174. $(Build/Prepare)
  175. $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
  176. touch $$@
  177. $(call Build/Exports,$(STAMP_CONFIGURED))
  178. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(STAMP_CONFIGURED_DEPENDS)
  179. rm -f $(STAMP_CONFIGURED_WILDCARD)
  180. $(CleanStaging)
  181. $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
  182. $(Build/Configure)
  183. $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
  184. touch $$@
  185. $(call Build/Exports,$(STAMP_BUILT))
  186. $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
  187. rm -f $$@
  188. touch $$@_check
  189. $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
  190. $(Build/Compile)
  191. $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
  192. $(Build/Install)
  193. $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
  194. touch $$@
  195. $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
  196. $(STAMP_INSTALLED): $(STAMP_BUILT)
  197. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  198. mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
  199. $(foreach hook,$(Hooks/InstallDev/Pre),\
  200. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  201. )
  202. $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
  203. $(foreach hook,$(Hooks/InstallDev/Post),\
  204. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  205. )
  206. if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
  207. $(SCRIPT_DIR)/clean-package.sh \
  208. "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
  209. "$(STAGING_DIR)"; \
  210. fi
  211. if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
  212. (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
  213. $(call locked, \
  214. mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
  215. $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
  216. ,staging-dir); \
  217. fi
  218. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  219. touch $$@
  220. ifdef Build/InstallDev
  221. $(_pkg_target)compile: $(STAMP_INSTALLED)
  222. endif
  223. $(_pkg_target)prepare: $(STAMP_PREPARED)
  224. $(_pkg_target)configure: $(STAMP_CONFIGURED)
  225. $(_pkg_target)dist: $(STAMP_CONFIGURED)
  226. $(_pkg_target)distcheck: $(STAMP_CONFIGURED)
  227. ifneq ($(CONFIG_AUTOREMOVE),)
  228. compile:
  229. -touch -r $(PKG_BUILD_DIR)/.built $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null
  230. $(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | \
  231. $(XARGS) rm -rf
  232. endif
  233. endef
  234. define Build/DefaultTargets
  235. $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE)$(USE_GIT_SRC_CHECKOUT),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  236. $(if $(DUMP),,$(Build/CoreTargets))
  237. define Build/DefaultTargets
  238. endef
  239. endef
  240. define BuildPackage
  241. $(eval $(Package/Default))
  242. $(eval $(Package/$(1)))
  243. ifdef DESCRIPTION
  244. $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
  245. endif
  246. ifndef Package/$(1)/description
  247. define Package/$(1)/description
  248. $(TITLE)
  249. endef
  250. endif
  251. BUILD_PACKAGES += $(1)
  252. $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(1)))
  253. $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
  254. ifeq ($($(FIELD)),)
  255. $$(error Package/$(1) is missing the $(FIELD) field)
  256. endif
  257. )
  258. $(if $(DUMP), \
  259. $(if $(CHECK),,$(Dumpinfo/Package)), \
  260. $(foreach target, \
  261. $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
  262. $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
  263. ), $(BuildTarget/$(target)) \
  264. ) \
  265. )
  266. $(if $(PKG_HOST_ONLY),,$(call Build/DefaultTargets,$(1)))
  267. endef
  268. define pkg_install_files
  269. $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
  270. endef
  271. define pkg_install_bin
  272. $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
  273. endef
  274. Build/Prepare=$(call Build/Prepare/Default,)
  275. Build/Configure=$(call Build/Configure/Default,)
  276. Build/Compile=$(call Build/Compile/Default,)
  277. Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
  278. Build/Dist=$(call Build/Dist/Default,)
  279. Build/DistCheck=$(call Build/DistCheck/Default,)
  280. .NOTPARALLEL:
  281. .PHONY: prepare-package-install
  282. prepare-package-install:
  283. @mkdir -p $(PKG_INFO_DIR)
  284. @rm -f $(PKG_INSTALL_STAMP)
  285. @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
  286. $(PACKAGE_DIR):
  287. mkdir -p $@
  288. compile:
  289. .install: .compile
  290. install: compile
  291. force-clean-build: FORCE
  292. rm -rf $(PKG_BUILD_DIR)
  293. clean-build: $(if $(wildcard $(PKG_BUILD_DIR)/.autoremove),force-clean-build)
  294. clean: force-clean-build
  295. $(CleanStaging)
  296. $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
  297. $(Build/Clean)
  298. rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
  299. dist:
  300. $(Build/Dist)
  301. distcheck:
  302. $(Build/DistCheck)