# - `.SHELLFLAGS` was introduced in GNU Make 3.82 and has no effect on the version of GNU Make installed on Mac OS X, which is 3.81.
# - The `-e` flag causes `bash` to exit immediately if a `bash` executed command fails.
# - The `-u` flag causes `bash` to exit with an error message if a variable is accessed without being defined.
# - The `pipefail` option specifies that, if any of the commands in a pipeline fail, the entire pipeline fails. Otherwise the return value of a pipeline is the return value of the last command.
# - The `-c` flag is in the default value of `.SHELLFLAGS`, which must be preserved, as this is how `make` passes the script to be executed to `bash`.
#
.SHELLFLAGS := -eu -o pipefail -c
# Remove targets if its recipe fails.
#
# ## Notes
#
# - Mentioning this target anywhere in a Makefile prevents a user from re-running make and using an incomplete or invalid target.
# - When debugging, it may be necessary to comment this line out so the incomplete or invalid target can be inspected.
# Define the folder name convention for test files:
TESTS_FOLDER ?= test
# Define the folder name convention for test fixtures:
TESTS_FIXTURES_FOLDER ?= $(TESTS_FOLDER)/fixtures
# Define a filepath pattern for benchmark files:
BENCHMARKS_FILTER ?= .*/.*
# Define a filepath pattern for example files:
EXAMPLES_FILTER ?= .*/.*
# Define a filepath pattern for test files:
TESTS_FILTER ?= .*/.*
# Define a filename pattern for benchmark files:
BENCHMARKS_PATTERN ?= benchmark*.js
# Define a filename pattern for example files:
EXAMPLES_PATTERN ?= *.js
# Define a filename pattern for test files:
TESTS_PATTERN ?= test*.js
# Define Node environments:
ifdefNODE_ENV
NODE_ENV_BENCHMARK := $(NODE_ENV)
NODE_ENV_EXAMPLES := $(NODE_ENV)
NODE_ENV_TEST := $(NODE_ENV)
else
NODE_ENV ?=
NODE_ENV_BENCHMARK ?= benchmark
NODE_ENV_EXAMPLES ?= examples
NODE_ENV_TEST ?= test
endif
# Define whether delete operations should be safe (i.e., deleted items are sent to trash, rather than permanently deleted):
SAFE_DELETE ?= false
# Define the delete command:
ifeq ($(SAFE_DELETE), true)
# FIXME: -rm -rf
DELETE := -rm
DELETE_FLAGS := -rf
else
DELETE ?= -rm
DELETE_FLAGS ?= -rf
endif
# Determine the `open` command:
ifeq ($(OS), Darwin)
OPEN ?= open
else
OPEN ?= xdg-open
endif
# TODO: add Windows command
# Define the command for `node`:
NODE ?= node
# Define the command for `npm`:
NPM ?= npm
# Define the path to a JavaScript test runner.
#
# ## Notes
#
# - We reference the `bin` file directly in order to support using `istanbul` for code coverage on Windows (https://github.com/gotwarlost/istanbul#usage-on-windows)
JAVASCRIPT_TEST ?= $(NODE_MODULES)/tape/bin/tape
# Define any command-line options to use when invoking the test runner:
JAVASCRIPT_TEST_FLAGS ?=
# Define the path to the executable for parsing TAP output:
TAP_REPORTER ?= $(BIN_DIR)/tap-min
# Define the path to the Istanbul executable:
ISTANBUL ?= $(BIN_DIR)/istanbul
# Define which files and directories to exclude from coverage instrumentation:
ISTANBUL_EXCLUDES_FLAGS ?= \
--no-default-excludes \
-x 'node_modules/**' \
-x 'reports/**' \
-x 'tmp/**' \
-x 'deps/**' \
-x 'dist/**' \
-x "**/$(SRC_FOLDER)/**" \
-x "**/$(TESTS_FOLDER)/**" \
-x "**/$(EXAMPLES_FOLDER)/**" \
-x "**/$(BENCHMARKS_FOLDER)/**" \
-x "**/$(CONFIG_FOLDER)/**" \
-x "**/$(DOCUMENTATION_FOLDER)/**"
# Define the command to generate test coverage:
ISTANBUL_COVER ?= $(ISTANBUL) cover
# Define the type of report Istanbul should produce:
ISTANBUL_COVER_REPORT_FORMAT ?= lcov
# Define the command-line options to be used when generating code coverage:
ISTANBUL_COVER_FLAGS ?= \
$(ISTANBUL_EXCLUDES_FLAGS)\
--dir $(COVERAGE_DIR)\
--report $(ISTANBUL_COVER_REPORT_FORMAT)
# 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.
ifeq ($(OS), Darwin)
find_kernel_prefix := -E
else
find_kernel_prefix :=
endif
# Common exclude flags that most recipes for finding package files should use (Note: order does matter to some degree):
FIND_COMMON_EXCLUDE_FLAGS ?= \
'!' -path "$(ROOT_DIR)/.*" \
'!' -path "$(NODE_MODULES)/*" \
'!' -path "$(BUILD_DIR)/*" \
'!' -path "$(REPORTS_DIR)/*" \
# Define exclusion flags to use when searching for benchmark files: