2 # Copyright (c) 2017-2018 Nest Labs Inc. All Rights Reserved.
3 # Copyright (c) 2018 Google LLC. All Rights Reserved.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 # This make file supports generating distributions of
32 abs_builddir := $(CURDIR)
33 abs_top_builddir := $(CURDIR)
41 abs_srcdir := $(CURDIR)
42 abs_top_srcdir := $(CURDIR)
44 distdir = $(PACKAGE)-$(VERSION)
46 dist_tgz_TARGETS = $(distdir)$(TGZ_EXTENSION)
47 dist_txz_TARGETS = $(distdir)$(TXZ_EXTENSION)
49 DISTFILES := $(shell $(CAT) MANIFEST)
52 # Package version files:
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.
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.
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.
67 # When present, the .local-version file is preferred first, the
68 # .dist-version second, and the .default-version last.
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.
76 VERSION_FILE := $(if $(wildcard $(builddir)/.local-version),$(builddir)/.local-version,$(if $(wildcard $(srcdir)/.dist-version),$(srcdir)/.dist-version,$(srcdir)/.default-version))
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.
86 export MAYBE_PACKAGE_VERSION := $(if $(filter 0,$(MAKELEVEL)),$(shell cat $(VERSION_FILE) 2> /dev/null),$(MAYBE_PACKAGE_VERSION))
88 PACKAGE_VERSION ?= $(MAYBE_PACKAGE_VERSION)
90 VERSION = $(PACKAGE_VERSION)
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;
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";
106 # check-file <macro suffix>
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>.
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.
116 # This macro will ensure that any required parent directories are created
117 # prior to invoking check-file-<macro suffix>.
119 # This macro is similar to and inspired by that from Linux Kbuild and
122 # <macro suffix> - The name, suffixed to "check-file-", which indicates
123 # the make macro to invoke.
128 echo ' CHECK $(@)'; \
129 $(MKDIR) -p $(dir $(@)); \
130 $(call check-file-$(1),$(<),$(@).N); \
131 if [ -r "$(@)" ] && $(CMP) -s "$(@)" "$(@).N"; then \
135 $(MV) -f "$(@).N" "$(@)"; \
140 # check-file-.local-version
142 # Speculatively regenerate .local-version and check to see if it needs
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.
149 # This is called from $(call check-file,.local-version).
151 define check-file-.local-version
152 if [ "$(origin PACKAGE_VERSION)" != "file" ]; then \
153 echo "$(PACKAGE_VERSION)" > "$(2)"; \
155 $(abs_top_srcdir)/scripts/mkversion \
156 -b "$(PACKAGE_VERSION)" "$(top_srcdir)" \
162 # check-file-.dist-version
164 # Speculatively regenerate .dist-version and check to see if it needs
167 # This is called from $(call check-file,.dist-version).
169 define check-file-.dist-version
170 $(CAT) "$(1)" > "$(2)"
174 # Version file regeneration rules.
178 $(builddir)/.local-version: $(srcdir)/.default-version force
180 $(distdir)/.dist-version: $(builddir)/.local-version force
182 $(distdir)/.dist-version $(builddir)/.local-version:
183 $(call check-file,$(@F))
187 dist-hook: $(distdir)/.dist-version
190 # Stage the distribution files to a distribution directory
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 -))
199 # Produce an architecture-independent distribution using a tar archive
200 # with gzip compression
202 $(dist_tgz_TARGETS): stage
203 $(NL_V_TGZ)$(dist_tgz_ARCHIVE) $(distdir) | $(dist_tgz_COMPRESS) > "$(@)"
206 # Produce an architecture-independent distribution using a tar archive
207 # with xz compression
209 $(dist_txz_TARGETS): stage
210 $(NL_V_TXZ)$(dist_txz_ARCHIVE) $(distdir) | $(dist_txz_COMPRESS) > "$(@)"
213 # Produce an architecture-independent distribution of the
214 # nlbuild-autotools core.
216 dist: $(DIST_TARGETS) .local-version
217 $(call nl-remove-dir,$(distdir))
219 dist-tgz: $(dist_tgz_TARGETS)
221 dist-txz: $(dist_txz_TARGETS)
224 # Produce prebuilt GNU autotools binaries for the architecture of the
225 # CURRENT build machine and install them in THIS nlbuild-autotools
230 $(NL_V_MAKE)$(MAKE) -C tools $(@)
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.
237 toolsdist: .local-version
238 $(NL_V_MAKE)$(MAKE) -C tools $(@)
241 $(NL_V_MAKE)$(MAKE) -C tools $(@)