Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 1 | # |
| 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 | |
| 18 | SRC = %%SRC%% |
| 19 | OBJ = %%OBJ%% |
| 20 | GCDA = %%GCDA%% |
| 21 | GCNO = %%GCNO%% |
| 22 | |
| 23 | BC_SRC = %%BC_SRC%% |
| 24 | BC_OBJ = %%BC_OBJ%% |
| 25 | BC_GCDA = %%BC_GCDA%% |
| 26 | BC_GCNO = %%BC_GCNO%% |
| 27 | |
| 28 | DC_SRC = %%DC_SRC%% |
| 29 | DC_OBJ = %%DC_OBJ%% |
| 30 | DC_GCDA = %%DC_GCDA%% |
| 31 | DC_GCNO = %%DC_GCNO%% |
| 32 | |
| 33 | BC_ENABLED_NAME = BC_ENABLED |
| 34 | BC_ENABLED = %%BC_ENABLED%% |
| 35 | DC_ENABLED_NAME = DC_ENABLED |
| 36 | DC_ENABLED = %%DC_ENABLED%% |
| 37 | |
| 38 | VERSION = 1.1 |
| 39 | |
| 40 | GEN_DIR = gen |
| 41 | GEN = strgen |
| 42 | GEN_EXEC = $(GEN_DIR)/$(GEN) |
| 43 | GEN_C = $(GEN_DIR)/$(GEN).c |
| 44 | |
| 45 | BC_LIB = $(GEN_DIR)/lib.bc |
| 46 | BC_LIB_C = $(GEN_DIR)/lib.c |
| 47 | BC_LIB_O = $(GEN_DIR)/lib.o |
| 48 | |
| 49 | BC_HELP = $(GEN_DIR)/bc_help.txt |
| 50 | BC_HELP_C = $(GEN_DIR)/bc_help.c |
| 51 | BC_HELP_O = $(GEN_DIR)/bc_help.o |
| 52 | |
| 53 | DC_HELP = $(GEN_DIR)/dc_help.txt |
| 54 | DC_HELP_C = $(GEN_DIR)/dc_help.c |
| 55 | DC_HELP_O = $(GEN_DIR)/dc_help.o |
| 56 | |
| 57 | BIN = bin |
| 58 | |
| 59 | BC = bc |
| 60 | DC = dc |
| 61 | BC_EXEC = $(BIN)/$(BC) |
| 62 | DC_EXEC = $(BIN)/$(DC) |
| 63 | |
| 64 | PREFIX = %%PREFIX%% |
| 65 | DESTDIR = %%DESTDIR%% |
| 66 | BC_ENABLE_SIGNALS = %%SIGNALS%% |
| 67 | BC_ENABLE_HISTORY = %%HISTORY%% |
| 68 | |
Gavin Howard | c6547d6 | 2018-12-19 12:52:08 -0700 | [diff] [blame^] | 69 | RM = rm |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 70 | INSTALL = ./install.sh |
| 71 | LINK = ./link.sh |
| 72 | KARATSUBA = ./karatsuba.py |
| 73 | |
| 74 | VALGRIND_ARGS = --error-exitcode=1 --leak-check=full --show-leak-kinds=all |
| 75 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 76 | BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%% |
| 77 | |
| 78 | CFLAGS1 = %%CFLAGS%% |
| 79 | CFLAGS = $(CFLAGS1) -Wall -Wextra -pedantic -std=c99 -funsigned-char |
| 80 | |
| 81 | CPPFLAGS1 = %%CPPFLAGS%% |
| 82 | CPPFLAGS2 = $(CPPFLAGS1) -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED) |
| 83 | CPPFLAGS3 = $(CPPFLAGS2) -I./include/ -D_POSIX_C_SOURCE=200809L -DVERSION=$(VERSION) |
| 84 | CPPFLAGS4 = $(CPPFLAGS3) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN) |
| 85 | CPPFLAGS5 = $(CPPFLAGS4) -DBC_ENABLE_SIGNALS=$(BC_ENABLE_SIGNALS) |
| 86 | CPPFLAGS = $(CPPFLAGS5) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY) |
| 87 | |
| 88 | LDFLAGS = %%LDFLAGS%% |
| 89 | |
| 90 | CC = %%CC%% |
| 91 | HOSTCC = %%HOSTCC%% |
| 92 | |
| 93 | all: make_bin $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_OBJ) $(DC_OBJ) $(OBJ) |
Gavin Howard | 4f3cf8d | 2018-12-13 11:33:19 -0700 | [diff] [blame] | 94 | $(CC) $(CFLAGS) $(OBJ) $(DC_OBJ) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(DC_HELP_O) -o $(%%MAIN_EXEC%%) |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 95 | %%LINK%% |
| 96 | |
| 97 | $(GEN_EXEC): |
| 98 | $(HOSTCC) $(CFLAGS) -o $(GEN_EXEC) $(GEN_C) |
| 99 | |
| 100 | $(BC_LIB_C): $(GEN_EXEC) $(BC_LIB) |
Gavin Howard | 3f9b574 | 2018-12-13 17:31:00 -0700 | [diff] [blame] | 101 | $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name $(BC_ENABLED_NAME) 1 |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 102 | |
| 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 | |
| 109 | make_bin: |
| 110 | mkdir -p $(BIN) |
| 111 | |
| 112 | help: |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 113 | @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 Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 139 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 140 | test_all: test timeconst |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 141 | |
Gavin Howard | 3109a59 | 2018-12-13 11:34:23 -0700 | [diff] [blame] | 142 | test: test_bc test_dc |
| 143 | |
| 144 | test_bc: |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 145 | %%BC_TEST%% |
Gavin Howard | 3109a59 | 2018-12-13 11:34:23 -0700 | [diff] [blame] | 146 | |
| 147 | test_dc: |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 148 | %%DC_TEST%% |
| 149 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 150 | timeconst: |
| 151 | %%TIMECONST%% |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 152 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 153 | valgrind_all: valgrind valgrind_timeconst |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 154 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 155 | valgrind: valgrind_bc valgrind_dc |
| 156 | |
| 157 | valgrind_bc: |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 158 | %%VG_BC_TEST%% |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 159 | |
| 160 | valgrind_dc: |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 161 | %%VG_DC_TEST%% |
| 162 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 163 | valgrind_timeconst: |
| 164 | %%TIMECONST_VG%% |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 165 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 166 | karatsuba: |
| 167 | %%KARATSUBA%% |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 168 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 169 | karatsuba_test: |
| 170 | %%KARATSUBA_TEST%% |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 171 | |
Gavin Howard | c27fccb | 2018-12-13 13:33:35 -0700 | [diff] [blame] | 172 | coverage:%%COVERAGE_PREREQS%% |
| 173 | %%COVERAGE%% |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 174 | |
| 175 | version: |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 176 | @printf "$(VERSION)" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 177 | |
| 178 | libcname: |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 179 | @printf "$(BC_LIB_C)" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 180 | |
| 181 | clean: |
| 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 Howard | 3a686c7 | 2018-12-13 13:59:55 -0700 | [diff] [blame] | 192 | $(RM) -f *.gcda *.gcno |
| 193 | $(RM) -f *.profraw |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 194 | $(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 | |
| 202 | clean_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 | |
| 210 | install: |
| 211 | $(INSTALL) $(DESTDIR)$(PREFIX)/$(BIN) $(BIN) |
| 212 | |
| 213 | uninstall: |
| 214 | $(RM) -f $(DESTDIR)$(PREFIX)/$(BC_EXEC) |
| 215 | $(RM) -f $(DESTDIR)$(PREFIX)/$(DC_EXEC) |
| 216 | |
| 217 | .PHONY: help clean clean_tests install uninstall test |