-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMakefile.defs
225 lines (201 loc) · 6.84 KB
/
Makefile.defs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Copyright 2020 Joyent, Inc.
# Copyright 2022 MNX Cloud, Inc.
#
#
# Makefile.defs: common defines.
#
# NOTE: This makefile comes from the "eng" repo. If you find yourself changing
# this file, you should ensure that you test all consumers of it, since
# eng.git is a git submodule of several repositories. After testing, push
# changes to the eng.git repository as normal, then do the following for
# each component that uses eng.git, likely reusing the original ticket subject
# for the commit message as was used for the eng.git push.
#
# $ git submodule update --remote deps/eng
# $ git add deps/eng
# $ git commit -m "TOOLS-xxxx some description" deps/eng
#
# Then create a PR as usual for review.
#
#
# This makefile defines some useful defines. Include it at the top of
# your Makefile.
#
# Definitions in this Makefile:
#
# TOP The absolute path to the project directory. The top dir.
# BRANCH The current git branch.
# TIMESTAMP The timestamp for the build. This can be set via
# the TIMESTAMP envvar (used by MG-based builds).
# STAMP A build stamp to use in built package names.
#
# MAKE_STAMPS_DIR The directory in which make stamp files are to be
# created. See comments below on expensive targets.
#
# CACHE_DIR A directory tree in which temporary files may be
# collected by download, tarball extraction, etc. This
# directory is completely removed by "make distclean".
# Files in this directory are not intended to be shipped.
#
#
# Note that variables that start with "ENGBLD_" are ones we expect developers
# may want to override in their environment, usually to modify build output
# destinations, but sometimes to modify the behavior of the build.
#
# Be explicit about assuming bash for inline shell execution
SHELL ?= /bin/bash
TOP ?= $(shell pwd)
#
# Mountain Gorilla-spec'd versioning.
# See "Package Versioning" in MG's README.md:
# <https://mo.joyent.com/mountain-gorilla/blob/master/README.md#L139-200>
#
# Need GNU awk for multi-char arg to "-F".
_AWK := $(shell (which gawk >/dev/null && echo gawk) \
|| (which nawk >/dev/null && echo nawk) \
|| echo awk)
BRANCH := $(shell git symbolic-ref HEAD | $(_AWK) -F/ '{print $$3}')
ifeq ($(TIMESTAMP),)
TIMESTAMP := $(shell date -u "+%Y%m%dT%H%M%SZ")
endif
_GITDESCRIBE := g$(shell git describe --all --long --dirty | $(_AWK) -F'-g' '{print $$NF}')
STAMP := $(BRANCH)-$(TIMESTAMP)-$(_GITDESCRIBE)
# node-gyp will print build info useful for debugging with V=1
export V=1
CACHE_DIR ?= cache
DISTCLEAN_FILES += $(CACHE_DIR)
# Many components assemble *-pkg*.gz tarballs as build products
CLEAN_FILES += $(NAME)-pkg*.gz
#
# EXPENSIVE TARGETS AND MAKE STAMP FILES
#
# Targets which are expensive to run and lack a single file that marks
# completion are difficult to track with make; e.g., "npm install". One
# solution to this problem is to create "stamp" files with symbolic names which
# are created as the final step in a complex make rule in order to mark
# completion.
#
# In order to make these more uniform, and easier to target with "make clean",
# we will attempt to store them under a single directory. Note that these
# files are never targets for shipping in build artefacts.
#
# Stamp-backed targets come in several parts. First, a macro should be defined
# which names a file in the MAKE_STAMPS_DIR directory. Then, a target which
# creates this stamp file must be provided. The recipe for this target should
# use MAKE_STAMP_REMOVE and MAKE_STAMP_CREATE to perform the appropriate stamp
# management.
#
# For example:
#
# --- Makefile.*.defs:
#
# $(STAMP_EXPENSIVE_RESULT) := $(MAKE_STAMPS_DIR)/expensive-result
#
# --- Makefile.*.targ:
#
# $(STAMP_EXPENSIVE_RESULT): input/file another/input/file
# $(MAKE_STAMP_REMOVE)
# rm -rf output_tree/ # <--- ensure a clean slate
# expensive_program -o output_tree/ $^
# $(MAKE_STAMP_CREATE)
#
# NOTE: Every stamp file is exposed as an implicit "stamp-$STAMP_NAME" target.
# The example above could be built manually by invoking:
#
# make stamp-expensive-result
#
MAKE_STAMPS_DIR ?= make_stamps
CLEAN_FILES += $(MAKE_STAMPS_DIR)
MAKE_STAMP_REMOVE = mkdir -p $(@D); rm -f $(@)
MAKE_STAMP_CREATE = mkdir -p $(@D); touch $(@)
#
# Nearly all components in Triton/Manta currently require the build machine to
# be running this platform image, validated as part of validate-buildenv.sh.
# Makefiles that allow newer platforms should override this.
#
BUILD_PLATFORM=20181206T011455Z
#
# The manta path where the bits-upload target stores build artifacts, via
# ./deps/eng/tools/bits-upload.sh. This can be a Manta path, or an absolute
# filesystem path. If the latter, be sure to also set
# $ENGBLD_BITS_UPLOAD_LOCAL=true, see below.
#
ENGBLD_DEST_OUT_PATH ?= /public/builds
#
# Makefiles must declare whether they need to construct a ZFS image
# by setting ENGBLD_USE_BUILDIMAGE to 'true'. We use this mechanism
# so that we can conditionally add a buildimage dependency to the
# 'bits-upload' target.
#
ifeq ($(ENGBLD_USE_BUILDIMAGE), true)
BUILDIMAGE_TARG = buildimage
else
BUILDIMAGE_TARG =
endif
#
# If bits-upload should use a local dest_dir, set that argument based on
# $ENGBLD_BITS_UPLOAD_LOCAL in the environment.
#
ifeq ($(ENGBLD_BITS_UPLOAD_LOCAL), true)
BITS_UPLOAD_LOCAL_ARG = -L
else
BITS_UPLOAD_LOCAL_ARG =
endif
#
# If bits-upload should publish images to updates.tritondatacenter.com, set that
# argument based on $ENGBLD_BITS_UPLOAD_IMGAPI in the environment.
#
ifeq ($(ENGBLD_BITS_UPLOAD_IMGAPI), true)
BITS_UPLOAD_IMGAPI_ARG = -p
else
BITS_UPLOAD_IMGAPI_ARG =
endif
#
# A directory for build artifacts, used by the bits-upload, publish and
# buildimage targets. If BITS_DIR is set, use that instead, to remain
# compatible with MG-driven builds.
#
ENGBLD_BITS_DIR ?= $(TOP)/bits
ifdef BITS_DIR
ENGBLD_BITS_DIR = $(BITS_DIR)
endif
STAMP_BUILDIMAGE_PREP := $(MAKE_STAMPS_DIR)/buildimage-prep
#
# Metadata needed by buildimage to construct the image.
# This gets used when generating the image's manifest file.
#
BUILDIMAGE_VERSION ?= $(STAMP)
BUILDIMAGE_STAGEDIR = /tmp/buildimage-$(NAME)-$(STAMP)
BUILDIMAGE_MF ?= \
{"name": "$(BUILDIMAGE_NAME)",\
"description": "$(BUILDIMAGE_DESC)",\
"version": "$(BUILDIMAGE_VERSION)",\
"tags": {"smartdc_service": true}\
}
#
# Crude detection of whether we're likely to need to use
# pfexec to gain root-like privileges. Note that this means
# $(PFEXEC) will only be defined if we're running the build
# as non-root.
#
UID = $(shell /usr/bin/id -u)
ifeq ($(UID), 0)
PFEXEC=
else
PFEXEC=/usr/bin/pfexec
endif
#
# Avoid pkgsrc curl because that lacks modern TLS support on the ancient
# pkgsrcs still used on some smartos@1.6.3-based builds.
#
ifeq ($(shell uname -s),SunOS)
CURL ?= /usr/bin/curl
else
CURL ?= curl
endif