package.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. 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=$(PKG_BUILD_DIR)/.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)/download.mk
  84. include $(INCLUDE_DIR)/quilt.mk
  85. include $(INCLUDE_DIR)/package-defaults.mk
  86. include $(INCLUDE_DIR)/package-dumpinfo.mk
  87. include $(INCLUDE_DIR)/package-ipkg.mk
  88. include $(INCLUDE_DIR)/package-bin.mk
  89. include $(INCLUDE_DIR)/autotools.mk
  90. override MAKEFLAGS=
  91. CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
  92. CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
  93. SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
  94. PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
  95. unexport QUIET CONFIG_SITE
  96. ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
  97. ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
  98. define Build/Autoclean
  99. $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
  100. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
  101. $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
  102. endef
  103. endif
  104. endif
  105. define Download/default
  106. FILE:=$(PKG_SOURCE)
  107. URL:=$(PKG_SOURCE_URL)
  108. SUBDIR:=$(PKG_SOURCE_SUBDIR)
  109. PROTO:=$(PKG_SOURCE_PROTO)
  110. $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
  111. $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
  112. VERSION:=$(PKG_SOURCE_VERSION)
  113. MD5SUM:=$(PKG_MD5SUM)
  114. endef
  115. ifdef USE_GIT_TREE
  116. define Build/Prepare/Default
  117. mkdir -p $(PKG_BUILD_DIR)
  118. ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
  119. ( cd $(PKG_BUILD_DIR); git checkout .)
  120. endef
  121. endif
  122. ifdef USE_SOURCE_DIR
  123. define Build/Prepare/Default
  124. rm -rf $(PKG_BUILD_DIR)
  125. $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
  126. ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
  127. touch $(PKG_BUILD_DIR)/.source_dir
  128. endef
  129. endif
  130. define Build/Exports/Default
  131. $(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))
  132. $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
  133. $(1) : export PATH=$$(TARGET_PATH_PKG)
  134. $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
  135. $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
  136. $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
  137. $(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache
  138. endef
  139. Build/Exports=$(Build/Exports/Default)
  140. define Build/DefaultTargets
  141. $(if $(QUILT),$(Build/Quilt))
  142. $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  143. $(call Build/Autoclean)
  144. download:
  145. $(foreach hook,$(Hooks/Download),
  146. $(call $(hook))$(sep)
  147. )
  148. $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
  149. $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
  150. @-rm -rf $(PKG_BUILD_DIR)
  151. @mkdir -p $(PKG_BUILD_DIR)
  152. $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
  153. $(Build/Prepare)
  154. $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
  155. touch $$@
  156. $(call Build/Exports,$(STAMP_CONFIGURED))
  157. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(STAMP_CONFIGURED_DEPENDS)
  158. $(CleanStaging)
  159. $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
  160. $(Build/Configure)
  161. $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
  162. rm -f $(STAMP_CONFIGURED_WILDCARD)
  163. touch $$@
  164. $(call Build/Exports,$(STAMP_BUILT))
  165. $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
  166. $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
  167. $(Build/Compile)
  168. $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
  169. $(Build/Install)
  170. $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
  171. touch $$@
  172. $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
  173. $(STAMP_INSTALLED): $(STAMP_BUILT)
  174. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  175. mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
  176. $(foreach hook,$(Hooks/InstallDev/Pre),\
  177. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  178. )
  179. $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
  180. $(foreach hook,$(Hooks/InstallDev/Post),\
  181. $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
  182. )
  183. if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
  184. $(SCRIPT_DIR)/clean-package.sh \
  185. "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
  186. "$(STAGING_DIR)"; \
  187. fi
  188. if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
  189. (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
  190. $(call locked, \
  191. mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
  192. $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
  193. ,staging-dir); \
  194. fi
  195. rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
  196. touch $$@
  197. ifdef Build/InstallDev
  198. compile: $(STAMP_INSTALLED)
  199. endif
  200. define Build/DefaultTargets
  201. endef
  202. prepare: $(STAMP_PREPARED)
  203. configure: $(STAMP_CONFIGURED)
  204. dist: $(STAMP_CONFIGURED)
  205. distcheck: $(STAMP_CONFIGURED)
  206. endef
  207. define Build/IncludeOverlay
  208. $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_DIR_NAME).mk))
  209. define Build/IncludeOverlay
  210. endef
  211. endef
  212. define BuildPackage
  213. $(Build/IncludeOverlay)
  214. $(eval $(Package/Default))
  215. $(eval $(Package/$(1)))
  216. ifdef DESCRIPTION
  217. $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
  218. endif
  219. ifndef Package/$(1)/description
  220. define Package/$(1)/description
  221. $(TITLE)
  222. endef
  223. endif
  224. BUILD_PACKAGES += $(1)
  225. $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(DEPENDS)))
  226. $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
  227. ifeq ($($(FIELD)),)
  228. $$(error Package/$(1) is missing the $(FIELD) field)
  229. endif
  230. )
  231. $(if $(DUMP), \
  232. $(Dumpinfo/Package), \
  233. $(foreach target, \
  234. $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
  235. $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
  236. ), $(BuildTarget/$(target)) \
  237. ) \
  238. )
  239. $(if $(PKG_HOST_ONLY)$(DUMP),,$(call Build/DefaultTargets,$(1)))
  240. endef
  241. define pkg_install_files
  242. $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
  243. endef
  244. define pkg_install_bin
  245. $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
  246. endef
  247. Build/Prepare=$(call Build/Prepare/Default,)
  248. Build/Configure=$(call Build/Configure/Default,)
  249. Build/Compile=$(call Build/Compile/Default,)
  250. Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
  251. Build/Dist=$(call Build/Dist/Default,)
  252. Build/DistCheck=$(call Build/DistCheck/Default,)
  253. .NOTPARALLEL:
  254. .PHONY: prepare-package-install
  255. prepare-package-install:
  256. @mkdir -p $(PKG_INFO_DIR)
  257. @touch $(PKG_INSTALL_STAMP).clean
  258. @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
  259. $(PACKAGE_DIR):
  260. mkdir -p $@
  261. dumpinfo:
  262. download:
  263. prepare:
  264. configure:
  265. compile: prepare-package-install
  266. install: compile
  267. clean: FORCE
  268. $(CleanStaging)
  269. $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
  270. $(Build/Clean)
  271. rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
  272. rm -rf $(PKG_BUILD_DIR)
  273. dist:
  274. $(Build/Dist)
  275. distcheck:
  276. $(Build/DistCheck)