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