An implementation of Unix dc and POSIX bc with GNU and BSD extensions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

216 lines
5.9 KiB

#
# Copyright 2018 Gavin D. Howard
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
%%WARNING%%
.POSIX:
SRC = %%SRC%%
OBJ = %%OBJ%%
GCDA = %%GCDA%%
GCNO = %%GCNO%%
BC_SRC = %%BC_SRC%%
BC_OBJ = %%BC_OBJ%%
BC_GCDA = %%BC_GCDA%%
BC_GCNO = %%BC_GCNO%%
DC_SRC = %%DC_SRC%%
DC_OBJ = %%DC_OBJ%%
DC_GCDA = %%DC_GCDA%%
DC_GCNO = %%DC_GCNO%%
BC_ENABLED_NAME = BC_ENABLED
BC_ENABLED = %%BC_ENABLED%%
DC_ENABLED_NAME = DC_ENABLED
DC_ENABLED = %%DC_ENABLED%%
VERSION = 1.1
GEN_DIR = gen
GEN = strgen
GEN_EXEC = $(GEN_DIR)/$(GEN)
GEN_C = $(GEN_DIR)/$(GEN).c
BC_LIB = $(GEN_DIR)/lib.bc
BC_LIB_C = $(GEN_DIR)/lib.c
BC_LIB_O = $(GEN_DIR)/lib.o
BC_HELP = $(GEN_DIR)/bc_help.txt
BC_HELP_C = $(GEN_DIR)/bc_help.c
BC_HELP_O = $(GEN_DIR)/bc_help.o
DC_HELP = $(GEN_DIR)/dc_help.txt
DC_HELP_C = $(GEN_DIR)/dc_help.c
DC_HELP_O = $(GEN_DIR)/dc_help.o
BIN = bin
BC = bc
DC = dc
BC_EXEC = $(BIN)/$(BC)
DC_EXEC = $(BIN)/$(DC)
PREFIX = %%PREFIX%%
DESTDIR = %%DESTDIR%%
BC_ENABLE_SIGNALS = %%SIGNALS%%
BC_ENABLE_HISTORY = %%HISTORY%%
INSTALL = ./install.sh
LINK = ./link.sh
KARATSUBA = ./karatsuba.py
VALGRIND_ARGS = --error-exitcode=1 --leak-check=full --show-leak-kinds=all
BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%%
CFLAGS1 = %%CFLAGS%%
CFLAGS = $(CFLAGS1) -Wall -Wextra -pedantic -std=c99 -funsigned-char
CPPFLAGS1 = %%CPPFLAGS%%
CPPFLAGS2 = $(CPPFLAGS1) -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
CPPFLAGS3 = $(CPPFLAGS2) -I./include/ -D_POSIX_C_SOURCE=200809L -DVERSION=$(VERSION)
CPPFLAGS4 = $(CPPFLAGS3) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
CPPFLAGS5 = $(CPPFLAGS4) -DBC_ENABLE_SIGNALS=$(BC_ENABLE_SIGNALS)
CPPFLAGS = $(CPPFLAGS5) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY)
LDFLAGS = %%LDFLAGS%%
CC = %%CC%%
HOSTCC = %%HOSTCC%%
all: make_bin $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_OBJ) $(DC_OBJ) $(OBJ)
$(CC) $(CFLAGS) $(OBJ) $(DC_OBJ) $(BC_OBJ) $(BC_LIB_O) $(BC_HELP_O) $(DC_HELP_O) -o $(%%MAIN_EXEC%%)
%%LINK%%
$(GEN_EXEC):
$(HOSTCC) $(CFLAGS) -o $(GEN_EXEC) $(GEN_C)
$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
$(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name $(BC_ENABLED_NAME) 1
$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
$(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED_NAME)
$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
$(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED_NAME)
make_bin:
mkdir -p $(BIN)
help:
@printf 'all targets use config.mak, if there is one\n'
@printf '\n'
@printf 'available targets:\n'
@printf '\n'
@printf ' all (default) builds %%EXECUTABLES%%\n'
@printf ' clean removes all build files\n'
@printf ' clean_tests removes all build files as well as generated tests\n'
@printf ' install installs to %s%s/bin\n' "$(DESTDIR)" "$(PREFIX)"
@printf ' karatsuba runs the karatsuba script (requires Python 3)\n'
@printf ' karatsuba_test runs the karatsuba script while running tests\n'
@printf ' (requires Python 3)\n'
@printf ' uninstall uninstalls from %s%s/bin\n' "$(DESTDIR)" "$(PREFIX)"
@printf ' test runs the test suite\n'
@printf ' test_all runs the test suite as well as the Linux timeconst.bc test,\n'
@printf ' if it exists and bc has been built\n'
@printf ' test_bc runs the bc test suite, if bc has been built\n'
@printf ' test_dc runs the dc test suite, if dc has been built\n'
@printf ' timeconst runs the test on the Linux timeconst.bc script,\n'
@printf ' if it exists and bc has been built\n'
@printf ' valgrind runs the test suite through valgrind\n'
@printf ' valgrind_all runs the test suite, and the Linux timeconst.bc test,\n'
@printf ' if it exists and bc has been built, through valgrind\n'
@printf ' valgrind_bc runs the bc test suite, if bc has been built,\n'
@printf ' through valgrind\n'
@printf ' valgrind_dc runs the dc test suite, if dc has been built,\n'
@printf ' through valgrind\n'
test_all: test timeconst
test: test_bc test_dc
test_bc:
%%BC_TEST%%
test_dc:
%%DC_TEST%%
timeconst:
%%TIMECONST%%
valgrind_all: valgrind valgrind_timeconst
valgrind: valgrind_bc valgrind_dc
valgrind_bc:
%%VG_BC_TEST%%
valgrind_dc:
%%VG_DC_TEST%%
valgrind_timeconst:
%%TIMECONST_VG%%
karatsuba:
%%KARATSUBA%%
karatsuba_test:
%%KARATSUBA_TEST%%
coverage:%%COVERAGE_PREREQS%%
%%COVERAGE%%
version:
@printf "$(VERSION)"
libcname:
@printf "$(BC_LIB_C)"
clean:
$(RM) -f $(OBJ)
$(RM) -f $(BC_OBJ)
$(RM) -f $(DC_OBJ)
$(RM) -f $(BC_EXEC)
$(RM) -f $(DC_EXEC)
$(RM) -f $(GCDA) $(GCNO)
$(RM) -f $(BC_GCDA) $(BC_GCNO)
$(RM) -f $(DC_GCDA) $(DC_GCNO)
$(RM) -f *.gcov
$(RM) -f *.html
$(RM) -f *.gcda *.gcno
$(RM) -f *.profraw
$(RM) -f $(GEN_EXEC)
$(RM) -f $(BC_LIB_C)
$(RM) -f $(BC_LIB_O)
$(RM) -f $(BC_HELP_C)
$(RM) -f $(BC_HELP_O)
$(RM) -f $(DC_HELP_C)
$(RM) -f $(DC_HELP_O)
clean_tests: clean
$(RM) -f tests/bc/parse.txt tests/bc/parse_results.txt
$(RM) -f tests/bc/print.txt tests/bc/print_results.txt
$(RM) -f tests/bc/bessel.txt tests/bc/bessel_results.txt
$(RM) -f .log_test.txt .log_bc.txt
$(RM) -f .math.txt .results.txt .ops.txt
$(RM) -f .test.txt
install:
$(INSTALL) $(DESTDIR)$(PREFIX)/$(BIN) $(BIN)
uninstall:
$(RM) -f $(DESTDIR)$(PREFIX)/$(BC_EXEC)
$(RM) -f $(DESTDIR)$(PREFIX)/$(DC_EXEC)
.PHONY: help clean clean_tests install uninstall test