Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlunit-test / repo / third_party / nlbuild-autotools / repo / Makefile
1 #
2 #    Copyright (c) 2017-2018 Nest Labs Inc. All Rights Reserved.
3 #    Copyright (c) 2018 Google LLC. All Rights Reserved.
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License");
6 #    you may not use this file except in compliance with the License.
7 #    You may obtain a copy of the License at
8 #
9 #    http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #    Unless required by applicable law or agreed to in writing, software
12 #    distributed under the License is distributed on an "AS IS" BASIS,
13 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #    See the License for the specific language governing permissions and
15 #    limitations under the License.
16 #
17
18 #
19 #    Description:
20 #      This make file supports generating distributions of
21 #      nlbuild-autotools.
22 #
23
24 include Common.mak
25
26 #
27 # Build directories
28 #
29
30 builddir         := .
31 top_builddir     := .
32 abs_builddir     := $(CURDIR)
33 abs_top_builddir := $(CURDIR)
34
35 #
36 # Source directories
37 #
38
39 srcdir           := .
40 top_srcdir       := .
41 abs_srcdir       := $(CURDIR)
42 abs_top_srcdir   := $(CURDIR)
43
44 distdir           = $(PACKAGE)-$(VERSION)
45
46 dist_tgz_TARGETS  = $(distdir)$(TGZ_EXTENSION)
47 dist_txz_TARGETS  = $(distdir)$(TXZ_EXTENSION)
48
49 DISTFILES        := $(shell $(CAT) MANIFEST)
50
51 #
52 # Package version files:
53 #
54 # .default-version - The default package version. This file is ALWAYS checked
55 #                    in and should always represent the current baseline
56 #                    version of the package.
57 #
58 # .dist-version    - The distributed package version. This file is NEVER
59 #                    checked in within the upstream repository, is auto-
60 #                    generated, and is only found in the package distribution.
61 #
62 # .local-version   - The current source code controlled package version. This
63 #                    file is NEVER checked in within the upstream repository,
64 #                    is auto-generated, and can always be found in both the
65 #                    build tree and distribution.
66 #
67 # When present, the .local-version file is preferred first, the
68 # .dist-version second, and the .default-version last.
69 #
70
71 # VERSION_FILE should be and is intentionally an immediate (:=) rather
72 # than a deferred (=) variable to ensure the value binds once and only once
73 # for a given MAKELEVEL even as .local-version and .dist-version are created
74 # during makefile execution.
75
76 VERSION_FILE                      := $(if $(wildcard $(builddir)/.local-version),$(builddir)/.local-version,$(if $(wildcard $(srcdir)/.dist-version),$(srcdir)/.dist-version,$(srcdir)/.default-version))
77
78 #
79 # The two-level variables and the check against MAKELEVEL ensures that
80 # not only can the package version be overridden from the command line
81 # but also when the version is NOT overridden that we bind the version
82 # once and only once across potential sub-makes to prevent the version
83 # from flapping as VERSION_FILE changes.
84 #
85
86 export MAYBE_PACKAGE_VERSION      := $(if $(filter 0,$(MAKELEVEL)),$(shell cat $(VERSION_FILE) 2> /dev/null),$(MAYBE_PACKAGE_VERSION))
87
88 PACKAGE_VERSION                   ?= $(MAYBE_PACKAGE_VERSION)
89
90 VERSION                            = $(PACKAGE_VERSION)
91
92 #
93 # Verbosity
94 #
95 _NL_V_COPY                         = $(_NL_V_COPY_$(V))
96 _NL_V_COPY_                        = $(_NL_V_COPY_$(NL_DEFAULT_VERBOSITY))
97 _NL_V_COPY_0                       = @for file in $(DISTFILES); do echo "  COPY     $${file}"; done;
98 _NL_V_COPY_1                       = 
99
100 _NL_V_MAKE                         = $(_NL_V_MAKE_$(V))
101 _NL_V_MAKE_                        = $(_NL_V_MAKE_$(NL_DEFAULT_VERBOSITY))
102 _NL_V_MAKE_0                       = @echo "  MAKE     dist-hook";
103 _NL_V_MAKE_1                       = 
104
105 #
106 # check-file <macro suffix>
107 #
108 # Check whether a file, referenced by the $(@) variable, should be
109 # updated / regenerated based on its dependencies, referenced by the
110 # $(<) variable by running the make macro check-file-<macro suffix>.
111 #
112 # The $(<) is passed as the first argument if the macro wants to process
113 # it and the prospective new output file, which the macro MUST
114 # generate, as the second.
115 #
116 # This macro will ensure that any required parent directories are created
117 # prior to invoking check-file-<macro suffix>.
118 #
119 # This macro is similar to and inspired by that from Linux Kbuild and
120 # elsewhere.
121 #
122 #   <macro suffix> - The name, suffixed to "check-file-", which indicates
123 #                    the make macro to invoke.
124 #
125 #
126 define check-file
127 $(NL_V_AT)set -e;                                   \
128 echo '  CHECK    $(@)';                             \
129 $(MKDIR) -p $(dir $(@));                            \
130 $(call check-file-$(1),$(<),$(@).N);                \
131 if [ -r "$(@)" ] && $(CMP) -s "$(@)" "$(@).N"; then \
132     $(RM) -f "$(@).N";                              \
133 else                                                \
134     echo '  GEN      $(@)';                         \
135     $(MV) -f "$(@).N" "$(@)";                       \
136 fi
137 endef # check-file
138
139 #
140 # check-file-.local-version
141 #
142 # Speculatively regenerate .local-version and check to see if it needs
143 # to be updated.
144 #
145 # If PACKAGE_VERSION has been supplied anywhere other than in this file
146 # (which is implicitly the contents of .local-version), then use that;
147 # otherwise, attempt to generate it from the SCM system.
148 #
149 # This is called from $(call check-file,.local-version).
150 #
151 define check-file-.local-version
152 if [ "$(origin PACKAGE_VERSION)" != "file" ]; then     \
153     echo "$(PACKAGE_VERSION)" > "$(2)";                \
154 else                                                   \
155     $(abs_top_srcdir)/scripts/mkversion                \
156         -b "$(PACKAGE_VERSION)" "$(top_srcdir)"        \
157         > "$(2)";                                      \
158 fi
159 endef
160
161 #
162 # check-file-.dist-version
163 #
164 # Speculatively regenerate .dist-version and check to see if it needs
165 # to be updated.
166 #
167 # This is called from $(call check-file,.dist-version).
168 #
169 define check-file-.dist-version
170 $(CAT) "$(1)" > "$(2)"
171 endef
172
173 #
174 # Version file regeneration rules.
175 #
176 .PHONY: force
177
178 $(builddir)/.local-version: $(srcdir)/.default-version force
179
180 $(distdir)/.dist-version: $(builddir)/.local-version force
181
182 $(distdir)/.dist-version $(builddir)/.local-version:
183         $(call check-file,$(@F))
184
185 all: .local-version
186
187 dist-hook: $(distdir)/.dist-version
188
189 #
190 # Stage the distribution files to a distribution directory
191 #
192 stage: $(DISTFILES) .local-version
193         $(call nl-remove-dir,$(distdir))
194         $(call nl-create-dir,$(distdir))
195         $(_NL_V_MAKE)$(MAKE) -s distdir="$(distdir)" dist-hook
196         $(_NL_V_COPY)(cd $(abs_top_srcdir); $(dist_tar_ARCHIVE) $(DISTFILES) | (cd $(abs_builddir)/$(distdir); $(TAR) xfBp -))
197
198 #
199 # Produce an architecture-independent distribution using a tar archive
200 # with gzip compression
201 #
202 $(dist_tgz_TARGETS): stage
203         $(NL_V_TGZ)$(dist_tgz_ARCHIVE) $(distdir) | $(dist_tgz_COMPRESS) > "$(@)"
204
205 #
206 # Produce an architecture-independent distribution using a tar archive
207 # with xz compression
208 #
209 $(dist_txz_TARGETS): stage
210         $(NL_V_TXZ)$(dist_txz_ARCHIVE) $(distdir) | $(dist_txz_COMPRESS) > "$(@)"
211
212 #
213 # Produce an architecture-independent distribution of the
214 # nlbuild-autotools core.
215 #
216 dist: $(DIST_TARGETS) .local-version
217         $(call nl-remove-dir,$(distdir))
218
219 dist-tgz: $(dist_tgz_TARGETS)
220
221 dist-txz: $(dist_txz_TARGETS)
222
223 #
224 # Produce prebuilt GNU autotools binaries for the architecture of the
225 # CURRENT build machine and install them in THIS nlbuild-autotools
226 # package.
227 #
228 .PHONY: tools
229 tools:
230         $(NL_V_MAKE)$(MAKE) -C tools $(@)
231
232 #
233 # Produce prebuilt GNU autotools architecture-dependent and -independent
234 # binaries for the architecture of the CURRENT build machine and PACKAGE
235 # them up for EXTERNAL distribution.
236 #
237 toolsdist: .local-version
238         $(NL_V_MAKE)$(MAKE) -C tools $(@)
239
240 clean: clean-local
241         $(NL_V_MAKE)$(MAKE) -C tools $(@)