imx6: image: Remove custom mkfs targz override as base should be fine now
[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
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)/hardening.mk
38 include $(INCLUDE_DIR)/prereq.mk
39 include $(INCLUDE_DIR)/host.mk
40 include $(INCLUDE_DIR)/unpack.mk
41 include $(INCLUDE_DIR)/depends.mk
42
43 find_library_dependencies = $(wildcard $(patsubst %,$(STAGING_DIR)/pkginfo/%.version, \
44 $(filter-out $(BUILD_PACKAGES),$(foreach dep, \
45 $(filter-out @%, $(patsubst +%,%,$(1))), \
46 $(if $(findstring :,$(dep)), \
47 $(word 2,$(subst :,$(space),$(dep))), \
48 $(dep) \
49 ) \
50 ))))
51
52 STAMP_NO_AUTOREBUILD=$(wildcard $(PKG_BUILD_DIR)/.no_autorebuild)
53 PREV_STAMP_PREPARED:=$(if $(STAMP_NO_AUTOREBUILD),$(wildcard $(PKG_BUILD_DIR)/.prepared*))
54 ifneq ($(PREV_STAMP_PREPARED),)
55 STAMP_PREPARED:=$(PREV_STAMP_PREPARED)
56 CONFIG_AUTOREBUILD:=
57 else
58 STAMP_PREPARED=$(PKG_BUILD_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))$(call confvar,$(PKG_PREPARED_DEPENDS)))
59 endif
60 STAMP_CONFIGURED=$(PKG_BUILD_DIR)/.configured$(if $(DUMP),,_$(call confvar,$(PKG_CONFIG_DEPENDS)))
61 STAMP_CONFIGURED_WILDCARD=$(patsubst %_$(call confvar,$(PKG_CONFIG_DEPENDS)),%_*,$(STAMP_CONFIGURED))
62 STAMP_BUILT:=$(PKG_BUILD_DIR)/.built
63 STAMP_INSTALLED:=$(STAGING_DIR)/stamp/.$(PKG_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),)_installed
64
65 STAGING_FILES_LIST:=$(PKG_NAME)$(if $(BUILD_VARIANT),.$(BUILD_VARIANT),).list
66
67 define CleanStaging
68 rm -f $(STAMP_INSTALLED)
69 @-(\
70 cd "$(STAGING_DIR)"; \
71 if [ -f packages/$(STAGING_FILES_LIST) ]; then \
72 cat packages/$(STAGING_FILES_LIST) | xargs -r rm -f 2>/dev/null; \
73 fi; \
74 )
75 endef
76
77 ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
78 USE_GIT_TREE:=1
79 QUILT:=1
80 endif
81 ifdef USE_SOURCE_DIR
82 QUILT:=1
83 endif
84 ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
85 QUILT:=1
86 endif
87
88 PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
89 PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
90
91 include $(INCLUDE_DIR)/download.mk
92 include $(INCLUDE_DIR)/quilt.mk
93 include $(INCLUDE_DIR)/package-defaults.mk
94 include $(INCLUDE_DIR)/package-dumpinfo.mk
95 include $(INCLUDE_DIR)/package-ipkg.mk
96 include $(INCLUDE_DIR)/package-bin.mk
97 include $(INCLUDE_DIR)/autotools.mk
98
99 override MAKEFLAGS=
100 CONFIG_SITE:=$(INCLUDE_DIR)/site/$(ARCH)
101 CUR_MAKEFILE:=$(filter-out Makefile,$(firstword $(MAKEFILE_LIST)))
102 SUBMAKE:=$(NO_TRACE_MAKE) $(if $(CUR_MAKEFILE),-f $(CUR_MAKEFILE))
103 PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig:$(STAGING_DIR)/usr/share/pkgconfig
104 unexport QUIET CONFIG_SITE
105
106 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
107 ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
108 define Build/Autoclean
109 $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
110 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
111 $(if $(filter prepare,$(MAKECMDGOALS)),,$(call rdep,$(PKG_BUILD_DIR),$(STAMP_BUILT),,-x "*/.dep_*" -x "*/ipkg*"))
112 endef
113 endif
114 endif
115
116 define Download/default
117 FILE:=$(PKG_SOURCE)
118 URL:=$(PKG_SOURCE_URL)
119 SUBDIR:=$(PKG_SOURCE_SUBDIR)
120 PROTO:=$(PKG_SOURCE_PROTO)
121 $(if $(PKG_SOURCE_MIRROR),MIRROR:=$(filter 1,$(PKG_MIRROR)))
122 $(if $(PKG_MIRROR_MD5SUM),MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM))
123 VERSION:=$(PKG_SOURCE_VERSION)
124 MD5SUM:=$(PKG_MD5SUM)
125 endef
126
127 ifdef USE_GIT_TREE
128 define Build/Prepare/Default
129 mkdir -p $(PKG_BUILD_DIR)
130 ln -s $(CURDIR)/git-src $(PKG_BUILD_DIR)/.git
131 ( cd $(PKG_BUILD_DIR); git checkout .)
132 endef
133 endif
134 ifdef USE_SOURCE_DIR
135 define Build/Prepare/Default
136 rm -rf $(PKG_BUILD_DIR)
137 $(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
138 ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
139 touch $(PKG_BUILD_DIR)/.source_dir
140 endef
141 endif
142
143 define Build/Exports/Default
144 $(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))
145 $(1) : export STAGING_PREFIX=$$(STAGING_DIR)/usr
146 $(1) : export PATH=$$(TARGET_PATH_PKG)
147 $(1) : export CONFIG_SITE:=$$(CONFIG_SITE)
148 $(1) : export PKG_CONFIG_PATH:=$$(PKG_CONFIG_PATH)
149 $(1) : export PKG_CONFIG_LIBDIR:=$$(PKG_CONFIG_PATH)
150 $(1) : export CCACHE_DIR:=$(STAGING_DIR)/ccache
151 endef
152 Build/Exports=$(Build/Exports/Default)
153
154 define Build/DefaultTargets
155 $(if $(QUILT),$(Build/Quilt))
156 $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
157 $(call Build/Autoclean)
158
159 download:
160 $(foreach hook,$(Hooks/Download),
161 $(call $(hook))$(sep)
162 )
163
164 $(STAMP_PREPARED) : export PATH=$$(TARGET_PATH_PKG)
165 $(STAMP_PREPARED):
166 @-rm -rf $(PKG_BUILD_DIR)
167 @mkdir -p $(PKG_BUILD_DIR)
168 $(foreach hook,$(Hooks/Prepare/Pre),$(call $(hook))$(sep))
169 $(Build/Prepare)
170 $(foreach hook,$(Hooks/Prepare/Post),$(call $(hook))$(sep))
171 touch $$@
172
173 $(call Build/Exports,$(STAMP_CONFIGURED))
174 $(STAMP_CONFIGURED): $(STAMP_PREPARED)
175 $(CleanStaging)
176 $(foreach hook,$(Hooks/Configure/Pre),$(call $(hook))$(sep))
177 $(Build/Configure)
178 $(foreach hook,$(Hooks/Configure/Post),$(call $(hook))$(sep))
179 rm -f $(STAMP_CONFIGURED_WILDCARD)
180 touch $$@
181
182 $(call Build/Exports,$(STAMP_BUILT))
183 $(STAMP_BUILT): $(STAMP_CONFIGURED)
184 $(foreach hook,$(Hooks/Compile/Pre),$(call $(hook))$(sep))
185 $(Build/Compile)
186 $(foreach hook,$(Hooks/Compile/Post),$(call $(hook))$(sep))
187 $(Build/Install)
188 $(foreach hook,$(Hooks/Install/Post),$(call $(hook))$(sep))
189 touch $$@
190
191 $(STAMP_INSTALLED) : export PATH=$$(TARGET_PATH_PKG)
192 $(STAMP_INSTALLED): $(STAMP_BUILT)
193 rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
194 mkdir -p $(TMP_DIR)/stage-$(PKG_NAME)/host $(STAGING_DIR)/packages $(STAGING_DIR_HOST)/packages
195 $(foreach hook,$(Hooks/InstallDev/Pre),\
196 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
197 )
198 $(call Build/InstallDev,$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)
199 $(foreach hook,$(Hooks/InstallDev/Post),\
200 $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
201 )
202 if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
203 $(SCRIPT_DIR)/clean-package.sh \
204 "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
205 "$(STAGING_DIR)"; \
206 fi
207 if [ -d $(TMP_DIR)/stage-$(PKG_NAME) ]; then \
208 (cd $(TMP_DIR)/stage-$(PKG_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_NAME).files); \
209 $(call locked, \
210 mv $(TMP_DIR)/stage-$(PKG_NAME).files $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) && \
211 $(CP) $(TMP_DIR)/stage-$(PKG_NAME)/* $(STAGING_DIR)/; \
212 ,staging-dir); \
213 fi
214 rm -rf $(TMP_DIR)/stage-$(PKG_NAME)
215 touch $$@
216
217 ifdef Build/InstallDev
218 compile: $(STAMP_INSTALLED)
219 endif
220
221 define Build/DefaultTargets
222 endef
223
224 prepare: $(STAMP_PREPARED)
225 configure: $(STAMP_CONFIGURED)
226 dist: $(STAMP_CONFIGURED)
227 distcheck: $(STAMP_CONFIGURED)
228 endef
229
230 define Build/IncludeOverlay
231 $(eval -include $(wildcard $(TOPDIR)/overlay/*/$(PKG_NAME).mk))
232 define Build/IncludeOverlay
233 endef
234 endef
235
236 define BuildPackage
237 $(Build/IncludeOverlay)
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 $(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)$(DUMP),,$(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 @touch $(PKG_INSTALL_STAMP).clean
292 @echo "$(filter-out essential,$(PKG_FLAGS))" > $(PKG_INSTALL_STAMP).flags
293
294 $(PACKAGE_DIR):
295 mkdir -p $@
296
297 dumpinfo:
298 download:
299 prepare:
300 configure:
301 compile: prepare-package-install
302 install: compile
303
304 clean: FORCE
305 $(CleanStaging)
306 $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
307 $(Build/Clean)
308 rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)
309 rm -rf $(PKG_BUILD_DIR)
310
311 dist:
312 $(Build/Dist)
313
314 distcheck:
315 $(Build/DistCheck)