blob: 5969510277cb80e99605ceba7f6a837ba7e0322b [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#
15%%WARNING%%
16.POSIX:
17
18SRC = %%SRC%%
19OBJ = %%OBJ%%
20GCDA = %%GCDA%%
21GCNO = %%GCNO%%
22
23BC_SRC = %%BC_SRC%%
24BC_OBJ = %%BC_OBJ%%
25BC_GCDA = %%BC_GCDA%%
26BC_GCNO = %%BC_GCNO%%
27
28DC_SRC = %%DC_SRC%%
29DC_OBJ = %%DC_OBJ%%
30DC_GCDA = %%DC_GCDA%%
31DC_GCNO = %%DC_GCNO%%
32
33BC_ENABLED_NAME = BC_ENABLED
34BC_ENABLED = %%BC_ENABLED%%
35DC_ENABLED_NAME = DC_ENABLED
36DC_ENABLED = %%DC_ENABLED%%
37
38VERSION = 1.1
39
40GEN_DIR = gen
41GEN = strgen
42GEN_EXEC = $(GEN_DIR)/$(GEN)
43GEN_C = $(GEN_DIR)/$(GEN).c
44
45BC_LIB = $(GEN_DIR)/lib.bc
46BC_LIB_C = $(GEN_DIR)/lib.c
47BC_LIB_O = $(GEN_DIR)/lib.o
48
49BC_HELP = $(GEN_DIR)/bc_help.txt
50BC_HELP_C = $(GEN_DIR)/bc_help.c
51BC_HELP_O = $(GEN_DIR)/bc_help.o
52
53DC_HELP = $(GEN_DIR)/dc_help.txt
54DC_HELP_C = $(GEN_DIR)/dc_help.c
55DC_HELP_O = $(GEN_DIR)/dc_help.o
56
57BIN = bin
58
59BC = bc
60DC = dc
61BC_EXEC = $(BIN)/$(BC)
62DC_EXEC = $(BIN)/$(DC)
63
64PREFIX = %%PREFIX%%
65DESTDIR = %%DESTDIR%%
66BC_ENABLE_SIGNALS = %%SIGNALS%%
67BC_ENABLE_HISTORY = %%HISTORY%%
68
Gavin Howardc6547d62018-12-19 12:52:08 -070069RM = rm
Gavin Howard27fa9cd2018-12-12 02:52:52 -070070INSTALL = ./install.sh
71LINK = ./link.sh
72KARATSUBA = ./karatsuba.py
73
74VALGRIND_ARGS = --error-exitcode=1 --leak-check=full --show-leak-kinds=all
75
Gavin Howard27fa9cd2018-12-12 02:52:52 -070076BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%%
77
78CFLAGS1 = %%CFLAGS%%
79CFLAGS = $(CFLAGS1) -Wall -Wextra -pedantic -std=c99 -funsigned-char
80
81CPPFLAGS1 = %%CPPFLAGS%%
82CPPFLAGS2 = $(CPPFLAGS1) -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
83CPPFLAGS3 = $(CPPFLAGS2) -I./include/ -D_POSIX_C_SOURCE=200809L -DVERSION=$(VERSION)
84CPPFLAGS4 = $(CPPFLAGS3) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
85CPPFLAGS5 = $(CPPFLAGS4) -DBC_ENABLE_SIGNALS=$(BC_ENABLE_SIGNALS)
86CPPFLAGS = $(CPPFLAGS5) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY)
87
88LDFLAGS = %%LDFLAGS%%
89
90CC = %%CC%%
91HOSTCC = %%HOSTCC%%
92
93all: make_bin $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_OBJ) $(DC_OBJ) $(OBJ)
Gavin Howard4f3cf8d2018-12-13 11:33:19 -070094 $(CC) $(CFLAGS) $(OBJ) $(DC_OBJ) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(DC_HELP_O) -o $(%%MAIN_EXEC%%)
Gavin Howard27fa9cd2018-12-12 02:52:52 -070095 %%LINK%%
96
97$(GEN_EXEC):
98 $(HOSTCC) $(CFLAGS) -o $(GEN_EXEC) $(GEN_C)
99
100$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
Gavin Howard3f9b5742018-12-13 17:31:00 -0700101 $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name $(BC_ENABLED_NAME) 1
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700102
103$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
104 $(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED_NAME)
105
106$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
107 $(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED_NAME)
108
109make_bin:
110 mkdir -p $(BIN)
111
112help:
Gavin Howardd15e01d2018-12-19 12:49:02 -0700113 @printf 'all targets use config.mak, if there is one\n'
114 @printf '\n'
115 @printf 'available targets:\n'
116 @printf '\n'
117 @printf ' all (default) builds %%EXECUTABLES%%\n'
118 @printf ' clean removes all build files\n'
119 @printf ' clean_tests removes all build files as well as generated tests\n'
120 @printf ' install installs to %s%s/bin\n' "$(DESTDIR)" "$(PREFIX)"
121 @printf ' karatsuba runs the karatsuba script (requires Python 3)\n'
122 @printf ' karatsuba_test runs the karatsuba script while running tests\n'
123 @printf ' (requires Python 3)\n'
124 @printf ' uninstall uninstalls from %s%s/bin\n' "$(DESTDIR)" "$(PREFIX)"
125 @printf ' test runs the test suite\n'
126 @printf ' test_all runs the test suite as well as the Linux timeconst.bc test,\n'
127 @printf ' if it exists and bc has been built\n'
128 @printf ' test_bc runs the bc test suite, if bc has been built\n'
129 @printf ' test_dc runs the dc test suite, if dc has been built\n'
130 @printf ' timeconst runs the test on the Linux timeconst.bc script,\n'
131 @printf ' if it exists and bc has been built\n'
132 @printf ' valgrind runs the test suite through valgrind\n'
133 @printf ' valgrind_all runs the test suite, and the Linux timeconst.bc test,\n'
134 @printf ' if it exists and bc has been built, through valgrind\n'
135 @printf ' valgrind_bc runs the bc test suite, if bc has been built,\n'
136 @printf ' through valgrind\n'
137 @printf ' valgrind_dc runs the dc test suite, if dc has been built,\n'
138 @printf ' through valgrind\n'
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700139
Gavin Howardc27fccb2018-12-13 13:33:35 -0700140test_all: test timeconst
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700141
Gavin Howard3109a592018-12-13 11:34:23 -0700142test: test_bc test_dc
143
144test_bc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700145 %%BC_TEST%%
Gavin Howard3109a592018-12-13 11:34:23 -0700146
147test_dc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700148 %%DC_TEST%%
149
Gavin Howardc27fccb2018-12-13 13:33:35 -0700150timeconst:
151 %%TIMECONST%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700152
Gavin Howardc27fccb2018-12-13 13:33:35 -0700153valgrind_all: valgrind valgrind_timeconst
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700154
Gavin Howardc27fccb2018-12-13 13:33:35 -0700155valgrind: valgrind_bc valgrind_dc
156
157valgrind_bc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700158 %%VG_BC_TEST%%
Gavin Howardc27fccb2018-12-13 13:33:35 -0700159
160valgrind_dc:
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700161 %%VG_DC_TEST%%
162
Gavin Howardc27fccb2018-12-13 13:33:35 -0700163valgrind_timeconst:
164 %%TIMECONST_VG%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700165
Gavin Howardc27fccb2018-12-13 13:33:35 -0700166karatsuba:
167 %%KARATSUBA%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700168
Gavin Howardc27fccb2018-12-13 13:33:35 -0700169karatsuba_test:
170 %%KARATSUBA_TEST%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700171
Gavin Howardc27fccb2018-12-13 13:33:35 -0700172coverage:%%COVERAGE_PREREQS%%
173 %%COVERAGE%%
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700174
175version:
Gavin Howardd15e01d2018-12-19 12:49:02 -0700176 @printf "$(VERSION)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700177
178libcname:
Gavin Howardd15e01d2018-12-19 12:49:02 -0700179 @printf "$(BC_LIB_C)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700180
181clean:
182 $(RM) -f $(OBJ)
183 $(RM) -f $(BC_OBJ)
184 $(RM) -f $(DC_OBJ)
185 $(RM) -f $(BC_EXEC)
186 $(RM) -f $(DC_EXEC)
187 $(RM) -f $(GCDA) $(GCNO)
188 $(RM) -f $(BC_GCDA) $(BC_GCNO)
189 $(RM) -f $(DC_GCDA) $(DC_GCNO)
190 $(RM) -f *.gcov
191 $(RM) -f *.html
Gavin Howard3a686c72018-12-13 13:59:55 -0700192 $(RM) -f *.gcda *.gcno
193 $(RM) -f *.profraw
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700194 $(RM) -f $(GEN_EXEC)
195 $(RM) -f $(BC_LIB_C)
196 $(RM) -f $(BC_LIB_O)
197 $(RM) -f $(BC_HELP_C)
198 $(RM) -f $(BC_HELP_O)
199 $(RM) -f $(DC_HELP_C)
200 $(RM) -f $(DC_HELP_O)
201
202clean_tests: clean
203 $(RM) -f tests/bc/parse.txt tests/bc/parse_results.txt
204 $(RM) -f tests/bc/print.txt tests/bc/print_results.txt
205 $(RM) -f tests/bc/bessel.txt tests/bc/bessel_results.txt
206 $(RM) -f .log_test.txt .log_bc.txt
207 $(RM) -f .math.txt .results.txt .ops.txt
208 $(RM) -f .test.txt
209
210install:
211 $(INSTALL) $(DESTDIR)$(PREFIX)/$(BIN) $(BIN)
212
213uninstall:
214 $(RM) -f $(DESTDIR)$(PREFIX)/$(BC_EXEC)
215 $(RM) -f $(DESTDIR)$(PREFIX)/$(DC_EXEC)
216
217.PHONY: help clean clean_tests install uninstall test