-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
295 lines (261 loc) · 9.95 KB
/
Makefile
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#
# 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.
#
#
# Makefile: annotated sample Makefile using eng.git Makefile system
#
# The eng.git repository contains a system of Makefile components that provide
# pluggable Makefile functionality (the way is typically done for other
# programming environments, but isn't commonly done for Makefiles). Makefiles
# defined in this repository generate targets for:
#
# * building the current repository as an npm package
# * checking syntax and style for JavaScript, JSON, bash files,
# and SMF manifests
# * generating API documentation from restdown sources
# * generating manual pages from Markdown sources
# * building a copy of Node with this repository
# * loading a prebuilt copy of Node in this repository
# * fetching git submodules as they are needed
#
# This top-level Makefile is both a sample Makefile for new repositories and
# a demo for how to use each of the Makefile components here. If you find this
# comment in a Makefile outside of eng.git, that's a bug and should be fixed.
# Repos are expected to completely rewrite this file (possibly using it as a
# template).
#
# Writing new Makefile components is not hard, but requires thinking through how
# they may need to be customized. Here are some guidelines:
#
# * "Callers" (top-level Makefiles) should be able to use Makefile
# components by setting specific Make variables ("input variables" for the
# component) and then including the Makefile. The component works by
# defining output variables and (optionally) targets. See existing
# components for examples. Document clearly the input and output
# variables for each new Makefile component.
#
# * Most components actually consist of two files: a "defs" file that
# consumes input variables and produces output variables, and a separate
# "targ" file that defines targets. Consumers include the "defs" Makefile
# towards the top of their Makefile, before they've defined their own
# repo-specific targets. If components define targets at this point,
# they'd become default targets, and can also lead to dependency problems.
# Consumers include the "targ" Makefile after all definitions have been
# made.
#
# * Usually, a component should not define phony top-level targets (like
# "check" or "manpages"). Instead, just define variables (like
# MY_COMPONENTS_CHECK_TARGETS or MAN_OUTPUTS) that the caller can use to
# trivially define such a target themselves.
#
# * If you want to be able to use this Makefile more than once (e.g., with
# different parameters), that's possible, but tricky. See
# Makefile.manpages.{defs,targ} for an example.
#
#
# IMPORTANT: This sample Makefile should consist solely of repo-specific
# configuration, plus "include" directives for the common Makefile components,
# plus trivial, repo-specific targets. Repo-specific targets and recipes are
# okay, but generic targets and recipes do NOT belong here. If you find
# yourself wanting to add support for new targets here, you should add them to a
# new or existing pluggable Makefile component, document it clearly, and include
# that Makefile here.
#
#
# If a project produces a SmartOS image for use in Triton or Manta, the name of
# the image should be specified here. Additional metadata for the image can be
# set using BUILDIMAGE_* macros.
#
NAME = myproject
#
# Tools
#
TAPE := ./node_modules/.bin/tape
#
# If we need to use buildimage, make sure we declare that before including
# Makefile.defs since that conditionally sets macros based on
# ENGBLD_USE_BUILDIMAGE.
#
ENGBLD_USE_BUILDIMAGE = true
#
# Makefile.defs defines variables used as part of the build process.
# Ensure we have the eng submodule before attempting to include it.
#
ENGBLD_REQUIRE := $(shell git submodule update --init deps/eng)
include ./deps/eng/tools/mk/Makefile.defs
TOP ?= $(error Unable to access eng.git submodule Makefiles.)
#
# Configuration used by Makefile.defs and Makefile.targ to generate
# "check" and "docs" targets.
#
BASH_FILES = tools/check-copyright
DOC_FILES = index.md boilerplateapi.md
JSON_FILES = package.json
JS_FILES := $(shell find lib test -name '*.js') tools/bashstyle
JSL_FILES_NODE = $(JS_FILES)
JSSTYLE_FILES = $(JS_FILES)
JSL_CONF_NODE = tools/jsl.node.conf
JSSTYLE_FLAGS = -f tools/jsstyle.conf
#
# Configuration used by Makefile.smf.defs to generate "check" and "all" targets
# for SMF manifest files.
#
SMF_MANIFESTS_IN = smf/manifests/bapi.xml.in
include ./deps/eng/tools/mk/Makefile.smf.defs
#
# Historically, Node packages that make use of binary add-ons must ship their
# own Node built with the same compiler, compiler options, and Node version that
# the add-on was built with. On SmartOS systems, we use prebuilt Node images
# via Makefile.node_prebuilt.defs. On other systems, we build our own Node
# binary as part of the build process. Other options are possible -- it depends
# on the need of your repository.
#
NODE_PREBUILT_VERSION = v6.17.0
ifeq ($(shell uname -s),SunOS)
NODE_PREBUILT_TAG = zone64
# Use the sdcnode build for [email protected]
NODE_PREBUILT_IMAGE = c2c31b00-1d60-11e9-9a77-ff9f06554b0f
include ./deps/eng/tools/mk/Makefile.node_prebuilt.defs
else
NPM=npm
NODE=node
NPM_EXEC=$(shell which npm)
NODE_EXEC=$(shell which node)
endif
#
# If a project needs to include Triton/Manta agents as part of its image,
# include Makefile.agent_prebuilt.defs and define an AGENTS macro to specify
# which agents are required.
#
include ./deps/eng/tools/mk/Makefile.agent_prebuilt.defs
#
# CTF support.
#
include ./tools/mk/Makefile.ctf.defs
#
# If a project includes some components written in the Go language, the Go
# toolchain will need to be available on the build machine. At present, the
# Makefile library only handles obtaining a toolchain for SmartOS systems.
#
ifeq ($(shell uname -s),SunOS)
GO_PREBUILT_VERSION = 1.9.2
GO_TARGETS = $(STAMP_GO_TOOLCHAIN)
GO_TEST_TARGETS = test_go
include ./deps/eng/tools/mk/Makefile.go_prebuilt.defs
endif
#
# Makefile.node_modules.defs provides a common target for installing modules
# with NPM from a dependency specification in a "package.json" file. By
# including this Makefile, we can depend on $(STAMP_NODE_MODULES) to drive "npm
# install" correctly.
#
include ./deps/eng/tools/mk/Makefile.node_modules.defs
#
# Configuration used by Makefile.manpages.defs to generate manual pages.
# See that Makefile for details. MAN_SECTION must be eagerly defined (with
# ":="), but the Makefile can be used multiple times to build manual pages for
# different sections.
#
MAN_INROOT = docs/man
MAN_OUTROOT = man
CLEAN_FILES += $(MAN_OUTROOT)
MAN_SECTION := 1
include ./deps/eng/tools/mk/Makefile.manpages.defs
MAN_SECTION := 3bapi
include ./deps/eng/tools/mk/Makefile.manpages.defs
#
# If a project produces a SmartOS image for use in Manta/Triton, the build
# should produce a tarball containing the components built from this workspace,
# including any node_modules imported along with the build of node itself
# (either built locally or prebuilt)
#
RELEASE_TARBALL = $(NAME)-pkg-$(STAMP).tar.gz
#
# To support the 'buildimage' target in Makefile.targ, metadata required for the
# image should be set here.
#
# This image is triton-origin-x86_64-18.4.0
BASE_IMAGE_UUID = a9368831-958e-432d-a031-f8ce6768d190
BUILDIMAGE_NAME = manta-myproject
BUILDIMAGE_DESC = My Project Has A Description
AGENTS = amon config registrar
BUILDIMAGE_PKGSRC = foobar-42 ook-1.0.1b cheese-0.4cheddar
#
# The default image contents are set to $(TOP)/$(RELEASE_TARBALL)
# in Makefile.targ. To override those, set $(BUILDIMAGE_PKG) to the
# full path of the required tarball.
#
# BUILDIMAGE_PKG=$(TOP)/bar/mytarball.tar.gz
#
#
# Set for buildimage to have pkgin update and full-upgrade before installing
# BUILDIMAGE_PKGSRC packages.
#
# BUILDIMAGE_DO_PKGSRC_UPGRADE=true
#
# Repo-specific targets
#
.PHONY: all
all: $(SMF_MANIFESTS) $(STAMP_NODE_MODULES) $(GO_TARGETS) | $(REPO_DEPS)
#
# If a project produces a SmartOS image for use in Manta/Triton, a release
# target should construct the RELEASE_TARBALL file
#
.PHONY: release
release:
echo "Do work here"
#
# This example Makefile defines a special target for building manual pages. You
# may want to make these dependencies part of "all" instead.
#
.PHONY: manpages
manpages: $(MAN_OUTPUTS)
.PHONY: test
test: $(STAMP_NODE_MODULES) $(GO_TEST_TARGETS) $(TEST_CTF_TARGETS)
$(NODE) $(TAPE) test/*.test.js
#
# This test demonstrates a basic use of the project-local Go toolchain.
#
.PHONY: test_go
test_go: $(STAMP_GO_TOOLCHAIN)
@$(GO) version
$(GO) run src/tellmewhereto.go
#
# Example ctfconvert usage
#
HELLOCTF_OBJS = helloctf.o
HELLOCTF_CFLAGS = -gdwarf-2 -m64 -std=c99 -D__EXTENSIONS__ \
-Wall -Wextra -Werror \
-Wno-unused-parameter \
-Isrc/
HELLOCTF_OBJDIR = $(CACHE_DIR)/helloctf.obj
helloctf: $(HELLOCTF_OBJS:%=$(HELLOCTF_OBJDIR)/%) $(STAMP_CTF_TOOLS)
gcc -o $@ $(HELLOCTF_OBJS:%=$(HELLOCTF_OBJDIR)/%) $(HELLOCTF_CFLAGS)
$(CTFCONVERT) $@
$(HELLOCTF_OBJDIR)/%.o: src/%.c
@mkdir -p $(@D)
gcc -o $@ -c $(HELLOCTF_CFLAGS) $<
CLEAN_FILES += $(HELLOCTF_OBJDIR) helloctf
#
# Target definitions. This is where we include the target Makefiles for
# the "defs" Makefiles we included above.
#
include ./deps/eng/tools/mk/Makefile.deps
ifeq ($(shell uname -s),SunOS)
include ./deps/eng/tools/mk/Makefile.node_prebuilt.targ
include ./deps/eng/tools/mk/Makefile.go_prebuilt.targ
include ./deps/eng/tools/mk/Makefile.agent_prebuilt.targ
endif
MAN_SECTION := 1
include ./deps/eng/tools/mk/Makefile.manpages.targ
MAN_SECTION := 3bapi
include ./deps/eng/tools/mk/Makefile.manpages.targ
include ./deps/eng/tools/mk/Makefile.smf.targ
include ./deps/eng/tools/mk/Makefile.node_modules.targ
include ./deps/eng/tools/mk/Makefile.ctf.targ
include ./deps/eng/tools/mk/Makefile.targ