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