blob: 00c200638f82620027bc8282ed85d4ced87c2801 [file] [log] [blame]
Gavin Howard27fa9cd2018-12-12 02:52:52 -07001#
2# Copyright 2018 Gavin D. Howard
3#
4# Permission to use, copy, modify, and/or distribute this software for any
5# purpose with or without fee is hereby granted.
6#
7# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13# PERFORMANCE OF THIS SOFTWARE.
14#
Gavin Howardb55ad002018-12-20 16:59:23 -070015# %%WARNING%%
16#
Gavin Howard27fa9cd2018-12-12 02:52:52 -070017.POSIX:
18
19SRC = %%SRC%%
20OBJ = %%OBJ%%
21GCDA = %%GCDA%%
22GCNO = %%GCNO%%
23
24BC_SRC = %%BC_SRC%%
25BC_OBJ = %%BC_OBJ%%
26BC_GCDA = %%BC_GCDA%%
27BC_GCNO = %%BC_GCNO%%
28
29DC_SRC = %%DC_SRC%%
30DC_OBJ = %%DC_OBJ%%
31DC_GCDA = %%DC_GCDA%%
32DC_GCNO = %%DC_GCNO%%
33
Gavin Howardbf813392018-12-20 10:49:00 -070034HISTORY_SRC = %%HISTORY_SRC%%
35HISTORY_OBJ = %%HISTORY_OBJ%%
36HISTORY_GCDA = %%HISTORY_GCDA%%
37HISTORY_GCNO = %%HISTORY_GCNO%%
38
Gavin Howard27fa9cd2018-12-12 02:52:52 -070039BC_ENABLED_NAME = BC_ENABLED
40BC_ENABLED = %%BC_ENABLED%%
41DC_ENABLED_NAME = DC_ENABLED
42DC_ENABLED = %%DC_ENABLED%%
43
Gavin Howardc0d45932019-01-04 13:28:44 -070044VERSION = 1.1-dev
Gavin Howard27fa9cd2018-12-12 02:52:52 -070045
46GEN_DIR = gen
47GEN = strgen
48GEN_EXEC = $(GEN_DIR)/$(GEN)
49GEN_C = $(GEN_DIR)/$(GEN).c
50
Gavin Howard4dff5452018-12-20 10:06:58 -070051GEN_EMU = %%GEN_EMU%%
52
Gavin Howard27fa9cd2018-12-12 02:52:52 -070053BC_LIB = $(GEN_DIR)/lib.bc
54BC_LIB_C = $(GEN_DIR)/lib.c
Gavin Howarda1cd1222019-01-02 14:40:46 -070055BC_LIB_O = %%BC_LIB_O%%
Gavin Howardaba12e72019-01-07 17:48:27 -070056BC_LIB_GCDA = $(GEN_DIR)/lib.gcda
57BC_LIB_GCNO = $(GEN_DIR)/lib.gcno
Gavin Howard27fa9cd2018-12-12 02:52:52 -070058
Gavin Howard6fcb5042018-12-26 17:44:06 -070059BC_LIB2 = $(GEN_DIR)/lib2.bc
60BC_LIB2_C = $(GEN_DIR)/lib2.c
Gavin Howard9fbeaa82018-12-27 18:13:28 -070061BC_LIB2_O = %%BC_LIB2_O%%
Gavin Howardaba12e72019-01-07 17:48:27 -070062BC_LIB2_GCDA = $(GEN_DIR)/lib2.gcda
63BC_LIB2_GCNO = $(GEN_DIR)/lib2.gcno
Gavin Howard6fcb5042018-12-26 17:44:06 -070064
Gavin Howard27fa9cd2018-12-12 02:52:52 -070065BC_HELP = $(GEN_DIR)/bc_help.txt
66BC_HELP_C = $(GEN_DIR)/bc_help.c
Gavin Howarda1cd1222019-01-02 14:40:46 -070067BC_HELP_O = %%BC_HELP_O%%
Gavin Howardaba12e72019-01-07 17:48:27 -070068BC_HELP_GCDA = $(GEN_DIR)/bc_help.gcda
69BC_HELP_GCNO = $(GEN_DIR)/bc_help.gcno
Gavin Howard27fa9cd2018-12-12 02:52:52 -070070
71DC_HELP = $(GEN_DIR)/dc_help.txt
72DC_HELP_C = $(GEN_DIR)/dc_help.c
Gavin Howarda1cd1222019-01-02 14:40:46 -070073DC_HELP_O = %%DC_HELP_O%%
Gavin Howardaba12e72019-01-07 17:48:27 -070074DC_HELP_GCDA = $(GEN_DIR)/dc_help.gcda
75DC_HELP_GCNO = $(GEN_DIR)/dc_help.gcno
Gavin Howard27fa9cd2018-12-12 02:52:52 -070076
77BIN = bin
78
79BC = bc
80DC = dc
81BC_EXEC = $(BIN)/$(BC)
82DC_EXEC = $(BIN)/$(DC)
83
84PREFIX = %%PREFIX%%
85DESTDIR = %%DESTDIR%%
86BC_ENABLE_SIGNALS = %%SIGNALS%%
87BC_ENABLE_HISTORY = %%HISTORY%%
Gavin Howardc868e092018-12-21 13:39:32 -070088BC_ENABLE_REFERENCES = %%REFERENCES%%
Gavin Howard6fcb5042018-12-26 17:44:06 -070089BC_ENABLE_EXTRA_MATH_NAME = BC_ENABLE_EXTRA_MATH
90BC_ENABLE_EXTRA_MATH = %%EXTRA_MATH%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -070091
Gavin Howardc6547d62018-12-19 12:52:08 -070092RM = rm
Gavin Howard7ff15ae2018-12-20 10:28:23 -070093MKDIR = mkdir
94
Gavin Howard27fa9cd2018-12-12 02:52:52 -070095INSTALL = ./install.sh
96LINK = ./link.sh
97KARATSUBA = ./karatsuba.py
98
Gavin Howardd4fece32019-01-08 02:06:22 -070099VALGRIND_ARGS = --error-exitcode=1 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700100
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700101BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%%
102
Gavin Howardabbb2902018-12-20 10:10:15 -0700103CPPFLAGS1 = %%CPPFLAGS%%
104CPPFLAGS2 = $(CPPFLAGS1) -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
105CPPFLAGS3 = $(CPPFLAGS2) -I./include/ -D_POSIX_C_SOURCE=200809L -DVERSION=$(VERSION)
106CPPFLAGS4 = $(CPPFLAGS3) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
Gavin Howardc868e092018-12-21 13:39:32 -0700107CPPFLAGS5 = $(CPPFLAGS4) -DBC_ENABLE_REFERENCES=$(BC_ENABLE_REFERENCES)
Gavin Howard87250702018-12-31 15:49:33 -0700108CPPFLAGS6 = $(CPPFLAGS5) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH)
Gavin Howardb0416592019-01-04 09:47:50 -0700109CPPFLAGS = $(CPPFLAGS6) -DBC_ENABLE_SIGNALS=$(BC_ENABLE_SIGNALS) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY)
Gavin Howardabbb2902018-12-20 10:10:15 -0700110CFLAGS = $(CPPFLAGS) %%CFLAGS%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700111LDFLAGS = %%LDFLAGS%%
112
Gavin Howard593a5182019-01-17 10:22:45 -0700113HOSTCFLAGS = %%HOSTCFLAGS%%
114
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700115CC = %%CC%%
116HOSTCC = %%HOSTCC%%
117
Gavin Howard78bff702019-01-01 10:31:10 -0700118all: make_bin $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O) $(BC_OBJ) $(DC_OBJ) $(HISTORY_OBJ) $(OBJ)
119 $(CC) $(CPPFLAGS) $(CFLAGS) $(OBJ) $(DC_OBJ) $(BC_OBJ) $(HISTORY_OBJ) $(BC_HELP_O) $(DC_HELP_O) \
120 $(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O) $(LDFLAGS) -o $(%%MAIN_EXEC%%)
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700121 %%LINK%%
122
123$(GEN_EXEC):
Gavin Howard593a5182019-01-17 10:22:45 -0700124 $(HOSTCC) $(HOSTCFLAGS) -o $(GEN_EXEC) $(GEN_C)
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700125
126$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
Gavin Howard1cbfe242019-01-09 17:13:11 -0700127 $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc.h bc_lib_name $(BC_ENABLED_NAME) 1
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700128
Gavin Howard6fcb5042018-12-26 17:44:06 -0700129$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2)
Gavin Howard1cbfe242019-01-09 17:13:11 -0700130 $(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) bc_lib2 bc.h bc_lib2_name \
Gavin Howard6fcb5042018-12-26 17:44:06 -0700131 "$(BC_ENABLED_NAME) && $(BC_ENABLE_EXTRA_MATH_NAME)" 1
132
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700133$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
Gavin Howard1cbfe242019-01-09 17:13:11 -0700134 $(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help bc.h "" $(BC_ENABLED_NAME)
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700135
136$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
Gavin Howard1cbfe242019-01-09 17:13:11 -0700137 $(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help dc.h "" $(DC_ENABLED_NAME)
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700138
139make_bin:
Gavin Howard7ff15ae2018-12-20 10:28:23 -0700140 $(MKDIR) -p $(BIN)
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700141
142help:
Gavin Howardd15e01d2018-12-19 12:49:02 -0700143 @printf 'available targets:\n'
144 @printf '\n'
145 @printf ' all (default) builds %%EXECUTABLES%%\n'
146 @printf ' clean removes all build files\n'
Gavin Howarddf68c752019-01-07 17:48:44 -0700147 @printf ' clean_config removes all build files as well as the generated Makefile\n'
Gavin Howardd15e01d2018-12-19 12:49:02 -0700148 @printf ' clean_tests removes all build files as well as generated tests\n'
149 @printf ' install installs to %s%s/bin\n' "$(DESTDIR)" "$(PREFIX)"
150 @printf ' karatsuba runs the karatsuba script (requires Python 3)\n'
151 @printf ' karatsuba_test runs the karatsuba script while running tests\n'
152 @printf ' (requires Python 3)\n'
153 @printf ' uninstall uninstalls from %s%s/bin\n' "$(DESTDIR)" "$(PREFIX)"
154 @printf ' test runs the test suite\n'
155 @printf ' test_all runs the test suite as well as the Linux timeconst.bc test,\n'
156 @printf ' if it exists and bc has been built\n'
157 @printf ' test_bc runs the bc test suite, if bc has been built\n'
158 @printf ' test_dc runs the dc test suite, if dc has been built\n'
159 @printf ' timeconst runs the test on the Linux timeconst.bc script,\n'
160 @printf ' if it exists and bc has been built\n'
161 @printf ' valgrind runs the test suite through valgrind\n'
162 @printf ' valgrind_all runs the test suite, and the Linux timeconst.bc test,\n'
163 @printf ' if it exists and bc has been built, through valgrind\n'
164 @printf ' valgrind_bc runs the bc test suite, if bc has been built,\n'
165 @printf ' through valgrind\n'
166 @printf ' valgrind_dc runs the dc test suite, if dc has been built,\n'
167 @printf ' through valgrind\n'
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700168
Gavin Howardc27fccb2018-12-13 13:33:35 -0700169test_all: test timeconst
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700170
Gavin Howard3109a592018-12-13 11:34:23 -0700171test: test_bc test_dc
172
173test_bc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700174 %%BC_TEST%%
Gavin Howard3109a592018-12-13 11:34:23 -0700175
176test_dc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700177 %%DC_TEST%%
178
Gavin Howardc27fccb2018-12-13 13:33:35 -0700179timeconst:
180 %%TIMECONST%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700181
Gavin Howardc27fccb2018-12-13 13:33:35 -0700182valgrind: valgrind_bc valgrind_dc
183
184valgrind_bc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700185 %%VG_BC_TEST%%
Gavin Howardc27fccb2018-12-13 13:33:35 -0700186
187valgrind_dc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700188 %%VG_DC_TEST%%
189
Gavin Howardc27fccb2018-12-13 13:33:35 -0700190karatsuba:
191 %%KARATSUBA%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700192
Gavin Howardc27fccb2018-12-13 13:33:35 -0700193karatsuba_test:
194 %%KARATSUBA_TEST%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700195
Gavin Howardc27fccb2018-12-13 13:33:35 -0700196coverage:%%COVERAGE_PREREQS%%
197 %%COVERAGE%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700198
199version:
Gavin Howard40c1c4a2018-12-27 17:50:02 -0700200 @printf '%s' "$(VERSION)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700201
202libcname:
Gavin Howard40c1c4a2018-12-27 17:50:02 -0700203 @printf '%s' "$(BC_LIB_C)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700204
Gavin Howard7220b8a2018-12-27 17:49:27 -0700205extra_math:
Gavin Howard77244112018-12-27 17:50:40 -0700206 @printf '%s' "$(BC_ENABLE_EXTRA_MATH)"
Gavin Howard7220b8a2018-12-27 17:49:27 -0700207
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700208clean:
Gavin Howardff1cc302018-12-27 13:22:36 -0700209 @printf 'Cleaning files...\n'
Gavin Howard103d5bb2018-12-27 13:21:48 -0700210 @$(RM) -f $(OBJ)
211 @$(RM) -f $(BC_OBJ)
212 @$(RM) -f $(DC_OBJ)
213 @$(RM) -f $(HISTORY_OBJ)
214 @$(RM) -f $(BC_EXEC)
215 @$(RM) -f $(DC_EXEC)
216 @$(RM) -fr $(BIN)
217 @$(RM) -f $(GCDA) $(GCNO)
218 @$(RM) -f $(BC_GCDA) $(BC_GCNO)
219 @$(RM) -f $(DC_GCDA) $(DC_GCNO)
220 @$(RM) -f $(HISTORY_GCDA) $(HISTORY_GCNO)
221 @$(RM) -f *.gcov
222 @$(RM) -f *.html
223 @$(RM) -f *.gcda *.gcno
224 @$(RM) -f *.profraw
225 @$(RM) -f $(GEN_EXEC)
Gavin Howardaba12e72019-01-07 17:48:27 -0700226 @$(RM) -f $(BC_LIB_C) $(BC_LIB_O)
227 @$(RM) -f $(BC_LIB_GCDA) $(BC_LIB_GCNO)
228 @$(RM) -f $(BC_LIB2_C) $(BC_LIB2_O)
229 @$(RM) -f $(BC_LIB2_GCDA) $(BC_LIB2_GCNO)
230 @$(RM) -f $(BC_HELP_C) $(BC_HELP_O)
231 @$(RM) -f $(BC_HELP_GCDA) $(BC_HELP_GCNO)
232 @$(RM) -f $(DC_HELP_C) $(DC_HELP_O)
233 @$(RM) -f $(DC_HELP_GCDA) $(DC_HELP_GCNO)
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700234
Gavin Howard68f4a4e2019-01-07 17:50:15 -0700235clean_config: clean
236 @printf 'Cleaning config...\n'
237 @$(RM) -f Makefile
238
239clean_tests: clean clean_config
Gavin Howardff1cc302018-12-27 13:22:36 -0700240 @printf 'Cleaning test files...\n'
Gavin Howard103d5bb2018-12-27 13:21:48 -0700241 @$(RM) -f tests/bc/parse.txt tests/bc/parse_results.txt
242 @$(RM) -f tests/bc/print.txt tests/bc/print_results.txt
243 @$(RM) -f tests/bc/bessel.txt tests/bc/bessel_results.txt
244 @$(RM) -f .log_test.txt .log_bc.txt
245 @$(RM) -f .math.txt .results.txt .ops.txt
246 @$(RM) -f .test.txt
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700247
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700248install:
249 $(INSTALL) $(DESTDIR)$(PREFIX)/$(BIN) $(BIN)
250
251uninstall:
252 $(RM) -f $(DESTDIR)$(PREFIX)/$(BC_EXEC)
253 $(RM) -f $(DESTDIR)$(PREFIX)/$(DC_EXEC)
254
255.PHONY: help clean clean_tests install uninstall test