1616# limitations under the License.
1717# /
1818
19-
2019# VARIABLES #
2120
2221ifndef VERBOSE
2322 QUIET := @
23+ else
24+ QUIET :=
2425endif
2526
26- # Determine the OS:
27+ # Determine the OS ([1][1], [2][2]).
2728#
2829# [1]: https://en.wikipedia.org/wiki/Uname#Examples
2930# [2]: http://stackoverflow.com/a/27776822/2225624
@@ -36,6 +37,10 @@ ifneq (, $(findstring MSYS,$(OS)))
3637else
3738ifneq (, $(findstring CYGWIN,$(OS ) ) )
3839 OS := WINNT
40+ else
41+ ifneq (, $(findstring Windows_NT,$(OS ) ) )
42+ OS := WINNT
43+ endif
3944endif
4045endif
4146endif
@@ -54,7 +59,7 @@ CFLAGS ?= \
5459 -Wall \
5560 -pedantic
5661
57- # Determine whether to generate [ position independent code][1]:
62+ # Determine whether to generate position independent code ([1 ][1], [2][2]).
5863#
5964# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
6065# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
6469 fPIC ?= -fPIC
6570endif
6671
72+ # List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73+ INCLUDE ?=
74+
75+ # List of source files:
76+ SOURCE_FILES ?=
77+
78+ # List of libraries (e.g., `-lopenblas -lpthread`):
79+ LIBRARIES ?=
80+
81+ # List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82+ LIBPATH ?=
83+
6784# List of C targets:
68- c_targets := benchmark .out
85+ c_targets := example .out
6986
7087
71- # TARGETS #
88+ # RULES #
7289
73- # Default target.
90+ # /
91+ # Compiles source files.
7492#
75- # This target is the default target.
76-
93+ # @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94+ # @param {string} [CFLAGS] - C compiler options
95+ # @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96+ # @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97+ # @param {string} [SOURCE_FILES] - list of source files
98+ # @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99+ # @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
100+ #
101+ # @example
102+ # make
103+ #
104+ # @example
105+ # make all
106+ # /
77107all : $(c_targets )
78108
79109.PHONY : all
80110
81-
82- # Compile C source.
111+ # /
112+ # Compiles C source files .
83113#
84- # This target compiles C source files.
85-
114+ # @private
115+ # @param {string} CC - C compiler (e.g., `gcc`)
116+ # @param {string} CFLAGS - C compiler options
117+ # @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118+ # @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119+ # @param {string} SOURCE_FILES - list of source files
120+ # @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121+ # @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122+ # /
86123$(c_targets ) : % .out: % .c
87- $(QUIET ) $(CC ) $(CFLAGS ) $(fPIC ) -o $@ $< -lm
88-
124+ $(QUIET ) $(CC ) $(CFLAGS ) $(fPIC ) $(INCLUDE ) -o $@ $(SOURCE_FILES ) $< $(LIBPATH ) -lm $(LIBRARIES )
89125
90- # Run a benchmark.
126+ # /
127+ # Runs compiled examples.
91128#
92- # This target runs a benchmark.
93-
129+ # @example
130+ # make run
131+ # /
94132run : $(c_targets )
95133 $(QUIET ) ./$<
96134
97135.PHONY : run
98136
99-
100- # Perform clean-up .
137+ # /
138+ # Removes generated files .
101139#
102- # This target removes generated files.
103-
140+ # @example
141+ # make clean
142+ # /
104143clean :
105144 $(QUIET ) -rm -f * .o * .out
106145
0 commit comments