Skip to content

Commit 847d874

Browse files
committed
Refactor Makefile by splitting into separate sub-files
1 parent 855a959 commit 847d874

File tree

29 files changed

+953
-403
lines changed

29 files changed

+953
-403
lines changed

Makefile

Lines changed: 28 additions & 399 deletions
Large diffs are not rendered by default.

tools/make/Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
# VARIABLES #
3+
4+
# Define the command for `npm`:
5+
NPM ?= npm
6+
7+
# Define the command for `node`:
8+
NODE ?= node
9+
10+
# Determine the host kernel:
11+
KERNEL ?= $(shell uname -s)
12+
13+
# Based on the kernel, determine the `open` command:
14+
ifeq ($(KERNEL), Darwin)
15+
OPEN ?= open
16+
else
17+
OPEN ?= xdg-open
18+
endif
19+
20+
21+
# DEPENDENCIES #
22+
23+
include $(TOOLS_MAKE_DIR)/lib/help/Makefile
24+
include $(TOOLS_MAKE_DIR)/lib/find/Makefile
25+
include $(TOOLS_MAKE_DIR)/lib/lint/Makefile
26+
include $(TOOLS_MAKE_DIR)/lib/notes/Makefile
27+
include $(TOOLS_MAKE_DIR)/lib/install/Makefile
28+
include $(TOOLS_MAKE_DIR)/lib/test/Makefile
29+
include $(TOOLS_MAKE_DIR)/lib/test-cov/Makefile
30+
include $(TOOLS_MAKE_DIR)/lib/test-browsers/Makefile
31+
include $(TOOLS_MAKE_DIR)/lib/test-ci/Makefile
32+
include $(TOOLS_MAKE_DIR)/lib/coverage-service/Makefile
33+
include $(TOOLS_MAKE_DIR)/lib/examples/Makefile
34+
include $(TOOLS_MAKE_DIR)/lib/docs/Makefile
35+
36+
37+
# TARGETS #
38+
39+
# Perform clean-up.
40+
#
41+
# This target runs the project's cleanup sequence.
42+
43+
clean: clean-node clean-cov clean-docs
44+
-rm -rf $(BUILD_DIR)
45+
-rm -rf $(REPORTS_DIR)
46+
47+
48+
.PHONY: clean
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Makefile
22
===
3-
> Project Makefile.
3+
> Development utility.
44
5-
[`make`][make] is the project's primary development tool. For an overview of `make`, see the `make` [manual][make].
5+
This project uses [`make`][make] as its development utility. For an overview of `make`, see the `make` [manual][make].
66

77

88
## Usage
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# VARIABLES #
3+
4+
# Define the code coverage service to use:
5+
COVERAGE_SERVICE ?= codecov
6+
7+
# Define the path of the `lcov.info` file which will be sent to the coverage service:
8+
LCOV_INFO_PATH ?= $(COVERAGE_DIR)/lcov.info
9+
10+
11+
# DEPENDENCIES #
12+
13+
ifeq ($(COVERAGE_SERVICE), codecov)
14+
include $(TOOLS_MAKE_DIR)/lib/coverage-service/codecov.mk
15+
endif
16+
17+
18+
# TARGETS #
19+
20+
# Report coverage statistics.
21+
#
22+
# This target sends coverage statistics to a hosted code coverage service.
23+
24+
coverage:
25+
ifeq ($(COVERAGE_SERVICE), codecov)
26+
@$(MAKE) -f $(THIS_FILE) coverage-codecov
27+
endif
28+
29+
30+
.PHONY: coverage
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# VARIABLES #
3+
4+
CAT ?= cat
5+
6+
# Define the path to the Codecov executable:
7+
CODECOV ?= $(BIN)/codecov
8+
9+
10+
# TARGETS #
11+
12+
# Report coverage statistics.
13+
#
14+
# This target sends coverage statistics to [Codecov][1].
15+
#
16+
# To install Codecov:
17+
# $ npm install codecov
18+
#
19+
# [1] https://codecov.io/
20+
21+
coverage-codecov:
22+
$(NPM) install codecov
23+
$(CAT) $(LCOV_INFO_PATH) | $(CODECOV)
24+
25+
.PHONY: coverage-codecov

tools/make/lib/docs/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
# DEPENDENCIES #
3+
4+
include $(TOOLS_MAKE_DIR)/lib/docs/jsdoc.mk
5+
6+
7+
# TARGETS #
8+
9+
# Generate documentation.
10+
#
11+
# This target runs tasks to generate documentation.
12+
13+
docs: docs-jsdoc
14+
15+
16+
# Remove generated documentation.
17+
#
18+
# This target cleans generated documentation by removing it entirely.
19+
20+
clean-docs: clean-jsdoc
21+
22+
23+
.PHONY: docs clean-docs

tools/make/lib/docs/jsdoc.mk

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
# VARIABLES #
3+
4+
# Define the path of the JSDoc executable:
5+
JSDOC ?= $(BIN)/jsdoc
6+
7+
# Define the path to the JSDoc configuration file:
8+
JSDOC_CONF ?= $(CONFIG_DIR)/jsdoc.conf.json
9+
10+
# Define the path to the JSDoc JSON template:
11+
JSDOC_JSON_TEMPLATE ?= $(ROOT)/tools/docs/jsdoc/templates/json
12+
13+
# Define the output directory for JSDoc:
14+
JSDOC_OUT ?= $(DOCS_DIR)/jsdoc
15+
16+
# Define the output directory for JSDoc JSON:
17+
JSDOC_JSON_OUT ?= $(JSDOC_OUT)/json
18+
19+
# Define the output filepath for JSDoc JSON:
20+
JSDOC_JSON_PATH ?= $(JSDOC_JSON_OUT)/jsdoc.json
21+
22+
# Define the path to the JSDoc HTML template:
23+
JSDOC_HTML_TEMPLATE ?= templates/default
24+
25+
# Define the output directory for JSDoc HTML documentation:
26+
JSDOC_HTML_OUT ?= $(JSDOC_OUT)/static
27+
28+
# Define the output filepath for HTML documentation:
29+
JSDOC_HTML_PATH ?= $(JSDOC_HTML_OUT)/index.html
30+
31+
# Define command-line options to be used when invoking the JSDoc executable to generate HTML documentation:
32+
JSDOC_HTML_FLAGS ?= --template $(JSDOC_HTML_TEMPLATE) \
33+
--configure $(JSDOC_CONF) \
34+
--encoding utf8 \
35+
--destination $(JSDOC_HTML_OUT) \
36+
--verbose
37+
38+
# Define command-line options to be used when invoking the JSDoc executable to generate JSDoc JSON:
39+
JSDOC_JSON_FLAGS ?= --template $(JSDOC_JSON_TEMPLATE) \
40+
--configure $(JSDOC_CONF) \
41+
--encoding utf8 \
42+
--destination console
43+
44+
45+
# TARGETS #
46+
47+
# Generate JSDoc HTML documentation.
48+
#
49+
# This target generates source HTML documentation from [JSDoc][1]-style comments.
50+
#
51+
# To install JSDoc:
52+
# $ npm install jsdoc
53+
#
54+
# [1] http://usejsdoc.org/
55+
56+
docs-src: docs-jsdoc
57+
58+
docs-jsdoc: node_modules
59+
-rm -rf $(JSDOC_HTML_OUT)
60+
mkdir -p $(JSDOC_HTML_OUT)
61+
$(JSDOC) $(JSDOC_HTML_FLAGS) $(SOURCES)
62+
63+
64+
# Generate JSDoc JSON.
65+
#
66+
# This target generates JSDoc JSON from [JSDoc][1]-style comments.
67+
#
68+
# To install JSDoc:
69+
# $ npm install jsdoc
70+
#
71+
# [1] http://usejsdoc.org/
72+
73+
jsdoc-json: node_modules
74+
-rm -f $(JSDOC_JSON_PATH)
75+
mkdir -p $(JSDOC_JSON_OUT)
76+
$(JSDOC) $(JSDOC_JSON_FLAGS) $(SOURCES) > $(JSDOC_JSON_PATH)
77+
78+
79+
# View HTML documentation.
80+
#
81+
# This target opens JSDoc HTML documentation in a local web browser.
82+
83+
view-src-docs:
84+
$(OPEN) $(JSDOC_HTML_PATH)
85+
86+
87+
# Remove a JSDoc output directory.
88+
#
89+
# This target cleans up a JSDoc output directory by removing it entirely.
90+
91+
clean-jsdoc:
92+
-rm -rf $(JSDOC_OUT)
93+
94+
95+
.PHONY: docs-src docs-jsdoc jsdoc-json view-src-docs clean-jsdoc
96+

tools/make/lib/examples/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# VARIABLES #
3+
4+
# Define the command for `node`:
5+
NODE ?= node
6+
7+
8+
# TARGETS #
9+
10+
# Run examples.
11+
#
12+
# This target runs a list of examples in sequential order. Note that we assume the examples can be run using Node.js.
13+
14+
examples: node_modules
15+
for file in $(EXAMPLES); do \
16+
echo ""; \
17+
echo "Running example: $$file"; \
18+
$(NODE) $$file; \
19+
done
20+
21+
.PHONY: examples

tools/make/lib/find/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
# VARIABLES #
3+
4+
# Define a generic filename pattern:
5+
FILES_PATTERN ?= *.*
6+
7+
# Define a generic filepath pattern:
8+
FILES_FILTER ?= .*/.*
9+
10+
# Define a filename pattern for source files:
11+
SOURCES_PATTERN ?= *.js
12+
13+
# Define a filepath pattern for source files:
14+
SOURCES_FILTER ?= .*/.*
15+
16+
# Define a filename pattern for test files:
17+
TESTS_PATTERN ?= test*.js
18+
19+
# Define a filepath pattern for test files:
20+
TESTS_FILTER ?= .*/.*
21+
22+
# Define a filename pattern for example files:
23+
EXAMPLES_PATTERN ?= *.js
24+
25+
# Define a filepath pattern for example files:
26+
EXAMPLES_FILTER ?= .*/.*
27+
28+
29+
# DEPENDENCIES #
30+
31+
include $(TOOLS_MAKE_DIR)/lib/find/files.mk
32+
include $(TOOLS_MAKE_DIR)/lib/find/sources.mk
33+
include $(TOOLS_MAKE_DIR)/lib/find/tests.mk
34+
include $(TOOLS_MAKE_DIR)/lib/find/examples.mk

tools/make/lib/find/examples.mk

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# VARIABLES #
3+
4+
# On Mac OSX, in order to use `|` and other regular expression operators, we need to use enhanced regular expression syntax (-E); see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man7/re_format.7.html#//apple_ref/doc/man/7/re_format.
5+
6+
ifeq ($(KERNEL), Darwin)
7+
# TODO: does not list top-level examples?
8+
EXAMPLES ?= $(shell find -E $(ROOT) \
9+
-name "$(EXAMPLES_PATTERN)" \
10+
-path "$(ROOT)/**/$(EXAMPLES_DIR)/**" \
11+
-regex "$(EXAMPLES_FILTER)" \
12+
-not -path "$(ROOT)/.*" \
13+
-not -path "$(NODE_MODULES)/*" \
14+
-not -path "$(BUILD_DIR)/*" \
15+
-not -path "$(REPORTS_DIR)/*" \
16+
)
17+
else
18+
# TODO: does not list top-level examples?
19+
EXAMPLES ?= $(shell find $(ROOT) \
20+
-name "$(EXAMPLES_PATTERN)" \
21+
-path "$(ROOT)/**/$(EXAMPLES_DIR)/**" \
22+
-regextype posix-extended \
23+
-regex "$(EXAMPLES_FILTER)" \
24+
-not -path "$(ROOT)/.*" \
25+
-not -path "$(NODE_MODULES)/*" \
26+
-not -path "$(BUILD_DIR)/*" \
27+
-not -path "$(REPORTS_DIR)/*" \
28+
)
29+
endif
30+
31+
32+
# TARGETS #
33+
34+
# List example files.
35+
#
36+
# This target prints a newline-delimited list of example files.
37+
38+
list-examples:
39+
@printf '%s\n' $(EXAMPLES)
40+
41+
42+
.PHONY: list-examples

0 commit comments

Comments
 (0)