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.
 
 
 
 
 

299 lines
8.7 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%%
HISTORY_SRC = %%HISTORY_SRC%%
HISTORY_OBJ = %%HISTORY_OBJ%%
HISTORY_GCDA = %%HISTORY_GCDA%%
HISTORY_GCNO = %%HISTORY_GCNO%%
BC_ENABLED_NAME = BC_ENABLED
BC_ENABLED = %%BC_ENABLED%%
DC_ENABLED_NAME = DC_ENABLED
DC_ENABLED = %%DC_ENABLED%%
VERSION = 1.2.0-dev
GEN_DIR = gen
GEN = strgen
GEN_EXEC = $(GEN_DIR)/$(GEN)
GEN_C = $(GEN_DIR)/$(GEN).c
GEN_EMU = %%GEN_EMU%%
BC_LIB = $(GEN_DIR)/lib.bc
BC_LIB_C = $(GEN_DIR)/lib.c
BC_LIB_O = %%BC_LIB_O%%
BC_LIB_GCDA = $(GEN_DIR)/lib.gcda
BC_LIB_GCNO = $(GEN_DIR)/lib.gcno
BC_LIB2 = $(GEN_DIR)/lib2.bc
BC_LIB2_C = $(GEN_DIR)/lib2.c
BC_LIB2_O = %%BC_LIB2_O%%
BC_LIB2_GCDA = $(GEN_DIR)/lib2.gcda
BC_LIB2_GCNO = $(GEN_DIR)/lib2.gcno
BC_HELP = $(GEN_DIR)/bc_help.txt
BC_HELP_C = $(GEN_DIR)/bc_help.c
BC_HELP_O = %%BC_HELP_O%%
BC_HELP_GCDA = $(GEN_DIR)/bc_help.gcda
BC_HELP_GCNO = $(GEN_DIR)/bc_help.gcno
DC_HELP = $(GEN_DIR)/dc_help.txt
DC_HELP_C = $(GEN_DIR)/dc_help.c
DC_HELP_O = %%DC_HELP_O%%
DC_HELP_GCDA = $(GEN_DIR)/dc_help.gcda
DC_HELP_GCNO = $(GEN_DIR)/dc_help.gcno
BIN = bin
LOCALE = locale
BC = bc
DC = dc
BC_EXEC = $(BIN)/$(BC)
DC_EXEC = $(BIN)/$(DC)
EXEC_SUFFIX = %%EXECSUFFIX%%
MANUALS = manuals
BC_MANPAGE_NAME = $(BC).1
BC_MANPAGE = $(MANUALS)/$(BC_MANPAGE_NAME)
BC_RONN = $(BC_MANPAGE).ronn
DC_MANPAGE_NAME = $(DC).1
DC_MANPAGE = $(MANUALS)/$(DC_MANPAGE_NAME)
DC_RONN = $(DC_MANPAGE).ronn
MANPAGE_INSTALL_ARGS = -Dm644
DESTDIR = %%DESTDIR%%
BINDIR = %%BINDIR%%
MAN1DIR = %%MAN1DIR%%
MAIN_EXEC = $(%%MAIN_EXEC%%)
EXEC = $(%%EXEC%%)
LOCALEDIR = %%LOCALEDIR%%/$(MAIN_EXEC)
BC_ENABLE_SIGNALS = %%SIGNALS%%
BC_ENABLE_HISTORY = %%HISTORY%%
BC_ENABLE_REFERENCES = %%REFERENCES%%
BC_ENABLE_EXTRA_MATH_NAME = BC_ENABLE_EXTRA_MATH
BC_ENABLE_EXTRA_MATH = %%EXTRA_MATH%%
BC_ENABLE_NLS = %%NLS%%
RM = rm
MKDIR = mkdir
INSTALL = ./install.sh
SAFE_INSTALL = ./safe-install.sh
LINK = ./link.sh
KARATSUBA = ./karatsuba.py
LOCALE_INSTALL = ./locale.sh
VALGRIND_ARGS = --error-exitcode=100 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all
RONN_ARGS = --roff --organization="Gavin D. Howard" --manual="General Commands Manual"
BC_NUM_KARATSUBA_LEN = %%KARATSUBA_LEN%%
CPPFLAGS1 = %%CPPFLAGS%%
CPPFLAGS2 = $(CPPFLAGS1) -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
CPPFLAGS3 = $(CPPFLAGS2) -I./include/ -DVERSION=$(VERSION) -DLOCALEDIR=$(LOCALEDIR)
CPPFLAGS4 = $(CPPFLAGS3) -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700
CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
CPPFLAGS6 = $(CPPFLAGS5) -DBC_ENABLE_NLS=$(BC_ENABLE_NLS) -DBC_ENABLE_REFERENCES=$(BC_ENABLE_REFERENCES)
CPPFLAGS7 = $(CPPFLAGS6) -D$(BC_ENABLE_EXTRA_MATH_NAME)=$(BC_ENABLE_EXTRA_MATH)
CPPFLAGS = $(CPPFLAGS7) -DBC_ENABLE_SIGNALS=$(BC_ENABLE_SIGNALS) -DBC_ENABLE_HISTORY=$(BC_ENABLE_HISTORY)
CFLAGS = $(CPPFLAGS) %%CFLAGS%%
LDFLAGS = %%LDFLAGS%%
HOSTCFLAGS = %%HOSTCFLAGS%%
CC = %%CC%%
HOSTCC = %%HOSTCC%%
all: make_bin $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O) $(BC_OBJ) $(DC_OBJ) $(HISTORY_OBJ) $(OBJ)
$(CC) $(CPPFLAGS) $(CFLAGS) $(OBJ) $(DC_OBJ) $(BC_OBJ) $(HISTORY_OBJ) $(BC_HELP_O) $(DC_HELP_O) \
$(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O) $(LDFLAGS) -o $(EXEC)
%%LINK%%
$(GEN_EXEC):
$(HOSTCC) $(HOSTCFLAGS) -o $(GEN_EXEC) $(GEN_C)
$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
$(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc.h bc_lib_name $(BC_ENABLED_NAME) 1
$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2)
$(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) bc_lib2 bc.h bc_lib2_name \
"$(BC_ENABLED_NAME) && $(BC_ENABLE_EXTRA_MATH_NAME)" 1
$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
$(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help bc.h "" $(BC_ENABLED_NAME)
$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
$(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help dc.h "" $(DC_ENABLED_NAME)
make_bin:
$(MKDIR) -p $(BIN)
help:
@printf 'available targets:\n'
@printf '\n'
@printf ' all (default) builds %%EXECUTABLES%%\n'
@printf ' clean removes all build files\n'
@printf ' clean_config removes all build files as well as the generated Makefile\n'
@printf ' clean_tests removes all build files, the generated Makefile,\n
@printf ' and generated tests\n'
@printf ' install installs binaries to "%s%s"\n' "$(DESTDIR)" "$(BINDIR)"
@printf ' and (if enabled) manpages to "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)"
@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 binaries from "%s%s"\n' "$(DESTDIR)" "$(BINDIR)"
@printf ' and (if enabled) manpages from "%s%s"\n' "$(DESTDIR)" "$(MAN1DIR)"
@printf ' test runs the test suite\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_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: test_bc timeconst test_dc
test_bc:
%%BC_TEST%%
test_dc:
%%DC_TEST%%
timeconst:
%%TIMECONST%%
valgrind: valgrind_bc valgrind_dc
valgrind_bc:
%%VG_BC_TEST%%
valgrind_dc:
%%VG_DC_TEST%%
karatsuba:
%%KARATSUBA%%
karatsuba_test:
%%KARATSUBA_TEST%%
coverage:%%COVERAGE_PREREQS%%
%%COVERAGE%%
version:
@printf '%s' "$(VERSION)"
libcname:
@printf '%s' "$(BC_LIB_C)"
extra_math:
@printf '%s' "$(BC_ENABLE_EXTRA_MATH)"
manpages:
ronn $(RONN_ARGS) $(BC_RONN)
ronn $(RONN_ARGS) $(DC_RONN)
clean:
@printf 'Cleaning files...\n'
@$(RM) -f $(OBJ)
@$(RM) -f $(BC_OBJ)
@$(RM) -f $(DC_OBJ)
@$(RM) -f $(HISTORY_OBJ)
@$(RM) -f $(BC_EXEC)
@$(RM) -f $(DC_EXEC)
@$(RM) -fr $(BIN)
@$(RM) -f $(GCDA) $(GCNO)
@$(RM) -f $(BC_GCDA) $(BC_GCNO)
@$(RM) -f $(DC_GCDA) $(DC_GCNO)
@$(RM) -f $(HISTORY_GCDA) $(HISTORY_GCNO)
@$(RM) -f *.gcov
@$(RM) -f *.html
@$(RM) -f *.gcda *.gcno
@$(RM) -f *.profraw
@$(RM) -f $(LOCALE)/*.cat
@$(RM) -f $(GEN_EXEC)
@$(RM) -f $(BC_LIB_C) $(BC_LIB_O)
@$(RM) -f $(BC_LIB_GCDA) $(BC_LIB_GCNO)
@$(RM) -f $(BC_LIB2_C) $(BC_LIB2_O)
@$(RM) -f $(BC_LIB2_GCDA) $(BC_LIB2_GCNO)
@$(RM) -f $(BC_HELP_C) $(BC_HELP_O)
@$(RM) -f $(BC_HELP_GCDA) $(BC_HELP_GCNO)
@$(RM) -f $(DC_HELP_C) $(DC_HELP_O)
@$(RM) -f $(DC_HELP_GCDA) $(DC_HELP_GCNO)
clean_config: clean
@printf 'Cleaning config...\n'
@$(RM) -f Makefile
clean_tests: clean clean_config
@printf 'Cleaning test files...\n'
@$(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_*.txt
@$(RM) -f .math.txt .results.txt .ops.txt
@$(RM) -f .test.txt
install_locales:
$(LOCALE_INSTALL) $(LOCALEDIR)
install_bc_manpage:
$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME)
install_dc_manpage:
$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(DC_MANPAGE) $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME)
install:%%INSTALL_LOCALES_PREREQS%%%%INSTALL_PREREQS%%
$(INSTALL) $(DESTDIR)$(BINDIR) "$(EXEC_SUFFIX)"
uninstall_locales:
$(RM) -fr $(LOCALEDIR)
uninstall_bc_manpage:
$(RM) -f $(DESTDIR)$(MAN1DIR)/$(BC_MANPAGE_NAME)
uninstall_bc:
$(RM) -f $(DESTDIR)$(BINDIR)/$(BC)$(EXEC_SUFFIX)
uninstall_dc_manpage:
$(RM) -f $(DESTDIR)$(MAN1DIR)/$(DC_MANPAGE_NAME)
uninstall_dc:
$(RM) -f $(DESTDIR)$(BINDIR)/$(DC)$(EXEC_SUFFIX)
uninstall:%%UNINSTALL_LOCALES_PREREQS%%%%UNINSTALL_MAN_PREREQS%%%%UNINSTALL_PREREQS%%