package.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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_CHECK_FORMAT_SECURITY ?= 1
  15. PKG_CC_STACKPROTECTOR_REGULAR ?= 1
  16. PKG_CC_STACKPROTECTOR_STRONG ?= 1
  17. PKG_FORTIFY_SOURCE_1 ?= 1
  18. PKG_FORTIFY_SOURCE_2 ?= 1
  19. PKG_RELRO_PARTIAL ?= 1
  20. PKG_RELRO_FULL ?= 1
  21. ifneq ($(CONFIG_PKG_BUILD_USE_JOBSERVER),)
  22. MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) -j)
  23. else
  24. MAKE_J:=-j$(CONFIG_PKG_BUILD_JOBS)
  25. endif
  26. ifeq ($(strip $(PKG_BUILD_PARALLEL)),0)
  27. PKG_JOBS?=-j1
  28. else
  29. PKG_JOBS?=$(if $(PKG_BUILD_PARALLEL)$(CONFIG_PKG_DEFAULT_PARALLEL),\
  30. $(if $(CONFIG_PKG_BUILD_PARALLEL),$(MAKE_J),-j1),-j1)
  31. endif
  32. ifdef CONFIG_USE_MIPS16
  33. ifeq ($(strip $(PKG_USE_MIPS16)),1)
  34. TARGET_ASFLAGS_DEFAULT = $(filter-out -mips16 -minterlink-mips16,$(TARGET_CFLAGS))
  35. TARGET_CFLAGS += -mips16 -minterlink-mips16
  36. endif
  37. endif
  38. ifdef CONFIG_PKG_CHECK_FORMAT_SECURITY
  39. ifeq ($(strip $(PKG_CHECK_FORMAT_SECURITY)),1)
  40. TARGET_CFLAGS += -Wformat -Werror=format-security
  41. endif
  42. endif
  43. ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR
  44. ifeq ($(strip $(PKG_CC_STACKPROTECTOR_REGULAR)),1)
  45. TARGET_CFLAGS += -fstack-protector
  46. endif
  47. endif
  48. ifdef CONFIG_PKG_CC_STACKPROTECTOR_STRONG
  49. ifeq ($(strip $(PKG_CC_STACKPROTECTOR_STRONG)),1)
  50. TARGET_CFLAGS += -fstack-protector-strong
  51. endif
  52. endif
  53. ifdef CONFIG_PKG_FORTIFY_SOURCE_1
  54. ifeq ($(strip $(PKG_FORTIFY_SOURCE_1)),1)
  55. TARGET_CFLAGS += -D_FORTIFY_SOURCE=1
  56. endif
  57. endif
  58. ifdef CONFIG_PKG_FORTIFY_SOURCE_2
  59. ifeq ($(strip $(PKG_FORTIFY_SOURCE_2)),1)
  60. TARGET_CFLAGS += -D_FORTIFY_SOURCE=2
  61. endif
  62. endif
  63. ifdef CONFIG_PKG_RELRO_PARTIAL
  64. ifeq ($(strip $(PKG_RELRO_PARTIAL)),1)
  65. TARGET_CFLAGS += -Wl,-z,relro
  66. endif
  67. endif
  68. ifdef CONFIG_PKG_RELRO_FULL
  69. ifeq ($(strip $(PKG_RELRO_FULL)),1)
  70. TARGET_CFLAGS += -Wl,-z,now -Wl,-z,relro
  71. endif
  72. endif
  73. include $(INCLUDE_DIR)/prereq.mk
  74. include $(INCLUDE_DIR)/host.mk
  75. include $(INCLUDE_DIR)/unpack.mk
  76. include $(INCLUDE_DIR)/depends.mk
  77. find_library_dependencies = $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
  78. $(filter-out $(BUILD_PACKAGES),$(foreach dep, \
  79. $(filter-out @%, $(patsubst +%,%,$(1))), \
  80. $(if $(findstring :,$(dep)), \
  81. $(word 2,$(subst :,$(space),$(dep))), \
  82. $(dep) \
  83. ) \
  84. ))))
  85. STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
  86. PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
  87. ifneq ($(PREV_STAMP_PREPARED),)
  88. STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
  89. CONFIG_AUTOREBUILD:=
  90. else
  91. STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))$(call confvar,$(PKG_PREPARED_DEPENDS)))
  92. endif
  93. STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
  94. STAMP_CONFIGURED_WILDCARD=$(patsubst %_$(call confvar,$(PKG_CONFIG_DEPENDS)),%_*,$(STAMP_CONFIGURED))
  95. STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
  96. STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
  97. STAGING_FILES_LIST:=$(PKG_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
  98. define CleanStaging
  99. rm -f $(STAMP_INSTALLED)
  100. @-(\
  101. cd "$(STAGING_DIR)"; \
  102. if [ -f packages/$(STAGING_FILES_LIST) ]; then \
  103. cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
  104. fi; \
  105. )
  106. endef
  107. ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
  108. USE_GIT_TREE:=1
  109. QUILT:=1
  110. endif
  111. ifdef USE_SOURCE_DIR
  112. QUILT:=1
  113. endif
  114. ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
  115. QUILT:=1
  116. endif
  117. PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
  118. PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
  119. include $(INCLUDE_DIR)/download.mk
  120. include $(INCLUDE_DIR)/quilt.mk
  121. include $(INCLUDE_DIR)/package-defaults.mk
  122. include $(INCLUDE_DIR)/package-dumpinfo.mk
  123. include $(INCLUDE_DIR)/package-ipkg.mk
  124. include $(INCLUDE_DIR)/package-bin.mk
  125. include $(INCLUDE_DIR)/autotools.mk
  126. override MAKEFLAGS=
  127. CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
  128. CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
  129. SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
  130. PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
  131. unexport QUIET CONFIG_SITE
  132. ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
  133. ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
  134. define Build/Autoclean
  135. $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
  136. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
  137. $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
  138. endef
  139. endif
  140. endif
  141. define Download/default
  142. FILE:=$(PKG_SOURCE)
  143. URL:=$(PKG_SOURCE_URL)
  144. SUBDIR:=$(PKG_SOURCE_SUBDIR)
  145. PROTO:=$(PKG_SOURCE_PROTO)
  146. $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
  147. $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
  148. VERSION:=$(PKG_SOURCE_VERSION)
  149. MD5SUM:=$(PKG_MD5SUM)
  150. endef
  151. ifdef USE_GIT_TREE
  152. define Build/Prepare/Default
  153. mkdir -p $(PKG_BUILD_DIR)
  154. ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
  155. ( cd $(PKG_BUILD_DIR); git checkout .)
  156. endef
  157. endif
  158. ifdef USE_SOURCE_DIR
  159. define Build/Prepare/Default
  160. rm -rf $(PKG_BUILD_DIR)
  161. $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
  162. ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
  163. touch $(PKG_BUILD_DIR)/.source_dir
  164. endef
  165. endif
  166. define Build/Exports/Default
  167. $(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))
  168. $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
  169. $(1) : export PATH=$$(TARGET_PATH_PKG)
  170. $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
  171. $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
  172. $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
  173. $(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache
  174. endef
  175. Build/Exports=$(Build/Exports/Default)
  176. define Build/DefaultTargets
  177. $(if $(QUILT),$(Build/Quilt))
  178. $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  179. $(call Build/Autoclean)
  180. download:
  181. $(foreach hook,$(Hooks/Download),
  182. $(call $(hook))$(sep)
  183. )
  184. $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
  185. $(STAMP_PREPARED):
  186. @-rm -rf $(PKG_BUILD_DIR)
  187. @mkdir -p $(PKG_BUILD_DIR)
  188. $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
  189. $(Build/Prepare)
  190. $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
  191. touch $$@
  192. $(call Build/Exports,$(STAMP_CONFIGURED))
  193. $(STAMP_CONFIGURED): $(STAMP_PREPARED)
  194. $(CleanStaging)
  195. $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
  196. $(Build/Configure)
  197. $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
  198. rm -f $(STAMP_CONFIGURED_WILDCARD)
  199. touch $$@
  200. $(call Build/Exports,$(STAMP_BUILT))
  201. $(STAMP_BUILT): $(STAMP_CONFIGURED)
  202. $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
  203. $(Build/Compile)
  204. $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
  205. $(Build/Install)
  206. $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
  207. touch $$@
  208. $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
  209. $(STAMP_INSTALLED): $(STAMP_BUILT)
  210. rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
  211. mkdir -p $(TMP_DIR)/stage-$(PKG_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
  212. $(foreach hook,$(Hooks/InstallDev/Pre),\
  213. $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
  214. )
  215. $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)
  216. $(foreach hook,$(Hooks/InstallDev/Post),\
  217. $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
  218. )
  219. if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
  220. $(SCRIPT_DIR)/clean-package.sh \
  221. "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
  222. "$(STAGING_DIR)"; \
  223. fi
  224. if [ -d $(TMP_DIR)/stage-$(PKG_NAME) ]; then \
  225. (cd $(TMP_DIR)/stage-$(PKG_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_NAME).files); \
  226. $(call locked, \
  227. mv $(TMP_DIR)/stage-$(PKG_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
  228. $(CP) $(TMP_DIR)/stage-$(PKG_NAME)/* $(STAGING_DIR)/; \
  229. ,staging-dir); \
  230. fi
  231. rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
  232. touch $$@
  233. ifdef Build/InstallDev
  234. compile: $(STAMP_INSTALLED)
  235. endif
  236. define Build/DefaultTargets
  237. endef
  238. prepare: $(STAMP_PREPARED)
  239. configure: $(STAMP_CONFIGURED)
  240. dist: $(STAMP_CONFIGURED)
  241. distcheck: $(STAMP_CONFIGURED)
  242. endef
  243. define Build/IncludeOverlay
  244. $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_NAME).mk))
  245. define Build/IncludeOverlay
  246. endef
  247. endef
  248. define BuildPackage
  249. $(Build/IncludeOverlay)
  250. $(eval $(Package/Default))
  251. $(eval $(Package/$(1)))
  252. ifdef DESCRIPTION
  253. $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
  254. endif
  255. ifndef Package/$(1)/description
  256. define Package/$(1)/description
  257. $(TITLE)
  258. endef
  259. endif
  260. BUILD_PACKAGES += $(1)
  261. $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(DEPENDS)))
  262. $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
  263. ifeq ($($(FIELD)),)
  264. $$(error Package/$(1) is missing the $(FIELD) field)
  265. endif
  266. )
  267. $(if $(DUMP), \
  268. $(Dumpinfo/Package), \
  269. $(foreach target, \
  270. $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
  271. $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
  272. ), $(BuildTarget/$(target)) \
  273. ) \
  274. )
  275. $(if $(PKG_HOST_ONLY)$(DUMP),,$(call Build/DefaultTargets,$(1)))
  276. endef
  277. define pkg_install_files
  278. $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
  279. endef
  280. define pkg_install_bin
  281. $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
  282. endef
  283. Build/Prepare=$(call Build/Prepare/Default,)
  284. Build/Configure=$(call Build/Configure/Default,)
  285. Build/Compile=$(call Build/Compile/Default,)
  286. Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
  287. Build/Dist=$(call Build/Dist/Default,)
  288. Build/DistCheck=$(call Build/DistCheck/Default,)
  289. .NOTPARALLEL:
  290. .PHONY: prepare-package-install
  291. prepare-package-install:
  292. @mkdir -p $(PKG_INFO_DIR)
  293. @touch $(PKG_INSTALL_STAMP).clean
  294. @echo "$(filter-out essential,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
  295. $(PACKAGE_DIR):
  296. mkdir -p $@
  297. dumpinfo:
  298. download:
  299. prepare:
  300. configure:
  301. compile: prepare-package-install
  302. install: compile
  303. clean: FORCE
  304. $(CleanStaging)
  305. $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
  306. $(Build/Clean)
  307. rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
  308. rm -rf $(PKG_BUILD_DIR)
  309. dist:
  310. $(Build/Dist)
  311. distcheck:
  312. $(Build/DistCheck)