1# 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2018-2020 Gavin D. Howard and contributors. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are met: 8# 9# * Redistributions of source code must retain the above copyright notice, this 10# list of conditions and the following disclaimer. 11# 12# * Redistributions in binary form must reproduce the above copyright notice, 13# this list of conditions and the following disclaimer in the documentation 14# and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26# POSSIBILITY OF SUCH DAMAGE. 27# 28# %%WARNING%% 29# 30.POSIX: 31 32VERSION = 3.2.4 33 34SRC = %%SRC%% 35OBJ = %%OBJ%% 36GCDA = %%GCDA%% 37GCNO = %%GCNO%% 38 39BC_ENABLED_NAME = BC_ENABLED 40BC_ENABLED = %%BC_ENABLED%% 41DC_ENABLED_NAME = DC_ENABLED 42DC_ENABLED = %%DC_ENABLED%% 43 44GEN_DIR = gen 45GEN = %%GEN%% 46GEN_EXEC = $(GEN_DIR)/$(GEN) 47GEN_C = $(GEN_DIR)/$(GEN).c 48 49GEN_EMU = %%GEN_EMU%% 50 51BC_LIB = $(GEN_DIR)/lib.bc 52BC_LIB_C = $(GEN_DIR)/lib.c 53BC_LIB_O = %%BC_LIB_O%% 54BC_LIB_GCDA = $(GEN_DIR)/lib.gcda 55BC_LIB_GCNO = $(GEN_DIR)/lib.gcno 56 57BC_LIB2 = $(GEN_DIR)/lib2.bc 58BC_LIB2_C = $(GEN_DIR)/lib2.c 59BC_LIB2_O = %%BC_LIB2_O%% 60BC_LIB2_GCDA = $(GEN_DIR)/lib2.gcda 61BC_LIB2_GCNO = $(GEN_DIR)/lib2.gcno 62 63BC_HELP = $(GEN_DIR)/bc_help.txt 64BC_HELP_C = $(GEN_DIR)/bc_help.c 65BC_HELP_O = %%BC_HELP_O%% 66BC_HELP_GCDA = $(GEN_DIR)/bc_help.gcda 67BC_HELP_GCNO = $(GEN_DIR)/bc_help.gcno 68 69DC_HELP = $(GEN_DIR)/dc_help.txt 70DC_HELP_C = $(GEN_DIR)/dc_help.c 71DC_HELP_O = %%DC_HELP_O%% 72DC_HELP_GCDA = $(GEN_DIR)/dc_help.gcda 73DC_HELP_GCNO = $(GEN_DIR)/dc_help.gcno 74 75BIN = bin 76LOCALES = locales 77EXEC_SUFFIX = %%EXECSUFFIX%% 78EXEC_PREFIX = %%EXECPREFIX%% 79 80BC = bc 81DC = dc 82BC_EXEC = $(BIN)/$(EXEC_PREFIX)$(BC) 83DC_EXEC = $(BIN)/$(EXEC_PREFIX)$(DC) 84 85LIB = libbcl 86LIB_NAME = $(LIB).a 87LIBBC = $(BIN)/$(LIB_NAME) 88BCL = bcl 89BCL_TEST = $(BIN)/$(BCL) 90BCL_TEST_C = tests/$(BCL).c 91 92MANUALS = manuals 93BC_MANPAGE_NAME = $(EXEC_PREFIX)$(BC)$(EXEC_SUFFIX).1 94BC_MANPAGE = $(MANUALS)/$(BC).1 95BC_MD = $(BC_MANPAGE).md 96DC_MANPAGE_NAME = $(EXEC_PREFIX)$(DC)$(EXEC_SUFFIX).1 97DC_MANPAGE = $(MANUALS)/$(DC).1 98DC_MD = $(DC_MANPAGE).md 99BCL_MANPAGE_NAME = bcl.3 100BCL_MANPAGE = $(MANUALS)/$(BCL_MANPAGE_NAME) 101BCL_MD = $(BCL_MANPAGE).md 102 103MANPAGE_INSTALL_ARGS = -Dm644 104BINARY_INSTALL_ARGS = -Dm755 105 106BCL_HEADER_NAME = bcl.h 107BCL_HEADER = include/$(BCL_HEADER_NAME) 108 109%%DESTDIR%% 110BINDIR = %%BINDIR%% 111INCLUDEDIR = %%INCLUDEDIR%% 112LIBDIR = %%LIBDIR%% 113MAN1DIR = %%MAN1DIR%% 114MAN3DIR = %%MAN3DIR%% 115MAIN_EXEC = $(EXEC_PREFIX)$(%%MAIN_EXEC%%)$(EXEC_SUFFIX) 116EXEC = $(%%EXEC%%) 117NLSPATH = %%NLSPATH%% 118 119BC_ENABLE_LIBRARY = %%LIBRARY%% 120 121BC_ENABLE_HISTORY = %%HISTORY%% 122BC_ENABLE_EXTRA_MATH_NAME = BC_ENABLE_EXTRA_MATH 123BC_ENABLE_EXTRA_MATH = %%EXTRA_MATH%% 124BC_ENABLE_NLS = %%NLS%% 125BC_ENABLE_PROMPT = %%PROMPT%% 126BC_LONG_BIT = %%LONG_BIT%% 127 128RM = rm 129MKDIR = mkdir 130 131INSTALL = ./exec-install.sh 132SAFE_INSTALL = ./safe-install.sh 133LINK = ./link.sh 134MANPAGE = ./manpage.sh 135KARATSUBA = ./karatsuba.py 136LOCALE_INSTALL = ./locale_install.sh 137LOCALE_UNINSTALL = ./locale_uninstall.sh 138 139VALGRIND_ARGS = --error-exitcode=100 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all 140 141BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%% 142 143CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED) 144CPPFLAGS2 = $(CPPFLAGS1) -I./include/ -DVERSION=$(VERSION) %%LONG_BIT_DEFINE%% 145CPPFLAGS3 = $(CPPFLAGS2) -DEXECPREFIX=$(EXEC_PREFIX) -DMAINEXEC=$(MAIN_EXEC) 146CPPFLAGS4 = $(CPPFLAGS3) -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 147CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN) 148CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS) -DBC_ENABLE_PROMPT=$(BC_ENABLE_PROMPT) 149CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH) 150CPPFLAGS = $(CPPFLAGS7) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY) -DBC_ENABLE_LIBRARY=$(BC_ENABLE_LIBRARY) 151CFLAGS = $(CPPFLAGS) %%CPPFLAGS%% %%CFLAGS%% 152LDFLAGS = %%LDFLAGS%% 153 154HOSTCFLAGS = %%HOSTCFLAGS%% 155 156CC = %%CC%% 157HOSTCC = %%HOSTCC%% 158 159BC_LIB_C_ARGS = bc_lib bc_lib_name $(BC_ENABLED_NAME) 1 160BC_LIB2_C_ARGS = bc_lib2 bc_lib2_name "$(BC_ENABLED_NAME) && $(BC_ENABLE_EXTRA_MATH_NAME)" 1 161 162OBJS = $(BC_HELP_O) $(DC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(OBJ) 163OBJ_TARGETS = $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(OBJ) 164 165.c.o: 166 $(CC) $(CFLAGS) -o $@ -c $< 167 168all: %%ALL_PREREQ%% 169 170execs: make_bin $(OBJ_TARGETS) 171 $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(EXEC) 172 %%LINK%% 173 174library: make_bin $(OBJ) $(BC_LIB_O) $(BC_LIB2_O) 175 ar -r -cu $(LIBBC) $(BC_LIB_O) $(BC_LIB2_O) $(OBJ) 176 177$(GEN_EXEC): 178 %%GEN_EXEC_TARGET%% 179 180$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB) 181 $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) $(BC_LIB_C_ARGS) 182 183$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2) 184 $(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) $(BC_LIB2_C_ARGS) 185 186$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP) 187 $(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED_NAME) 188 189$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP) 190 $(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED_NAME) 191 192make_bin: 193 $(MKDIR) -p $(BIN) 194 195help: 196 @printf 'available targets:\n' 197 @printf '\n' 198 @printf ' all (default) builds %%EXECUTABLES%%\n' 199 @printf ' check alias for `make test`\n' 200 @printf ' clean removes all build files\n' 201 @printf ' clean_config removes all build files as well as the generated Makefile\n' 202 @printf ' clean_tests removes all build files, the generated Makefile,\n' 203 @printf ' and generated tests\n' 204 @printf ' install installs binaries to "%s%s"\n' "$(DESTDIR)" "$(BINDIR)" 205 @printf ' and (if enabled) manpages to "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)" 206 @printf ' karatsuba runs the karatsuba script (requires Python 3)\n' 207 @printf ' karatsuba_test runs the karatsuba script while running tests\n' 208 @printf ' (requires Python 3)\n' 209 @printf ' uninstall uninstalls binaries from "%s%s"\n' "$(DESTDIR)" "$(BINDIR)" 210 @printf ' and (if enabled) manpages from "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)" 211 @printf ' test runs the test suite\n' 212 @printf ' test_bc runs the bc test suite, if bc has been built\n' 213 @printf ' test_dc runs the dc test suite, if dc has been built\n' 214 @printf ' time_test runs the test suite, displaying times for some things\n' 215 @printf ' time_test_bc runs the bc test suite, displaying times for some things\n' 216 @printf ' time_test_dc runs the dc test suite, displaying times for some things\n' 217 @printf ' timeconst runs the test on the Linux timeconst.bc script,\n' 218 @printf ' if it exists and bc has been built\n' 219 @printf ' valgrind runs the test suite through valgrind\n' 220 @printf ' valgrind_bc runs the bc test suite, if bc has been built,\n' 221 @printf ' through valgrind\n' 222 @printf ' valgrind_dc runs the dc test suite, if dc has been built,\n' 223 @printf ' through valgrind\n' 224 225check: test 226 227test: %%TESTS%% 228 229test_bc: 230 %%BC_TEST%% 231 232test_dc: 233 %%DC_TEST%% 234 235time_test: time_test_bc timeconst time_test_dc 236 237time_test_bc: 238 %%BC_TIME_TEST%% 239 240time_test_dc: 241 %%DC_TIME_TEST%% 242 243timeconst: 244 %%TIMECONST%% 245 246library_test: library 247 $(CC) $(CFLAGS) $(BCL_TEST_C) $(LIBBC) -o $(BCL_TEST) 248 249test_library: library_test 250 $(BCL_TEST) 251 252valgrind: valgrind_bc valgrind_dc 253 254valgrind_bc: 255 %%VG_BC_TEST%% 256 257valgrind_dc: 258 %%VG_DC_TEST%% 259 260karatsuba: 261 %%KARATSUBA%% 262 263karatsuba_test: 264 %%KARATSUBA_TEST%% 265 266coverage_output: 267 %%COVERAGE_OUTPUT%% 268 269coverage:%%COVERAGE_PREREQS%% 270 271version: 272 @printf '%s' "$(VERSION)" 273 274libcname: 275 @printf '%s' "$(BC_LIB_C)" 276 277extra_math: 278 @printf '%s' "$(BC_ENABLE_EXTRA_MATH)" 279 280manpages: 281 $(MANPAGE) bc 282 $(MANPAGE) dc 283 $(MANPAGE) bcl 284 285clean_gen: 286 @$(RM) -f $(GEN_EXEC) 287 288clean:%%CLEAN_PREREQS%% 289 @printf 'Cleaning files...\n' 290 @$(RM) -f $(OBJ) 291 @$(RM) -f $(BC_EXEC) 292 @$(RM) -f $(DC_EXEC) 293 @$(RM) -fr $(BIN) 294 @$(RM) -f $(LOCALES)/*.cat 295 @$(RM) -f $(BC_LIB_C) $(BC_LIB_O) 296 @$(RM) -f $(BC_LIB2_C) $(BC_LIB2_O) 297 @$(RM) -f $(BC_HELP_C) $(BC_HELP_O) 298 @$(RM) -f $(DC_HELP_C) $(DC_HELP_O) 299 300clean_config: clean 301 @printf 'Cleaning config...\n' 302 @$(RM) -f Makefile 303 @$(RM) -f $(BC_MD) $(DC_MD) 304 @$(RM) -f $(BC_MANPAGE) $(DC_MANPAGE) 305 306clean_coverage: 307 @printf 'Cleaning coverage files...\n' 308 @$(RM) -f *.gcov 309 @$(RM) -f *.html 310 @$(RM) -f *.gcda *.gcno 311 @$(RM) -f *.profraw 312 @$(RM) -f $(GCDA) $(GCNO) 313 @$(RM) -f $(BC_GCDA) $(BC_GCNO) 314 @$(RM) -f $(DC_GCDA) $(DC_GCNO) 315 @$(RM) -f $(HISTORY_GCDA) $(HISTORY_GCNO) 316 @$(RM) -f $(RAND_GCDA) $(RAND_GCNO) 317 @$(RM) -f $(BC_LIB_GCDA) $(BC_LIB_GCNO) 318 @$(RM) -f $(BC_LIB2_GCDA) $(BC_LIB2_GCNO) 319 @$(RM) -f $(BC_HELP_GCDA) $(BC_HELP_GCNO) 320 @$(RM) -f $(DC_HELP_GCDA) $(DC_HELP_GCNO) 321 322clean_tests: clean clean_config clean_coverage 323 @printf 'Cleaning test files...\n' 324 @$(RM) -f tests/bc/parse.txt tests/bc/parse_results.txt 325 @$(RM) -f tests/bc/print.txt tests/bc/print_results.txt 326 @$(RM) -f tests/bc/bessel.txt tests/bc/bessel_results.txt 327 @$(RM) -f tests/bc/scripts/bessel.txt 328 @$(RM) -f tests/bc/scripts/parse.txt 329 @$(RM) -f tests/bc/scripts/print.txt 330 @$(RM) -f tests/bc/scripts/add.txt 331 @$(RM) -f tests/bc/scripts/divide.txt 332 @$(RM) -f tests/bc/scripts/multiply.txt 333 @$(RM) -f tests/bc/scripts/subtract.txt 334 @$(RM) -f tests/dc/scripts/prime.txt tests/dc/scripts/stream.txt 335 @$(RM) -f .log_*.txt 336 @$(RM) -f .math.txt .results.txt .ops.txt 337 @$(RM) -f .test.txt 338 @$(RM) -f tags .gdbbreakpoints .gdb_history .gdbsetup 339 @$(RM) -f cscope.* 340 @$(RM) -f bc.old 341 342install_locales: 343 %%INSTALL_LOCALES%% 344 345install_bc_manpage: 346 $(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME) 347 348install_dc_manpage: 349 $(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(DC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME) 350 351install_bcl_manpage: 352 $(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BCL_MANPAGE) $(DESTDIR)$(MAN3DIR)/$(BCL_MANPAGE_NAME) 353 354install_bcl_header: 355 $(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BCL_HEADER) $(DESTDIR)$(INCLUDEDIR)/$(BCL_HEADER_NAME) 356 357install_execs: 358 $(INSTALL) $(DESTDIR)$(BINDIR) "$(EXEC_SUFFIX)" 359 360install_library: 361 $(SAFE_INSTALL) $(BINARY_INSTALL_ARGS) $(LIBBC) $(DESTDIR)$(LIBDIR)/$(LIB_NAME) 362 363install:%%INSTALL_LOCALES_PREREQS%%%%INSTALL_MAN_PREREQS%%%%INSTALL_PREREQS%% 364 365uninstall_locales: 366 $(LOCALE_UNINSTALL) $(NLSPATH) $(MAIN_EXEC) $(DESTDIR) 367 368uninstall_bc_manpage: 369 $(RM) -f $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME) 370 371uninstall_bc: 372 $(RM) -f $(DESTDIR)$(BINDIR)/$(EXEC_PREFIX)$(BC)$(EXEC_SUFFIX) 373 374uninstall_dc_manpage: 375 $(RM) -f $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME) 376 377uninstall_dc: 378 $(RM) -f $(DESTDIR)$(BINDIR)/$(EXEC_PREFIX)$(DC)$(EXEC_SUFFIX) 379 380uninstall_library: 381 $(RM) -f $(DESTDIR)$(LIBDIR)/$(LIB_NAME) 382 383uninstall_bcl_header: 384 $(RM) -f $(DESTDIR)$(INCLUDEDIR)/$(BCL_HEADER_NAME) 385 386uninstall_bcl_manpage: 387 $(RM) -f $(DESTDIR)$(MAN3DIR)/$(BCL_MANPAGE_NAME) 388 389uninstall:%%UNINSTALL_LOCALES_PREREQS%%%%UNINSTALL_MAN_PREREQS%%%%UNINSTALL_PREREQS%% 390