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