package.mk 9.8 KB

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