aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Howard <gavin@yzena.com>2021-10-31 01:01:45 -0600
committerGavin Howard <gavin@yzena.com>2021-10-31 01:01:45 -0600
commit56a8da67d1d2a48360e256c469e3c1e914cc8c79 (patch)
tree2d7b6c8386a40fe226aad21802fd94892caa65d8
parentfb2428ca630c256fe2e0de1df25e1373fe1f5716 (diff)
downloadbc-56a8da67d1d2a48360e256c469e3c1e914cc8c79.tar.gz
Implement out-of-source builds
This took a lot of work, but it would have taken far more if I hadn't followed good practices from the start. Signed-off-by: Gavin Howard <gavin@yzena.com>
-rw-r--r--Makefile.in181
-rwxr-xr-xconfigure.sh96
-rwxr-xr-xscripts/exec-install.sh9
-rwxr-xr-xscripts/karatsuba.py7
-rwxr-xr-xtests/bc/timeconst.sh1
5 files changed, 157 insertions, 137 deletions
diff --git a/Makefile.in b/Makefile.in
index 86c13339..b9136a57 100644
--- a/Makefile.in
+++ b/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
@@ -118,7 +126,7 @@ 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%%
@@ -164,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
@@ -191,7 +199,7 @@ 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)
@@ -220,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)
@@ -250,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'
@@ -322,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'
@@ -346,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'
@@ -376,70 +392,70 @@ 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%%
@@ -449,37 +465,37 @@ 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 tests/history.sh dc 10 %%DC_TEST_EXEC%%
+ @sh $(TESTSDIR)/history.sh dc 10 %%DC_TEST_EXEC%%
test_history_header:
@printf '$(TEST_STARS)\n\nRunning history tests...\n\n'
@@ -516,7 +532,6 @@ 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)
@@ -526,8 +541,8 @@ clean:%%CLEAN_PREREQS%%
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'
@@ -555,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
@@ -592,7 +607,7 @@ 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_bcl_header
$(SAFE_INSTALL) $(BINARY_INSTALL_ARGS) $(LIBBC) $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
diff --git a/configure.sh b/configure.sh
index dd6a8813..7ab4236c 100755
--- a/configure.sh
+++ b/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.
@@ -394,14 +394,14 @@ find_src_files() {
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="$_find_src_files_args ! -path \"$scriptdir/src/${_find_src_files_a}\""
done
else
_find_src_files_args="-print"
fi
- printf '%s\n' $(find src/ -depth -name "*.c" $_find_src_files_args)
+ printf '%s\n' $(find "$scriptdir/src/" -depth -name "*.c" $_find_src_files_args)
}
# This function generates a list of files to go into the Makefile. It generates
@@ -418,10 +418,6 @@ gen_file_list() {
_gen_file_list_contents="$1"
shift
- p=$(pwd)
-
- cd "$scriptdir"
-
if [ "$#" -ge 1 ]; then
_gen_file_list_unneeded="$@"
else
@@ -437,7 +433,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")
@@ -449,8 +452,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"
}
@@ -481,16 +482,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
}
@@ -527,9 +528,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
@@ -581,10 +582,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
}
@@ -965,12 +966,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.
@@ -1237,14 +1238,14 @@ if [ "$nls" -ne 0 ]; then
flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
flags="$flags -DBC_ENABLE_HISTORY=$hist -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
- flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
+ flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
- "$CC" $CPPFLAGS $CFLAGS $flags -c "src/vm.c" -o "$scriptdir/vm.o" > /dev/null 2>&1
+ "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/vm.c" -o "./vm.o" > /dev/null 2>&1
err="$?"
- rm -rf "$scriptdir/vm.o"
+ rm -rf "./vm.o"
# If this errors, it is probably because of building on Windows,
# and NLS is not supported on Windows, so disable it.
@@ -1260,11 +1261,11 @@ if [ "$nls" -ne 0 ]; then
printf 'NLS works.\n\n'
printf 'Testing gencat...\n'
- gencat "$scriptdir/en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
+ gencat "./en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
err="$?"
- rm -rf "$scriptdir/en_US.cat"
+ rm -rf "./en_US.cat"
if [ "$err" -ne 0 ]; then
printf 'gencat does not work.\n'
@@ -1321,14 +1322,14 @@ if [ "$hist" -eq 1 ]; then
flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
- flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
+ flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
- "$CC" $CPPFLAGS $CFLAGS $flags -c "src/history.c" -o "$scriptdir/history.o" > /dev/null 2>&1
+ "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/history.c" -o "./history.o" > /dev/null 2>&1
err="$?"
- rm -rf "$scriptdir/history.o"
+ rm -rf "./history.o"
# If this errors, it is probably because of building on Windows,
# and history is not supported on Windows, so disable it.
@@ -1354,7 +1355,7 @@ if [ "$hist" -eq 0 ] || [ "$vg" -ne 0 ]; then
test_dc_history_prereqs=" test_dc_history_skip"
history_tests="@printf 'Skipping history tests...\\\\n'"
else
- history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n' \&\& tests/history.sh bc -a \&\& tests/history.sh dc -a \&\& printf '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
+ history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n' \&\& \$(TESTSDIR)/history.sh bc -a \&\& \$(TESTSDIR)/history.sh dc -a \&\& printf '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
fi
# Test OpenBSD. This is not in an if statement because regardless of whatever
@@ -1369,7 +1370,7 @@ set +e
printf 'Testing for OpenBSD...\n'
flags="-DBC_TEST_OPENBSD -DBC_ENABLE_AFL=0"
-"$CC" $CPPFLAGS $CFLAGS $flags -I./include -E "include/status.h" > /dev/null 2>&1
+"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/include/status.h" > /dev/null 2>&1
err="$?"
@@ -1447,7 +1448,7 @@ fi
# This convoluted mess does pull the version out. If you change the format of
# include/version.h, you may have to change this line.
-version=$(cat include/version.h | grep "VERSION " - | awk '{ print $3 }' -)
+version=$(cat "$scriptdir/include/version.h" | grep "VERSION " - | awk '{ print $3 }' -)
if [ "$library" -ne 0 ]; then
@@ -1465,7 +1466,7 @@ if [ "$library" -ne 0 ]; then
contents=$(replace "$contents" "LIBDIR" "$LIBDIR")
contents=$(replace "$contents" "VERSION" "$version")
- printf '%s\n' "$contents" > "$scriptdir/bcl.pc"
+ printf '%s\n' "$contents" > "./bcl.pc"
pkg_config_install="\$(SAFE_INSTALL) \$(PC_INSTALL_ARGS) \"\$(BCL_PC)\" \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\""
pkg_config_uninstall="\$(RM) -f \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\""
@@ -1597,11 +1598,15 @@ src_files=$(find_src_files $unneeded)
for f in $src_files; do
o=$(replace_ext "$f" "c" "o")
- SRC_TARGETS=$(printf '%s\n\n%s: %s %s\n\t$(CC) $(CFLAGS) -o %s -c %s\n' \
+ o=$(basename "$o")
+ SRC_TARGETS=$(printf '%s\n\nsrc/%s: src %s %s\n\t$(CC) $(CFLAGS) -o src/%s -c %s\n' \
"$SRC_TARGETS" "$o" "$headers" "$f" "$o" "$f")
done
# Replace all the placeholders.
+contents=$(replace "$contents" "ROOTDIR" "$scriptdir")
+contents=$(replace "$contents" "BUILDDIR" "$builddir")
+
contents=$(replace "$contents" "HEADERS" "$headers")
contents=$(replace "$contents" "BC_ENABLED" "$bc")
@@ -1717,7 +1722,7 @@ contents=$(replace "$contents" "BC_DEFAULT_EXPR_EXIT" "$bc_default_expr_exit")
contents=$(replace "$contents" "DC_DEFAULT_EXPR_EXIT" "$dc_default_expr_exit")
# Do the first print to the Makefile.
-printf '%s\n%s\n\n' "$contents" "$SRC_TARGETS" > "$scriptdir/Makefile"
+printf '%s\n%s\n\n' "$contents" "$SRC_TARGETS" > "Makefile"
# Generate the individual test targets.
if [ "$bc" -ne 0 ]; then
@@ -1732,12 +1737,11 @@ if [ "$dc" -ne 0 ]; then
gen_err_tests dc $dc_test_exec
fi
-cd "$scriptdir"
-
# Copy the correct manuals to the expected places.
-cp -f manuals/bc/$manpage_args.1.md manuals/bc.1.md
-cp -f manuals/bc/$manpage_args.1 manuals/bc.1
-cp -f manuals/dc/$manpage_args.1.md manuals/dc.1.md
-cp -f manuals/dc/$manpage_args.1 manuals/dc.1
+mkdir -p manuals
+cp -f "$scriptdir/manuals/bc/$manpage_args.1.md" manuals/bc.1.md
+cp -f "$scriptdir/manuals/bc/$manpage_args.1" manuals/bc.1
+cp -f "$scriptdir/manuals/dc/$manpage_args.1.md" manuals/dc.1.md
+cp -f "$scriptdir/manuals/dc/$manpage_args.1" manuals/dc.1
make clean > /dev/null
diff --git a/scripts/exec-install.sh b/scripts/exec-install.sh
index 25d56c6f..f36caa37 100755
--- a/scripts/exec-install.sh
+++ b/scripts/exec-install.sh
@@ -29,7 +29,7 @@
# Print usage and exit with an error.
usage() {
- printf "usage: %s install_dir exec_suffix\n" "$0" 1>&2
+ printf "usage: %s install_dir exec_suffix [bindir]\n" "$0" 1>&2
exit 1
}
@@ -49,7 +49,12 @@ shift
exec_suffix="$1"
shift
-bindir="$scriptdir/../bin"
+if [ "$#" -gt 0 ]; then
+ bindir="$1"
+ shift
+else
+ bindir="$scriptdir/../bin"
+fi
# Install or symlink, depending on the type of file. If it's a file, install it.
# If it's a symlink, create an equivalent in the install directory.
diff --git a/scripts/karatsuba.py b/scripts/karatsuba.py
index b8505186..9aa1c2a5 100755
--- a/scripts/karatsuba.py
+++ b/scripts/karatsuba.py
@@ -49,9 +49,6 @@ testdir = os.path.dirname(script)
if testdir == "":
testdir = os.getcwd()
-# We want to be in the root directory.
-os.chdir(testdir + "/..")
-
print("\nWARNING: This script is for distro and package maintainers.")
print("It is for finding the optimal Karatsuba number.")
print("Though it only needs to be run once per release/platform,")
@@ -116,7 +113,7 @@ try:
except KeyError:
flags["CFLAGS"] = "-flto"
-p = run([ "./configure.sh", "-O3" ], flags)
+p = run([ "{}/../configure.sh".format(testdir), "-O3" ], flags)
if p.returncode != 0:
print("configure.sh returned an error ({}); exiting...".format(p.returncode))
sys.exit(p.returncode)
@@ -161,7 +158,7 @@ try:
# Configure and compile.
print("\nCompiling...\n")
- p = run([ "./configure.sh", "-O3", "-k{}".format(i) ], config_env)
+ p = run([ "{}/../configure.sh".format(testdir), "-O3", "-k{}".format(i) ], config_env)
if p.returncode != 0:
print("configure.sh returned an error ({}); exiting...".format(p.returncode))
diff --git a/tests/bc/timeconst.sh b/tests/bc/timeconst.sh
index 45e10c77..8b6e1ec5 100755
--- a/tests/bc/timeconst.sh
+++ b/tests/bc/timeconst.sh
@@ -50,7 +50,6 @@ else
bc="$testdir/../../bin/bc"
fi
-#
out1="$outputdir/bc_outputs/bc_timeconst.txt"
out2="$outputdir/bc_outputs/bc_timeconst_results.txt"