Skip to content

Commit 94d971a

Browse files
committed
Add rules for running C++ examples
1 parent 6cdb381 commit 94d971a

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

tools/make/lib/examples/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# DEPENDENCIES #
2020

2121
include $(TOOLS_MAKE_LIB_DIR)/examples/c.mk
22+
include $(TOOLS_MAKE_LIB_DIR)/examples/cpp.mk
2223
include $(TOOLS_MAKE_LIB_DIR)/examples/javascript.mk
2324
include $(TOOLS_MAKE_LIB_DIR)/examples/markdown.mk
2425

@@ -57,7 +58,7 @@ examples: examples-javascript
5758
# @example
5859
# make examples-lang EXAMPLES_FILTER=.*/blas/base/dasum/.*
5960
#/
60-
examples-lang: examples-javascript examples-c
61+
examples-lang: examples-javascript examples-c examples-cpp
6162

6263
.PHONY: examples-lang
6364

tools/make/lib/examples/cpp.mk

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2018 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# VARIABLES #
20+
21+
# Define the path to a script for compiling a C++ example:
22+
compile_cpp_example_bin := $(TOOLS_DIR)/scripts/compile_cpp_example
23+
24+
25+
# RULES #
26+
27+
#/
28+
# Runs C++ examples consecutively.
29+
#
30+
# ## Notes
31+
#
32+
# - The recipe delegates to local Makefiles which are responsible for actually compiling and running the respective examples.
33+
# - This rule is useful when wanting to glob for C++ examples files (e.g., run all C++ examples for a particular package).
34+
#
35+
#
36+
# @param {string} [EXAMPLES_FILTER] - file path pattern (e.g., `.*/math/base/special/abs/.*`)
37+
# @param {string} [CXX_COMPILER] - C++ compiler (e.g., `g++`)
38+
#
39+
# @example
40+
# make examples-cpp
41+
#
42+
# @example
43+
# make examples-cpp EXAMPLES_FILTER=.*/strided/common/.*
44+
#/
45+
examples-cpp:
46+
$(QUIET) $(FIND_CPP_EXAMPLES_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
47+
echo ""; \
48+
echo "Running example: $$file"; \
49+
cd `dirname $$file` && $(MAKE) clean && \
50+
OS="$(OS)" \
51+
NODE="$(NODE)" \
52+
NODE_PATH="$(NODE_PATH)" \
53+
CXX_COMPILER="$(CXX)" \
54+
"${compile_cpp_example_bin}" $$file && \
55+
BOOST="$(DEPS_BOOST_BUILD_OUT)" $(MAKE) run || exit 1; \
56+
done
57+
58+
.PHONY: examples-cpp
59+
60+
#/
61+
# Runs a specified list of C++ examples consecutively.
62+
#
63+
# ## Notes
64+
#
65+
# - The recipe delegates to local Makefiles which are responsible for actually compiling and running the respective examples.
66+
# - This rule is useful when wanting to run a list of C++ examples files generated by some other command (e.g., a list of changed C++ examples files obtained via `git diff`).
67+
#
68+
#
69+
# @param {string} FILES - list of C++ example file paths
70+
# @param {string} [CXX_COMPILER] - C++ compiler (e.g., `g++`)
71+
#
72+
# @example
73+
# make examples-cpp-files FILES='/foo/example.cpp /bar/example.cpp'
74+
#/
75+
examples-cpp-files:
76+
$(QUIET) for file in $(FILES); do \
77+
echo ""; \
78+
echo "Running example: $$file"; \
79+
cd `dirname $$file` && $(MAKE) clean && \
80+
OS="$(OS)" \
81+
NODE="$(NODE)" \
82+
NODE_PATH="$(NODE_PATH)" \
83+
CXX_COMPILER="$(CXX)" \
84+
"${compile_cpp_example_bin}" $$file && \
85+
BOOST="$(DEPS_BOOST_BUILD_OUT)" $(MAKE) run || exit 1; \
86+
done
87+
88+
.PHONY: example-cpp-files

0 commit comments

Comments
 (0)