usbreset: Add missing header
[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,$(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 = \
57 $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
58 $(sort $(foreach dep4, \
59 $(sort $(foreach dep3, \
60 $(sort $(foreach dep2, \
61 $(sort $(foreach dep1, \
62 $(sort $(foreach dep0, \
63 $(Package/$(1)/depends), \
64 $(Package/$(dep0)/depends) $(dep0) \
65 )), \
66 $(Package/$(dep1)/depends) $(dep1) \
67 )), \
68 $(Package/$(dep2)/depends) $(dep2) \
69 )), \
70 $(Package/$(dep3)/depends) $(dep3) \
71 )), \
72 $(Package/$(dep4)/depends) $(dep4) \
73 )), \
74 ))
75
76
77 PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
78 STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
79 PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
80 ifneq ($(PREV_STAMP_PREPARED),)
81 STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
82 CONFIG_AUTOREBUILD:=
83 else
84 STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(PKG_PREPARED_DEPENDS)))
85 endif
86 STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
87 STAMP_CONFIGURED_WILDCARD=$(PKG_BUILD_DIR)/.configured_*
88 STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
89 STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
90
91 STAGING_FILES_LIST:=$(PKG_DIR_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
92
93 define CleanStaging
94 rm -f $(STAMP_INSTALLED)
95 @-(\
96 if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
97 $(SCRIPT_DIR)/clean-package.sh \
98 "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
99 "$(STAGING_DIR)"; \
100 fi; \
101 )
102 endef
103
104
105 PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
106
107 include $(INCLUDE_DIR)/package-defaults.mk
108 include $(INCLUDE_DIR)/package-dumpinfo.mk
109 include $(INCLUDE_DIR)/package-ipkg.mk
110 include $(INCLUDE_DIR)/package-bin.mk
111 include $(INCLUDE_DIR)/autotools.mk
112
113 _pkg_target:=$(if $(QUILT),,.)
114
115 override MAKEFLAGS=
116 CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
117 CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
118 SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
119 PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
120 unexport QUIET CONFIG_SITE
121
122 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
123 ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
124 define Build/Autoclean
125 $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
126 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
127 $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
128 endef
129 endif
130 endif
131
132 ifdef USE_GIT_TREE
133 define Build/Prepare/Default
134 mkdir -p $(PKG_BUILD_DIR)
135 ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
136 ( cd $(PKG_BUILD_DIR); \
137 git checkout .; \
138 git submodule update --recursive; \
139 git submodule foreach git config --unset core.worktree; \
140 git submodule foreach git checkout .; \
141 )
142 endef
143 endif
144 ifdef USE_SOURCE_DIR
145 define Build/Prepare/Default
146 rm -rf $(PKG_BUILD_DIR)
147 $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
148 ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
149 touch $(PKG_BUILD_DIR)/.source_dir
150 endef
151 endif
152
153 define Build/Exports/Default
154 $(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))
155 $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
156 $(1) : export PATH=$$(TARGET_PATH_PKG)
157 $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
158 $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
159 $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
160 $(if $(CONFIG_CCACHE),$(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache)
161 endef
162 Build/Exports=$(Build/Exports/Default)
163
164 define Build/CoreTargets
165 STAMP_PREPARED:=$$(STAMP_PREPARED)
166 STAMP_CONFIGURED:=$$(STAMP_CONFIGURED)
167
168 $(if $(QUILT),$(Build/Quilt))
169 $(call Build/Autoclean)
170 $(call DefaultTargets)
171
172 download:
173 $(foreach hook,$(Hooks/Download),
174 $(call $(hook))$(sep)
175 )
176
177 $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
178 $(STAMP_PREPARED): $(STAMP_PREPARED_DEPENDS)
179 @-rm -rf $(PKG_BUILD_DIR)
180 @mkdir -p $(PKG_BUILD_DIR)
181 touch $$@_check
182 $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
183 $(Build/Prepare)
184 $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
185 touch $$@
186
187 $(call Build/Exports,$(STAMP_CONFIGURED))
188 $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(STAMP_CONFIGURED_DEPENDS)
189 rm -f $(STAMP_CONFIGURED_WILDCARD)
190 $(CleanStaging)
191 $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
192 $(Build/Configure)
193 $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
194 touch $$@
195
196 $(call Build/Exports,$(STAMP_BUILT))
197 $(STAMP_BUILT): $(STAMP_CONFIGURED) $(STAMP_BUILT_DEPENDS)
198 rm -f $$@
199 touch $$@_check
200 $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
201 $(Build/Compile)
202 $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
203 $(Build/Install)
204 $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
205 touch $$@
206
207 $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
208 $(STAMP_INSTALLED): $(STAMP_BUILT)
209 rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
210 mkdir -p $(TMP_DIR)/stage-$(PKG_DIR_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
211 $(foreach hook,$(Hooks/InstallDev/Pre),\
212 $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
213 )
214 $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)
215 $(foreach hook,$(Hooks/InstallDev/Post),\
216 $(call $(hook),$(TMP_DIR)/stage-$(PKG_DIR_NAME),$(TMP_DIR)/stage-$(PKG_DIR_NAME)/host)$(sep)\
217 )
218 if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
219 $(SCRIPT_DIR)/clean-package.sh \
220 "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
221 "$(STAGING_DIR)"; \
222 fi
223 if [ -d $(TMP_DIR)/stage-$(PKG_DIR_NAME) ]; then \
224 (cd $(TMP_DIR)/stage-$(PKG_DIR_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_DIR_NAME).files); \
225 $(call locked, \
226 mv $(TMP_DIR)/stage-$(PKG_DIR_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
227 $(CP) $(TMP_DIR)/stage-$(PKG_DIR_NAME)/* $(STAGING_DIR)/; \
228 ,staging-dir); \
229 fi
230 rm -rf $(TMP_DIR)/stage-$(PKG_DIR_NAME)
231 touch $$@
232
233 ifdef Build/InstallDev
234 $(_pkg_target)compile: $(STAMP_INSTALLED)
235 endif
236
237 $(_pkg_target)prepare: $(STAMP_PREPARED)
238 $(_pkg_target)configure: $(STAMP_CONFIGURED)
239 $(_pkg_target)dist: $(STAMP_CONFIGURED)
240 $(_pkg_target)distcheck: $(STAMP_CONFIGURED)
241
242 ifneq ($(CONFIG_AUTOREMOVE),)
243 compile:
244 -touch -r $(PKG_BUILD_DIR)/.built $(PKG_BUILD_DIR)/.autoremove 2>/dev/null >/dev/null
245 $(FIND) $(PKG_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -and -not -name '.pkgdir' | \
246 $(XARGS) rm -rf
247 endif
248 endef
249
250 define Build/DefaultTargets
251 $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
252 $(if $(DUMP),,$(Build/CoreTargets))
253
254 define Build/DefaultTargets
255 endef
256 endef
257
258 define BuildPackage
259 $(eval $(Package/Default))
260 $(eval $(Package/$(1)))
261
262 ifdef DESCRIPTION
263 $$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
264 endif
265
266 ifndef Package/$(1)/description
267 define Package/$(1)/description
268 $(TITLE)
269 endef
270 endif
271
272 BUILD_PACKAGES += $(1)
273 $(STAMP_PREPARED): $$(if $(QUILT)$(DUMP),,$(call find_library_dependencies,$(1)))
274
275 $(foreach FIELD, TITLE CATEGORY SECTION VERSION,
276 ifeq ($($(FIELD)),)
277 $$(error Package/$(1) is missing the $(FIELD) field)
278 endif
279 )
280
281 $(if $(DUMP), \
282 $(if $(CHECK),,$(Dumpinfo/Package)), \
283 $(foreach target, \
284 $(if $(Package/$(1)/targets),$(Package/$(1)/targets), \
285 $(if $(PKG_TARGETS),$(PKG_TARGETS), ipkg) \
286 ), $(BuildTarget/$(target)) \
287 ) \
288 )
289 $(if $(PKG_HOST_ONLY),,$(call Build/DefaultTargets,$(1)))
290 endef
291
292 define pkg_install_files
293 $(foreach install_file,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_file)`; $(INSTALL_DATA) $(2)/$(install_file) $(3)/`dirname $(install_file)`;)
294 endef
295
296 define pkg_install_bin
297 $(foreach install_apps,$(1),$(INSTALL_DIR) $(3)/`dirname $(install_apps)`; $(INSTALL_BIN) $(2)/$(install_apps) $(3)/`dirname $(install_apps)`;)
298 endef
299
300 Build/Prepare=$(call Build/Prepare/Default,)
301 Build/Configure=$(call Build/Configure/Default,)
302 Build/Compile=$(call Build/Compile/Default,)
303 Build/Install=$(if $(PKG_INSTALL),$(call Build/Install/Default,))
304 Build/Dist=$(call Build/Dist/Default,)
305 Build/DistCheck=$(call Build/DistCheck/Default,)
306
307 .NOTPARALLEL:
308
309 .PHONY: prepare-package-install
310 prepare-package-install:
311 @mkdir -p $(PKG_INFO_DIR)
312 @rm -f $(PKG_INSTALL_STAMP)
313 @echo "$(filter-out essential nonshared,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
314
315 $(PACKAGE_DIR):
316 mkdir -p $@
317
318 compile:
319 .install: .compile
320 install: compile
321
322 force-clean-build: FORCE
323 rm -rf $(PKG_BUILD_DIR)
324
325 clean-build: $(if $(wildcard $(PKG_BUILD_DIR)/.autoremove),force-clean-build)
326
327 clean: force-clean-build
328 $(CleanStaging)
329 $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
330 $(Build/Clean)
331 rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
332
333 dist:
334 $(Build/Dist)
335
336 distcheck:
337 $(Build/DistCheck)