1################################################################################
2# WAF package infrastructure
3#
4# This file implements an infrastructure that eases development of package
5# .mk files for WAF packages. It should be used for all packages that use
6# WAF as their build system.
7#
8# See the Buildroot documentation for details on the usage of this
9# infrastructure
10#
11# In terms of implementation, this WAF infrastructure requires the .mk file
12# to only specify metadata information about the package: name, version,
13# download URL, etc.
14#
15# We still allow the package .mk file to override what the different steps
16# are doing, if needed. For example, if <PKG>_BUILD_CMDS is already defined,
17# it is used as the list of commands to perform to build the package,
18# instead of the default WAF behaviour. The package can also define some
19# post operation hooks.
20#
21################################################################################
22
23WAF_OPTS = $(if $(VERBOSE),-v) -j $(PARALLEL_JOBS)
24
25################################################################################
26# inner-waf-package -- defines how the configuration, compilation and
27# installation of a waf package should be done, implements a few hooks
28# to tune the build process for waf specifities and calls the generic
29# package infrastructure to generate the necessary make targets
30#
31#  argument 1 is the lowercase package name
32#  argument 2 is the uppercase package name, including a HOST_ prefix
33#             for host packages
34#  argument 3 is the uppercase package name, without the HOST_ prefix
35#             for host packages
36#  argument 4 is the type (target or host)
37################################################################################
38
39define inner-waf-package
40
41# The version of waflib has to match with the version of waf,
42# otherwise waf errors out with:
43# Waf script 'X' and library 'Y' do not match
44define WAF_PACKAGE_REMOVE_WAF_LIB
45	$$(RM) -fr $$(@D)/waf $$(@D)/waflib
46endef
47
48# We need host-python3 to run waf
49$(2)_DEPENDENCIES += host-python3
50
51$(2)_NEEDS_EXTERNAL_WAF ?= NO
52
53# If the package does not have its own waf, use our own.
54ifeq ($$($(2)_NEEDS_EXTERNAL_WAF),YES)
55$(2)_DEPENDENCIES += host-waf
56$(2)_WAF = $$(HOST_DIR)/bin/waf
57$(2)_POST_PATCH_HOOKS += WAF_PACKAGE_REMOVE_WAF_LIB
58else
59$(2)_WAF ?= ./waf
60endif
61
62#
63# Configure step. Only define it if not already defined by the package
64# .mk file.
65#
66ifndef $(2)_CONFIGURE_CMDS
67define $(2)_CONFIGURE_CMDS
68	cd $$($$(PKG)_SRCDIR) && \
69	$$(TARGET_CONFIGURE_OPTS) \
70	$$($(2)_CONF_ENV) \
71	$$(HOST_DIR)/bin/python3 $$($(2)_WAF) configure \
72		--prefix=/usr \
73		--libdir=/usr/lib \
74		$$($(2)_CONF_OPTS) \
75		$$($(2)_WAF_OPTS)
76endef
77endif
78
79#
80# Build step. Only define it if not already defined by the package .mk
81# file.
82#
83ifndef $(2)_BUILD_CMDS
84define $(2)_BUILD_CMDS
85	cd $$($$(PKG)_SRCDIR) && \
86	$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$(HOST_DIR)/bin/python3 $$($(2)_WAF) \
87		build $$(WAF_OPTS) $$($(2)_BUILD_OPTS) \
88		$$($(2)_WAF_OPTS)
89endef
90endif
91
92#
93# Staging installation step. Only define it if not already defined by
94# the package .mk file.
95#
96ifndef $(2)_INSTALL_STAGING_CMDS
97define $(2)_INSTALL_STAGING_CMDS
98	cd $$($$(PKG)_SRCDIR) && \
99	$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$(HOST_DIR)/bin/python3 $$($(2)_WAF) \
100		install --destdir=$$(STAGING_DIR) \
101		$$($(2)_INSTALL_STAGING_OPTS) \
102		$$($(2)_WAF_OPTS)
103endef
104endif
105
106#
107# Target installation step. Only define it if not already defined by
108# the package .mk file.
109#
110ifndef $(2)_INSTALL_TARGET_CMDS
111define $(2)_INSTALL_TARGET_CMDS
112	cd $$($$(PKG)_SRCDIR) && \
113	$$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$(HOST_DIR)/bin/python3 $$($(2)_WAF) \
114		install --destdir=$$(TARGET_DIR) \
115		$$($(2)_INSTALL_TARGET_OPTS) \
116		$$($(2)_WAF_OPTS)
117endef
118endif
119
120# Call the generic package infrastructure to generate the necessary
121# make targets
122$(call inner-generic-package,$(1),$(2),$(3),$(4))
123
124endef
125
126################################################################################
127# waf-package -- the target generator macro for WAF packages
128################################################################################
129
130waf-package = $(call inner-waf-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
131