git: aae002c70bd6 - stable/13 - contrib/bc: MFC version 5.2.1

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Fri, 04 Mar 2022 20:20:15 UTC
The branch stable/13 has been updated by se:

URL: https://cgit.FreeBSD.org/src/commit/?id=aae002c70bd6f483a567163d9ea7629e756e3370

commit aae002c70bd6f483a567163d9ea7629e756e3370
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2021-11-30 17:40:32 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2022-03-04 20:19:30 +0000

    contrib/bc: MFC version 5.2.1
    
    Merge commit 'e63540eed295749528548c2e3a90f5a6e57275c8'
    
    (cherry picked from commit 10041e99a0c29c9f99c4148fc173bb12dd26aa8d)
---
 contrib/bc/Makefile.in                 | 204 +++++++++++++++++++--------------
 contrib/bc/NEWS.md                     |  20 ++++
 contrib/bc/README.md                   |  60 +++++++---
 contrib/bc/bcl.pc.in                   |   8 ++
 contrib/bc/configure.sh                | 200 ++++++++++++++++++++++++--------
 contrib/bc/gen/bc_help.txt             |   7 ++
 contrib/bc/gen/dc_help.txt             |   7 ++
 contrib/bc/include/status.h            |  12 ++
 contrib/bc/include/version.h           |   2 +-
 contrib/bc/include/vm.h                |   6 +
 contrib/bc/locales/de_DE.ISO8859-1.msg |  10 +-
 contrib/bc/locales/de_DE.UTF-8.msg     |  10 +-
 contrib/bc/locales/en_US.msg           |  10 +-
 contrib/bc/locales/es_ES.ISO8859-1.msg |  10 +-
 contrib/bc/locales/es_ES.UTF-8.msg     |  10 +-
 contrib/bc/locales/fr_FR.ISO8859-1.msg |  10 +-
 contrib/bc/locales/fr_FR.UTF-8.msg     |  10 +-
 contrib/bc/locales/ja_JP.UTF-8.msg     |  10 +-
 contrib/bc/locales/ja_JP.eucJP.msg     |  10 +-
 contrib/bc/locales/nl_NL.ISO8859-1.msg |  10 +-
 contrib/bc/locales/nl_NL.UTF-8.msg     |  10 +-
 contrib/bc/locales/pl_PL.ISO8859-2.msg |  10 +-
 contrib/bc/locales/pl_PL.UTF-8.msg     |  10 +-
 contrib/bc/locales/pt_PT.ISO8859-1.msg |  10 +-
 contrib/bc/locales/pt_PT.UTF-8.msg     |  10 +-
 contrib/bc/locales/ru_RU.CP1251.msg    |  10 +-
 contrib/bc/locales/ru_RU.CP866.msg     |  10 +-
 contrib/bc/locales/ru_RU.ISO8859-5.msg |  10 +-
 contrib/bc/locales/ru_RU.KOI8-R.msg    |  10 +-
 contrib/bc/locales/ru_RU.UTF-8.msg     |  10 +-
 contrib/bc/locales/zh_CN.GB18030.msg   |  10 +-
 contrib/bc/locales/zh_CN.GB2312.msg    |  10 +-
 contrib/bc/locales/zh_CN.GBK.msg       |  10 +-
 contrib/bc/locales/zh_CN.UTF-8.msg     |  10 +-
 contrib/bc/locales/zh_CN.eucCN.msg     |  10 +-
 contrib/bc/manuals/bc/A.1              |  13 +++
 contrib/bc/manuals/bc/A.1.md           |  11 ++
 contrib/bc/manuals/bc/E.1              |  13 +++
 contrib/bc/manuals/bc/E.1.md           |  11 ++
 contrib/bc/manuals/bc/EH.1             |  13 +++
 contrib/bc/manuals/bc/EH.1.md          |  11 ++
 contrib/bc/manuals/bc/EHN.1            |  13 +++
 contrib/bc/manuals/bc/EHN.1.md         |  11 ++
 contrib/bc/manuals/bc/EN.1             |  13 +++
 contrib/bc/manuals/bc/EN.1.md          |  11 ++
 contrib/bc/manuals/bc/H.1              |  13 +++
 contrib/bc/manuals/bc/H.1.md           |  11 ++
 contrib/bc/manuals/bc/HN.1             |  13 +++
 contrib/bc/manuals/bc/HN.1.md          |  11 ++
 contrib/bc/manuals/bc/N.1              |  13 +++
 contrib/bc/manuals/bc/N.1.md           |  11 ++
 contrib/bc/manuals/build.md            |  17 +++
 contrib/bc/manuals/dc/A.1              |  13 +++
 contrib/bc/manuals/dc/A.1.md           |  11 ++
 contrib/bc/manuals/dc/E.1              |  13 +++
 contrib/bc/manuals/dc/E.1.md           |  11 ++
 contrib/bc/manuals/dc/EH.1             |  13 +++
 contrib/bc/manuals/dc/EH.1.md          |  11 ++
 contrib/bc/manuals/dc/EHN.1            |  13 +++
 contrib/bc/manuals/dc/EHN.1.md         |  11 ++
 contrib/bc/manuals/dc/EN.1             |  13 +++
 contrib/bc/manuals/dc/EN.1.md          |  11 ++
 contrib/bc/manuals/dc/H.1              |  13 +++
 contrib/bc/manuals/dc/H.1.md           |  11 ++
 contrib/bc/manuals/dc/HN.1             |  13 +++
 contrib/bc/manuals/dc/HN.1.md          |  11 ++
 contrib/bc/manuals/dc/N.1              |  13 +++
 contrib/bc/manuals/dc/N.1.md           |  11 ++
 contrib/bc/scripts/exec-install.sh     |   9 +-
 contrib/bc/scripts/karatsuba.py        |   7 +-
 contrib/bc/src/args.c                  |   2 +
 contrib/bc/src/bc_lex.c                |   2 +
 contrib/bc/src/bc_parse.c              |  49 +++++---
 contrib/bc/src/data.c                  |   3 +-
 contrib/bc/src/dc_lex.c                |   2 +
 contrib/bc/src/dc_parse.c              |   5 +-
 contrib/bc/src/file.c                  |  37 +++++-
 contrib/bc/src/history.c               |  95 +++++++++++----
 contrib/bc/src/lex.c                   |  17 ++-
 contrib/bc/src/library.c               |  18 ++-
 contrib/bc/src/opt.c                   |   2 +-
 contrib/bc/src/parse.c                 |  14 +--
 contrib/bc/src/program.c               |  53 ++++++++-
 contrib/bc/src/rand.c                  |  11 +-
 contrib/bc/src/read.c                  |   4 +
 contrib/bc/src/vm.c                    |  68 +++++++----
 contrib/bc/tests/bc/all.txt            |   1 +
 contrib/bc/tests/bc/misc8.txt          |   8 ++
 contrib/bc/tests/bc/misc8_results.txt  |   3 +
 contrib/bc/tests/bc/posix_errors.txt   |   1 +
 contrib/bc/tests/bc/timeconst.sh       |   1 -
 contrib/bc/tests/history.py            |   3 +-
 contrib/bc/tests/history.sh            |   2 +-
 contrib/bc/vs/bc.vcxproj               |   8 +-
 94 files changed, 1241 insertions(+), 361 deletions(-)

diff --git a/contrib/bc/Makefile.in b/contrib/bc/Makefile.in
index 3d6780d6ac95..b9136a57aa92 100644
--- a/contrib/bc/Makefile.in
+++ b/contrib/bc/Makefile.in
@@ -29,6 +29,15 @@
 #
 .POSIX:
 
+ROOTDIR = %%ROOTDIR%%
+INCDIR = $(ROOTDIR)/include
+SRCDIR = $(ROOTDIR)/src
+TESTSDIR = $(ROOTDIR)/tests
+SCRIPTSDIR = $(ROOTDIR)/scripts
+GENDIR = $(ROOTDIR)/gen
+
+BUILDDIR = %%BUILDDIR%%
+
 SRC = %%SRC%%
 OBJ = %%OBJ%%
 GCDA = %%GCDA%%
@@ -39,46 +48,45 @@ BC_ENABLED = %%BC_ENABLED%%
 DC_ENABLED_NAME = DC_ENABLED
 DC_ENABLED = %%DC_ENABLED%%
 
-HEADERS = include/args.h include/file.h include/lang.h include/lex.h include/num.h include/opt.h include/parse.h include/program.h include/read.h include/status.h include/vector.h include/vm.h
-BC_HEADERS = include/bc.h
-DC_HEADERS = include/dc.h
-HISTORY_HEADERS = include/history.h
-EXTRA_MATH_HEADERS = include/rand.h
-LIBRARY_HEADERS = include/bcl.h include/library.h
+HEADERS = $(INCDIR)/args.h $(INCDIR)/file.h $(INCDIR)/lang.h $(INCDIR)/lex.h $(INCDIR)/num.h $(INCDIR)/opt.h $(INCDIR)/parse.h $(INCDIR)/program.h $(INCDIR)/read.h $(INCDIR)/status.h $(INCDIR)/vector.h $(INCDIR)/vm.h
+BC_HEADERS = $(INCDIR)/bc.h
+DC_HEADERS = $(INCDIR)/dc.h
+HISTORY_HEADERS = $(INCDIR)/history.h
+EXTRA_MATH_HEADERS = $(INCDIR)/rand.h
+LIBRARY_HEADERS = $(INCDIR)/bcl.h $(INCDIR)/library.h
 
 GEN_DIR = gen
 GEN = %%GEN%%
 GEN_EXEC = $(GEN_DIR)/$(GEN)
-GEN_C = $(GEN_DIR)/$(GEN).c
+GEN_C = $(GENDIR)/$(GEN).c
 
 GEN_EMU = %%GEN_EMU%%
 
-BC_LIB = $(GEN_DIR)/lib.bc
+BC_LIB = $(GENDIR)/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 = $(GENDIR)/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 = $(GENDIR)/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 = $(GENDIR)/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
-LOCALES = locales
 EXEC_SUFFIX = %%EXECSUFFIX%%
 EXEC_PREFIX = %%EXECPREFIX%%
 
@@ -97,7 +105,7 @@ LIB_NAME = $(LIB).a
 LIBBC = $(BIN)/$(LIB_NAME)
 BCL = bcl
 BCL_TEST = $(BIN)/$(BCL)
-BCL_TEST_C = tests/$(BCL).c
+BCL_TEST_C = $(TESTSDIR)/$(BCL).c
 
 MANUALS = manuals
 BC_MANPAGE_NAME = $(EXEC_PREFIX)$(BC)$(EXEC_SUFFIX).1
@@ -112,9 +120,13 @@ BCL_MD = $(BCL_MANPAGE).md
 
 MANPAGE_INSTALL_ARGS = -Dm644
 BINARY_INSTALL_ARGS = -Dm755
+PC_INSTALL_ARGS = $(MANPAGE_INSTALL_ARGS)
+
+BCL_PC = $(BCL).pc
+PC_PATH = %%PC_PATH%%
 
 BCL_HEADER_NAME = bcl.h
-BCL_HEADER = include/$(BCL_HEADER_NAME)
+BCL_HEADER = $(INCDIR)/$(BCL_HEADER_NAME)
 
 %%DESTDIR%%
 BINDIR = %%BINDIR%%
@@ -146,6 +158,8 @@ BC_DEFAULT_TTY_MODE = %%BC_DEFAULT_TTY_MODE%%
 DC_DEFAULT_TTY_MODE = %%DC_DEFAULT_TTY_MODE%%
 BC_DEFAULT_PROMPT = %%BC_DEFAULT_PROMPT%%
 DC_DEFAULT_PROMPT = %%DC_DEFAULT_PROMPT%%
+BC_DEFAULT_EXPR_EXIT = %%BC_DEFAULT_EXPR_EXIT%%
+DC_DEFAULT_EXPR_EXIT = %%DC_DEFAULT_EXPR_EXIT%%
 
 RM = rm
 MKDIR = mkdir
@@ -158,13 +172,13 @@ MINISTAT_EXEC = $(SCRIPTS)/$(MINISTAT)
 BITFUNCGEN = bitfuncgen
 BITFUNCGEN_EXEC = $(SCRIPTS)/$(BITFUNCGEN)
 
-INSTALL = $(SCRIPTS)/exec-install.sh
-SAFE_INSTALL = $(SCRIPTS)/safe-install.sh
-LINK = $(SCRIPTS)/link.sh
-MANPAGE = $(SCRIPTS)/manpage.sh
-KARATSUBA = $(SCRIPTS)/karatsuba.py
-LOCALE_INSTALL = $(SCRIPTS)/locale_install.sh
-LOCALE_UNINSTALL = $(SCRIPTS)/locale_uninstall.sh
+INSTALL = $(SCRIPTSDIR)/exec-install.sh
+SAFE_INSTALL = $(SCRIPTSDIR)/safe-install.sh
+LINK = $(SCRIPTSDIR)/link.sh
+MANPAGE = $(SCRIPTSDIR)/manpage.sh
+KARATSUBA = $(SCRIPTSDIR)/karatsuba.py
+LOCALE_INSTALL = $(SCRIPTSDIR)/locale_install.sh
+LOCALE_UNINSTALL = $(SCRIPTSDIR)/locale_uninstall.sh
 
 VALGRIND_ARGS = --error-exitcode=100 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all
 
@@ -176,14 +190,16 @@ BC_DEFS0 = -DBC_DEFAULT_BANNER=$(BC_DEFAULT_BANNER)
 BC_DEFS1 = -DBC_DEFAULT_SIGINT_RESET=$(BC_DEFAULT_SIGINT_RESET)
 BC_DEFS2 = -DBC_DEFAULT_TTY_MODE=$(BC_DEFAULT_TTY_MODE)
 BC_DEFS3 = -DBC_DEFAULT_PROMPT=$(BC_DEFAULT_PROMPT)
-BC_DEFS = $(BC_DEFS0) $(BC_DEFS1) $(BC_DEFS2) $(BC_DEFS3)
+BC_DEFS4 = -DBC_DEFAULT_EXPR_EXIT=$(BC_DEFAULT_EXPR_EXIT)
+BC_DEFS = $(BC_DEFS0) $(BC_DEFS1) $(BC_DEFS2) $(BC_DEFS3) $(BC_DEFS4)
 DC_DEFS1 = -DDC_DEFAULT_SIGINT_RESET=$(DC_DEFAULT_SIGINT_RESET)
 DC_DEFS2 = -DDC_DEFAULT_TTY_MODE=$(DC_DEFAULT_TTY_MODE)
 DC_DEFS3 = -DDC_DEFAULT_PROMPT=$(DC_DEFAULT_PROMPT)
-DC_DEFS = $(DC_DEFS1) $(DC_DEFS2) $(DC_DEFS3)
+DC_DEFS4 = -DDC_DEFAULT_EXPR_EXIT=$(DC_DEFAULT_EXPR_EXIT)
+DC_DEFS = $(DC_DEFS1) $(DC_DEFS2) $(DC_DEFS3) $(DC_DEFS4)
 
 CPPFLAGS1 = -D$(BC_ENABLED_NAME)=$(BC_ENABLED) -D$(DC_ENABLED_NAME)=$(DC_ENABLED)
-CPPFLAGS2 = $(CPPFLAGS1) -I./include/ -DBUILD_TYPE=$(BC_BUILD_TYPE) %%LONG_BIT_DEFINE%%
+CPPFLAGS2 = $(CPPFLAGS1) -I$(INCDIR)/ -DBUILD_TYPE=$(BC_BUILD_TYPE) %%LONG_BIT_DEFINE%%
 CPPFLAGS3 = $(CPPFLAGS2) -DEXECPREFIX=$(EXEC_PREFIX) -DMAINEXEC=$(MAIN_EXEC)
 CPPFLAGS4 = $(CPPFLAGS3) -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 %%BSD%%
 CPPFLAGS5 = $(CPPFLAGS4) -DBC_NUM_KARATSUBA_LEN=$(BC_NUM_KARATSUBA_LEN)
@@ -212,7 +228,10 @@ all: %%DEFAULT_TARGET%%
 %%SECOND_TARGET%%: %%SECOND_TARGET_PREREQS%%
 	%%SECOND_TARGET_CMD%%
 
-$(GEN_EXEC):
+$(GEN_DIR):
+	mkdir -p $(GEN_DIR)
+
+$(GEN_EXEC): $(GEN_DIR)
 	%%GEN_EXEC_TARGET%%
 
 $(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
@@ -242,13 +261,18 @@ $(DC_HELP_O): $(DC_HELP_C)
 $(BIN):
 	$(MKDIR) -p $(BIN)
 
+src:
+	$(MKDIR) -p src
+
 headers: %%HEADERS%%
 
 $(MINISTAT):
-	$(HOSTCC) $(HOSTCFLAGS) -lm -o $(MINISTAT_EXEC) scripts/ministat.c
+	mkdir -p $(SCRIPTS)
+	$(HOSTCC) $(HOSTCFLAGS) -lm -o $(MINISTAT_EXEC) $(ROOTDIR)/scripts/ministat.c
 
 $(BITFUNCGEN):
-	$(HOSTCC) $(HOSTCFLAGS) -lm -o $(BITFUNCGEN_EXEC) scripts/bitfuncgen.c
+	mkdir -p $(SCRIPTS)
+	$(HOSTCC) $(HOSTCFLAGS) -lm -o $(BITFUNCGEN_EXEC) $(ROOTDIR)/scripts/bitfuncgen.c
 
 help:
 	@printf 'available targets:\n'
@@ -314,18 +338,18 @@ test_bc_tests:%%BC_TESTS%%
 test_bc_scripts:%%BC_SCRIPT_TESTS%%
 
 test_bc_stdin:
-	@sh tests/stdin.sh bc %%BC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/stdin.sh bc %%BC_TEST_EXEC%%
 
 test_bc_read:
-	@sh tests/read.sh bc %%BC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/read.sh bc %%BC_TEST_EXEC%%
 
 test_bc_errors: test_bc_error_lines%%BC_ERROR_TESTS%%
 
 test_bc_error_lines:
-	@sh tests/errors.sh bc %%BC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/errors.sh bc %%BC_TEST_EXEC%%
 
 test_bc_other:
-	@sh tests/other.sh bc $(BC_ENABLE_EXTRA_MATH) %%BC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/other.sh bc $(BC_ENABLE_EXTRA_MATH) %%BC_TEST_EXEC%%
 
 test_bc_header:
 	@printf '$(TEST_STARS)\n\nRunning bc tests...\n\n'
@@ -338,18 +362,18 @@ test_dc_tests:%%DC_TESTS%%
 test_dc_scripts:%%DC_SCRIPT_TESTS%%
 
 test_dc_stdin:
-	@sh tests/stdin.sh dc %%DC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/stdin.sh dc %%DC_TEST_EXEC%%
 
 test_dc_read:
-	@sh tests/read.sh dc %%DC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/read.sh dc %%DC_TEST_EXEC%%
 
 test_dc_errors: test_dc_error_lines%%DC_ERROR_TESTS%%
 
 test_dc_error_lines:
-	@sh tests/errors.sh dc %%DC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/errors.sh dc %%DC_TEST_EXEC%%
 
 test_dc_other:
-	@sh tests/other.sh dc $(BC_ENABLE_EXTRA_MATH) %%DC_TEST_EXEC%%
+	@export BC_TEST_OUTPUT_DIR="$(BUILDDIR)/tests"; sh $(TESTSDIR)/other.sh dc $(BC_ENABLE_EXTRA_MATH) %%DC_TEST_EXEC%%
 
 test_dc_header:
 	@printf '$(TEST_STARS)\n\nRunning dc tests...\n\n'
@@ -368,107 +392,110 @@ test_bc_history_skip:
 	@printf 'No bc history tests to run\n'
 
 test_bc_history0:
-	@sh tests/history.sh bc 0 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 0 %%BC_TEST_EXEC%%
 
 test_bc_history1:
-	@sh tests/history.sh bc 1 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 1 %%BC_TEST_EXEC%%
 
 test_bc_history2:
-	@sh tests/history.sh bc 2 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 2 %%BC_TEST_EXEC%%
 
 test_bc_history3:
-	@sh tests/history.sh bc 3 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 3 %%BC_TEST_EXEC%%
 
 test_bc_history4:
-	@sh tests/history.sh bc 4 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 4 %%BC_TEST_EXEC%%
 
 test_bc_history5:
-	@sh tests/history.sh bc 5 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 5 %%BC_TEST_EXEC%%
 
 test_bc_history6:
-	@sh tests/history.sh bc 6 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 6 %%BC_TEST_EXEC%%
 
 test_bc_history7:
-	@sh tests/history.sh bc 7 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 7 %%BC_TEST_EXEC%%
 
 test_bc_history8:
-	@sh tests/history.sh bc 8 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 8 %%BC_TEST_EXEC%%
 
 test_bc_history9:
-	@sh tests/history.sh bc 9 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 9 %%BC_TEST_EXEC%%
 
 test_bc_history10:
-	@sh tests/history.sh bc 10 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 10 %%BC_TEST_EXEC%%
 
 test_bc_history11:
-	@sh tests/history.sh bc 11 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 11 %%BC_TEST_EXEC%%
 
 test_bc_history12:
-	@sh tests/history.sh bc 12 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 12 %%BC_TEST_EXEC%%
 
 test_bc_history13:
-	@sh tests/history.sh bc 13 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 13 %%BC_TEST_EXEC%%
 
 test_bc_history14:
-	@sh tests/history.sh bc 14 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 14 %%BC_TEST_EXEC%%
 
 test_bc_history15:
-	@sh tests/history.sh bc 15 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 15 %%BC_TEST_EXEC%%
 
 test_bc_history16:
-	@sh tests/history.sh bc 16 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 16 %%BC_TEST_EXEC%%
 
 test_bc_history17:
-	@sh tests/history.sh bc 17 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 17 %%BC_TEST_EXEC%%
 
 test_bc_history18:
-	@sh tests/history.sh bc 18 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 18 %%BC_TEST_EXEC%%
 
 test_bc_history19:
-	@sh tests/history.sh bc 19 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 19 %%BC_TEST_EXEC%%
 
 test_bc_history20:
-	@sh tests/history.sh bc 20 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 20 %%BC_TEST_EXEC%%
 
 test_bc_history21:
-	@sh tests/history.sh bc 21 %%BC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh bc 21 %%BC_TEST_EXEC%%
 
 test_dc_history:%%DC_HISTORY_TEST_PREREQS%%
 
-test_dc_history_all: test_dc_history0 test_dc_history1 test_dc_history2 test_dc_history3 test_dc_history4 test_dc_history5 test_dc_history6 test_dc_history7 test_dc_history8 test_dc_history9
+test_dc_history_all: test_dc_history0 test_dc_history1 test_dc_history2 test_dc_history3 test_dc_history4 test_dc_history5 test_dc_history6 test_dc_history7 test_dc_history8 test_dc_history9 test_dc_history10
 
 test_dc_history_skip:
 	@printf 'No dc history tests to run\n'
 
 test_dc_history0:
-	@sh tests/history.sh dc 0 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 0 %%DC_TEST_EXEC%%
 
 test_dc_history1:
-	@sh tests/history.sh dc 1 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 1 %%DC_TEST_EXEC%%
 
 test_dc_history2:
-	@sh tests/history.sh dc 2 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 2 %%DC_TEST_EXEC%%
 
 test_dc_history3:
-	@sh tests/history.sh dc 3 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 3 %%DC_TEST_EXEC%%
 
 test_dc_history4:
-	@sh tests/history.sh dc 4 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 4 %%DC_TEST_EXEC%%
 
 test_dc_history5:
-	@sh tests/history.sh dc 5 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 5 %%DC_TEST_EXEC%%
 
 test_dc_history6:
-	@sh tests/history.sh dc 6 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 6 %%DC_TEST_EXEC%%
 
 test_dc_history7:
-	@sh tests/history.sh dc 7 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 7 %%DC_TEST_EXEC%%
 
 test_dc_history8:
-	@sh tests/history.sh dc 8 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 8 %%DC_TEST_EXEC%%
 
 test_dc_history9:
-	@sh tests/history.sh dc 9 %%DC_TEST_EXEC%%
+	@sh $(TESTSDIR)/history.sh dc 9 %%DC_TEST_EXEC%%
+
+test_dc_history10:
+	@sh $(TESTSDIR)/history.sh dc 10 %%DC_TEST_EXEC%%
 
 test_history_header:
 	@printf '$(TEST_STARS)\n\nRunning history tests...\n\n'
@@ -505,18 +532,17 @@ clean:%%CLEAN_PREREQS%%
 	@$(RM) -f $(BC_EXEC)
 	@$(RM) -f $(DC_EXEC)
 	@$(RM) -fr $(BIN)
-	@$(RM) -f $(LOCALES)/*.cat
 	@$(RM) -f $(BC_LIB_C) $(BC_LIB_O)
 	@$(RM) -f $(BC_LIB2_C) $(BC_LIB2_O)
 	@$(RM) -f $(BC_HELP_C) $(BC_HELP_O)
 	@$(RM) -f $(DC_HELP_C) $(DC_HELP_O)
-	@$(RM) -fr Debug/ Release/
+	@$(RM) -fr vs/bin/ vs/lib/
 
 clean_benchmarks:
 	@printf 'Cleaning benchmarks...\n'
 	@$(RM) -f $(MINISTAT_EXEC)
-	@$(RM) -f benchmarks/bc/*.txt
-	@$(RM) -f benchmarks/dc/*.txt
+	@$(RM) -f $(ROOTDIR)/benchmarks/bc/*.txt
+	@$(RM) -f $(ROOTDIR)/benchmarks/dc/*.txt
 
 clean_config: clean clean_benchmarks
 	@printf 'Cleaning config...\n'
@@ -544,19 +570,19 @@ clean_tests: clean clean_config clean_coverage
 	@printf 'Cleaning test files...\n'
 	@$(RM) -fr $(BC_TEST_OUTPUTS) $(DC_TEST_OUTPUTS)
 	@$(RM) -fr $(BC_FUZZ_OUTPUTS) $(DC_FUZZ_OUTPUTS)
-	@$(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 tests/bc/strings2.txt tests/bc/strings2_results.txt
-	@$(RM) -f tests/bc/scripts/bessel.txt
-	@$(RM) -f tests/bc/scripts/parse.txt
-	@$(RM) -f tests/bc/scripts/print.txt
-	@$(RM) -f tests/bc/scripts/add.txt
-	@$(RM) -f tests/bc/scripts/divide.txt
-	@$(RM) -f tests/bc/scripts/multiply.txt
-	@$(RM) -f tests/bc/scripts/subtract.txt
-	@$(RM) -f tests/bc/scripts/strings2.txt
-	@$(RM) -f tests/dc/scripts/prime.txt
+	@$(RM) -f $(TESTSDIR)/bc/parse.txt $(TESTSDIR)/bc/parse_results.txt
+	@$(RM) -f $(TESTSDIR)/bc/print.txt $(TESTSDIR)/bc/print_results.txt
+	@$(RM) -f $(TESTSDIR)/bc/bessel.txt $(TESTSDIR)/bc/bessel_results.txt
+	@$(RM) -f $(TESTSDIR)/bc/strings2.txt $(TESTSDIR)/bc/strings2_results.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/bessel.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/parse.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/print.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/add.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/divide.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/multiply.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/subtract.txt
+	@$(RM) -f $(TESTSDIR)/bc/scripts/strings2.txt
+	@$(RM) -f $(TESTSDIR)/dc/scripts/prime.txt
 	@$(RM) -f .log_*.txt
 	@$(RM) -f .math.txt .results.txt .ops.txt
 	@$(RM) -f .test.txt
@@ -581,10 +607,11 @@ install_bcl_header:
 	$(SAFE_INSTALL) $(MANPAGE_INSTALL_ARGS) $(BCL_HEADER) $(DESTDIR)$(INCLUDEDIR)/$(BCL_HEADER_NAME)
 
 install_execs:
-	$(INSTALL) $(DESTDIR)$(BINDIR) "$(EXEC_SUFFIX)"
+	$(INSTALL) $(DESTDIR)$(BINDIR) "$(EXEC_SUFFIX)" "$(BUILDDIR)/bin"
 
-install_library:
+install_library: install_bcl_header
 	$(SAFE_INSTALL) $(BINARY_INSTALL_ARGS) $(LIBBC) $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
+	%%PKG_CONFIG_INSTALL%%
 
 install:%%INSTALL_LOCALES_PREREQS%%%%INSTALL_MAN_PREREQS%%%%INSTALL_PREREQS%%
 
@@ -603,8 +630,9 @@ uninstall_dc_manpage:
 uninstall_dc:
 	$(RM) -f $(DESTDIR)$(BINDIR)/$(EXEC_PREFIX)$(DC)$(EXEC_SUFFIX)
 
-uninstall_library:
+uninstall_library: uninstall_bcl_header
 	$(RM) -f $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
+	%%PKG_CONFIG_UNINSTALL%%
 
 uninstall_bcl_header:
 	$(RM) -f $(DESTDIR)$(INCLUDEDIR)/$(BCL_HEADER_NAME)
diff --git a/contrib/bc/NEWS.md b/contrib/bc/NEWS.md
index 5251096d9f2a..5d0126b821a8 100644
--- a/contrib/bc/NEWS.md
+++ b/contrib/bc/NEWS.md
@@ -1,5 +1,25 @@
 # News
 
+## 5.2.1
+
+This is a production release that fixes two parse bugs when in POSIX standard
+mode. One of these bugs was due to a quirk of the POSIX grammar, and the other
+was because `bc` was too strict.
+
+## 5.2.0
+
+This is a production release that adds a new feature, fixes some bugs, and adds
+out-of-source builds and a `pkg-config` file for `bcl`.
+
+The new feature is the ability to turn off exiting on expressions. It is also
+possible to set the default using `configure.sh`. This behavior used to exist
+with the `BC_EXPR_EXIT` environment variable, which is now used again.
+
+Bugs fixed include:
+
+* Some possible race conditions with error handling.
+* Install and uninstall targets for `bcl` did not work.
+
 ## 5.1.1
 
 This is a production release that completes a bug fix from `5.1.0`. The bug
diff --git a/contrib/bc/README.md b/contrib/bc/README.md
index c46d66b7e3ea..259ab923bfc4 100644
--- a/contrib/bc/README.md
+++ b/contrib/bc/README.md
@@ -58,8 +58,8 @@ system.
 This `bc` should build unmodified on any POSIX-compliant system or on Windows
 starting with Windows 10 (though earlier versions may work).
 
-For more complex build requirements than the ones below, see the
-[build manual][5].
+For more complex build requirements than the ones below, see the [build
+manual][5].
 
 ### Windows
 
@@ -76,38 +76,45 @@ support) disabled, with both calculators built.
 
 #### `bc`
 
-To build `bc`, you can open the `bc.sln` file in Visual Studio, select the
+To build `bc`, you can open the `vs/bc.sln` file in Visual Studio, select the
 configuration, and build.
 
 You can also build using MSBuild with the following from the root directory:
 
 ```
-msbuild -property:Configuration=<config> bc.sln
+msbuild -property:Configuration=<config> vs/bc.sln
 ```
 
 where `<config>` is either one of `Debug` or `Release`.
 
+On Windows, the calculators are built as `vs/bin/<platform>/<config>/bc.exe` and
+`vs/bin/<Platform>/<Config>/dc.exe`, where `<platform>` can be either `Win32` or
+`x64`, and `<config>` can be `Debug` or `Release`.
+
+**Note**: On Windows, `dc.exe` is just copied from `bc.exe`; it is not linked.
+Patches are welcome for a way to do that.
+
 #### `bcl` (Library)
 
-To build the library, you can open the `bcl.sln` file in Visual Studio, select
-the configuration, and build.
+To build the library, you can open the `vs/bcl.sln` file in Visual Studio,
+select the configuration, and build.
 
 You can also build using MSBuild with the following from the root directory:
 
 ```
-msbuild -property:Configuration=<config> bcl.sln
+msbuild -property:Configuration=<config> vs/bcl.sln
 ```
 
-where `<config>` is either one of `Debug` or `Release`.
+where `<config>` is either one of `Debug`, `ReleaseMD`, or `ReleaseMT`.
+
+On Windows, the library is built as `vs/lib/<platform>/<config>/bcl.lib`, where
+`<platform>` can be either `Win32` or `x64`, and `<config>` can be `Debug`,
+`ReleaseMD`, or `ReleaseMT`.
 
 ### POSIX-Compatible Systems
 
 On POSIX-compatible systems, `bc` is built as `bin/bc` and `dc` is built as
-`bin/dc` by default. On Windows, they are built as `Release/bc/bc.exe` and
-`Release/bc/dc.exe`.
-
-**Note**: On Windows, `dc.exe` is just copied from `bc.exe`; it is not linked.
-Patches are welcome for a way to do that.
+`bin/dc` by default.
 
 #### Default
 
@@ -177,6 +184,24 @@ The library is built as `bin/libbcl.a` on POSIX-compatible systems or as
 
 #### Package and Distro Maintainers
 
+This section is for package and distro maintainers.
+
+##### Out-of-Source Builds
+
+Out-of-source builds are supported; just call `configure.sh` from the directory
+where the actual build will happen.
+
+For example, if the source is in `bc`, the build should happen in `build`, then
+call `configure.sh` and `make` like so:
+
+```
+../bc/configure.sh
+make
+```
+
+***WARNING***: The path to `configure.sh` from the build directory must not have
+spaces because `make` does not support target names with spaces.
+
 ##### Recommended Compiler
 
 When I ran benchmarks with my `bc` compiled under `clang`, it performed much
@@ -373,16 +398,12 @@ Files:
 
 	.gitignore           The git ignore file (maintainer use only).
 	.gitattributes       The git attributes file (maintainer use only).
-	bc.sln               The Visual Studio solution file for bc.
-	bc.vcxproj           The Visual Studio project file for bc.
-	bc.vcxproj.filters   The Visual Studio filters file for bc.
-	bcl.sln              The Visual Studio solution file for bcl.
-	bcl.vcxproj          The Visual Studio project file for bcl.
-	bcl.vcxproj.filters  The Visual Studio filters file for bcl.
+	bcl.pc.in            A template pkg-config file for bcl.
 	configure            A symlink to configure.sh to make packaging easier.
 	configure.sh         The configure script.
 	LICENSE.md           A Markdown form of the BSD 2-clause License.
 	Makefile.in          The Makefile template.
+	NEWS.md              The changelog.
 	NOTICE.md            List of contributors and copyright owners.
 	RELEASE.md           A checklist for making a release (maintainer use only).
 
@@ -395,6 +416,7 @@ Folders:
 	src      All source code.
 	scripts  A bunch of shell scripts to help with development and building.
 	tests    All tests.
+	vs       Files needed for the build on Windows.
 
 [1]: https://www.gnu.org/software/bc/
 [4]: ./LICENSE.md
diff --git a/contrib/bc/bcl.pc.in b/contrib/bc/bcl.pc.in
new file mode 100644
index 000000000000..f440eeca950f
--- /dev/null
+++ b/contrib/bc/bcl.pc.in
@@ -0,0 +1,8 @@
+includedir=%%INCLUDEDIR%%
+libdir=%%LIBDIR%%
+
+Name: bcl
+Description: Implemention of arbitrary-precision math from the bc calculator.
+Version: %%VERSION%%
+Cflags: -I${includedir}
+Libs: -L${libdir} -lbcl
diff --git a/contrib/bc/configure.sh b/contrib/bc/configure.sh
index de1339780073..76ffb2b9a18e 100755
--- a/contrib/bc/configure.sh
+++ b/contrib/bc/configure.sh
@@ -31,9 +31,9 @@ script="$0"
 scriptdir=$(dirname "$script")
 script=$(basename "$script")
 
-. "$scriptdir/scripts/functions.sh"
+builddir=$(pwd)
 
-cd "$scriptdir"
+. "$scriptdir/scripts/functions.sh"
 
 # Simply prints the help message and quits based on the argument.
 # @param val  The value to pass to exit. Must be an integer.
@@ -52,13 +52,15 @@ usage() {
 	printf 'usage:\n'
 	printf '    %s -h\n' "$script"
 	printf '    %s --help\n' "$script"
-	printf '    %s [-a|-bD|-dB|-c] [-CEfgGHlmMNPtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\n' "$script"
+	printf '    %s [-a|-bD|-dB|-c] [-CEfgGHlmMNtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script"
+	printf '       [-s SETTING] [-S SETTING]\n'
 	printf '    %s \\\n' "$script"
 	printf '       [--library|--bc-only --disable-dc|--dc-only --disable-bc|--coverage]  \\\n'
 	printf '       [--force --debug --disable-extra-math --disable-generated-tests]      \\\n'
 	printf '       [--disable-history --disable-man-pages --disable-nls --disable-strip] \\\n'
 	printf '       [--install-all-locales] [--opt=OPT_LEVEL]                             \\\n'
 	printf '       [--karatsuba-len=KARATSUBA_LEN]                                       \\\n'
+	printf '       [--set-default-on=SETTING] [--set-default-off=SETTING]                \\\n'
 	printf '       [--prefix=PREFIX] [--bindir=BINDIR] [--datarootdir=DATAROOTDIR]       \\\n'
 	printf '       [--datadir=DATADIR] [--mandir=MANDIR] [--man1dir=MAN1DIR]             \\\n'
 	printf '\n'
@@ -205,6 +207,9 @@ usage() {
 	printf '                 path (or contain one). This is treated the same as the POSIX\n'
 	printf '                 definition of $NLSPATH (see POSIX environment variables for\n'
 	printf '                 more information). Default is "/usr/share/locale/%%L/%%N".\n'
+	printf '    PC_PATH      The location to install pkg-config files to. Must be an\n'
+	printf '                 path or contain one. Default is the first path given by the\n'
+	printf '                 output of `pkg-config --variable=pc_path pkg-config`.\n'
 	printf '    EXECSUFFIX   The suffix to append to the executable names, used to not\n'
 	printf '                 interfere with other installed bc executables. Default is "".\n'
 	printf '    EXECPREFIX   The prefix to append to the executable names, used to not\n'
@@ -290,6 +295,18 @@ usage() {
 	printf '|                 | for dc should be on  |              |                      |\n'
 	printf '|                 | in tty mode.         |              |                      |\n'
 	printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
+	printf '| bc.expr_exit    | Whether to exit bc   |            1 | BC_EXPR_EXIT         |\n'
+	printf '|                 | if an expression or  |              |                      |\n'
+	printf '|                 | expression file is   |              |                      |\n'
+	printf '|                 | given with the -e or |              |                      |\n'
+	printf '|                 | -f options.          |              |                      |\n'
+	printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
+	printf '| dc.expr_exit    | Whether to exit dc   |            1 | DC_EXPR_EXIT         |\n'
+	printf '|                 | if an expression or  |              |                      |\n'
+	printf '|                 | expression file is   |              |                      |\n'
+	printf '|                 | given with the -e or |              |                      |\n'
+	printf '|                 | -f options.          |              |                      |\n'
+	printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
 	printf '\n'
 	printf 'These settings are not meant to be changed on a whim. They are meant to ensure\n'
 	printf 'that this bc and dc will conform to the expectations of the user on each\n'
@@ -374,19 +391,34 @@ replace() {
 # the arguments are all assumed to be source files that should *not* be built.
 find_src_files() {
 
+	_find_src_files_args=""
+
 	if [ "$#" -ge 1 ] && [ "$1" != "" ]; then
 
 		while [ "$#" -ge 1 ]; do
 			_find_src_files_a="${1## }"
 			shift
-			_find_src_files_args="$_find_src_files_args ! -path src/${_find_src_files_a}"
+			_find_src_files_args=$(printf '%s\n%s/src/%s\n' "$_find_src_files_args" "$scriptdir" "${_find_src_files_a}")
 		done
 
-	else
-		_find_src_files_args="-print"
 	fi
 
-	printf '%s\n' $(find src/ -depth -name "*.c" $_find_src_files_args)
+	_find_src_files_files=$(find "$scriptdir/src/" -depth -name "*.c" -print)
+
+	_find_src_files_result=""
+
+	for _find_src_files_f in $_find_src_files_files; do
+
+		# If this is true, the file is part of args, and therefore, unneeded.
+		if [ "${_find_src_files_args##*$_find_src_files_f}" != "${_find_src_files_args}" ]; then
+			continue
+		fi
+
+		_find_src_files_result=$(printf '%s\n%s\n' "$_find_src_files_result" "$_find_src_files_f")
+
+	done
+
+	printf '%s\n' "$_find_src_files_result"
 }
 
 # This function generates a list of files to go into the Makefile. It generates
@@ -403,10 +435,6 @@ gen_file_list() {
 	_gen_file_list_contents="$1"
 	shift
 
-	p=$(pwd)
-
-	cd "$scriptdir"
-
 	if [ "$#" -ge 1 ]; then
 		_gen_file_list_unneeded="$@"
 	else
@@ -422,7 +450,14 @@ gen_file_list() {
 	_gen_file_list_contents=$(replace "$_gen_file_list_contents" \
 		"$_gen_file_list_needle_src" "$_gen_file_list_replacement")
 
-	_gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "c" "o")
+	_gen_file_list_cbases=""
+
+	for _gen_file_list_f in $_gen_file_list_replacement; do
+		_gen_file_list_b=$(basename "$_gen_file_list_f")
+		_gen_file_list_cbases="$_gen_file_list_cbases src/$_gen_file_list_b"
+	done
+
+	_gen_file_list_replacement=$(replace_exts "$_gen_file_list_cbases" "c" "o")
 	_gen_file_list_contents=$(replace "$_gen_file_list_contents" \
 		"$_gen_file_list_needle_obj" "$_gen_file_list_replacement")
 
@@ -434,8 +469,6 @@ gen_file_list() {
 	_gen_file_list_contents=$(replace "$_gen_file_list_contents" \
 		"$_gen_file_list_needle_gcno" "$_gen_file_list_replacement")
 
-	cd "$p"
-
 	printf '%s\n' "$_gen_file_list_contents"
 }
 
@@ -466,16 +499,16 @@ gen_std_tests() {
 			if [ -z "${_gen_std_tests_extra_required##*$_gen_std_tests_t*}" ]; then
 				printf 'test_%s_%s:\n\t@printf "Skipping %s %s\\n"\n\n' \
 					"$_gen_std_tests_name" "$_gen_std_tests_t" "$_gen_std_tests_name" \
-					"$_gen_std_tests_t" >> "$scriptdir/Makefile"
+					"$_gen_std_tests_t" >> "Makefile"
 				continue
 			fi
 
 		fi
 
-		printf 'test_%s_%s:\n\t@sh tests/test.sh %s %s %s %s %s\n\n' \
-			"$_gen_std_tests_name" "$_gen_std_tests_t" "$_gen_std_tests_name" \
+		printf 'test_%s_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh \$(TESTSDIR)/test.sh %s %s %s %s %s\n\n' \
+			"$_gen_std_tests_name" "$_gen_std_tests_t" "$builddir" "$_gen_std_tests_name" \
 			"$_gen_std_tests_t" "$generate_tests" "$time_tests" \
-			"$*" >> "$scriptdir/Makefile"
+			"$*" >> "Makefile"
 
 	done
 }
@@ -512,9 +545,9 @@ gen_err_tests() {
 
 	for _gen_err_tests_t in $_gen_err_tests_fs; do
 
-		printf 'test_%s_error_%s:\n\t@sh tests/error.sh %s %s %s\n\n' \
-			"$_gen_err_tests_name" "$_gen_err_tests_t" "$_gen_err_tests_name" \
-			"$_gen_err_tests_t" "$*" >> "$scriptdir/Makefile"
+		printf 'test_%s_error_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh \$(TESTSDIR)/error.sh %s %s %s\n\n' \
+			"$_gen_err_tests_name" "$_gen_err_tests_t" "$builddir" "$_gen_err_tests_name" \
+			"$_gen_err_tests_t" "$*" >> "Makefile"
 
 	done
 
@@ -566,10 +599,10 @@ gen_script_tests() {
 
 		_gen_script_tests_b=$(basename "$_gen_script_tests_f" ".${_gen_script_tests_name}")
 
-		printf 'test_%s_script_%s:\n\t@sh tests/script.sh %s %s %s 1 %s %s %s\n\n' \
-			"$_gen_script_tests_name" "$_gen_script_tests_b" "$_gen_script_tests_name" \
+		printf 'test_%s_script_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh \$(TESTSDIR)/script.sh %s %s %s 1 %s %s %s\n\n' \
+			"$_gen_script_tests_name" "$_gen_script_tests_b" "$builddir" "$_gen_script_tests_name" \
 			"$_gen_script_tests_f" "$_gen_script_tests_extra_math" "$_gen_script_tests_generate" \
-			"$_gen_script_tests_time" "$*" >> "$scriptdir/Makefile"
+			"$_gen_script_tests_time" "$*" >> "Makefile"
 	done
 }
 
@@ -594,6 +627,8 @@ set_default() {
 		dc.tty_mode) dc_default_tty_mode="$_set_default_on" ;;
 		bc.prompt) bc_default_prompt="$_set_default_on" ;;
 		dc.prompt) dc_default_prompt="$_set_default_on" ;;
+		bc.expr_exit) bc_default_expr_exit="$_set_default_on";;
+		dc.expr_exit) dc_default_expr_exit="$_set_default_on";;
 		?) usage "Invalid setting: $_set_default_name" ;;
 
 	esac
@@ -656,6 +691,8 @@ bc_default_tty_mode=1
 dc_default_tty_mode=0
 bc_default_prompt=""
 dc_default_prompt=""
+bc_default_expr_exit=1
+dc_default_expr_exit=1
 
 # getopts is a POSIX utility, but it cannot handle long options. Thus, the
 # handling of long options is done by hand, and that's the reason that short and
@@ -946,12 +983,12 @@ executable="BC_EXEC"
 
 tests="test_bc timeconst test_dc"
 
-bc_test="@tests/all.sh bc $extra_math 1 $generate_tests $time_tests \$(BC_EXEC)"
-bc_test_np="@tests/all.sh -n bc $extra_math 1 $generate_tests $time_tests \$(BC_EXEC)"
-dc_test="@tests/all.sh dc $extra_math 1 $generate_tests $time_tests \$(DC_EXEC)"
-dc_test_np="@tests/all.sh -n dc $extra_math 1 $generate_tests $time_tests \$(DC_EXEC)"
+bc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh bc $extra_math 1 $generate_tests $time_tests \$(BC_EXEC)"
+bc_test_np="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh -n bc $extra_math 1 $generate_tests $time_tests \$(BC_EXEC)"
+dc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh dc $extra_math 1 $generate_tests $time_tests \$(DC_EXEC)"
+dc_test_np="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh -n dc $extra_math 1 $generate_tests $time_tests \$(DC_EXEC)"
 
-timeconst="@tests/bc/timeconst.sh tests/bc/scripts/timeconst.bc \$(BC_EXEC)"
+timeconst="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/bc/timeconst.sh \$(TESTSDIR)/bc/scripts/timeconst.bc \$(BC_EXEC)"
 
 # In order to have cleanup at exit, we need to be in
 # debug mode, so don't run valgrind without that.
@@ -999,6 +1036,11 @@ if [ "$library" -ne 0 ]; then
 	test_bc_history_prereqs=" test_bc_history_skip"
 	test_dc_history_prereqs=" test_dc_history_skip"
 
+	install_prereqs=" install_library"
+	uninstall_prereqs=" uninstall_library"
+	install_man_prereqs=" install_bcl_manpage"
+	uninstall_man_prereqs=" uninstall_bcl_manpage"
+
 elif [ "$bc_only" -eq 1 ]; then
 
 	bc=1
@@ -1151,6 +1193,24 @@ if [ -z "${LIBDIR+set}" ]; then
 	LIBDIR="$PREFIX/lib"
 fi
 
+if [ -z "${PC_PATH+set}" ]; then
+
+	set +e
+
+	command -v pkg-config > /dev/null
+	err=$?
+
+	set -e
+
+	if [ "$err" -eq 0 ]; then
+		PC_PATH=$(pkg-config --variable=pc_path pkg-config)
+		PC_PATH="${PC_PATH%%:*}"
+	else
+		PC_PATH=""
+	fi
*** 3207 LINES SKIPPED ***