4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
24 # Rules and Macros for building opens source software that uses the waf
25 # build system from https://waf.io/
27 # To use these rules, include $(WS_MAKE_RULES)/waf.mk in your Makefile
28 # and define "build", "install" targets appropriate to building your component.
31 # build: $(BUILD_32) \
34 # install: $(INSTALL_32) \
37 # Any additional pre/post configure, build, or install actions can be specified
38 # in your Makefile by setting them in on of the following macros:
39 # COMPONENT_PRE_BUILD_ACTION, COMPONENT_POST_BUILD_ACTION
40 # COMPONENT_PRE_INSTALL_ACTION, COMPONENT_POST_INSTALL_ACTION
42 # If component specific make targets need to be used for build or install, they
44 # COMPONENT_BUILD_TARGETS, COMPONENT_INSTALL_TARGETS
47 # Defaults to looking for waf script in top level of cloned source
50 CONFIGURE_PREFIX
= /usr
52 ifeq ($(strip $(PREFERRED_BITS
)),64)
53 CONFIGURE_BINDIR
.32 = $(CONFIGURE_PREFIX
)/bin
/$(MACH32
)
54 CONFIGURE_BINDIR
.64 = $(CONFIGURE_PREFIX
)/bin
55 CONFIGURE_SBINDIR
.32 = $(CONFIGURE_PREFIX
)/sbin
/$(MACH32
)
56 CONFIGURE_SBINDIR
.64 = $(CONFIGURE_PREFIX
)/sbin
58 CONFIGURE_BINDIR
.32 = $(CONFIGURE_PREFIX
)/bin
59 CONFIGURE_BINDIR
.64 = $(CONFIGURE_PREFIX
)/bin
/$(MACH64
)
60 CONFIGURE_SBINDIR
.32 = $(CONFIGURE_PREFIX
)/sbin
61 CONFIGURE_SBINDIR
.64 = $(CONFIGURE_PREFIX
)/sbin
/$(MACH64
)
63 CONFIGURE_LIBDIR
.32 = $(CONFIGURE_PREFIX
)/lib
64 CONFIGURE_LIBDIR
.64 = $(CONFIGURE_PREFIX
)/lib
/$(MACH64
)
65 CONFIGURE_MANDIR
= $(CONFIGURE_PREFIX
)/share
/man
66 CONFIGURE_LOCALEDIR
= $(CONFIGURE_PREFIX
)/share
/locale
68 CONFIGURE_DEFAULT_DIRS?
=yes
69 CONFIGURE_OPTIONS
+= --prefix=$(CONFIGURE_PREFIX
)
70 ifeq ($(CONFIGURE_DEFAULT_DIRS
),yes
)
71 CONFIGURE_OPTIONS
+= --mandir=$(CONFIGURE_MANDIR
)
72 ifeq ($(INITIAL_BITS
),64)
73 CONFIGURE_OPTIONS
+= --bindir=$(CONFIGURE_BINDIR
.32)
74 CONFIGURE_OPTIONS
+= --sbindir
=$(CONFIGURE_SBINDIR
.32)
76 CONFIGURE_OPTIONS
+= --bindir=$(CONFIGURE_BINDIR.
$(BITS
))
77 CONFIGURE_OPTIONS
+= --sbindir
=$(CONFIGURE_SBINDIR.
$(BITS
))
79 CONFIGURE_OPTIONS
+= --libdir=$(CONFIGURE_LIBDIR.
$(BITS
))
81 CONFIGURE_OPTIONS
+= $(CONFIGURE_OPTIONS.
$(BITS
))
82 CONFIGURE_OPTIONS
+= $(CONFIGURE_OPTIONS.
$(MACH
))
83 CONFIGURE_OPTIONS
+= $(CONFIGURE_OPTIONS.
$(MACH
).
$(BITS
))
85 CONFIGURE_ENV
+= CC
="$(CC) $(CC_BITS)"
86 CONFIGURE_ENV
+= CFLAGS
="$(CFLAGS)"
87 CONFIGURE_ENV
+= CXX
="$(CXX) $(CC_BITS)"
88 CONFIGURE_ENV
+= CXXFLAGS
="$(CXXFLAGS)"
89 CONFIGURE_ENV
+= LDFLAGS
="$(LDFLAGS)"
90 CONFIGURE_ENV
+= PKG_CONFIG_PATH
="$(PKG_CONFIG_PATH)"
91 CONFIGURE_ENV
+= PYTHON
="$(PYTHON)"
92 CONFIGURE_ENV
+= PYTHONDIR
="$(PYTHON_LIB)"
93 CONFIGURE_ENV
+= PYTHONARCHDIR
="$(PYTHON_VENDOR_PACKAGES)"
95 # configure the unpacked source
96 COMPONENT_CONFIGURE_TARGETS ?
= configure
98 $(BUILD_DIR_32
)/.configured
: BITS
=32
99 $(BUILD_DIR_64
)/.configured
: BITS
=64
100 $(BUILD_DIR
)/$(MACH32
)-%/.configured
: BITS
=32
101 $(BUILD_DIR
)/$(MACH64
)-%/.configured
: BITS
=64
102 $(foreach pyver
, $(PYTHON_VERSIONS
), \
103 $(eval
$(BUILD_DIR
)/%-$(pyver
)/.configured
: PYTHON_VERSION
=$(pyver
)) \
106 $(BUILD_DIR
)/%/.configured
: $(SOURCE_DIR
)/.prep
107 $(RM
) -r
$(@D
) ; $(MKDIR
) $(@D
)
108 $(ENV
) $(CLONEY_ARGS
) $(CLONEY
) $(SOURCE_DIR
) $(@D
)
109 $(COMPONENT_PRE_CONFIGURE_ACTION
)
110 (cd
$(@D
) ; $(ENV
) $(CONFIGURE_ENV
) \
111 $(WAF
) $(COMPONENT_CONFIGURE_TARGETS
) $(CONFIGURE_OPTIONS
))
112 $(COMPONENT_POST_CONFIGURE_ACTION
)
115 # build the configured source
116 COMPONENT_BUILD_TARGETS ?
= build
118 $(BUILD_DIR_32
)/.built
: BITS
=32
119 $(BUILD_DIR_64
)/.built
: BITS
=64
120 $(BUILD_DIR
)/$(MACH32
)-%/.built
: BITS
=32
121 $(BUILD_DIR
)/$(MACH64
)-%/.built
: BITS
=64
122 $(foreach pyver
, $(PYTHON_VERSIONS
), \
123 $(eval
$(BUILD_DIR
)/%-$(pyver
)/.built
: PYTHON_VERSION
=$(pyver
)) \
126 $(BUILD_DIR
)/%/.built
: $(BUILD_DIR
)/%/.configured
127 $(COMPONENT_PRE_BUILD_ACTION
)
128 (cd
$(@D
) ; $(ENV
) $(COMPONENT_BUILD_ENV
) \
129 $(WAF
) $(COMPONENT_BUILD_TARGETS
) $(COMPONENT_BUILD_ARGS
))
130 $(COMPONENT_POST_BUILD_ACTION
)
133 # If BUILD_STYLE is set, provide a default configure target.
134 ifeq ($(strip $(BUILD_STYLE
)),waf
)
135 configure
: $(CONFIGURE_
$(MK_BITS
))
138 # install the built source into a prototype area
139 COMPONENT_INSTALL_ARGS
+= --destdir
=$(PROTO_DIR
)
140 COMPONENT_INSTALL_ARGS
+= $(COMPONENT_INSTALL_ARGS.
$(BITS
))
142 $(BUILD_DIR_32
)/.installed
: BITS
=32
143 $(BUILD_DIR_64
)/.installed
: BITS
=64
144 $(BUILD_DIR
)/$(MACH32
)-%/.installed
: BITS
=32
145 $(BUILD_DIR
)/$(MACH64
)-%/.installed
: BITS
=64
146 $(foreach pyver
, $(PYTHON_VERSIONS
), \
147 $(eval
$(BUILD_DIR
)/%-$(pyver
)/.installed
: PYTHON_VERSION
=$(pyver
)) \
150 $(BUILD_DIR
)/%/.installed
: $(BUILD_DIR
)/%/.built
151 $(COMPONENT_PRE_INSTALL_ACTION
)
152 (cd
$(@D
) ; $(ENV
) $(COMPONENT_INSTALL_ENV
) \
153 $(WAF
) $(COMPONENT_INSTALL_TARGETS
) $(COMPONENT_INSTALL_ARGS
))
154 $(COMPONENT_POST_INSTALL_ACTION
)
157 # test the built source
158 COMPONENT_TEST_CMD
= $(WAF
)
159 COMPONENT_TEST_TARGETS
= test
161 $(BUILD_DIR_32
)/.tested-and-compared
: BITS
=32
162 $(BUILD_DIR_64
)/.tested-and-compared
: BITS
=64
163 $(BUILD_DIR
)/$(MACH32
)-%/.tested-and-compared
: BITS
=32
164 $(BUILD_DIR
)/$(MACH64
)-%/.tested-and-compared
: BITS
=64
165 $(foreach pyver
, $(PYTHON_VERSIONS
), \
166 $(eval
$(BUILD_DIR
)/%-$(pyver
)/.tested-and-compared
: PYTHON_VERSION
=$(pyver
)) \
169 $(BUILD_DIR
)/%/.tested-and-compared
: $(COMPONENT_TEST_DEP
)
170 $(RM
) -rf
$(COMPONENT_TEST_BUILD_DIR
)
171 $(MKDIR
) $(COMPONENT_TEST_BUILD_DIR
)
172 $(COMPONENT_PRE_TEST_ACTION
)
173 -(cd
$(COMPONENT_TEST_DIR
) ; \
174 $(COMPONENT_TEST_ENV_CMD
) $(COMPONENT_TEST_ENV
) \
175 $(COMPONENT_TEST_CMD
) \
176 $(COMPONENT_TEST_TARGETS
) $(COMPONENT_TEST_ARGS
)) \
177 &> $(COMPONENT_TEST_OUTPUT
)
178 $(COMPONENT_POST_TEST_ACTION
)
179 $(COMPONENT_TEST_CREATE_TRANSFORMS
)
180 $(COMPONENT_TEST_PERFORM_TRANSFORM
)
181 $(COMPONENT_TEST_COMPARE
)
182 $(COMPONENT_TEST_CLEANUP
)
185 $(BUILD_DIR_32
)/.tested
: BITS
=32
186 $(BUILD_DIR_64
)/.tested
: BITS
=64
187 $(BUILD_DIR
)/$(MACH32
)-%/.tested
: BITS
=32
188 $(BUILD_DIR
)/$(MACH64
)-%/.tested
: BITS
=64
189 $(foreach pyver
, $(PYTHON_VERSIONS
), \
190 $(eval
$(BUILD_DIR
)/%-$(pyver
)/.tested
: PYTHON_VERSION
=$(pyver
)) \
193 $(BUILD_DIR
)/%/.tested
: SHELLOPTS
=pipefail
194 $(BUILD_DIR
)/%/.tested
: $(COMPONENT_TEST_DEP
)
195 $(RM
) -rf
$(COMPONENT_TEST_BUILD_DIR
)
196 $(MKDIR
) $(COMPONENT_TEST_BUILD_DIR
)
197 $(COMPONENT_PRE_TEST_ACTION
)
198 (cd
$(COMPONENT_TEST_DIR
) ; \
199 $(COMPONENT_TEST_ENV_CMD
) $(COMPONENT_TEST_ENV
) \
200 $(COMPONENT_TEST_CMD
) \
201 $(COMPONENT_TEST_ARGS
) $(COMPONENT_TEST_TARGETS
)) \
202 |
& $(TEE
) $(COMPONENT_TEST_OUTPUT
)
203 $(COMPONENT_POST_TEST_ACTION
)
204 $(COMPONENT_TEST_CREATE_TRANSFORMS
)
205 $(COMPONENT_TEST_PERFORM_TRANSFORM
)
206 $(COMPONENT_TEST_CLEANUP
)
209 # Test the installed packages. The targets above depend on .built which
210 # means $(CLONEY) has already run. System-test needs cloning but not
211 # building; thus ideally, we would want to depend on .cloned here and below,
212 # but since we don't have that, we depend on .prep and run $(CLONEY) here.
213 $(BUILD_DIR
)/%/.system-tested-and-compared
: $(SOURCE_DIR
)/.prep
214 $(RM
) -rf
$(COMPONENT_TEST_BUILD_DIR
)
215 $(MKDIR
) $(COMPONENT_TEST_BUILD_DIR
)
216 $(ENV
) $(CLONEY_ARGS
) $(CLONEY
) $(SOURCE_DIR
) $(@D
)
217 $(COMPONENT_PRE_SYSTEM_TEST_ACTION
)
218 -(cd
$(COMPONENT_SYSTEM_TEST_DIR
) ; \
219 $(COMPONENT_SYSTEM_TEST_ENV_CMD
) $(COMPONENT_SYSTEM_TEST_ENV
) \
220 $(COMPONENT_SYSTEM_TEST_CMD
) \
221 $(COMPONENT_SYSTEM_TEST_ARGS
) $(COMPONENT_SYSTEM_TEST_TARGETS
)) \
222 &> $(COMPONENT_TEST_OUTPUT
)
223 $(COMPONENT_POST_SYSTEM_TEST_ACTION
)
224 $(COMPONENT_TEST_CREATE_TRANSFORMS
)
225 $(COMPONENT_TEST_PERFORM_TRANSFORM
)
226 $(COMPONENT_TEST_COMPARE
)
227 $(COMPONENT_SYSTEM_TEST_CLEANUP
)
230 $(BUILD_DIR
)/%/.system-tested
: SHELLOPTS
=pipefail
231 $(BUILD_DIR
)/%/.system-tested
: $(SOURCE_DIR
)/.prep
232 $(RM
) -rf
$(COMPONENT_TEST_BUILD_DIR
)
233 $(MKDIR
) $(COMPONENT_TEST_BUILD_DIR
)
234 $(ENV
) $(CLONEY_ARGS
) $(CLONEY
) $(SOURCE_DIR
) $(@D
)
235 $(COMPONENT_PRE_SYSTEM_TEST_ACTION
)
236 (cd
$(COMPONENT_SYSTEM_TEST_DIR
) ; \
237 $(COMPONENT_SYSTEM_TEST_ENV_CMD
) $(COMPONENT_SYSTEM_TEST_ENV
) \
238 $(COMPONENT_SYSTEM_TEST_CMD
) \
239 $(COMPONENT_SYSTEM_TEST_ARGS
) $(COMPONENT_SYSTEM_TEST_TARGETS
)) \
240 |
& $(TEE
) $(COMPONENT_TEST_OUTPUT
)
241 $(COMPONENT_POST_SYSTEM_TEST_ACTION
)
242 $(COMPONENT_TEST_CREATE_TRANSFORMS
)
243 $(COMPONENT_TEST_PERFORM_TRANSFORM
)
244 $(COMPONENT_SYSTEM_TEST_CLEANUP
)
248 $(RM
) -r
$(BUILD_DIR
) $(PROTO_DIR
)