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