13aa99676SStefan Eßer#! /bin/sh 23aa99676SStefan Eßer# 33aa99676SStefan Eßer# SPDX-License-Identifier: BSD-2-Clause 43aa99676SStefan Eßer# 5a970610aSStefan Eßer# Copyright (c) 2018-2024 Gavin D. Howard and contributors. 63aa99676SStefan Eßer# 73aa99676SStefan Eßer# Redistribution and use in source and binary forms, with or without 83aa99676SStefan Eßer# modification, are permitted provided that the following conditions are met: 93aa99676SStefan Eßer# 103aa99676SStefan Eßer# * Redistributions of source code must retain the above copyright notice, this 113aa99676SStefan Eßer# list of conditions and the following disclaimer. 123aa99676SStefan Eßer# 133aa99676SStefan Eßer# * Redistributions in binary form must reproduce the above copyright notice, 143aa99676SStefan Eßer# this list of conditions and the following disclaimer in the documentation 153aa99676SStefan Eßer# and/or other materials provided with the distribution. 163aa99676SStefan Eßer# 173aa99676SStefan Eßer# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 183aa99676SStefan Eßer# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 193aa99676SStefan Eßer# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 203aa99676SStefan Eßer# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 213aa99676SStefan Eßer# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 223aa99676SStefan Eßer# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 233aa99676SStefan Eßer# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 243aa99676SStefan Eßer# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 253aa99676SStefan Eßer# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 263aa99676SStefan Eßer# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 273aa99676SStefan Eßer# POSSIBILITY OF SUCH DAMAGE. 283aa99676SStefan Eßer# 293aa99676SStefan Eßer 303aa99676SStefan Eßerscript="$0" 313aa99676SStefan Eßerscriptdir=$(dirname "$script") 323aa99676SStefan Eßerscript=$(basename "$script") 333aa99676SStefan Eßer 3410041e99SStefan Eßerbuilddir=$(pwd) 353aa99676SStefan Eßer 3610041e99SStefan Eßer. "$scriptdir/scripts/functions.sh" 3710328f8bSStefan Eßer 3844d4804dSStefan Eßer# Simply prints the help message and quits based on the argument. 3900698711SStefan Eßer# @param msg The help message to print. 403aa99676SStefan Eßerusage() { 413aa99676SStefan Eßer 423aa99676SStefan Eßer if [ $# -gt 0 ]; then 433aa99676SStefan Eßer 443aa99676SStefan Eßer _usage_val=1 453aa99676SStefan Eßer 46d101cdd6SStefan Eßer printf '%s\n\n' "$1" 473aa99676SStefan Eßer 483aa99676SStefan Eßer else 493aa99676SStefan Eßer _usage_val=0 503aa99676SStefan Eßer fi 513aa99676SStefan Eßer 5250696a6eSStefan Eßer printf 'usage:\n' 5350696a6eSStefan Eßer printf ' %s -h\n' "$script" 543aa99676SStefan Eßer printf ' %s --help\n' "$script" 55d101cdd6SStefan Eßer printf ' %s [-a|-bD|-dB|-c] [-CeEfgGHilmMNPrtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script" 56d101cdd6SStefan Eßer printf ' [-s SETTING] [-S SETTING] [-p TYPE]\n' 573aa99676SStefan Eßer printf ' %s \\\n' "$script" 5850696a6eSStefan Eßer printf ' [--library|--bc-only --disable-dc|--dc-only --disable-bc|--coverage] \\\n' 5950696a6eSStefan Eßer printf ' [--force --debug --disable-extra-math --disable-generated-tests] \\\n' 6044d4804dSStefan Eßer printf ' [--disable-history --disable-man-pages --disable-nls --disable-strip] \\\n' 61d101cdd6SStefan Eßer printf ' [--enable-editline] [--enable-readline] [--enable-internal-history] \\\n' 62d101cdd6SStefan Eßer printf ' [--disable-problematic-tests] [--install-all-locales] \\\n' 63d101cdd6SStefan Eßer printf ' [--opt=OPT_LEVEL] [--karatsuba-len=KARATSUBA_LEN] \\\n' 6410041e99SStefan Eßer printf ' [--set-default-on=SETTING] [--set-default-off=SETTING] \\\n' 65d101cdd6SStefan Eßer printf ' [--predefined-build-type=TYPE] \\\n' 663aa99676SStefan Eßer printf ' [--prefix=PREFIX] [--bindir=BINDIR] [--datarootdir=DATAROOTDIR] \\\n' 673aa99676SStefan Eßer printf ' [--datadir=DATADIR] [--mandir=MANDIR] [--man1dir=MAN1DIR] \\\n' 68d101cdd6SStefan Eßer printf ' [--man3dir=MAN3DIR]\n' 69d101cdd6SStefan Eßer 70d101cdd6SStefan Eßer if [ "$_usage_val" -ne 0 ]; then 71*12e0d316SStefan Eßer exit "$_usage_val" 72d101cdd6SStefan Eßer fi 73d101cdd6SStefan Eßer 743aa99676SStefan Eßer printf '\n' 7550696a6eSStefan Eßer printf ' -a, --library\n' 7644d4804dSStefan Eßer printf ' Build the libbcl instead of the programs. This is meant to be used with\n' 7750696a6eSStefan Eßer printf ' Other software like programming languages that want to make use of the\n' 7850696a6eSStefan Eßer printf ' parsing and math capabilities. This option will install headers using\n' 7950696a6eSStefan Eßer printf ' `make install`.\n' 803aa99676SStefan Eßer printf ' -b, --bc-only\n' 8150696a6eSStefan Eßer printf ' Build bc only. It is an error if "-d", "--dc-only", "-B", or\n' 8250696a6eSStefan Eßer printf ' "--disable-bc" are specified too.\n' 833aa99676SStefan Eßer printf ' -B, --disable-bc\n' 843aa99676SStefan Eßer printf ' Disable bc. It is an error if "-b", "--bc-only", "-D", or "--disable-dc"\n' 853aa99676SStefan Eßer printf ' are specified too.\n' 863aa99676SStefan Eßer printf ' -c, --coverage\n' 8744d4804dSStefan Eßer printf ' Generate test coverage code. Requires gcov and gcovr.\n' 883aa99676SStefan Eßer printf ' It is an error if either "-b" ("-D") or "-d" ("-B") is specified.\n' 893aa99676SStefan Eßer printf ' Requires a compiler that use gcc-compatible coverage options\n' 9010328f8bSStefan Eßer printf ' -C, --disable-clean\n' 9110328f8bSStefan Eßer printf ' Disable the clean that configure.sh does before configure.\n' 923aa99676SStefan Eßer printf ' -d, --dc-only\n' 9350696a6eSStefan Eßer printf ' Build dc only. It is an error if "-b", "--bc-only", "-D", or\n' 9450696a6eSStefan Eßer printf ' "--disable-dc" are specified too.\n' 953aa99676SStefan Eßer printf ' -D, --disable-dc\n' 9650696a6eSStefan Eßer printf ' Disable dc. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"\n' 973aa99676SStefan Eßer printf ' are specified too.\n' 9878bc019dSStefan Eßer printf ' -e, --enable-editline\n' 9978bc019dSStefan Eßer printf ' Enable the use of libedit/editline. This is meant for those users that\n' 100d101cdd6SStefan Eßer printf ' want vi-like or Emacs-like behavior in history. This option is ignored\n' 101d101cdd6SStefan Eßer printf ' if history is disabled. If the -r or -i options are given with this\n' 102d101cdd6SStefan Eßer printf ' option, the last occurrence of all of the three is used.\n' 1033aa99676SStefan Eßer printf ' -E, --disable-extra-math\n' 1043aa99676SStefan Eßer printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n' 1053aa99676SStefan Eßer printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n' 1063aa99676SStefan Eßer printf ' function). Additionally, this option disables the extra printing\n' 1073aa99676SStefan Eßer printf ' functions in the math library.\n' 1083aa99676SStefan Eßer printf ' -f, --force\n' 1093aa99676SStefan Eßer printf ' Force use of all enabled options, even if they do not work. This\n' 1103aa99676SStefan Eßer printf ' option is to allow the maintainer a way to test that certain options\n' 11100698711SStefan Eßer printf ' are not failing invisibly. (Development only.)\n' 1123aa99676SStefan Eßer printf ' -g, --debug\n' 1133aa99676SStefan Eßer printf ' Build in debug mode. Adds the "-g" flag, and if there are no\n' 1143aa99676SStefan Eßer printf ' other CFLAGS, and "-O" was not given, this also adds the "-O0"\n' 1153aa99676SStefan Eßer printf ' flag. If this flag is *not* given, "-DNDEBUG" is added to CPPFLAGS\n' 1163aa99676SStefan Eßer printf ' and a strip flag is added to the link stage.\n' 1173aa99676SStefan Eßer printf ' -G, --disable-generated-tests\n' 1183aa99676SStefan Eßer printf ' Disable generating tests. This is for platforms that do not have a\n' 1193aa99676SStefan Eßer printf ' GNU bc-compatible bc to generate tests.\n' 1203aa99676SStefan Eßer printf ' -h, --help\n' 1213aa99676SStefan Eßer printf ' Print this help message and exit.\n' 1223aa99676SStefan Eßer printf ' -H, --disable-history\n' 1233aa99676SStefan Eßer printf ' Disable history.\n' 124d101cdd6SStefan Eßer printf ' -i, --enable-internal-history\n' 125d101cdd6SStefan Eßer printf ' Enable the internal history implementation and do not depend on either\n' 126d101cdd6SStefan Eßer printf ' editline or readline. This option is ignored if history is disabled.\n' 127d101cdd6SStefan Eßer printf ' If this option is given along with -e and -r, the last occurrence of\n' 128d101cdd6SStefan Eßer printf ' all of the three is used.\n' 1293aa99676SStefan Eßer printf ' -k KARATSUBA_LEN, --karatsuba-len KARATSUBA_LEN\n' 130a970610aSStefan Eßer printf ' Set the karatsuba length to KARATSUBA_LEN (default is 32).\n' 1313aa99676SStefan Eßer printf ' It is an error if KARATSUBA_LEN is not a number or is less than 16.\n' 132cf7becd2SStefan Eßer printf ' -l, --install-all-locales\n' 133cf7becd2SStefan Eßer printf ' Installs all locales, regardless of how many are on the system. This\n' 134cf7becd2SStefan Eßer printf ' option is useful for package maintainers who want to make sure that\n' 135cf7becd2SStefan Eßer printf ' a package contains all of the locales that end users might need.\n' 13610328f8bSStefan Eßer printf ' -m, --enable-memcheck\n' 13710328f8bSStefan Eßer printf ' Enable memcheck mode, to ensure no memory leaks. For development only.\n' 1383aa99676SStefan Eßer printf ' -M, --disable-man-pages\n' 1393aa99676SStefan Eßer printf ' Disable installing manpages.\n' 1403aa99676SStefan Eßer printf ' -N, --disable-nls\n' 1413aa99676SStefan Eßer printf ' Disable POSIX locale (NLS) support.\n' 142d101cdd6SStefan Eßer printf ' ***WARNING***: Locales ignore the prefix because they *must* be\n' 143d101cdd6SStefan Eßer printf ' installed at a fixed location to work at all. If you do not want that\n' 144d101cdd6SStefan Eßer printf ' to happen, you must disable locales (NLS) completely.\n' 1453aa99676SStefan Eßer printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n' 1463aa99676SStefan Eßer printf ' Set the optimization level. This can also be included in the CFLAGS,\n' 1473aa99676SStefan Eßer printf ' but it is provided, so maintainers can build optimized debug builds.\n' 1483aa99676SStefan Eßer printf ' This is passed through to the compiler, so it must be supported.\n' 149d101cdd6SStefan Eßer printf ' -p TYPE, --predefined-build-type=TYPE\n' 150d101cdd6SStefan Eßer printf ' Sets a given predefined build type with specific defaults. This is for\n' 151d101cdd6SStefan Eßer printf ' easy setting of predefined builds. For example, to get a build that\n' 152d101cdd6SStefan Eßer printf ' acts like the GNU bc by default, TYPE should be "GNU" (without the\n' 153d101cdd6SStefan Eßer printf ' quotes) This option *must* come before any others that might change the\n' 154d101cdd6SStefan Eßer printf ' build options. Currently supported values for TYPE include: "BSD" (for\n' 155d101cdd6SStefan Eßer printf ' matching the BSD bc and BSD dc), "GNU" (for matching the GNU bc and\n' 156d101cdd6SStefan Eßer printf ' dc), "GDH" (for the preferred build of the author, Gavin D. Howard),\n' 157d101cdd6SStefan Eßer printf ' and "DBG" (for the preferred debug build of the author). This will\n' 158d101cdd6SStefan Eßer printf ' also automatically enable a release build (except for "DBG").\n' 159d101cdd6SStefan Eßer printf ' -P, --disable-problematic-tests\n' 160d101cdd6SStefan Eßer printf ' Disables problematic tests. These tests usually include tests that\n' 161d101cdd6SStefan Eßer printf ' can cause a SIGKILL because of too much memory usage.\n' 16278bc019dSStefan Eßer printf ' -r, --enable-readline\n' 16378bc019dSStefan Eßer printf ' Enable the use of libreadline/readline. This is meant for those users\n' 16478bc019dSStefan Eßer printf ' that want vi-like or Emacs-like behavior in history. This option is\n' 165d101cdd6SStefan Eßer printf ' ignored if history is disabled. If this option is given along with -e\n' 166a970610aSStefan Eßer printf ' and -i, the last occurrence of all of the three is used.\n' 16744d4804dSStefan Eßer printf ' -s SETTING, --set-default-on SETTING\n' 16844d4804dSStefan Eßer printf ' Set the default named by SETTING to on. See below for possible values\n' 16944d4804dSStefan Eßer printf ' for SETTING. For multiple instances of the -s or -S for the the same\n' 17044d4804dSStefan Eßer printf ' setting, the last one is used.\n' 17144d4804dSStefan Eßer printf ' -S SETTING, --set-default-off SETTING\n' 17244d4804dSStefan Eßer printf ' Set the default named by SETTING to off. See below for possible values\n' 17344d4804dSStefan Eßer printf ' for SETTING. For multiple instances of the -s or -S for the the same\n' 17444d4804dSStefan Eßer printf ' setting, the last one is used.\n' 17510328f8bSStefan Eßer printf ' -t, --enable-test-timing\n' 17610328f8bSStefan Eßer printf ' Enable the timing of tests. This is for development only.\n' 1773aa99676SStefan Eßer printf ' -T, --disable-strip\n' 1783aa99676SStefan Eßer printf ' Disable stripping symbols from the compiled binary or binaries.\n' 1793aa99676SStefan Eßer printf ' Stripping symbols only happens when debug mode is off.\n' 18010328f8bSStefan Eßer printf ' -v, --enable-valgrind\n' 18110328f8bSStefan Eßer printf ' Enable a build appropriate for valgrind. For development only.\n' 18210328f8bSStefan Eßer printf ' -z, --enable-fuzz-mode\n' 18310328f8bSStefan Eßer printf ' Enable fuzzing mode. THIS IS FOR DEVELOPMENT ONLY.\n' 184*12e0d316SStefan Eßer printf ' -Z, --enable-ossfuzz-mode\n' 185*12e0d316SStefan Eßer printf ' Enable fuzzing mode for OSS-Fuzz. THIS IS FOR DEVELOPMENT ONLY.\n' 1863aa99676SStefan Eßer printf ' --prefix PREFIX\n' 1873aa99676SStefan Eßer printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n' 1883aa99676SStefan Eßer printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n' 1893aa99676SStefan Eßer printf ' Default is "/usr/local".\n' 190d101cdd6SStefan Eßer printf ' ***WARNING***: Locales ignore the prefix because they *must* be\n' 191d101cdd6SStefan Eßer printf ' installed at a fixed location to work at all. If you do not want that to\n' 192d101cdd6SStefan Eßer printf ' happen, you must disable locales (NLS) completely.\n' 1933aa99676SStefan Eßer printf ' --bindir BINDIR\n' 19450696a6eSStefan Eßer printf ' The directory to install binaries in. Overrides "$BINDIR" if it exists.\n' 1953aa99676SStefan Eßer printf ' Default is "$PREFIX/bin".\n' 19650696a6eSStefan Eßer printf ' --includedir INCLUDEDIR\n' 19750696a6eSStefan Eßer printf ' The directory to install headers in. Overrides "$INCLUDEDIR" if it\n' 19850696a6eSStefan Eßer printf ' exists. Default is "$PREFIX/include".\n' 19950696a6eSStefan Eßer printf ' --libdir LIBDIR\n' 20050696a6eSStefan Eßer printf ' The directory to install libraries in. Overrides "$LIBDIR" if it exists.\n' 20150696a6eSStefan Eßer printf ' Default is "$PREFIX/lib".\n' 2023aa99676SStefan Eßer printf ' --datarootdir DATAROOTDIR\n' 2033aa99676SStefan Eßer printf ' The root location for data files. Overrides "$DATAROOTDIR" if it exists.\n' 2043aa99676SStefan Eßer printf ' Default is "$PREFIX/share".\n' 2053aa99676SStefan Eßer printf ' --datadir DATADIR\n' 2063aa99676SStefan Eßer printf ' The location for data files. Overrides "$DATADIR" if it exists.\n' 2073aa99676SStefan Eßer printf ' Default is "$DATAROOTDIR".\n' 2083aa99676SStefan Eßer printf ' --mandir MANDIR\n' 2093aa99676SStefan Eßer printf ' The location to install manpages to. Overrides "$MANDIR" if it exists.\n' 2103aa99676SStefan Eßer printf ' Default is "$DATADIR/man".\n' 2113aa99676SStefan Eßer printf ' --man1dir MAN1DIR\n' 2123aa99676SStefan Eßer printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n' 2133aa99676SStefan Eßer printf ' it exists. Default is "$MANDIR/man1".\n' 21450696a6eSStefan Eßer printf ' --man3dir MAN3DIR\n' 21550696a6eSStefan Eßer printf ' The location to install Section 3 manpages to. Overrides "$MAN3DIR" if\n' 21650696a6eSStefan Eßer printf ' it exists. Default is "$MANDIR/man3".\n' 2173aa99676SStefan Eßer printf '\n' 2183aa99676SStefan Eßer printf 'In addition, the following environment variables are used:\n' 2193aa99676SStefan Eßer printf '\n' 2203aa99676SStefan Eßer printf ' CC C compiler. Must be compatible with POSIX c99. If there is a\n' 2213aa99676SStefan Eßer printf ' space in the basename of the compiler, the items after the\n' 2223aa99676SStefan Eßer printf ' first space are assumed to be compiler flags, and in that case,\n' 2233aa99676SStefan Eßer printf ' the flags are automatically moved into CFLAGS. Default is\n' 2243aa99676SStefan Eßer printf ' "c99".\n' 2253aa99676SStefan Eßer printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99. If there is\n' 2263aa99676SStefan Eßer printf ' a space in the basename of the compiler, the items after the\n' 2273aa99676SStefan Eßer printf ' first space are assumed to be compiler flags, and in the case,\n' 2283aa99676SStefan Eßer printf ' the flags are automatically moved into HOSTCFLAGS. Default is\n' 2293aa99676SStefan Eßer printf ' "$CC".\n' 2303aa99676SStefan Eßer printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n' 2313aa99676SStefan Eßer printf ' CFLAGS C compiler flags.\n' 2323aa99676SStefan Eßer printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n' 2333aa99676SStefan Eßer printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n' 2343aa99676SStefan Eßer printf ' CPPFLAGS C preprocessor flags. Default is "".\n' 2353aa99676SStefan Eßer printf ' LDFLAGS Linker flags. Default is "".\n' 2363aa99676SStefan Eßer printf ' PREFIX The prefix to install to. Default is "/usr/local".\n' 2373aa99676SStefan Eßer printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n' 238d101cdd6SStefan Eßer printf ' ***WARNING***: Locales ignore the prefix because they *must* be\n' 239d101cdd6SStefan Eßer printf ' installed at a fixed location to work at all. If you do not\n' 240d101cdd6SStefan Eßer printf ' want that to happen, you must disable locales (NLS) completely.\n' 24150696a6eSStefan Eßer printf ' BINDIR The directory to install binaries in. Default is "$PREFIX/bin".\n' 24250696a6eSStefan Eßer printf ' INCLUDEDIR The directory to install header files in. Default is\n' 24350696a6eSStefan Eßer printf ' "$PREFIX/include".\n' 24450696a6eSStefan Eßer printf ' LIBDIR The directory to install libraries in. Default is\n' 24550696a6eSStefan Eßer printf ' "$PREFIX/lib".\n' 2463aa99676SStefan Eßer printf ' DATAROOTDIR The root location for data files. Default is "$PREFIX/share".\n' 2473aa99676SStefan Eßer printf ' DATADIR The location for data files. Default is "$DATAROOTDIR".\n' 2483aa99676SStefan Eßer printf ' MANDIR The location to install manpages to. Default is "$DATADIR/man".\n' 2493aa99676SStefan Eßer printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n' 2503aa99676SStefan Eßer printf ' "$MANDIR/man1".\n' 25150696a6eSStefan Eßer printf ' MAN3DIR The location to install Section 3 manpages to. Default is\n' 25250696a6eSStefan Eßer printf ' "$MANDIR/man3".\n' 2533aa99676SStefan Eßer printf ' NLSPATH The location to install locale catalogs to. Must be an absolute\n' 2543aa99676SStefan Eßer printf ' path (or contain one). This is treated the same as the POSIX\n' 2553aa99676SStefan Eßer printf ' definition of $NLSPATH (see POSIX environment variables for\n' 2563aa99676SStefan Eßer printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n' 25710041e99SStefan Eßer printf ' PC_PATH The location to install pkg-config files to. Must be an\n' 25810041e99SStefan Eßer printf ' path or contain one. Default is the first path given by the\n' 25910041e99SStefan Eßer printf ' output of `pkg-config --variable=pc_path pkg-config`.\n' 2603aa99676SStefan Eßer printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n' 2613aa99676SStefan Eßer printf ' interfere with other installed bc executables. Default is "".\n' 2623aa99676SStefan Eßer printf ' EXECPREFIX The prefix to append to the executable names, used to not\n' 2633aa99676SStefan Eßer printf ' interfere with other installed bc executables. Default is "".\n' 2643aa99676SStefan Eßer printf ' DESTDIR For package creation. Default is "". If it is empty when\n' 2653aa99676SStefan Eßer printf ' `%s` is run, it can also be passed to `make install`\n' "$script" 2663aa99676SStefan Eßer printf ' later as an environment variable. If both are specified,\n' 2673aa99676SStefan Eßer printf ' the one given to `%s` takes precedence.\n' "$script" 2683aa99676SStefan Eßer printf ' LONG_BIT The number of bits in a C `long` type. This is mostly for the\n' 2693aa99676SStefan Eßer printf ' embedded space since this `bc` uses `long`s internally for\n' 2703aa99676SStefan Eßer printf ' overflow checking. In C99, a `long` is required to be 32 bits.\n' 2713aa99676SStefan Eßer printf ' For most normal desktop systems, setting this is unnecessary,\n' 2723aa99676SStefan Eßer printf ' except that 32-bit platforms with 64-bit longs may want to set\n' 2733aa99676SStefan Eßer printf ' it to `32`. Default is the default of `LONG_BIT` for the target\n' 2743aa99676SStefan Eßer printf ' platform. Minimum allowed is `32`. It is a build time error if\n' 2753aa99676SStefan Eßer printf ' the specified value of `LONG_BIT` is greater than the default\n' 2763aa99676SStefan Eßer printf ' value of `LONG_BIT` for the target platform.\n' 2773aa99676SStefan Eßer printf ' GEN_HOST Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to\n' 2783aa99676SStefan Eßer printf ' produce the C files that contain the help texts as well as the\n' 2793aa99676SStefan Eßer printf ' math libraries. By default, `gen/strgen.c` is used, compiled by\n' 2803aa99676SStefan Eßer printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n' 2813aa99676SStefan Eßer printf ' removes the need to compile and run an executable on the host\n' 2823aa99676SStefan Eßer printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n' 28378bc019dSStefan Eßer printf ' `gen/lib2.bc` is over 4095 characters, the max supported length\n' 28478bc019dSStefan Eßer printf ' of a string literal in C99, and `gen/strgen.sh` generates a\n' 28578bc019dSStefan Eßer printf ' string literal instead of an array, as `gen/strgen.c` does. For\n' 28678bc019dSStefan Eßer printf ' most production-ready compilers, this limit probably is not\n' 2873aa99676SStefan Eßer printf ' enforced, but it could be. Both options are still available for\n' 2883aa99676SStefan Eßer printf ' this reason. If you are sure your compiler does not have the\n' 2893aa99676SStefan Eßer printf ' limit and do not want to compile and run a binary on the host\n' 2903aa99676SStefan Eßer printf ' machine, set this variable to "0". Any other value, or a\n' 2913aa99676SStefan Eßer printf ' non-existent value, will cause the build system to compile and\n' 2923aa99676SStefan Eßer printf ' run `gen/strgen.c`. Default is "".\n' 2933aa99676SStefan Eßer printf ' GEN_EMU Emulator to run string generator code under (leave empty if not\n' 2943aa99676SStefan Eßer printf ' necessary). This is not necessary when using `gen/strgen.sh`.\n' 2953aa99676SStefan Eßer printf ' Default is "".\n' 2963aa99676SStefan Eßer printf '\n' 2973aa99676SStefan Eßer printf 'WARNING: even though `configure.sh` supports both option types, short and\n' 2983aa99676SStefan Eßer printf 'long, it does not support handling both at the same time. Use only one type.\n' 29944d4804dSStefan Eßer printf '\n' 30044d4804dSStefan Eßer printf 'Settings\n' 30144d4804dSStefan Eßer printf '========\n' 30244d4804dSStefan Eßer printf '\n' 30344d4804dSStefan Eßer printf 'bc and dc have some settings that, while they cannot be removed by build time\n' 30444d4804dSStefan Eßer printf 'options, can have their defaults changed at build time by packagers. Users are\n' 30544d4804dSStefan Eßer printf 'also able to change each setting with environment variables.\n' 30644d4804dSStefan Eßer printf '\n' 30744d4804dSStefan Eßer printf 'The following is a table of settings, along with their default values and the\n' 30844d4804dSStefan Eßer printf 'environment variables users can use to change them. (For the defaults, non-zero\n' 30944d4804dSStefan Eßer printf 'means on, and zero means off.)\n' 31044d4804dSStefan Eßer printf '\n' 31144d4804dSStefan Eßer printf '| Setting | Description | Default | Env Variable |\n' 31244d4804dSStefan Eßer printf '| =============== | ==================== | ============ | ==================== |\n' 31344d4804dSStefan Eßer printf '| bc.banner | Whether to display | 0 | BC_BANNER |\n' 31444d4804dSStefan Eßer printf '| | the bc version | | |\n' 31544d4804dSStefan Eßer printf '| | banner when in | | |\n' 31644d4804dSStefan Eßer printf '| | interactive mode. | | |\n' 31744d4804dSStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 31844d4804dSStefan Eßer printf '| bc.sigint_reset | Whether SIGINT will | 1 | BC_SIGINT_RESET |\n' 31944d4804dSStefan Eßer printf '| | reset bc, instead of | | |\n' 32044d4804dSStefan Eßer printf '| | exiting, when in | | |\n' 32144d4804dSStefan Eßer printf '| | interactive mode. | | |\n' 32244d4804dSStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 32344d4804dSStefan Eßer printf '| dc.sigint_reset | Whether SIGINT will | 1 | DC_SIGINT_RESET |\n' 32444d4804dSStefan Eßer printf '| | reset dc, instead of | | |\n' 32544d4804dSStefan Eßer printf '| | exiting, when in | | |\n' 32644d4804dSStefan Eßer printf '| | interactive mode. | | |\n' 32744d4804dSStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 32844d4804dSStefan Eßer printf '| bc.tty_mode | Whether TTY mode for | 1 | BC_TTY_MODE |\n' 32944d4804dSStefan Eßer printf '| | bc should be on when | | |\n' 33044d4804dSStefan Eßer printf '| | available. | | |\n' 33144d4804dSStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 33244d4804dSStefan Eßer printf '| dc.tty_mode | Whether TTY mode for | 0 | BC_TTY_MODE |\n' 33344d4804dSStefan Eßer printf '| | dc should be on when | | |\n' 33444d4804dSStefan Eßer printf '| | available. | | |\n' 33544d4804dSStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 33644d4804dSStefan Eßer printf '| bc.prompt | Whether the prompt | $BC_TTY_MODE | BC_PROMPT |\n' 33744d4804dSStefan Eßer printf '| | for bc should be on | | |\n' 33844d4804dSStefan Eßer printf '| | in tty mode. | | |\n' 33944d4804dSStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 34044d4804dSStefan Eßer printf '| dc.prompt | Whether the prompt | $DC_TTY_MODE | DC_PROMPT |\n' 34144d4804dSStefan Eßer printf '| | for dc should be on | | |\n' 34244d4804dSStefan Eßer printf '| | in tty mode. | | |\n' 34344d4804dSStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 34410041e99SStefan Eßer printf '| bc.expr_exit | Whether to exit bc | 1 | BC_EXPR_EXIT |\n' 34510041e99SStefan Eßer printf '| | if an expression or | | |\n' 34610041e99SStefan Eßer printf '| | expression file is | | |\n' 34710041e99SStefan Eßer printf '| | given with the -e or | | |\n' 34810041e99SStefan Eßer printf '| | -f options. | | |\n' 34910041e99SStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 35010041e99SStefan Eßer printf '| dc.expr_exit | Whether to exit dc | 1 | DC_EXPR_EXIT |\n' 35110041e99SStefan Eßer printf '| | if an expression or | | |\n' 35210041e99SStefan Eßer printf '| | expression file is | | |\n' 35310041e99SStefan Eßer printf '| | given with the -e or | | |\n' 35410041e99SStefan Eßer printf '| | -f options. | | |\n' 35510041e99SStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 356d101cdd6SStefan Eßer printf '| bc.digit_clamp | Whether to have bc | 0 | BC_DIGIT_CLAMP |\n' 357d101cdd6SStefan Eßer printf '| | clamp digits that | | |\n' 358d101cdd6SStefan Eßer printf '| | are greater than or | | |\n' 359d101cdd6SStefan Eßer printf '| | equal to the current | | |\n' 360d101cdd6SStefan Eßer printf '| | ibase when parsing | | |\n' 361d101cdd6SStefan Eßer printf '| | numbers. | | |\n' 362d101cdd6SStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 363d101cdd6SStefan Eßer printf '| dc.digit_clamp | Whether to have dc | 0 | DC_DIGIT_CLAMP |\n' 364d101cdd6SStefan Eßer printf '| | clamp digits that | | |\n' 365d101cdd6SStefan Eßer printf '| | are greater than or | | |\n' 366d101cdd6SStefan Eßer printf '| | equal to the current | | |\n' 367d101cdd6SStefan Eßer printf '| | ibase when parsing | | |\n' 368d101cdd6SStefan Eßer printf '| | numbers. | | |\n' 369d101cdd6SStefan Eßer printf '| --------------- | -------------------- | ------------ | -------------------- |\n' 37044d4804dSStefan Eßer printf '\n' 37144d4804dSStefan Eßer printf 'These settings are not meant to be changed on a whim. They are meant to ensure\n' 37244d4804dSStefan Eßer printf 'that this bc and dc will conform to the expectations of the user on each\n' 37344d4804dSStefan Eßer printf 'platform.\n' 3743aa99676SStefan Eßer 3753aa99676SStefan Eßer exit "$_usage_val" 3763aa99676SStefan Eßer} 3773aa99676SStefan Eßer 37844d4804dSStefan Eßer# Replaces a file extension in a filename. This is used mostly to turn filenames 37944d4804dSStefan Eßer# like `src/num.c` into `src/num.o`. In other words, it helps to link targets to 38044d4804dSStefan Eßer# the files they depend on. 38144d4804dSStefan Eßer# 38244d4804dSStefan Eßer# @param file The filename. 38344d4804dSStefan Eßer# @param ext1 The extension to replace. 38444d4804dSStefan Eßer# @param ext2 The new extension. 3853aa99676SStefan Eßerreplace_ext() { 3863aa99676SStefan Eßer 3873aa99676SStefan Eßer if [ "$#" -ne 3 ]; then 3883aa99676SStefan Eßer err_exit "Invalid number of args to $0" 3893aa99676SStefan Eßer fi 3903aa99676SStefan Eßer 3913aa99676SStefan Eßer _replace_ext_file="$1" 3923aa99676SStefan Eßer _replace_ext_ext1="$2" 3933aa99676SStefan Eßer _replace_ext_ext2="$3" 3943aa99676SStefan Eßer 3959a995fe1SStefan Eßer _replace_ext_result="${_replace_ext_file%.$_replace_ext_ext1}.$_replace_ext_ext2" 3963aa99676SStefan Eßer 3973aa99676SStefan Eßer printf '%s\n' "$_replace_ext_result" 3983aa99676SStefan Eßer} 3993aa99676SStefan Eßer 40044d4804dSStefan Eßer# Replaces a file extension in every filename given in a list. The list is just 40144d4804dSStefan Eßer# a space-separated list of words, so filenames are expected to *not* have 40244d4804dSStefan Eßer# spaces in them. See the documentation for `replace_ext()`. 40344d4804dSStefan Eßer# 40444d4804dSStefan Eßer# @param files The list of space-separated filenames to replace extensions for. 40544d4804dSStefan Eßer# @param ext1 The extension to replace. 40644d4804dSStefan Eßer# @param ext2 The new extension. 4073aa99676SStefan Eßerreplace_exts() { 4083aa99676SStefan Eßer 4093aa99676SStefan Eßer if [ "$#" -ne 3 ]; then 4103aa99676SStefan Eßer err_exit "Invalid number of args to $0" 4113aa99676SStefan Eßer fi 4123aa99676SStefan Eßer 4133aa99676SStefan Eßer _replace_exts_files="$1" 4143aa99676SStefan Eßer _replace_exts_ext1="$2" 4153aa99676SStefan Eßer _replace_exts_ext2="$3" 4163aa99676SStefan Eßer 4173aa99676SStefan Eßer for _replace_exts_file in $_replace_exts_files; do 4183aa99676SStefan Eßer _replace_exts_new_name=$(replace_ext "$_replace_exts_file" "$_replace_exts_ext1" "$_replace_exts_ext2") 4193aa99676SStefan Eßer _replace_exts_result="$_replace_exts_result $_replace_exts_new_name" 4203aa99676SStefan Eßer done 4213aa99676SStefan Eßer 4223aa99676SStefan Eßer printf '%s\n' "$_replace_exts_result" 4233aa99676SStefan Eßer} 4243aa99676SStefan Eßer 42544d4804dSStefan Eßer# Finds a placeholder in @a str and replaces it. This is the workhorse of 42644d4804dSStefan Eßer# configure.sh. It's what replaces placeholders in Makefile.in with the data 42744d4804dSStefan Eßer# needed for the chosen build. Below, you will see a lot of calls to this 42844d4804dSStefan Eßer# function. 42944d4804dSStefan Eßer# 43044d4804dSStefan Eßer# Note that needle can never contain an exclamation point. For more information, 43144d4804dSStefan Eßer# see substring_replace() in scripts/functions.sh. 43244d4804dSStefan Eßer# 43344d4804dSStefan Eßer# @param str The string to find and replace placeholders in. 43444d4804dSStefan Eßer# @param needle The placeholder name. 43544d4804dSStefan Eßer# @param replacement The string to use to replace the placeholder. 4363aa99676SStefan Eßerreplace() { 4373aa99676SStefan Eßer 4383aa99676SStefan Eßer if [ "$#" -ne 3 ]; then 4393aa99676SStefan Eßer err_exit "Invalid number of args to $0" 4403aa99676SStefan Eßer fi 4413aa99676SStefan Eßer 4423aa99676SStefan Eßer _replace_str="$1" 4433aa99676SStefan Eßer _replace_needle="$2" 4443aa99676SStefan Eßer _replace_replacement="$3" 4453aa99676SStefan Eßer 4463aa99676SStefan Eßer substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement" 4473aa99676SStefan Eßer} 4483aa99676SStefan Eßer 44944d4804dSStefan Eßer# This function finds all the source files that need to be built. If there is 45044d4804dSStefan Eßer# only one argument and it is empty, then all source files are built. Otherwise, 45144d4804dSStefan Eßer# the arguments are all assumed to be source files that should *not* be built. 45210328f8bSStefan Eßerfind_src_files() { 45310328f8bSStefan Eßer 45410041e99SStefan Eßer _find_src_files_args="" 45510041e99SStefan Eßer 45610328f8bSStefan Eßer if [ "$#" -ge 1 ] && [ "$1" != "" ]; then 45710328f8bSStefan Eßer 45810328f8bSStefan Eßer while [ "$#" -ge 1 ]; do 45910328f8bSStefan Eßer _find_src_files_a="${1## }" 46010328f8bSStefan Eßer shift 46110041e99SStefan Eßer _find_src_files_args=$(printf '%s\n%s/src/%s\n' "$_find_src_files_args" "$scriptdir" "${_find_src_files_a}") 46210328f8bSStefan Eßer done 46310328f8bSStefan Eßer 46410328f8bSStefan Eßer fi 46510328f8bSStefan Eßer 466e6857bd4SStefan Eßer _find_src_files_files=$(find "$scriptdir/src" -depth -name "*.c" -print | LC_ALL=C sort) 46710041e99SStefan Eßer 46810041e99SStefan Eßer _find_src_files_result="" 46910041e99SStefan Eßer 47010041e99SStefan Eßer for _find_src_files_f in $_find_src_files_files; do 47110041e99SStefan Eßer 47210041e99SStefan Eßer # If this is true, the file is part of args, and therefore, unneeded. 47310041e99SStefan Eßer if [ "${_find_src_files_args##*$_find_src_files_f}" != "${_find_src_files_args}" ]; then 47410041e99SStefan Eßer continue 47510041e99SStefan Eßer fi 47610041e99SStefan Eßer 47710041e99SStefan Eßer _find_src_files_result=$(printf '%s\n%s\n' "$_find_src_files_result" "$_find_src_files_f") 47810041e99SStefan Eßer 47910041e99SStefan Eßer done 48010041e99SStefan Eßer 48110041e99SStefan Eßer printf '%s\n' "$_find_src_files_result" 48210328f8bSStefan Eßer} 48310328f8bSStefan Eßer 48444d4804dSStefan Eßer# This function generates a list of files to go into the Makefile. It generates 48544d4804dSStefan Eßer# the list of object files, as well as the list of test coverage files. 48644d4804dSStefan Eßer# 48744d4804dSStefan Eßer# @param contents The contents of the Makefile template to put the list of 48844d4804dSStefan Eßer# files into. 48950696a6eSStefan Eßergen_file_list() { 4903aa99676SStefan Eßer 49150696a6eSStefan Eßer if [ "$#" -lt 1 ]; then 4923aa99676SStefan Eßer err_exit "Invalid number of args to $0" 4933aa99676SStefan Eßer fi 4943aa99676SStefan Eßer 49550696a6eSStefan Eßer _gen_file_list_contents="$1" 4963aa99676SStefan Eßer shift 4973aa99676SStefan Eßer 49850696a6eSStefan Eßer if [ "$#" -ge 1 ]; then 49910328f8bSStefan Eßer _gen_file_list_unneeded="$@" 5003aa99676SStefan Eßer else 50110328f8bSStefan Eßer _gen_file_list_unneeded="" 5023aa99676SStefan Eßer fi 5033aa99676SStefan Eßer 50450696a6eSStefan Eßer _gen_file_list_needle_src="SRC" 50550696a6eSStefan Eßer _gen_file_list_needle_obj="OBJ" 50650696a6eSStefan Eßer _gen_file_list_needle_gcda="GCDA" 50750696a6eSStefan Eßer _gen_file_list_needle_gcno="GCNO" 50850696a6eSStefan Eßer 50910328f8bSStefan Eßer _gen_file_list_replacement=$(find_src_files $_gen_file_list_unneeded | tr '\n' ' ') 51050696a6eSStefan Eßer _gen_file_list_contents=$(replace "$_gen_file_list_contents" \ 51150696a6eSStefan Eßer "$_gen_file_list_needle_src" "$_gen_file_list_replacement") 51250696a6eSStefan Eßer 51310041e99SStefan Eßer _gen_file_list_cbases="" 51410041e99SStefan Eßer 51510041e99SStefan Eßer for _gen_file_list_f in $_gen_file_list_replacement; do 51610041e99SStefan Eßer _gen_file_list_b=$(basename "$_gen_file_list_f") 51710041e99SStefan Eßer _gen_file_list_cbases="$_gen_file_list_cbases src/$_gen_file_list_b" 51810041e99SStefan Eßer done 51910041e99SStefan Eßer 52010041e99SStefan Eßer _gen_file_list_replacement=$(replace_exts "$_gen_file_list_cbases" "c" "o") 52150696a6eSStefan Eßer _gen_file_list_contents=$(replace "$_gen_file_list_contents" \ 52250696a6eSStefan Eßer "$_gen_file_list_needle_obj" "$_gen_file_list_replacement") 52350696a6eSStefan Eßer 52450696a6eSStefan Eßer _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "o" "gcda") 52550696a6eSStefan Eßer _gen_file_list_contents=$(replace "$_gen_file_list_contents" \ 52650696a6eSStefan Eßer "$_gen_file_list_needle_gcda" "$_gen_file_list_replacement") 52750696a6eSStefan Eßer 52850696a6eSStefan Eßer _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "gcda" "gcno") 52950696a6eSStefan Eßer _gen_file_list_contents=$(replace "$_gen_file_list_contents" \ 53050696a6eSStefan Eßer "$_gen_file_list_needle_gcno" "$_gen_file_list_replacement") 53150696a6eSStefan Eßer 53250696a6eSStefan Eßer printf '%s\n' "$_gen_file_list_contents" 5333aa99676SStefan Eßer} 5343aa99676SStefan Eßer 53544d4804dSStefan Eßer# Generates the proper test targets for each test to have its own target. This 53644d4804dSStefan Eßer# allows `make test` to run in parallel. 53744d4804dSStefan Eßer# 53844d4804dSStefan Eßer# @param name Which calculator to generate tests for. 53944d4804dSStefan Eßer# @param extra_math An integer that, if non-zero, activates extra math tests. 54044d4804dSStefan Eßer# @param time_tests An integer that, if non-zero, tells the test suite to time 54144d4804dSStefan Eßer# the execution of each test. 542d43fa8efSStefan Eßergen_std_tests() { 54310328f8bSStefan Eßer 544d43fa8efSStefan Eßer _gen_std_tests_name="$1" 54510328f8bSStefan Eßer shift 54610328f8bSStefan Eßer 547d43fa8efSStefan Eßer _gen_std_tests_extra_math="$1" 54810328f8bSStefan Eßer shift 54910328f8bSStefan Eßer 550d43fa8efSStefan Eßer _gen_std_tests_time_tests="$1" 55110328f8bSStefan Eßer shift 55210328f8bSStefan Eßer 553d43fa8efSStefan Eßer _gen_std_tests_extra_required=$(cat "$scriptdir/tests/extra_required.txt") 55410328f8bSStefan Eßer 555d43fa8efSStefan Eßer for _gen_std_tests_t in $(cat "$scriptdir/tests/$_gen_std_tests_name/all.txt"); do 55610328f8bSStefan Eßer 557d43fa8efSStefan Eßer if [ "$_gen_std_tests_extra_math" -eq 0 ]; then 55810328f8bSStefan Eßer 559d43fa8efSStefan Eßer if [ -z "${_gen_std_tests_extra_required##*$_gen_std_tests_t*}" ]; then 56010328f8bSStefan Eßer printf 'test_%s_%s:\n\t@printf "Skipping %s %s\\n"\n\n' \ 561d43fa8efSStefan Eßer "$_gen_std_tests_name" "$_gen_std_tests_t" "$_gen_std_tests_name" \ 56210041e99SStefan Eßer "$_gen_std_tests_t" >> "Makefile" 56310328f8bSStefan Eßer continue 56410328f8bSStefan Eßer fi 56510328f8bSStefan Eßer 56610328f8bSStefan Eßer fi 56710328f8bSStefan Eßer 568d101cdd6SStefan Eßer printf 'test_%s_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh $(TESTSDIR)/test.sh %s %s %s %s %s\n\n' \ 56910041e99SStefan Eßer "$_gen_std_tests_name" "$_gen_std_tests_t" "$builddir" "$_gen_std_tests_name" \ 570d43fa8efSStefan Eßer "$_gen_std_tests_t" "$generate_tests" "$time_tests" \ 57110041e99SStefan Eßer "$*" >> "Makefile" 57210328f8bSStefan Eßer 57310328f8bSStefan Eßer done 57410328f8bSStefan Eßer} 57510328f8bSStefan Eßer 57644d4804dSStefan Eßer# Generates a list of test targets that will be used as prerequisites for other 57744d4804dSStefan Eßer# targets. 57844d4804dSStefan Eßer# 57944d4804dSStefan Eßer# @param name The name of the calculator to generate test targets for. 580d43fa8efSStefan Eßergen_std_test_targets() { 58110328f8bSStefan Eßer 582d43fa8efSStefan Eßer _gen_std_test_targets_name="$1" 58310328f8bSStefan Eßer shift 58410328f8bSStefan Eßer 585d43fa8efSStefan Eßer _gen_std_test_targets_tests=$(cat "$scriptdir/tests/${_gen_std_test_targets_name}/all.txt") 58610328f8bSStefan Eßer 587d43fa8efSStefan Eßer for _gen_std_test_targets_t in $_gen_std_test_targets_tests; do 588d43fa8efSStefan Eßer printf ' test_%s_%s' "$_gen_std_test_targets_name" "$_gen_std_test_targets_t" 589d43fa8efSStefan Eßer done 590d43fa8efSStefan Eßer 591d43fa8efSStefan Eßer printf '\n' 592d43fa8efSStefan Eßer} 593d43fa8efSStefan Eßer 594d43fa8efSStefan Eßer# Generates the proper test targets for each error test to have its own target. 595d43fa8efSStefan Eßer# This allows `make test_bc_errors` and `make test_dc_errors` to run in 596d43fa8efSStefan Eßer# parallel. 597d43fa8efSStefan Eßer# 598d43fa8efSStefan Eßer# @param name Which calculator to generate tests for. 599d43fa8efSStefan Eßergen_err_tests() { 600d43fa8efSStefan Eßer 601d43fa8efSStefan Eßer _gen_err_tests_name="$1" 602d43fa8efSStefan Eßer shift 603d43fa8efSStefan Eßer 604d43fa8efSStefan Eßer _gen_err_tests_fs=$(ls "$scriptdir/tests/$_gen_err_tests_name/errors/") 605d43fa8efSStefan Eßer 606d43fa8efSStefan Eßer for _gen_err_tests_t in $_gen_err_tests_fs; do 607d43fa8efSStefan Eßer 608d101cdd6SStefan Eßer printf 'test_%s_error_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh $(TESTSDIR)/error.sh %s %s %s %s\n\n' \ 60910041e99SStefan Eßer "$_gen_err_tests_name" "$_gen_err_tests_t" "$builddir" "$_gen_err_tests_name" \ 610d101cdd6SStefan Eßer "$_gen_err_tests_t" "$problematic_tests" "$*" >> "Makefile" 611d43fa8efSStefan Eßer 612d43fa8efSStefan Eßer done 613d43fa8efSStefan Eßer 614d43fa8efSStefan Eßer} 615d43fa8efSStefan Eßer 616d43fa8efSStefan Eßer# Generates a list of error test targets that will be used as prerequisites for 617d43fa8efSStefan Eßer# other targets. 618d43fa8efSStefan Eßer# 619d43fa8efSStefan Eßer# @param name The name of the calculator to generate test targets for. 620d43fa8efSStefan Eßergen_err_test_targets() { 621d43fa8efSStefan Eßer 622d43fa8efSStefan Eßer _gen_err_test_targets_name="$1" 623d43fa8efSStefan Eßer shift 624d43fa8efSStefan Eßer 625d43fa8efSStefan Eßer _gen_err_test_targets_tests=$(ls "$scriptdir/tests/$_gen_err_test_targets_name/errors/") 626d43fa8efSStefan Eßer 627d43fa8efSStefan Eßer for _gen_err_test_targets_t in $_gen_err_test_targets_tests; do 628d43fa8efSStefan Eßer printf ' test_%s_error_%s' "$_gen_err_test_targets_name" "$_gen_err_test_targets_t" 62910328f8bSStefan Eßer done 63010328f8bSStefan Eßer 63110328f8bSStefan Eßer printf '\n' 63210328f8bSStefan Eßer} 63310328f8bSStefan Eßer 63444d4804dSStefan Eßer# Generates the proper script test targets for each script test to have its own 63544d4804dSStefan Eßer# target. This allows `make test` to run in parallel. 63644d4804dSStefan Eßer# 63744d4804dSStefan Eßer# @param name Which calculator to generate tests for. 63844d4804dSStefan Eßer# @param extra_math An integer that, if non-zero, activates extra math tests. 63944d4804dSStefan Eßer# @param generate An integer that, if non-zero, activates generated tests. 64044d4804dSStefan Eßer# @param time_tests An integer that, if non-zero, tells the test suite to time 64144d4804dSStefan Eßer# the execution of each test. 64210328f8bSStefan Eßergen_script_tests() { 64310328f8bSStefan Eßer 64410328f8bSStefan Eßer _gen_script_tests_name="$1" 64510328f8bSStefan Eßer shift 64610328f8bSStefan Eßer 64710328f8bSStefan Eßer _gen_script_tests_extra_math="$1" 64810328f8bSStefan Eßer shift 64910328f8bSStefan Eßer 65010328f8bSStefan Eßer _gen_script_tests_generate="$1" 65110328f8bSStefan Eßer shift 65210328f8bSStefan Eßer 65310328f8bSStefan Eßer _gen_script_tests_time="$1" 65410328f8bSStefan Eßer shift 65510328f8bSStefan Eßer 65610328f8bSStefan Eßer _gen_script_tests_tests=$(cat "$scriptdir/tests/$_gen_script_tests_name/scripts/all.txt") 65710328f8bSStefan Eßer 65810328f8bSStefan Eßer for _gen_script_tests_f in $_gen_script_tests_tests; do 65910328f8bSStefan Eßer 66010328f8bSStefan Eßer _gen_script_tests_b=$(basename "$_gen_script_tests_f" ".${_gen_script_tests_name}") 66110328f8bSStefan Eßer 662d101cdd6SStefan Eßer 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' \ 66310041e99SStefan Eßer "$_gen_script_tests_name" "$_gen_script_tests_b" "$builddir" "$_gen_script_tests_name" \ 66410328f8bSStefan Eßer "$_gen_script_tests_f" "$_gen_script_tests_extra_math" "$_gen_script_tests_generate" \ 66510041e99SStefan Eßer "$_gen_script_tests_time" "$*" >> "Makefile" 66610328f8bSStefan Eßer done 66710328f8bSStefan Eßer} 66810328f8bSStefan Eßer 66944d4804dSStefan Eßerset_default() { 67044d4804dSStefan Eßer 67144d4804dSStefan Eßer _set_default_on="$1" 67244d4804dSStefan Eßer shift 67344d4804dSStefan Eßer 67444d4804dSStefan Eßer _set_default_name="$1" 67544d4804dSStefan Eßer shift 67644d4804dSStefan Eßer 67744d4804dSStefan Eßer # The reason that the variables that are being set do not have the same 67844d4804dSStefan Eßer # non-collision avoidance that the other variables do is that we *do* want 67944d4804dSStefan Eßer # the settings of these variables to leak out of the function. They adjust 68044d4804dSStefan Eßer # the settings outside of the function. 68144d4804dSStefan Eßer case "$_set_default_name" in 68244d4804dSStefan Eßer 68344d4804dSStefan Eßer bc.banner) bc_default_banner="$_set_default_on" ;; 68444d4804dSStefan Eßer bc.sigint_reset) bc_default_sigint_reset="$_set_default_on" ;; 68544d4804dSStefan Eßer dc.sigint_reset) dc_default_sigint_reset="$_set_default_on" ;; 68644d4804dSStefan Eßer bc.tty_mode) bc_default_tty_mode="$_set_default_on" ;; 68744d4804dSStefan Eßer dc.tty_mode) dc_default_tty_mode="$_set_default_on" ;; 68844d4804dSStefan Eßer bc.prompt) bc_default_prompt="$_set_default_on" ;; 68944d4804dSStefan Eßer dc.prompt) dc_default_prompt="$_set_default_on" ;; 69010041e99SStefan Eßer bc.expr_exit) bc_default_expr_exit="$_set_default_on";; 69110041e99SStefan Eßer dc.expr_exit) dc_default_expr_exit="$_set_default_on";; 692d101cdd6SStefan Eßer bc.digit_clamp) bc_default_digit_clamp="$_set_default_on";; 693d101cdd6SStefan Eßer dc.digit_clamp) dc_default_digit_clamp="$_set_default_on";; 69444d4804dSStefan Eßer ?) usage "Invalid setting: $_set_default_name" ;; 69544d4804dSStefan Eßer 69644d4804dSStefan Eßer esac 69744d4804dSStefan Eßer} 69844d4804dSStefan Eßer 699d101cdd6SStefan Eßerpredefined_build() { 700d101cdd6SStefan Eßer 701d101cdd6SStefan Eßer _predefined_build_type="$1" 702d101cdd6SStefan Eßer shift 703d101cdd6SStefan Eßer 704d101cdd6SStefan Eßer # The reason that the variables that are being set do not have the same 705d101cdd6SStefan Eßer # non-collision avoidance that the other variables do is that we *do* want 706d101cdd6SStefan Eßer # the settings of these variables to leak out of the function. They adjust 707d101cdd6SStefan Eßer # the settings outside of the function. 708d101cdd6SStefan Eßer case "$_predefined_build_type" in 709d101cdd6SStefan Eßer 710d101cdd6SStefan Eßer BSD) 711d101cdd6SStefan Eßer bc_only=0 712d101cdd6SStefan Eßer dc_only=0 713d101cdd6SStefan Eßer coverage=0 714d101cdd6SStefan Eßer debug=0 715d101cdd6SStefan Eßer optimization="3" 716d101cdd6SStefan Eßer hist=1 717d101cdd6SStefan Eßer hist_impl="editline" 718d101cdd6SStefan Eßer extra_math=1 719d101cdd6SStefan Eßer generate_tests=$generate_tests 720d101cdd6SStefan Eßer install_manpages=0 721d101cdd6SStefan Eßer nls=1 722d101cdd6SStefan Eßer force=0 723d101cdd6SStefan Eßer strip_bin=1 724d101cdd6SStefan Eßer all_locales=0 725d101cdd6SStefan Eßer library=0 726d101cdd6SStefan Eßer fuzz=0 727*12e0d316SStefan Eßer ossfuzz=0 728d101cdd6SStefan Eßer time_tests=0 729d101cdd6SStefan Eßer vg=0 730d101cdd6SStefan Eßer memcheck=0 731d101cdd6SStefan Eßer clean=1 732d101cdd6SStefan Eßer bc_default_banner=0 733d101cdd6SStefan Eßer bc_default_sigint_reset=1 734d101cdd6SStefan Eßer dc_default_sigint_reset=1 735d101cdd6SStefan Eßer bc_default_tty_mode=1 736d101cdd6SStefan Eßer dc_default_tty_mode=0 737d101cdd6SStefan Eßer bc_default_prompt="" 738d101cdd6SStefan Eßer dc_default_prompt="" 739d101cdd6SStefan Eßer bc_default_expr_exit=1 740d101cdd6SStefan Eßer dc_default_expr_exit=1 741d101cdd6SStefan Eßer bc_default_digit_clamp=0 742d101cdd6SStefan Eßer dc_default_digit_clamp=0;; 743d101cdd6SStefan Eßer 744d101cdd6SStefan Eßer GNU) 745d101cdd6SStefan Eßer bc_only=0 746d101cdd6SStefan Eßer dc_only=0 747d101cdd6SStefan Eßer coverage=0 748d101cdd6SStefan Eßer debug=0 749d101cdd6SStefan Eßer optimization="3" 750d101cdd6SStefan Eßer hist=1 751d101cdd6SStefan Eßer hist_impl="internal" 752d101cdd6SStefan Eßer extra_math=1 753d101cdd6SStefan Eßer generate_tests=$generate_tests 754d101cdd6SStefan Eßer install_manpages=1 755d101cdd6SStefan Eßer nls=1 756d101cdd6SStefan Eßer force=0 757d101cdd6SStefan Eßer strip_bin=1 758d101cdd6SStefan Eßer all_locales=0 759d101cdd6SStefan Eßer library=0 760d101cdd6SStefan Eßer fuzz=0 761*12e0d316SStefan Eßer ossfuzz=0 762d101cdd6SStefan Eßer time_tests=0 763d101cdd6SStefan Eßer vg=0 764d101cdd6SStefan Eßer memcheck=0 765d101cdd6SStefan Eßer clean=1 766d101cdd6SStefan Eßer bc_default_banner=1 767d101cdd6SStefan Eßer bc_default_sigint_reset=1 768d101cdd6SStefan Eßer dc_default_sigint_reset=0 769d101cdd6SStefan Eßer bc_default_tty_mode=1 770d101cdd6SStefan Eßer dc_default_tty_mode=0 771d101cdd6SStefan Eßer bc_default_prompt="" 772d101cdd6SStefan Eßer dc_default_prompt="" 773d101cdd6SStefan Eßer bc_default_expr_exit=1 774d101cdd6SStefan Eßer dc_default_expr_exit=1 775d101cdd6SStefan Eßer bc_default_digit_clamp=1 776d101cdd6SStefan Eßer dc_default_digit_clamp=0;; 777d101cdd6SStefan Eßer 778d101cdd6SStefan Eßer GDH) 779*12e0d316SStefan Eßer CFLAGS="-Weverything -Wno-padded -Wno-unsafe-buffer-usage -Wno-poison-system-directories" 780*12e0d316SStefan Eßer CFLAGS="$CFLAGS -Wno-switch-default -Werror -pedantic -std=c11" 781d101cdd6SStefan Eßer bc_only=0 782d101cdd6SStefan Eßer dc_only=0 783d101cdd6SStefan Eßer coverage=0 784d101cdd6SStefan Eßer debug=0 785d101cdd6SStefan Eßer optimization="3" 786d101cdd6SStefan Eßer hist=1 787d101cdd6SStefan Eßer hist_impl="internal" 788d101cdd6SStefan Eßer extra_math=1 789d101cdd6SStefan Eßer generate_tests=1 790d101cdd6SStefan Eßer install_manpages=1 791d101cdd6SStefan Eßer nls=0 792d101cdd6SStefan Eßer force=0 793d101cdd6SStefan Eßer strip_bin=1 794d101cdd6SStefan Eßer all_locales=0 795d101cdd6SStefan Eßer library=0 796d101cdd6SStefan Eßer fuzz=0 797*12e0d316SStefan Eßer ossfuzz=0 798d101cdd6SStefan Eßer time_tests=0 799d101cdd6SStefan Eßer vg=0 800d101cdd6SStefan Eßer memcheck=0 801d101cdd6SStefan Eßer clean=1 802d101cdd6SStefan Eßer bc_default_banner=1 803d101cdd6SStefan Eßer bc_default_sigint_reset=1 804d101cdd6SStefan Eßer dc_default_sigint_reset=1 805d101cdd6SStefan Eßer bc_default_tty_mode=1 806d101cdd6SStefan Eßer dc_default_tty_mode=1 807d101cdd6SStefan Eßer bc_default_prompt="" 808d101cdd6SStefan Eßer dc_default_prompt="" 809d101cdd6SStefan Eßer bc_default_expr_exit=0 810d101cdd6SStefan Eßer dc_default_expr_exit=0 811d101cdd6SStefan Eßer bc_default_digit_clamp=1 812d101cdd6SStefan Eßer dc_default_digit_clamp=1;; 813d101cdd6SStefan Eßer 814d101cdd6SStefan Eßer DBG) 815*12e0d316SStefan Eßer CFLAGS="-Weverything -Wno-padded -Wno-unsafe-buffer-usage -Wno-poison-system-directories" 816*12e0d316SStefan Eßer CFLAGS="$CFLAGS -Wno-switch-default -Werror -pedantic -std=c11" 817d101cdd6SStefan Eßer bc_only=0 818d101cdd6SStefan Eßer dc_only=0 819d101cdd6SStefan Eßer coverage=0 820d101cdd6SStefan Eßer debug=1 821d101cdd6SStefan Eßer optimization="0" 822d101cdd6SStefan Eßer hist=1 823d101cdd6SStefan Eßer hist_impl="internal" 824d101cdd6SStefan Eßer extra_math=1 825d101cdd6SStefan Eßer generate_tests=1 826d101cdd6SStefan Eßer install_manpages=1 827d101cdd6SStefan Eßer nls=1 828d101cdd6SStefan Eßer force=0 829d101cdd6SStefan Eßer strip_bin=1 830d101cdd6SStefan Eßer all_locales=0 831d101cdd6SStefan Eßer library=0 832d101cdd6SStefan Eßer fuzz=0 833*12e0d316SStefan Eßer ossfuzz=0 834d101cdd6SStefan Eßer time_tests=0 835d101cdd6SStefan Eßer vg=0 836d101cdd6SStefan Eßer memcheck=1 837d101cdd6SStefan Eßer clean=1 838d101cdd6SStefan Eßer bc_default_banner=1 839d101cdd6SStefan Eßer bc_default_sigint_reset=1 840d101cdd6SStefan Eßer dc_default_sigint_reset=1 841d101cdd6SStefan Eßer bc_default_tty_mode=1 842d101cdd6SStefan Eßer dc_default_tty_mode=1 843d101cdd6SStefan Eßer bc_default_prompt="" 844d101cdd6SStefan Eßer dc_default_prompt="" 845d101cdd6SStefan Eßer bc_default_expr_exit=0 846d101cdd6SStefan Eßer dc_default_expr_exit=0 847d101cdd6SStefan Eßer bc_default_digit_clamp=1 848d101cdd6SStefan Eßer dc_default_digit_clamp=1;; 849d101cdd6SStefan Eßer 850d101cdd6SStefan Eßer ?|'') usage "Invalid user build: \"$_predefined_build_type\". Accepted types are BSD, GNU, GDH, DBG.";; 851d101cdd6SStefan Eßer 852d101cdd6SStefan Eßer esac 853d101cdd6SStefan Eßer} 854d101cdd6SStefan Eßer 85544d4804dSStefan Eßer# Generates a list of script test targets that will be used as prerequisites for 85644d4804dSStefan Eßer# other targets. 85744d4804dSStefan Eßer# 85844d4804dSStefan Eßer# @param name The name of the calculator to generate script test targets for. 85910328f8bSStefan Eßergen_script_test_targets() { 86010328f8bSStefan Eßer 86110328f8bSStefan Eßer _gen_script_test_targets_name="$1" 86210328f8bSStefan Eßer shift 86310328f8bSStefan Eßer 86410328f8bSStefan Eßer _gen_script_test_targets_tests=$(cat "$scriptdir/tests/$_gen_script_test_targets_name/scripts/all.txt") 86510328f8bSStefan Eßer 86610328f8bSStefan Eßer for _gen_script_test_targets_f in $_gen_script_test_targets_tests; do 86710328f8bSStefan Eßer _gen_script_test_targets_b=$(basename "$_gen_script_test_targets_f" \ 86810328f8bSStefan Eßer ".$_gen_script_test_targets_name") 86910328f8bSStefan Eßer printf ' test_%s_script_%s' "$_gen_script_test_targets_name" \ 87010328f8bSStefan Eßer "$_gen_script_test_targets_b" 87110328f8bSStefan Eßer done 87210328f8bSStefan Eßer 87310328f8bSStefan Eßer printf '\n' 87410328f8bSStefan Eßer} 87510328f8bSStefan Eßer 87644d4804dSStefan Eßer# This is a list of defaults, but it is also the list of possible options for 87744d4804dSStefan Eßer# users to change. 87844d4804dSStefan Eßer# 87944d4804dSStefan Eßer# The development options are: force (force options even if they fail), valgrind 88044d4804dSStefan Eßer# (build in a way suitable for valgrind testing), memcheck (same as valgrind), 88144d4804dSStefan Eßer# and fuzzing (build in a way suitable for fuzzing). 8823aa99676SStefan Eßerbc_only=0 8833aa99676SStefan Eßerdc_only=0 8843aa99676SStefan Eßercoverage=0 8853aa99676SStefan Eßerkaratsuba_len=32 8863aa99676SStefan Eßerdebug=0 8873aa99676SStefan Eßerhist=1 888d101cdd6SStefan Eßerhist_impl="internal" 8893aa99676SStefan Eßerextra_math=1 8903aa99676SStefan Eßeroptimization="" 8913aa99676SStefan Eßergenerate_tests=1 8923aa99676SStefan Eßerinstall_manpages=1 8933aa99676SStefan Eßernls=1 8943aa99676SStefan Eßerforce=0 8953aa99676SStefan Eßerstrip_bin=1 896cf7becd2SStefan Eßerall_locales=0 89750696a6eSStefan Eßerlibrary=0 89810328f8bSStefan Eßerfuzz=0 899*12e0d316SStefan Eßerossfuzz=0 90010328f8bSStefan Eßertime_tests=0 90110328f8bSStefan Eßervg=0 90210328f8bSStefan Eßermemcheck=0 90310328f8bSStefan Eßerclean=1 904d101cdd6SStefan Eßerproblematic_tests=1 9053aa99676SStefan Eßer 90644d4804dSStefan Eßer# The empty strings are because they depend on TTY mode. If they are directly 90744d4804dSStefan Eßer# set, though, they will be integers. We test for empty strings later. 90844d4804dSStefan Eßerbc_default_banner=0 90944d4804dSStefan Eßerbc_default_sigint_reset=1 91044d4804dSStefan Eßerdc_default_sigint_reset=1 91144d4804dSStefan Eßerbc_default_tty_mode=1 91244d4804dSStefan Eßerdc_default_tty_mode=0 91344d4804dSStefan Eßerbc_default_prompt="" 91444d4804dSStefan Eßerdc_default_prompt="" 91510041e99SStefan Eßerbc_default_expr_exit=1 91610041e99SStefan Eßerdc_default_expr_exit=1 917d101cdd6SStefan Eßerbc_default_digit_clamp=0 918d101cdd6SStefan Eßerdc_default_digit_clamp=0 91944d4804dSStefan Eßer 92044d4804dSStefan Eßer# getopts is a POSIX utility, but it cannot handle long options. Thus, the 92144d4804dSStefan Eßer# handling of long options is done by hand, and that's the reason that short and 92244d4804dSStefan Eßer# long options cannot be mixed. 923*12e0d316SStefan Eßerwhile getopts "abBcdDeEfgGhHik:lMmNO:p:PrS:s:tTvzZ-" opt; do 9243aa99676SStefan Eßer 9253aa99676SStefan Eßer case "$opt" in 92650696a6eSStefan Eßer a) library=1 ;; 9273aa99676SStefan Eßer b) bc_only=1 ;; 9283aa99676SStefan Eßer B) dc_only=1 ;; 9293aa99676SStefan Eßer c) coverage=1 ;; 93010328f8bSStefan Eßer C) clean=0 ;; 9313aa99676SStefan Eßer d) dc_only=1 ;; 9323aa99676SStefan Eßer D) bc_only=1 ;; 933d101cdd6SStefan Eßer e) hist_impl="editline" ;; 9343aa99676SStefan Eßer E) extra_math=0 ;; 9353aa99676SStefan Eßer f) force=1 ;; 9363aa99676SStefan Eßer g) debug=1 ;; 9373aa99676SStefan Eßer G) generate_tests=0 ;; 9383aa99676SStefan Eßer h) usage ;; 9393aa99676SStefan Eßer H) hist=0 ;; 940d101cdd6SStefan Eßer i) hist_impl="internal" ;; 9413aa99676SStefan Eßer k) karatsuba_len="$OPTARG" ;; 942cf7becd2SStefan Eßer l) all_locales=1 ;; 94310328f8bSStefan Eßer m) memcheck=1 ;; 9443aa99676SStefan Eßer M) install_manpages=0 ;; 9453aa99676SStefan Eßer N) nls=0 ;; 9463aa99676SStefan Eßer O) optimization="$OPTARG" ;; 947d101cdd6SStefan Eßer p) predefined_build "$OPTARG" ;; 948d101cdd6SStefan Eßer P) problematic_tests=0 ;; 949d101cdd6SStefan Eßer r) hist_impl="readline" ;; 95044d4804dSStefan Eßer S) set_default 0 "$OPTARG" ;; 95144d4804dSStefan Eßer s) set_default 1 "$OPTARG" ;; 95210328f8bSStefan Eßer t) time_tests=1 ;; 9533aa99676SStefan Eßer T) strip_bin=0 ;; 95410328f8bSStefan Eßer v) vg=1 ;; 95510328f8bSStefan Eßer z) fuzz=1 ;; 956*12e0d316SStefan Eßer Z) ossfuzz=1 ;; 9573aa99676SStefan Eßer -) 9583aa99676SStefan Eßer arg="$1" 9593aa99676SStefan Eßer arg="${arg#--}" 9603aa99676SStefan Eßer LONG_OPTARG="${arg#*=}" 9613aa99676SStefan Eßer case $arg in 9623aa99676SStefan Eßer help) usage ;; 96350696a6eSStefan Eßer library) library=1 ;; 9643aa99676SStefan Eßer bc-only) bc_only=1 ;; 9653aa99676SStefan Eßer dc-only) dc_only=1 ;; 9663aa99676SStefan Eßer coverage) coverage=1 ;; 9673aa99676SStefan Eßer debug) debug=1 ;; 9683aa99676SStefan Eßer force) force=1 ;; 9693aa99676SStefan Eßer prefix=?*) PREFIX="$LONG_OPTARG" ;; 9703aa99676SStefan Eßer prefix) 9713aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 9723aa99676SStefan Eßer usage "No argument given for '--$arg' option" 9733aa99676SStefan Eßer fi 9743aa99676SStefan Eßer PREFIX="$2" 9753aa99676SStefan Eßer shift ;; 9763aa99676SStefan Eßer bindir=?*) BINDIR="$LONG_OPTARG" ;; 9773aa99676SStefan Eßer bindir) 9783aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 9793aa99676SStefan Eßer usage "No argument given for '--$arg' option" 9803aa99676SStefan Eßer fi 9813aa99676SStefan Eßer BINDIR="$2" 9823aa99676SStefan Eßer shift ;; 98350696a6eSStefan Eßer includedir=?*) INCLUDEDIR="$LONG_OPTARG" ;; 98450696a6eSStefan Eßer includedir) 98550696a6eSStefan Eßer if [ "$#" -lt 2 ]; then 98650696a6eSStefan Eßer usage "No argument given for '--$arg' option" 98750696a6eSStefan Eßer fi 98850696a6eSStefan Eßer INCLUDEDIR="$2" 98950696a6eSStefan Eßer shift ;; 99050696a6eSStefan Eßer libdir=?*) LIBDIR="$LONG_OPTARG" ;; 99150696a6eSStefan Eßer libdir) 99250696a6eSStefan Eßer if [ "$#" -lt 2 ]; then 99350696a6eSStefan Eßer usage "No argument given for '--$arg' option" 99450696a6eSStefan Eßer fi 99550696a6eSStefan Eßer LIBDIR="$2" 99650696a6eSStefan Eßer shift ;; 9973aa99676SStefan Eßer datarootdir=?*) DATAROOTDIR="$LONG_OPTARG" ;; 9983aa99676SStefan Eßer datarootdir) 9993aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 10003aa99676SStefan Eßer usage "No argument given for '--$arg' option" 10013aa99676SStefan Eßer fi 10023aa99676SStefan Eßer DATAROOTDIR="$2" 10033aa99676SStefan Eßer shift ;; 10043aa99676SStefan Eßer datadir=?*) DATADIR="$LONG_OPTARG" ;; 10053aa99676SStefan Eßer datadir) 10063aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 10073aa99676SStefan Eßer usage "No argument given for '--$arg' option" 10083aa99676SStefan Eßer fi 10093aa99676SStefan Eßer DATADIR="$2" 10103aa99676SStefan Eßer shift ;; 10113aa99676SStefan Eßer mandir=?*) MANDIR="$LONG_OPTARG" ;; 10123aa99676SStefan Eßer mandir) 10133aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 10143aa99676SStefan Eßer usage "No argument given for '--$arg' option" 10153aa99676SStefan Eßer fi 10163aa99676SStefan Eßer MANDIR="$2" 10173aa99676SStefan Eßer shift ;; 10183aa99676SStefan Eßer man1dir=?*) MAN1DIR="$LONG_OPTARG" ;; 10193aa99676SStefan Eßer man1dir) 10203aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 10213aa99676SStefan Eßer usage "No argument given for '--$arg' option" 10223aa99676SStefan Eßer fi 10233aa99676SStefan Eßer MAN1DIR="$2" 10243aa99676SStefan Eßer shift ;; 102550696a6eSStefan Eßer man3dir=?*) MAN3DIR="$LONG_OPTARG" ;; 102650696a6eSStefan Eßer man3dir) 102750696a6eSStefan Eßer if [ "$#" -lt 2 ]; then 102850696a6eSStefan Eßer usage "No argument given for '--$arg' option" 102950696a6eSStefan Eßer fi 103050696a6eSStefan Eßer MAN3DIR="$2" 103150696a6eSStefan Eßer shift ;; 10323aa99676SStefan Eßer karatsuba-len=?*) karatsuba_len="$LONG_OPTARG" ;; 10333aa99676SStefan Eßer karatsuba-len) 10343aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 10353aa99676SStefan Eßer usage "No argument given for '--$arg' option" 10363aa99676SStefan Eßer fi 10373aa99676SStefan Eßer karatsuba_len="$1" 10383aa99676SStefan Eßer shift ;; 10393aa99676SStefan Eßer opt=?*) optimization="$LONG_OPTARG" ;; 10403aa99676SStefan Eßer opt) 10413aa99676SStefan Eßer if [ "$#" -lt 2 ]; then 10423aa99676SStefan Eßer usage "No argument given for '--$arg' option" 10433aa99676SStefan Eßer fi 10443aa99676SStefan Eßer optimization="$1" 10453aa99676SStefan Eßer shift ;; 104644d4804dSStefan Eßer set-default-on=?*) set_default 1 "$LONG_OPTARG" ;; 104744d4804dSStefan Eßer set-default-on) 104844d4804dSStefan Eßer if [ "$#" -lt 2 ]; then 104944d4804dSStefan Eßer usage "No argument given for '--$arg' option" 105044d4804dSStefan Eßer fi 105144d4804dSStefan Eßer set_default 1 "$1" 105244d4804dSStefan Eßer shift ;; 105344d4804dSStefan Eßer set-default-off=?*) set_default 0 "$LONG_OPTARG" ;; 105444d4804dSStefan Eßer set-default-off) 105544d4804dSStefan Eßer if [ "$#" -lt 2 ]; then 105644d4804dSStefan Eßer usage "No argument given for '--$arg' option" 105744d4804dSStefan Eßer fi 105844d4804dSStefan Eßer set_default 0 "$1" 105944d4804dSStefan Eßer shift ;; 1060d101cdd6SStefan Eßer predefined-build-type=?*) predefined_build "$LONG_OPTARG" ;; 1061d101cdd6SStefan Eßer predefined-build-type) 1062d101cdd6SStefan Eßer if [ "$#" -lt 2 ]; then 1063d101cdd6SStefan Eßer usage "No argument given for '--$arg' option" 1064d101cdd6SStefan Eßer fi 1065d101cdd6SStefan Eßer predefined_build "$1" 1066d101cdd6SStefan Eßer shift ;; 10673aa99676SStefan Eßer disable-bc) dc_only=1 ;; 10683aa99676SStefan Eßer disable-dc) bc_only=1 ;; 106910328f8bSStefan Eßer disable-clean) clean=0 ;; 10703aa99676SStefan Eßer disable-extra-math) extra_math=0 ;; 10713aa99676SStefan Eßer disable-generated-tests) generate_tests=0 ;; 10723aa99676SStefan Eßer disable-history) hist=0 ;; 10733aa99676SStefan Eßer disable-man-pages) install_manpages=0 ;; 10743aa99676SStefan Eßer disable-nls) nls=0 ;; 10753aa99676SStefan Eßer disable-strip) strip_bin=0 ;; 1076d101cdd6SStefan Eßer disable-problematic-tests) problematic_tests=0 ;; 1077d101cdd6SStefan Eßer enable-editline) hist_impl="editline" ;; 1078d101cdd6SStefan Eßer enable-readline) hist_impl="readline" ;; 1079d101cdd6SStefan Eßer enable-internal-history) hist_impl="internal" ;; 108010328f8bSStefan Eßer enable-test-timing) time_tests=1 ;; 108110328f8bSStefan Eßer enable-valgrind) vg=1 ;; 108210328f8bSStefan Eßer enable-fuzz-mode) fuzz=1 ;; 1083*12e0d316SStefan Eßer enable-ossfuzz-mode) ossfuzz=1 ;; 108410328f8bSStefan Eßer enable-memcheck) memcheck=1 ;; 1085cf7becd2SStefan Eßer install-all-locales) all_locales=1 ;; 10863aa99676SStefan Eßer help* | bc-only* | dc-only* | coverage* | debug*) 10873aa99676SStefan Eßer usage "No arg allowed for --$arg option" ;; 108810328f8bSStefan Eßer disable-bc* | disable-dc* | disable-clean*) 108910328f8bSStefan Eßer usage "No arg allowed for --$arg option" ;; 109010328f8bSStefan Eßer disable-extra-math*) 10913aa99676SStefan Eßer usage "No arg allowed for --$arg option" ;; 10923aa99676SStefan Eßer disable-generated-tests* | disable-history*) 10933aa99676SStefan Eßer usage "No arg allowed for --$arg option" ;; 10943aa99676SStefan Eßer disable-man-pages* | disable-nls* | disable-strip*) 10953aa99676SStefan Eßer usage "No arg allowed for --$arg option" ;; 1096d101cdd6SStefan Eßer disable-problematic-tests*) 1097d101cdd6SStefan Eßer usage "No arg allowed for --$arg option" ;; 109810328f8bSStefan Eßer enable-fuzz-mode* | enable-test-timing* | enable-valgrind*) 109910328f8bSStefan Eßer usage "No arg allowed for --$arg option" ;; 110010328f8bSStefan Eßer enable-memcheck* | install-all-locales*) 1101cf7becd2SStefan Eßer usage "No arg allowed for --$arg option" ;; 110278bc019dSStefan Eßer enable-editline* | enable-readline*) 110378bc019dSStefan Eßer usage "No arg allowed for --$arg option" ;; 1104d101cdd6SStefan Eßer enable-internal-history*) 1105d101cdd6SStefan Eßer usage "No arg allowed for --$arg option" ;; 11063aa99676SStefan Eßer '') break ;; # "--" terminates argument processing 11073aa99676SStefan Eßer * ) usage "Invalid option $LONG_OPTARG" ;; 11083aa99676SStefan Eßer esac 11093aa99676SStefan Eßer shift 11103aa99676SStefan Eßer OPTIND=1 ;; 111144d4804dSStefan Eßer ?) usage "Invalid option: $opt" ;; 11123aa99676SStefan Eßer esac 11133aa99676SStefan Eßer 11143aa99676SStefan Eßerdone 11153aa99676SStefan Eßer 111644d4804dSStefan Eßer# Sometimes, developers don't want configure.sh to do a config clean. But 111744d4804dSStefan Eßer# sometimes they do. 111810328f8bSStefan Eßerif [ "$clean" -ne 0 ]; then 111910328f8bSStefan Eßer if [ -f ./Makefile ]; then 112010328f8bSStefan Eßer make clean_config > /dev/null 112110328f8bSStefan Eßer fi 112210328f8bSStefan Eßerfi 112310328f8bSStefan Eßer 112444d4804dSStefan Eßer# It is an error to say that bc only should be built and likewise for dc. 11253aa99676SStefan Eßerif [ "$bc_only" -eq 1 ] && [ "$dc_only" -eq 1 ]; then 11263aa99676SStefan Eßer usage "Can only specify one of -b(-D) or -d(-B)" 11273aa99676SStefan Eßerfi 11283aa99676SStefan Eßer 112944d4804dSStefan Eßer# The library is mutually exclusive to the calculators, so it's an error to 113044d4804dSStefan Eßer# give an option for either of them. 113150696a6eSStefan Eßerif [ "$library" -ne 0 ]; then 113250696a6eSStefan Eßer if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then 113350696a6eSStefan Eßer usage "Must not specify -b(-D) or -d(-B) when building the library" 113450696a6eSStefan Eßer fi 113550696a6eSStefan Eßerfi 113650696a6eSStefan Eßer 113744d4804dSStefan Eßer# KARATSUBA_LEN must be an integer and must be 16 or greater. 11383aa99676SStefan Eßercase $karatsuba_len in 11393aa99676SStefan Eßer (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;; 11403aa99676SStefan Eßer (*) ;; 11413aa99676SStefan Eßeresac 11423aa99676SStefan Eßer 11433aa99676SStefan Eßerif [ "$karatsuba_len" -lt 16 ]; then 11443aa99676SStefan Eßer usage "KARATSUBA_LEN is less than 16" 11453aa99676SStefan Eßerfi 11463aa99676SStefan Eßer 11473aa99676SStefan Eßerset -e 11483aa99676SStefan Eßer 11493aa99676SStefan Eßerif [ -z "${LONG_BIT+set}" ]; then 11503aa99676SStefan Eßer LONG_BIT_DEFINE="" 11513aa99676SStefan Eßerelif [ "$LONG_BIT" -lt 32 ]; then 11523aa99676SStefan Eßer usage "LONG_BIT is less than 32" 11533aa99676SStefan Eßerelse 1154d101cdd6SStefan Eßer LONG_BIT_DEFINE="-DBC_LONG_BIT=$LONG_BIT" 11553aa99676SStefan Eßerfi 11563aa99676SStefan Eßer 11573aa99676SStefan Eßerif [ -z "$CC" ]; then 11583aa99676SStefan Eßer CC="c99" 11593aa99676SStefan Eßerelse 116044d4804dSStefan Eßer 116144d4804dSStefan Eßer # I had users complain that, if they gave CFLAGS as part of CC, which 116244d4804dSStefan Eßer # autotools allows in its braindead way, the build would fail with an error. 116344d4804dSStefan Eßer # I don't like adjusting for autotools, but oh well. These lines puts the 116444d4804dSStefan Eßer # stuff after the first space into CFLAGS. 11653aa99676SStefan Eßer ccbase=$(basename "$CC") 11663aa99676SStefan Eßer suffix=" *" 11673aa99676SStefan Eßer prefix="* " 11683aa99676SStefan Eßer 11693aa99676SStefan Eßer if [ "${ccbase%%$suffix}" != "$ccbase" ]; then 11703aa99676SStefan Eßer ccflags="${ccbase#$prefix}" 11713aa99676SStefan Eßer cc="${ccbase%%$suffix}" 11723aa99676SStefan Eßer ccdir=$(dirname "$CC") 11733aa99676SStefan Eßer if [ "$ccdir" = "." ] && [ "${CC#.}" = "$CC" ]; then 11743aa99676SStefan Eßer ccdir="" 11753aa99676SStefan Eßer else 11763aa99676SStefan Eßer ccdir="$ccdir/" 11773aa99676SStefan Eßer fi 11783aa99676SStefan Eßer CC="${ccdir}${cc}" 11793aa99676SStefan Eßer CFLAGS="$CFLAGS $ccflags" 11803aa99676SStefan Eßer fi 11813aa99676SStefan Eßerfi 11823aa99676SStefan Eßer 11833aa99676SStefan Eßerif [ -z "$HOSTCC" ] && [ -z "$HOST_CC" ]; then 11843aa99676SStefan Eßer HOSTCC="$CC" 11853aa99676SStefan Eßerelif [ -z "$HOSTCC" ]; then 11863aa99676SStefan Eßer HOSTCC="$HOST_CC" 11873aa99676SStefan Eßerfi 11883aa99676SStefan Eßer 11893aa99676SStefan Eßerif [ "$HOSTCC" != "$CC" ]; then 119044d4804dSStefan Eßer 119144d4804dSStefan Eßer # Like above, this splits HOSTCC and HOSTCFLAGS. 11923aa99676SStefan Eßer ccbase=$(basename "$HOSTCC") 11933aa99676SStefan Eßer suffix=" *" 11943aa99676SStefan Eßer prefix="* " 11953aa99676SStefan Eßer 11963aa99676SStefan Eßer if [ "${ccbase%%$suffix}" != "$ccbase" ]; then 11973aa99676SStefan Eßer ccflags="${ccbase#$prefix}" 11983aa99676SStefan Eßer cc="${ccbase%%$suffix}" 11993aa99676SStefan Eßer ccdir=$(dirname "$HOSTCC") 12003aa99676SStefan Eßer if [ "$ccdir" = "." ] && [ "${HOSTCC#.}" = "$HOSTCC" ]; then 12013aa99676SStefan Eßer ccdir="" 12023aa99676SStefan Eßer else 12033aa99676SStefan Eßer ccdir="$ccdir/" 12043aa99676SStefan Eßer fi 12053aa99676SStefan Eßer HOSTCC="${ccdir}${cc}" 12063aa99676SStefan Eßer HOSTCFLAGS="$HOSTCFLAGS $ccflags" 12073aa99676SStefan Eßer fi 12083aa99676SStefan Eßerfi 12093aa99676SStefan Eßer 12103aa99676SStefan Eßerif [ -z "${HOSTCFLAGS+set}" ] && [ -z "${HOST_CFLAGS+set}" ]; then 12113aa99676SStefan Eßer HOSTCFLAGS="$CFLAGS" 12123aa99676SStefan Eßerelif [ -z "${HOSTCFLAGS+set}" ]; then 12133aa99676SStefan Eßer HOSTCFLAGS="$HOST_CFLAGS" 12143aa99676SStefan Eßerfi 12153aa99676SStefan Eßer 121644d4804dSStefan Eßer# Store these for the cross compilation detection later. 121744d4804dSStefan EßerOLDCFLAGS="$CFLAGS" 121844d4804dSStefan EßerOLDHOSTCFLAGS="$HOSTCFLAGS" 121944d4804dSStefan Eßer 12203aa99676SStefan Eßerlink="@printf 'No link necessary\\\\n'" 12213aa99676SStefan Eßermain_exec="BC" 12223aa99676SStefan Eßerexecutable="BC_EXEC" 12233aa99676SStefan Eßer 1224d43fa8efSStefan Eßertests="test_bc timeconst test_dc" 122550696a6eSStefan Eßer 1226d101cdd6SStefan Eßerbc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh bc $extra_math 1 $generate_tests $problematic_tests $time_tests \$(BC_EXEC)" 1227d101cdd6SStefan Eßerbc_test_np="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh -n bc $extra_math 1 $generate_tests $problematic_tests $time_tests \$(BC_EXEC)" 1228d101cdd6SStefan Eßerdc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh dc $extra_math 1 $generate_tests $problematic_tests $time_tests \$(DC_EXEC)" 1229d101cdd6SStefan Eßerdc_test_np="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh -n dc $extra_math 1 $generate_tests $problematic_tests $time_tests \$(DC_EXEC)" 12303aa99676SStefan Eßer 123110041e99SStefan Eßertimeconst="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/bc/timeconst.sh \$(TESTSDIR)/bc/scripts/timeconst.bc \$(BC_EXEC)" 12323aa99676SStefan Eßer 12333aa99676SStefan Eßer# In order to have cleanup at exit, we need to be in 12343aa99676SStefan Eßer# debug mode, so don't run valgrind without that. 123510328f8bSStefan Eßerif [ "$vg" -ne 0 ]; then 123610328f8bSStefan Eßer debug=1 123710328f8bSStefan Eßer bc_test_exec='valgrind $(VALGRIND_ARGS) $(BC_EXEC)' 123810328f8bSStefan Eßer dc_test_exec='valgrind $(VALGRIND_ARGS) $(DC_EXEC)' 1239d101cdd6SStefan Eßer bcl_test_exec='valgrind $(VALGRIND_ARGS) $(BCL_TEST)' 12403aa99676SStefan Eßerelse 124110328f8bSStefan Eßer bc_test_exec='$(BC_EXEC)' 124210328f8bSStefan Eßer dc_test_exec='$(DC_EXEC)' 1243d101cdd6SStefan Eßer bcl_test_exec='$(BCL_TEST)' 12443aa99676SStefan Eßerfi 12453aa99676SStefan Eßer 124644d4804dSStefan Eßertest_bc_history_prereqs="test_bc_history_all" 124744d4804dSStefan Eßertest_dc_history_prereqs="test_dc_history_all" 124844d4804dSStefan Eßer 12493aa99676SStefan Eßerkaratsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'" 12503aa99676SStefan Eßerkaratsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'" 12513aa99676SStefan Eßer 12523aa99676SStefan Eßerbc_lib="\$(GEN_DIR)/lib.o" 12533aa99676SStefan Eßerbc_help="\$(GEN_DIR)/bc_help.o" 12543aa99676SStefan Eßerdc_help="\$(GEN_DIR)/dc_help.o" 12553aa99676SStefan Eßer 125610328f8bSStefan Eßerdefault_target_prereqs="\$(BIN) \$(OBJS)" 125710328f8bSStefan Eßerdefault_target_cmd="\$(CC) \$(CFLAGS) \$(OBJS) \$(LDFLAGS) -o \$(EXEC)" 125810328f8bSStefan Eßerdefault_target="\$(DC_EXEC)" 125910328f8bSStefan Eßer 126010328f8bSStefan Eßersecond_target_prereqs="" 126110328f8bSStefan Eßersecond_target_cmd="$default_target_cmd" 126210328f8bSStefan Eßersecond_target="\$(BC_EXEC)" 126310328f8bSStefan Eßer 126444d4804dSStefan Eßer# This if/else if chain is for setting the defaults that change based on whether 126544d4804dSStefan Eßer# the library is being built, bc only, dc only, or both calculators. 126610328f8bSStefan Eßerif [ "$library" -ne 0 ]; then 126710328f8bSStefan Eßer 126810328f8bSStefan Eßer extra_math=1 126910328f8bSStefan Eßer nls=0 127010328f8bSStefan Eßer hist=0 127110328f8bSStefan Eßer bc=1 127210328f8bSStefan Eßer dc=1 127310328f8bSStefan Eßer 127410328f8bSStefan Eßer default_target_prereqs="\$(BIN) \$(OBJ)" 127510328f8bSStefan Eßer default_target_cmd="ar -r -cu \$(LIBBC) \$(OBJ)" 127610328f8bSStefan Eßer default_target="\$(LIBBC)" 127710328f8bSStefan Eßer tests="test_library" 127844d4804dSStefan Eßer test_bc_history_prereqs=" test_bc_history_skip" 127944d4804dSStefan Eßer test_dc_history_prereqs=" test_dc_history_skip" 128010328f8bSStefan Eßer 128110041e99SStefan Eßer install_prereqs=" install_library" 128210041e99SStefan Eßer uninstall_prereqs=" uninstall_library" 128310041e99SStefan Eßer install_man_prereqs=" install_bcl_manpage" 128410041e99SStefan Eßer uninstall_man_prereqs=" uninstall_bcl_manpage" 128510041e99SStefan Eßer 128610328f8bSStefan Eßerelif [ "$bc_only" -eq 1 ]; then 12873aa99676SStefan Eßer 12883aa99676SStefan Eßer bc=1 12893aa99676SStefan Eßer dc=0 12903aa99676SStefan Eßer 12913aa99676SStefan Eßer dc_help="" 12923aa99676SStefan Eßer 12933aa99676SStefan Eßer executables="bc" 12943aa99676SStefan Eßer 12953aa99676SStefan Eßer dc_test="@printf 'No dc tests to run\\\\n'" 1296d43fa8efSStefan Eßer dc_test_np="@printf 'No dc tests to run\\\\n'" 129744d4804dSStefan Eßer test_dc_history_prereqs=" test_dc_history_skip" 12983aa99676SStefan Eßer 129950696a6eSStefan Eßer install_prereqs=" install_execs" 130050696a6eSStefan Eßer install_man_prereqs=" install_bc_manpage" 13013aa99676SStefan Eßer uninstall_prereqs=" uninstall_bc" 13023aa99676SStefan Eßer uninstall_man_prereqs=" uninstall_bc_manpage" 13033aa99676SStefan Eßer 130410328f8bSStefan Eßer default_target="\$(BC_EXEC)" 130510328f8bSStefan Eßer second_target="\$(DC_EXEC)" 1306d43fa8efSStefan Eßer tests="test_bc timeconst" 130710328f8bSStefan Eßer 13083aa99676SStefan Eßerelif [ "$dc_only" -eq 1 ]; then 13093aa99676SStefan Eßer 13103aa99676SStefan Eßer bc=0 13113aa99676SStefan Eßer dc=1 13123aa99676SStefan Eßer 13133aa99676SStefan Eßer bc_lib="" 13143aa99676SStefan Eßer bc_help="" 13153aa99676SStefan Eßer 13163aa99676SStefan Eßer executables="dc" 13173aa99676SStefan Eßer 13183aa99676SStefan Eßer main_exec="DC" 13193aa99676SStefan Eßer executable="DC_EXEC" 13203aa99676SStefan Eßer 13213aa99676SStefan Eßer bc_test="@printf 'No bc tests to run\\\\n'" 1322d43fa8efSStefan Eßer bc_test_np="@printf 'No bc tests to run\\\\n'" 132344d4804dSStefan Eßer test_bc_history_prereqs=" test_bc_history_skip" 13243aa99676SStefan Eßer 13253aa99676SStefan Eßer timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'" 13263aa99676SStefan Eßer 132750696a6eSStefan Eßer install_prereqs=" install_execs" 132850696a6eSStefan Eßer install_man_prereqs=" install_dc_manpage" 13293aa99676SStefan Eßer uninstall_prereqs=" uninstall_dc" 13303aa99676SStefan Eßer uninstall_man_prereqs=" uninstall_dc_manpage" 13313aa99676SStefan Eßer 1332d43fa8efSStefan Eßer tests="test_dc" 133310328f8bSStefan Eßer 1334*12e0d316SStefan Eßerelif [ "$ossfuzz" -eq 1 ]; then 1335*12e0d316SStefan Eßer 1336*12e0d316SStefan Eßer if [ "$bc_only" -ne 0 ] || [ "$dc_only" -ne 0 ]; then 1337*12e0d316SStefan Eßer usage "An OSS-Fuzz build must build both fuzzers." 1338*12e0d316SStefan Eßer fi 1339*12e0d316SStefan Eßer 1340*12e0d316SStefan Eßer bc=1 1341*12e0d316SStefan Eßer dc=1 1342*12e0d316SStefan Eßer 1343*12e0d316SStefan Eßer # Expressions *cannot* exit in an OSS-Fuzz build. 1344*12e0d316SStefan Eßer bc_default_expr_exit=0 1345*12e0d316SStefan Eßer dc_default_expr_exit=0 1346*12e0d316SStefan Eßer 1347*12e0d316SStefan Eßer executables="bc_fuzzer and dc_fuzzer" 1348*12e0d316SStefan Eßer 1349*12e0d316SStefan Eßer karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)" 1350*12e0d316SStefan Eßer karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)" 1351*12e0d316SStefan Eßer 1352*12e0d316SStefan Eßer if [ "$library" -eq 0 ]; then 1353*12e0d316SStefan Eßer install_prereqs=" install_execs" 1354*12e0d316SStefan Eßer install_man_prereqs=" install_bc_manpage install_dc_manpage" 1355*12e0d316SStefan Eßer uninstall_prereqs=" uninstall_bc uninstall_dc" 1356*12e0d316SStefan Eßer uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage" 1357*12e0d316SStefan Eßer else 1358*12e0d316SStefan Eßer install_prereqs=" install_library install_bcl_header" 1359*12e0d316SStefan Eßer install_man_prereqs=" install_bcl_manpage" 1360*12e0d316SStefan Eßer uninstall_prereqs=" uninstall_library uninstall_bcl_header" 1361*12e0d316SStefan Eßer uninstall_man_prereqs=" uninstall_bcl_manpage" 1362*12e0d316SStefan Eßer tests="test_library" 1363*12e0d316SStefan Eßer fi 1364*12e0d316SStefan Eßer 1365*12e0d316SStefan Eßer second_target_prereqs="src/bc_fuzzer.o $default_target_prereqs" 1366*12e0d316SStefan Eßer default_target_prereqs="\$(BC_FUZZER) src/dc_fuzzer.o $default_target_prereqs" 1367*12e0d316SStefan Eßer default_target_cmd="\$(CXX) \$(CFLAGS) src/dc_fuzzer.o \$(LIB_FUZZING_ENGINE) \$(OBJS) \$(LDFLAGS) -o \$(DC_FUZZER) \&\& ln -sf ./dc_fuzzer_c \$(DC_FUZZER_C)" 1368*12e0d316SStefan Eßer second_target_cmd="\$(CXX) \$(CFLAGS) src/bc_fuzzer.o \$(LIB_FUZZING_ENGINE) \$(OBJS) \$(LDFLAGS) -o \$(BC_FUZZER) \&\& ln -sf ./bc_fuzzer_c \$(BC_FUZZER_C)" 1369*12e0d316SStefan Eßer 1370*12e0d316SStefan Eßer default_target="\$(DC_FUZZER) \$(DC_FUZZER_C)" 1371*12e0d316SStefan Eßer second_target="\$(BC_FUZZER) \$(BC_FUZZER_C)" 1372*12e0d316SStefan Eßer 13733aa99676SStefan Eßerelse 13743aa99676SStefan Eßer 13753aa99676SStefan Eßer bc=1 13763aa99676SStefan Eßer dc=1 13773aa99676SStefan Eßer 13783aa99676SStefan Eßer executables="bc and dc" 13793aa99676SStefan Eßer 13803aa99676SStefan Eßer karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)" 13813aa99676SStefan Eßer karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)" 13823aa99676SStefan Eßer 138350696a6eSStefan Eßer if [ "$library" -eq 0 ]; then 138450696a6eSStefan Eßer install_prereqs=" install_execs" 138550696a6eSStefan Eßer install_man_prereqs=" install_bc_manpage install_dc_manpage" 13863aa99676SStefan Eßer uninstall_prereqs=" uninstall_bc uninstall_dc" 13873aa99676SStefan Eßer uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage" 138850696a6eSStefan Eßer else 138950696a6eSStefan Eßer install_prereqs=" install_library install_bcl_header" 139050696a6eSStefan Eßer install_man_prereqs=" install_bcl_manpage" 139150696a6eSStefan Eßer uninstall_prereqs=" uninstall_library uninstall_bcl_header" 139250696a6eSStefan Eßer uninstall_man_prereqs=" uninstall_bcl_manpage" 139350696a6eSStefan Eßer tests="test_library" 139450696a6eSStefan Eßer fi 13953aa99676SStefan Eßer 139610328f8bSStefan Eßer second_target_prereqs="$default_target_prereqs" 139710328f8bSStefan Eßer default_target_prereqs="$second_target" 139810328f8bSStefan Eßer default_target_cmd="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)" 139910328f8bSStefan Eßer 140010328f8bSStefan Eßerfi 140110328f8bSStefan Eßer 1402*12e0d316SStefan Eßerif [ "$fuzz" -ne 0 ] && [ "$ossfuzz" -ne 0 ]; then 1403*12e0d316SStefan Eßer usage "Fuzzing mode and OSS-Fuzz mode are mutually exclusive" 1404*12e0d316SStefan Eßerfi 1405*12e0d316SStefan Eßer 140644d4804dSStefan Eßer# We need specific stuff for fuzzing. 1407*12e0d316SStefan Eßerif [ "$fuzz" -ne 0 ] || [ "$ossfuzz" -ne 0 ]; then 140810328f8bSStefan Eßer debug=1 140910328f8bSStefan Eßer hist=0 141010328f8bSStefan Eßer nls=0 141110328f8bSStefan Eßer optimization="3" 14123aa99676SStefan Eßerfi 14133aa99676SStefan Eßer 141444d4804dSStefan Eßer# This sets some necessary things for debug mode. 14153aa99676SStefan Eßerif [ "$debug" -eq 1 ]; then 14163aa99676SStefan Eßer 14173aa99676SStefan Eßer if [ -z "$CFLAGS" ] && [ -z "$optimization" ]; then 14183aa99676SStefan Eßer CFLAGS="-O0" 14193aa99676SStefan Eßer fi 14203aa99676SStefan Eßer 14213aa99676SStefan Eßer CFLAGS="-g $CFLAGS" 14223aa99676SStefan Eßer 14233aa99676SStefan Eßerelse 14243aa99676SStefan Eßer CPPFLAGS="-DNDEBUG $CPPFLAGS" 14253aa99676SStefan Eßerfi 14263aa99676SStefan Eßer 142744d4804dSStefan Eßer# Set optimization CFLAGS. 14283aa99676SStefan Eßerif [ -n "$optimization" ]; then 14293aa99676SStefan Eßer CFLAGS="-O$optimization $CFLAGS" 14303aa99676SStefan Eßerfi 14313aa99676SStefan Eßer 143244d4804dSStefan Eßer# Set test coverage defaults. 14333aa99676SStefan Eßerif [ "$coverage" -eq 1 ]; then 14343aa99676SStefan Eßer 14353aa99676SStefan Eßer if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then 14363aa99676SStefan Eßer usage "Can only specify -c without -b or -d" 14373aa99676SStefan Eßer fi 14383aa99676SStefan Eßer 14393aa99676SStefan Eßer CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS" 14403aa99676SStefan Eßer CPPFLAGS="-DNDEBUG $CPPFLAGS" 14413aa99676SStefan Eßer 14423aa99676SStefan Eßer COVERAGE_OUTPUT="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA) \$(HISTORY_GCDA) \$(RAND_GCDA)" 14433aa99676SStefan Eßer COVERAGE_OUTPUT="$COVERAGE_OUTPUT;\$(RM) -f \$(GEN)*.gc*" 144444d4804dSStefan Eßer COVERAGE_OUTPUT="$COVERAGE_OUTPUT;gcovr --exclude-unreachable-branches --exclude-throw-branches --html-details --output index.html" 14453aa99676SStefan Eßer COVERAGE_PREREQS=" test coverage_output" 14463aa99676SStefan Eßer 14473aa99676SStefan Eßerelse 14483aa99676SStefan Eßer COVERAGE_OUTPUT="@printf 'Coverage not generated\\\\n'" 14493aa99676SStefan Eßer COVERAGE_PREREQS="" 14503aa99676SStefan Eßerfi 14513aa99676SStefan Eßer 145244d4804dSStefan Eßer# Set some defaults. 14533aa99676SStefan Eßerif [ -z "${DESTDIR+set}" ]; then 14543aa99676SStefan Eßer destdir="" 14553aa99676SStefan Eßerelse 14563aa99676SStefan Eßer destdir="DESTDIR = $DESTDIR" 14573aa99676SStefan Eßerfi 14583aa99676SStefan Eßer 1459d101cdd6SStefan Eßer# defprefix is for a warning about locales later. 14603aa99676SStefan Eßerif [ -z "${PREFIX+set}" ]; then 14613aa99676SStefan Eßer PREFIX="/usr/local" 1462d101cdd6SStefan Eßer defprefix=1 1463d101cdd6SStefan Eßerelse 1464d101cdd6SStefan Eßer defprefix=0 14653aa99676SStefan Eßerfi 14663aa99676SStefan Eßer 14673aa99676SStefan Eßerif [ -z "${BINDIR+set}" ]; then 14683aa99676SStefan Eßer BINDIR="$PREFIX/bin" 14693aa99676SStefan Eßerfi 14703aa99676SStefan Eßer 147150696a6eSStefan Eßerif [ -z "${INCLUDEDIR+set}" ]; then 147250696a6eSStefan Eßer INCLUDEDIR="$PREFIX/include" 147350696a6eSStefan Eßerfi 147450696a6eSStefan Eßer 147550696a6eSStefan Eßerif [ -z "${LIBDIR+set}" ]; then 147650696a6eSStefan Eßer LIBDIR="$PREFIX/lib" 147750696a6eSStefan Eßerfi 147850696a6eSStefan Eßer 147910041e99SStefan Eßerif [ -z "${PC_PATH+set}" ]; then 148010041e99SStefan Eßer 148110041e99SStefan Eßer set +e 148210041e99SStefan Eßer 148310041e99SStefan Eßer command -v pkg-config > /dev/null 148410041e99SStefan Eßer err=$? 148510041e99SStefan Eßer 148610041e99SStefan Eßer set -e 148710041e99SStefan Eßer 148810041e99SStefan Eßer if [ "$err" -eq 0 ]; then 148910041e99SStefan Eßer PC_PATH=$(pkg-config --variable=pc_path pkg-config) 149010041e99SStefan Eßer PC_PATH="${PC_PATH%%:*}" 149110041e99SStefan Eßer else 149210041e99SStefan Eßer PC_PATH="" 149310041e99SStefan Eßer fi 149410041e99SStefan Eßer 149510041e99SStefan Eßerfi 149610041e99SStefan Eßer 149744d4804dSStefan Eßer# Set a default for the DATAROOTDIR. This is done if either manpages will be 1498d101cdd6SStefan Eßer# installed, or locales are enabled because that's probably where NLSPATH 149944d4804dSStefan Eßer# points. 15003aa99676SStefan Eßerif [ "$install_manpages" -ne 0 ] || [ "$nls" -ne 0 ]; then 15013aa99676SStefan Eßer if [ -z "${DATAROOTDIR+set}" ]; then 15023aa99676SStefan Eßer DATAROOTDIR="$PREFIX/share" 15033aa99676SStefan Eßer fi 15043aa99676SStefan Eßerfi 15053aa99676SStefan Eßer 150644d4804dSStefan Eßer# Set defaults for manpage environment variables. 15073aa99676SStefan Eßerif [ "$install_manpages" -ne 0 ]; then 15083aa99676SStefan Eßer 15093aa99676SStefan Eßer if [ -z "${DATADIR+set}" ]; then 15103aa99676SStefan Eßer DATADIR="$DATAROOTDIR" 15113aa99676SStefan Eßer fi 15123aa99676SStefan Eßer 15133aa99676SStefan Eßer if [ -z "${MANDIR+set}" ]; then 15143aa99676SStefan Eßer MANDIR="$DATADIR/man" 15153aa99676SStefan Eßer fi 15163aa99676SStefan Eßer 15173aa99676SStefan Eßer if [ -z "${MAN1DIR+set}" ]; then 15183aa99676SStefan Eßer MAN1DIR="$MANDIR/man1" 15193aa99676SStefan Eßer fi 15203aa99676SStefan Eßer 152150696a6eSStefan Eßer if [ -z "${MAN3DIR+set}" ]; then 152250696a6eSStefan Eßer MAN3DIR="$MANDIR/man3" 152350696a6eSStefan Eßer fi 152450696a6eSStefan Eßer 15253aa99676SStefan Eßerelse 152650696a6eSStefan Eßer install_man_prereqs="" 15273aa99676SStefan Eßer uninstall_man_prereqs="" 15283aa99676SStefan Eßerfi 15293aa99676SStefan Eßer 153044d4804dSStefan Eßer# Here is where we test NLS (the locale system). This is done by trying to 153144d4804dSStefan Eßer# compile src/vm.c, which has the relevant code. If it fails, then it is 153244d4804dSStefan Eßer# disabled. 15333aa99676SStefan Eßerif [ "$nls" -ne 0 ]; then 15343aa99676SStefan Eßer 15353aa99676SStefan Eßer set +e 15363aa99676SStefan Eßer 15373aa99676SStefan Eßer printf 'Testing NLS...\n' 15383aa99676SStefan Eßer 15393aa99676SStefan Eßer flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc" 154044d4804dSStefan Eßer flags="$flags -DBC_ENABLE_HISTORY=$hist -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0" 1541*12e0d316SStefan Eßer flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -DBC_ENABLE_OSSFUZZ=0" 1542*12e0d316SStefan Eßer flags="$flags -I$scriptdir/include/ -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" 15433aa99676SStefan Eßer 1544d101cdd6SStefan Eßer ccbase=$(basename "$CC") 1545d101cdd6SStefan Eßer 1546d101cdd6SStefan Eßer if [ "$ccbase" = "clang" ]; then 1547d101cdd6SStefan Eßer flags="$flags -Wno-unreachable-code" 1548d101cdd6SStefan Eßer fi 1549d101cdd6SStefan Eßer 1550*12e0d316SStefan Eßer "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/vm.c" -E > /dev/null 15513aa99676SStefan Eßer 15523aa99676SStefan Eßer err="$?" 15533aa99676SStefan Eßer 155410041e99SStefan Eßer rm -rf "./vm.o" 15553aa99676SStefan Eßer 1556*12e0d316SStefan Eßer # If this errors, it is probably because of building on Windows or musl, 1557*12e0d316SStefan Eßer # and NLS is not supported on Windows or musl, so disable it. 15583aa99676SStefan Eßer if [ "$err" -ne 0 ]; then 15593aa99676SStefan Eßer printf 'NLS does not work.\n' 15603aa99676SStefan Eßer if [ $force -eq 0 ]; then 15613aa99676SStefan Eßer printf 'Disabling NLS...\n\n' 15623aa99676SStefan Eßer nls=0 15633aa99676SStefan Eßer else 15643aa99676SStefan Eßer printf 'Forcing NLS...\n\n' 15653aa99676SStefan Eßer fi 15663aa99676SStefan Eßer else 15673aa99676SStefan Eßer printf 'NLS works.\n\n' 15683aa99676SStefan Eßer 15693aa99676SStefan Eßer printf 'Testing gencat...\n' 1570*12e0d316SStefan Eßer gencat "./en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 15713aa99676SStefan Eßer 15723aa99676SStefan Eßer err="$?" 15733aa99676SStefan Eßer 157410041e99SStefan Eßer rm -rf "./en_US.cat" 15753aa99676SStefan Eßer 15763aa99676SStefan Eßer if [ "$err" -ne 0 ]; then 15773aa99676SStefan Eßer printf 'gencat does not work.\n' 15783aa99676SStefan Eßer if [ $force -eq 0 ]; then 15793aa99676SStefan Eßer printf 'Disabling NLS...\n\n' 15803aa99676SStefan Eßer nls=0 15813aa99676SStefan Eßer else 15823aa99676SStefan Eßer printf 'Forcing NLS...\n\n' 15833aa99676SStefan Eßer fi 15843aa99676SStefan Eßer else 15853aa99676SStefan Eßer 15863aa99676SStefan Eßer printf 'gencat works.\n\n' 15873aa99676SStefan Eßer 158844d4804dSStefan Eßer # It turns out that POSIX locales are really terrible, and running 158944d4804dSStefan Eßer # gencat on one machine is not guaranteed to make those cat files 159044d4804dSStefan Eßer # portable to another machine, so we had better warn the user here. 159144d4804dSStefan Eßer if [ "$HOSTCC" != "$CC" ] || [ "$OLDHOSTCFLAGS" != "$OLDCFLAGS" ]; then 15923aa99676SStefan Eßer printf 'Cross-compile detected.\n\n' 15933aa99676SStefan Eßer printf 'WARNING: Catalog files generated with gencat may not be portable\n' 15943aa99676SStefan Eßer printf ' across different architectures.\n\n' 15953aa99676SStefan Eßer fi 15963aa99676SStefan Eßer 15973aa99676SStefan Eßer if [ -z "$NLSPATH" ]; then 15983aa99676SStefan Eßer NLSPATH="/usr/share/locale/%L/%N" 15993aa99676SStefan Eßer fi 16003aa99676SStefan Eßer 16013aa99676SStefan Eßer install_locales_prereqs=" install_locales" 16023aa99676SStefan Eßer uninstall_locales_prereqs=" uninstall_locales" 16033aa99676SStefan Eßer 16043aa99676SStefan Eßer fi 16053aa99676SStefan Eßer 16063aa99676SStefan Eßer fi 16073aa99676SStefan Eßer 16083aa99676SStefan Eßer set -e 16093aa99676SStefan Eßer 16103aa99676SStefan Eßerelse 16113aa99676SStefan Eßer install_locales_prereqs="" 16123aa99676SStefan Eßer uninstall_locales_prereqs="" 1613cf7becd2SStefan Eßer all_locales=0 1614cf7becd2SStefan Eßerfi 1615cf7becd2SStefan Eßer 1616cf7becd2SStefan Eßerif [ "$nls" -ne 0 ] && [ "$all_locales" -ne 0 ]; then 1617cf7becd2SStefan Eßer install_locales="\$(LOCALE_INSTALL) -l \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)" 1618cf7becd2SStefan Eßerelse 1619cf7becd2SStefan Eßer install_locales="\$(LOCALE_INSTALL) \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)" 16203aa99676SStefan Eßerfi 16213aa99676SStefan Eßer 162244d4804dSStefan Eßer# Like the above tested locale support, this tests history. 16233aa99676SStefan Eßerif [ "$hist" -eq 1 ]; then 16243aa99676SStefan Eßer 1625d101cdd6SStefan Eßer if [ "$hist_impl" = "editline" ]; then 1626d101cdd6SStefan Eßer editline=1 1627d101cdd6SStefan Eßer readline=0 1628d101cdd6SStefan Eßer elif [ "$hist_impl" = "readline" ]; then 1629d101cdd6SStefan Eßer editline=0 1630d101cdd6SStefan Eßer readline=1 1631d101cdd6SStefan Eßer else 1632d101cdd6SStefan Eßer editline=0 1633d101cdd6SStefan Eßer readline=0 163478bc019dSStefan Eßer fi 163578bc019dSStefan Eßer 16363aa99676SStefan Eßer set +e 16373aa99676SStefan Eßer 16383aa99676SStefan Eßer printf 'Testing history...\n' 16393aa99676SStefan Eßer 16403aa99676SStefan Eßer flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc" 164144d4804dSStefan Eßer flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0" 164278bc019dSStefan Eßer flags="$flags -DBC_ENABLE_EDITLINE=$editline -DBC_ENABLE_READLINE=$readline" 1643*12e0d316SStefan Eßer flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -DBC_ENABLE_OSSFUZZ=0" 1644*12e0d316SStefan Eßer flags="$flags -I$scriptdir/include/ -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" 16453aa99676SStefan Eßer 1646*12e0d316SStefan Eßer "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/history.c" -E > /dev/null 16473aa99676SStefan Eßer 16483aa99676SStefan Eßer err="$?" 16493aa99676SStefan Eßer 165010041e99SStefan Eßer rm -rf "./history.o" 16513aa99676SStefan Eßer 16523aa99676SStefan Eßer # If this errors, it is probably because of building on Windows, 16533aa99676SStefan Eßer # and history is not supported on Windows, so disable it. 16543aa99676SStefan Eßer if [ "$err" -ne 0 ]; then 16553aa99676SStefan Eßer printf 'History does not work.\n' 16563aa99676SStefan Eßer if [ $force -eq 0 ]; then 16573aa99676SStefan Eßer printf 'Disabling history...\n\n' 16583aa99676SStefan Eßer hist=0 16593aa99676SStefan Eßer else 16603aa99676SStefan Eßer printf 'Forcing history...\n\n' 16613aa99676SStefan Eßer fi 16623aa99676SStefan Eßer else 16633aa99676SStefan Eßer printf 'History works.\n\n' 16643aa99676SStefan Eßer fi 16653aa99676SStefan Eßer 16663aa99676SStefan Eßer set -e 16673aa99676SStefan Eßer 1668d101cdd6SStefan Eßerelse 1669d101cdd6SStefan Eßer 1670d101cdd6SStefan Eßer editline=0 1671d101cdd6SStefan Eßer readline=0 1672d101cdd6SStefan Eßer 16733aa99676SStefan Eßerfi 16743aa99676SStefan Eßer 167578bc019dSStefan Eßer# We have to disable the history tests if it is disabled or valgrind is on. Or 167678bc019dSStefan Eßer# if we are using editline or readline. 167744d4804dSStefan Eßerif [ "$hist" -eq 0 ] || [ "$vg" -ne 0 ]; then 167844d4804dSStefan Eßer test_bc_history_prereqs=" test_bc_history_skip" 167944d4804dSStefan Eßer test_dc_history_prereqs=" test_dc_history_skip" 168044d4804dSStefan Eßer history_tests="@printf 'Skipping history tests...\\\\n'" 168178bc019dSStefan Eßer CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0" 168244d4804dSStefan Eßerelse 168378bc019dSStefan Eßer 168478bc019dSStefan Eßer if [ "$editline" -eq 0 ] && [ "$readline" -eq 0 ]; then 168578bc019dSStefan Eßer history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n'" 168678bc019dSStefan Eßer history_tests="$history_tests \&\& \$(TESTSDIR)/history.sh bc -a \&\&" 168778bc019dSStefan Eßer history_tests="$history_tests \$(TESTSDIR)/history.sh dc -a \&\& printf" 168878bc019dSStefan Eßer history_tests="$history_tests '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'" 168978bc019dSStefan Eßer else 169078bc019dSStefan Eßer test_bc_history_prereqs=" test_bc_history_skip" 169178bc019dSStefan Eßer test_dc_history_prereqs=" test_dc_history_skip" 169278bc019dSStefan Eßer history_tests="@printf 'Skipping history tests...\\\\n'" 169378bc019dSStefan Eßer fi 169478bc019dSStefan Eßer 169578bc019dSStefan Eßer # We are also setting the CFLAGS and LDFLAGS here. 169678bc019dSStefan Eßer if [ "$editline" -ne 0 ]; then 169778bc019dSStefan Eßer LDFLAGS="$LDFLAGS -ledit" 169876238846SStefan Eßer CPPFLAGS="$CPPFLAGS -DBC_ENABLE_EDITLINE=1 -DBC_ENABLE_READLINE=0" 169978bc019dSStefan Eßer elif [ "$readline" -ne 0 ]; then 170078bc019dSStefan Eßer LDFLAGS="$LDFLAGS -lreadline" 170176238846SStefan Eßer CPPFLAGS="$CPPFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=1" 170278bc019dSStefan Eßer else 170376238846SStefan Eßer CPPFLAGS="$CPPFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0" 170478bc019dSStefan Eßer fi 170578bc019dSStefan Eßer 170678bc019dSStefan Eßerfi 170778bc019dSStefan Eßer 170878bc019dSStefan Eßer# Test FreeBSD. This is not in an if statement because regardless of whatever 170978bc019dSStefan Eßer# the user says, we need to know if we are on FreeBSD. If we are, we cannot set 171078bc019dSStefan Eßer# _POSIX_C_SOURCE and _XOPEN_SOURCE. The FreeBSD headers turn *off* stuff when 171178bc019dSStefan Eßer# that is done. 171278bc019dSStefan Eßerset +e 171378bc019dSStefan Eßerprintf 'Testing for FreeBSD...\n' 171478bc019dSStefan Eßer 171578bc019dSStefan Eßerflags="-DBC_TEST_FREEBSD -DBC_ENABLE_AFL=0" 1716*12e0d316SStefan Eßer"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/scripts/os.c" > /dev/null 171778bc019dSStefan Eßer 171878bc019dSStefan Eßererr="$?" 171978bc019dSStefan Eßer 172078bc019dSStefan Eßerif [ "$err" -ne 0 ]; then 172178bc019dSStefan Eßer printf 'On FreeBSD. Not using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n' 172278bc019dSStefan Eßerelse 172378bc019dSStefan Eßer printf 'Not on FreeBSD. Using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n' 172478bc019dSStefan Eßer CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" 172544d4804dSStefan Eßerfi 172644d4804dSStefan Eßer 1727a970610aSStefan Eßer# Test macOS. This is not in an if statement because regardless of whatever the 1728a970610aSStefan Eßer# user says, we need to know if we are on macOS. If we are, we have to set 172976238846SStefan Eßer# _DARWIN_C_SOURCE. 1730a970610aSStefan Eßerprintf 'Testing for macOS...\n' 173176238846SStefan Eßer 173276238846SStefan Eßerflags="-DBC_TEST_APPLE -DBC_ENABLE_AFL=0" 1733*12e0d316SStefan Eßer"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/scripts/os.c" > /dev/null 173476238846SStefan Eßer 173576238846SStefan Eßererr="$?" 173676238846SStefan Eßer 173776238846SStefan Eßerif [ "$err" -ne 0 ]; then 1738a970610aSStefan Eßer printf 'On macOS. Using _DARWIN_C_SOURCE.\n\n' 173976238846SStefan Eßer apple="-D_DARWIN_C_SOURCE" 174076238846SStefan Eßerelse 1741a970610aSStefan Eßer printf 'Not on macOS.\n\n' 174276238846SStefan Eßer apple="" 174376238846SStefan Eßerfi 174476238846SStefan Eßer 1745a970610aSStefan Eßer# We can't use the linker's strip flag on macOS. 1746a970610aSStefan Eßerif [ "$debug" -eq 0 ] && [ "$apple" = "" ] && [ "$strip_bin" -ne 0 ]; then 1747e6857bd4SStefan Eßer LDFLAGS="-s $LDFLAGS" 1748e6857bd4SStefan Eßerfi 1749e6857bd4SStefan Eßer 175044d4804dSStefan Eßer# Test OpenBSD. This is not in an if statement because regardless of whatever 175144d4804dSStefan Eßer# the user says, we need to know if we are on OpenBSD to activate _BSD_SOURCE. 175244d4804dSStefan Eßer# No, I cannot `#define _BSD_SOURCE` in a header because OpenBSD's patched GCC 175344d4804dSStefan Eßer# and Clang complain that that is only allowed for system headers. Sigh....So we 175444d4804dSStefan Eßer# have to check at configure time and set it on the compiler command-line. And 175544d4804dSStefan Eßer# we have to set it because we also set _POSIX_C_SOURCE, which OpenBSD headers 175644d4804dSStefan Eßer# detect, and when they detect it, they turn off _BSD_SOURCE unless it is 175744d4804dSStefan Eßer# specifically requested. 175844d4804dSStefan Eßerprintf 'Testing for OpenBSD...\n' 175944d4804dSStefan Eßer 176044d4804dSStefan Eßerflags="-DBC_TEST_OPENBSD -DBC_ENABLE_AFL=0" 1761*12e0d316SStefan Eßer"$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/scripts/os.c" > /dev/null 176244d4804dSStefan Eßer 176344d4804dSStefan Eßererr="$?" 176444d4804dSStefan Eßer 176544d4804dSStefan Eßerif [ "$err" -ne 0 ]; then 1766d101cdd6SStefan Eßer 176744d4804dSStefan Eßer printf 'On OpenBSD. Using _BSD_SOURCE.\n\n' 176844d4804dSStefan Eßer bsd="-D_BSD_SOURCE" 1769d101cdd6SStefan Eßer 1770d101cdd6SStefan Eßer # Readline errors on OpenBSD, for some weird reason. 1771d101cdd6SStefan Eßer if [ "$readline" -ne 0 ]; then 1772d101cdd6SStefan Eßer usage "Cannot use readline on OpenBSD" 1773d101cdd6SStefan Eßer fi 1774d101cdd6SStefan Eßer 177544d4804dSStefan Eßerelse 177644d4804dSStefan Eßer printf 'Not on OpenBSD.\n\n' 177744d4804dSStefan Eßer bsd="" 177844d4804dSStefan Eßerfi 177944d4804dSStefan Eßer 178076238846SStefan Eßerset -e 178176238846SStefan Eßer 178250696a6eSStefan Eßerif [ "$library" -eq 1 ]; then 178350696a6eSStefan Eßer bc_lib="" 178450696a6eSStefan Eßerfi 178550696a6eSStefan Eßer 178650696a6eSStefan Eßerif [ "$extra_math" -eq 1 ] && [ "$bc" -ne 0 ] && [ "$library" -eq 0 ]; then 17873aa99676SStefan Eßer BC_LIB2_O="\$(GEN_DIR)/lib2.o" 17883aa99676SStefan Eßerelse 17893aa99676SStefan Eßer BC_LIB2_O="" 17903aa99676SStefan Eßerfi 17913aa99676SStefan Eßer 1792d101cdd6SStefan EßerGEN_DIR="$scriptdir/gen" 1793d101cdd6SStefan Eßer 179444d4804dSStefan Eßer# These lines set the appropriate targets based on whether `gen/strgen.c` or 179544d4804dSStefan Eßer# `gen/strgen.sh` is used. 17963aa99676SStefan EßerGEN="strgen" 1797*12e0d316SStefan EßerGEN_EXEC_TARGET="\$(HOSTCC) -DBC_ENABLE_AFL=0 -DBC_ENABLE_OSSFUZZ=0 -I$scriptdir/include/ \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)" 179844d4804dSStefan EßerCLEAN_PREREQS=" clean_gen clean_coverage" 17993aa99676SStefan Eßer 18003aa99676SStefan Eßerif [ -z "${GEN_HOST+set}" ]; then 18013aa99676SStefan Eßer GEN_HOST=1 18023aa99676SStefan Eßerelse 18033aa99676SStefan Eßer if [ "$GEN_HOST" -eq 0 ]; then 18043aa99676SStefan Eßer GEN="strgen.sh" 18053aa99676SStefan Eßer GEN_EXEC_TARGET="@printf 'Do not need to build gen/strgen.c\\\\n'" 180644d4804dSStefan Eßer CLEAN_PREREQS=" clean_coverage" 18073aa99676SStefan Eßer fi 18083aa99676SStefan Eßerfi 18093aa99676SStefan Eßer 1810*12e0d316SStefan Eßer# The fuzzer files are always unneeded because they'll be built separately. 18113aa99676SStefan Eßermanpage_args="" 1812*12e0d316SStefan Eßerunneeded="bc_fuzzer.c dc_fuzzer.c" 181310328f8bSStefan Eßerheaders="\$(HEADERS)" 18143aa99676SStefan Eßer 181544d4804dSStefan Eßer# This series of if statements figure out what source files are *not* needed. 18163aa99676SStefan Eßerif [ "$extra_math" -eq 0 ]; then 181778bc019dSStefan Eßer exclude_extra_math=1 18183aa99676SStefan Eßer manpage_args="E" 181910328f8bSStefan Eßer unneeded="$unneeded rand.c" 182010328f8bSStefan Eßerelse 182178bc019dSStefan Eßer exclude_extra_math=0 182210328f8bSStefan Eßer headers="$headers \$(EXTRA_MATH_HEADERS)" 18233aa99676SStefan Eßerfi 18243aa99676SStefan Eßer 182544d4804dSStefan Eßer# All of these next if statements set the build type and mark certain source 182644d4804dSStefan Eßer# files as unneeded so that they won't have targets generated for them. 182744d4804dSStefan Eßer 18283aa99676SStefan Eßerif [ "$hist" -eq 0 ]; then 18293aa99676SStefan Eßer manpage_args="${manpage_args}H" 183010328f8bSStefan Eßer unneeded="$unneeded history.c" 183110328f8bSStefan Eßerelse 183210328f8bSStefan Eßer headers="$headers \$(HISTORY_HEADERS)" 18333aa99676SStefan Eßerfi 18343aa99676SStefan Eßer 18353aa99676SStefan Eßerif [ "$nls" -eq 0 ]; then 18363aa99676SStefan Eßer manpage_args="${manpage_args}N" 18373aa99676SStefan Eßerfi 18383aa99676SStefan Eßer 183950696a6eSStefan Eßerif [ "$bc" -eq 0 ]; then 184050696a6eSStefan Eßer unneeded="$unneeded bc.c bc_lex.c bc_parse.c" 184110328f8bSStefan Eßerelse 184210328f8bSStefan Eßer headers="$headers \$(BC_HEADERS)" 184350696a6eSStefan Eßerfi 184450696a6eSStefan Eßer 184550696a6eSStefan Eßerif [ "$dc" -eq 0 ]; then 184650696a6eSStefan Eßer unneeded="$unneeded dc.c dc_lex.c dc_parse.c" 184710328f8bSStefan Eßerelse 184810328f8bSStefan Eßer headers="$headers \$(DC_HEADERS)" 184950696a6eSStefan Eßerfi 185050696a6eSStefan Eßer 185110041e99SStefan Eßer# This convoluted mess does pull the version out. If you change the format of 185210041e99SStefan Eßer# include/version.h, you may have to change this line. 185310041e99SStefan Eßerversion=$(cat "$scriptdir/include/version.h" | grep "VERSION " - | awk '{ print $3 }' -) 185410041e99SStefan Eßer 185550696a6eSStefan Eßerif [ "$library" -ne 0 ]; then 185610041e99SStefan Eßer 185750696a6eSStefan Eßer unneeded="$unneeded args.c opt.c read.c file.c main.c" 185850696a6eSStefan Eßer unneeded="$unneeded lang.c lex.c parse.c program.c" 185950696a6eSStefan Eßer unneeded="$unneeded bc.c bc_lex.c bc_parse.c" 186050696a6eSStefan Eßer unneeded="$unneeded dc.c dc_lex.c dc_parse.c" 186110328f8bSStefan Eßer headers="$headers \$(LIBRARY_HEADERS)" 186210041e99SStefan Eßer 186310041e99SStefan Eßer if [ "$PC_PATH" != "" ]; then 186410041e99SStefan Eßer 186510041e99SStefan Eßer contents=$(cat "$scriptdir/bcl.pc.in") 186610041e99SStefan Eßer 186710041e99SStefan Eßer contents=$(replace "$contents" "INCLUDEDIR" "$INCLUDEDIR") 186810041e99SStefan Eßer contents=$(replace "$contents" "LIBDIR" "$LIBDIR") 186910041e99SStefan Eßer contents=$(replace "$contents" "VERSION" "$version") 187010041e99SStefan Eßer 1871175a4d10SStefan Eßer printf '%s\n' "$contents" > "$scriptdir/bcl.pc" 187210041e99SStefan Eßer 187310041e99SStefan Eßer pkg_config_install="\$(SAFE_INSTALL) \$(PC_INSTALL_ARGS) \"\$(BCL_PC)\" \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\"" 187410041e99SStefan Eßer pkg_config_uninstall="\$(RM) -f \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\"" 187510041e99SStefan Eßer 187650696a6eSStefan Eßer else 187710041e99SStefan Eßer 187810041e99SStefan Eßer pkg_config_install="" 187910041e99SStefan Eßer pkg_config_uninstall="" 188010041e99SStefan Eßer 188110041e99SStefan Eßer fi 188210041e99SStefan Eßer 1883*12e0d316SStefan Eßerelif [ "$ossfuzz" -ne 0 ]; then 1884*12e0d316SStefan Eßer 1885*12e0d316SStefan Eßer unneeded="$unneeded library.c main.c" 1886*12e0d316SStefan Eßer 1887*12e0d316SStefan Eßer PC_PATH="" 1888*12e0d316SStefan Eßer pkg_config_install="" 1889*12e0d316SStefan Eßer pkg_config_uninstall="" 1890*12e0d316SStefan Eßer 189110041e99SStefan Eßerelse 189210041e99SStefan Eßer 189350696a6eSStefan Eßer unneeded="$unneeded library.c" 189410041e99SStefan Eßer 189510041e99SStefan Eßer PC_PATH="" 189610041e99SStefan Eßer pkg_config_install="" 189710041e99SStefan Eßer pkg_config_uninstall="" 189810041e99SStefan Eßer 189950696a6eSStefan Eßerfi 190050696a6eSStefan Eßer 1901*12e0d316SStefan Eßer# library.c, bc_fuzzer.c, and dc_fuzzer.c are not needed under normal 1902*12e0d316SStefan Eßer# circumstances. 190344d4804dSStefan Eßerif [ "$unneeded" = "" ]; then 1904*12e0d316SStefan Eßer unneeded="library.c bc_fuzzer.c dc_fuzzer.c" 190544d4804dSStefan Eßerfi 190644d4804dSStefan Eßer 190744d4804dSStefan Eßer# This sets the appropriate manpage for a full build. 190810328f8bSStefan Eßerif [ "$manpage_args" = "" ]; then 190910328f8bSStefan Eßer manpage_args="A" 191010328f8bSStefan Eßerfi 191110328f8bSStefan Eßer 1912*12e0d316SStefan Eßerif [ "$vg" -ne 0 ] || [ "$ossfuzz" -ne 0 ]; then 191310328f8bSStefan Eßer memcheck=1 191410328f8bSStefan Eßerfi 191510328f8bSStefan Eßer 191644d4804dSStefan Eßerif [ "$bc_default_prompt" = "" ]; then 191744d4804dSStefan Eßer bc_default_prompt="$bc_default_tty_mode" 191844d4804dSStefan Eßerfi 191944d4804dSStefan Eßer 192044d4804dSStefan Eßerif [ "$dc_default_prompt" = "" ]; then 192144d4804dSStefan Eßer dc_default_prompt="$dc_default_tty_mode" 192244d4804dSStefan Eßerfi 192344d4804dSStefan Eßer 192444d4804dSStefan Eßer# Generate the test targets and prerequisites. 1925d43fa8efSStefan Eßerbc_tests=$(gen_std_test_targets bc) 192610328f8bSStefan Eßerbc_script_tests=$(gen_script_test_targets bc) 1927d43fa8efSStefan Eßerbc_err_tests=$(gen_err_test_targets bc) 1928d43fa8efSStefan Eßerdc_tests=$(gen_std_test_targets dc) 192910328f8bSStefan Eßerdc_script_tests=$(gen_script_test_targets dc) 1930d43fa8efSStefan Eßerdc_err_tests=$(gen_err_test_targets dc) 193110328f8bSStefan Eßer 1932e6857bd4SStefan Eßerprintf 'unneeded: %s\n' "$unneeded" 1933e6857bd4SStefan Eßer 19343aa99676SStefan Eßer# Print out the values; this is for debugging. 193510041e99SStefan Eßerprintf 'Version: %s\n' "$version" 193610041e99SStefan Eßer 19373aa99676SStefan Eßerif [ "$bc" -ne 0 ]; then 19383aa99676SStefan Eßer printf 'Building bc\n' 19393aa99676SStefan Eßerelse 19403aa99676SStefan Eßer printf 'Not building bc\n' 19413aa99676SStefan Eßerfi 19423aa99676SStefan Eßerif [ "$dc" -ne 0 ]; then 19433aa99676SStefan Eßer printf 'Building dc\n' 19443aa99676SStefan Eßerelse 19453aa99676SStefan Eßer printf 'Not building dc\n' 19463aa99676SStefan Eßerfi 19473aa99676SStefan Eßerprintf '\n' 194850696a6eSStefan Eßerprintf 'BC_ENABLE_LIBRARY=%s\n\n' "$library" 19493aa99676SStefan Eßerprintf 'BC_ENABLE_HISTORY=%s\n' "$hist" 19503aa99676SStefan Eßerprintf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math" 1951d101cdd6SStefan Eßerprintf 'BC_ENABLE_NLS=%s\n\n' "$nls" 195210328f8bSStefan Eßerprintf 'BC_ENABLE_AFL=%s\n' "$fuzz" 19533aa99676SStefan Eßerprintf '\n' 19543aa99676SStefan Eßerprintf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len" 19553aa99676SStefan Eßerprintf '\n' 19563aa99676SStefan Eßerprintf 'CC=%s\n' "$CC" 19573aa99676SStefan Eßerprintf 'CFLAGS=%s\n' "$CFLAGS" 19583aa99676SStefan Eßerprintf 'HOSTCC=%s\n' "$HOSTCC" 19593aa99676SStefan Eßerprintf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS" 19603aa99676SStefan Eßerprintf 'CPPFLAGS=%s\n' "$CPPFLAGS" 19613aa99676SStefan Eßerprintf 'LDFLAGS=%s\n' "$LDFLAGS" 19623aa99676SStefan Eßerprintf 'PREFIX=%s\n' "$PREFIX" 19633aa99676SStefan Eßerprintf 'BINDIR=%s\n' "$BINDIR" 196450696a6eSStefan Eßerprintf 'INCLUDEDIR=%s\n' "$INCLUDEDIR" 196550696a6eSStefan Eßerprintf 'LIBDIR=%s\n' "$LIBDIR" 19663aa99676SStefan Eßerprintf 'DATAROOTDIR=%s\n' "$DATAROOTDIR" 19673aa99676SStefan Eßerprintf 'DATADIR=%s\n' "$DATADIR" 19683aa99676SStefan Eßerprintf 'MANDIR=%s\n' "$MANDIR" 19693aa99676SStefan Eßerprintf 'MAN1DIR=%s\n' "$MAN1DIR" 197050696a6eSStefan Eßerprintf 'MAN3DIR=%s\n' "$MAN3DIR" 19713aa99676SStefan Eßerprintf 'NLSPATH=%s\n' "$NLSPATH" 197210041e99SStefan Eßerprintf 'PC_PATH=%s\n' "$PC_PATH" 19733aa99676SStefan Eßerprintf 'EXECSUFFIX=%s\n' "$EXECSUFFIX" 19743aa99676SStefan Eßerprintf 'EXECPREFIX=%s\n' "$EXECPREFIX" 19753aa99676SStefan Eßerprintf 'DESTDIR=%s\n' "$DESTDIR" 19763aa99676SStefan Eßerprintf 'LONG_BIT=%s\n' "$LONG_BIT" 19773aa99676SStefan Eßerprintf 'GEN_HOST=%s\n' "$GEN_HOST" 19783aa99676SStefan Eßerprintf 'GEN_EMU=%s\n' "$GEN_EMU" 197944d4804dSStefan Eßerprintf '\n' 198044d4804dSStefan Eßerprintf 'Setting Defaults\n' 198144d4804dSStefan Eßerprintf '================\n' 198244d4804dSStefan Eßerprintf 'bc.banner=%s\n' "$bc_default_banner" 198344d4804dSStefan Eßerprintf 'bc.sigint_reset=%s\n' "$bc_default_sigint_reset" 198444d4804dSStefan Eßerprintf 'dc.sigint_reset=%s\n' "$dc_default_sigint_reset" 198544d4804dSStefan Eßerprintf 'bc.tty_mode=%s\n' "$bc_default_tty_mode" 198644d4804dSStefan Eßerprintf 'dc.tty_mode=%s\n' "$dc_default_tty_mode" 198744d4804dSStefan Eßerprintf 'bc.prompt=%s\n' "$bc_default_prompt" 198844d4804dSStefan Eßerprintf 'dc.prompt=%s\n' "$dc_default_prompt" 198910041e99SStefan Eßerprintf 'bc.expr_exit=%s\n' "$bc_default_expr_exit" 199010041e99SStefan Eßerprintf 'dc.expr_exit=%s\n' "$dc_default_expr_exit" 1991d101cdd6SStefan Eßerprintf 'bc.digit_clamp=%s\n' "$bc_default_digit_clamp" 1992d101cdd6SStefan Eßerprintf 'dc.digit_clamp=%s\n' "$dc_default_digit_clamp" 1993d101cdd6SStefan Eßer 1994d101cdd6SStefan Eßer# This code outputs a warning. The warning is to not surprise users when locales 1995d101cdd6SStefan Eßer# are installed outside of the prefix. This warning is suppressed when the 1996d101cdd6SStefan Eßer# default prefix is used, as well, so as not to panic users just installing by 1997d101cdd6SStefan Eßer# hand. I believe this will be okay because NLSPATH is usually in /usr and the 1998d101cdd6SStefan Eßer# default prefix is /usr/local, so they'll be close that way. 1999d101cdd6SStefan Eßerif [ "$nls" -ne 0 ] && [ "${NLSPATH#$PREFIX}" = "${NLSPATH}" ] && [ "$defprefix" -eq 0 ]; then 2000d101cdd6SStefan Eßer printf '\n********************************************************************************\n\n' 2001d101cdd6SStefan Eßer printf 'WARNING: Locales will *NOT* be installed in $PREFIX (%s).\n' "$PREFIX" 2002d101cdd6SStefan Eßer printf '\n' 2003d101cdd6SStefan Eßer printf ' This is because they *MUST* be installed at a fixed location to even\n' 2004d101cdd6SStefan Eßer printf ' work, and that fixed location is $NLSPATH (%s).\n' "$NLSPATH" 2005d101cdd6SStefan Eßer printf '\n' 2006d101cdd6SStefan Eßer printf ' This location is *outside* of $PREFIX. If you do not wish to install\n' 2007d101cdd6SStefan Eßer printf ' locales outside of $PREFIX, you must disable NLS with the -N or the\n' 2008d101cdd6SStefan Eßer printf ' --disable-nls options.\n' 2009d101cdd6SStefan Eßer printf '\n' 2010d101cdd6SStefan Eßer printf ' The author apologizes for the inconvenience, but the need to install\n' 2011d101cdd6SStefan Eßer printf ' the locales at a fixed location is mandated by POSIX, and it is not\n' 2012d101cdd6SStefan Eßer printf ' possible for the author to change that requirement.\n' 2013d101cdd6SStefan Eßer printf '\n********************************************************************************\n' 2014d101cdd6SStefan Eßerfi 201544d4804dSStefan Eßer 201644d4804dSStefan Eßer# This is where the real work begins. This is the point at which the Makefile.in 201744d4804dSStefan Eßer# template is edited and output to the Makefile. 20183aa99676SStefan Eßer 20193aa99676SStefan Eßercontents=$(cat "$scriptdir/Makefile.in") 20203aa99676SStefan Eßer 20213aa99676SStefan Eßerneedle="WARNING" 20223aa99676SStefan Eßerreplacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***' 20233aa99676SStefan Eßer 20243aa99676SStefan Eßercontents=$(replace "$contents" "$needle" "$replacement") 20253aa99676SStefan Eßer 202644d4804dSStefan Eßer# The contents are edited to have the list of files to build. 202710328f8bSStefan Eßercontents=$(gen_file_list "$contents" $unneeded) 202810328f8bSStefan Eßer 202910328f8bSStefan EßerSRC_TARGETS="" 203010328f8bSStefan Eßer 203144d4804dSStefan Eßer# This line and loop generates the individual targets for source files. I used 203244d4804dSStefan Eßer# to just use an implicit target, but that was found to be inadequate when I 203344d4804dSStefan Eßer# added the library. 203410328f8bSStefan Eßersrc_files=$(find_src_files $unneeded) 203510328f8bSStefan Eßer 203610328f8bSStefan Eßerfor f in $src_files; do 203710328f8bSStefan Eßer o=$(replace_ext "$f" "c" "o") 203810041e99SStefan Eßer o=$(basename "$o") 203910041e99SStefan Eßer SRC_TARGETS=$(printf '%s\n\nsrc/%s: src %s %s\n\t$(CC) $(CFLAGS) -o src/%s -c %s\n' \ 204010328f8bSStefan Eßer "$SRC_TARGETS" "$o" "$headers" "$f" "$o" "$f") 204110328f8bSStefan Eßerdone 204210328f8bSStefan Eßer 204344d4804dSStefan Eßer# Replace all the placeholders. 204410041e99SStefan Eßercontents=$(replace "$contents" "ROOTDIR" "$scriptdir") 204510041e99SStefan Eßercontents=$(replace "$contents" "BUILDDIR" "$builddir") 204610041e99SStefan Eßer 204710328f8bSStefan Eßercontents=$(replace "$contents" "HEADERS" "$headers") 204810328f8bSStefan Eßer 20493aa99676SStefan Eßercontents=$(replace "$contents" "BC_ENABLED" "$bc") 20503aa99676SStefan Eßercontents=$(replace "$contents" "DC_ENABLED" "$dc") 205110328f8bSStefan Eßer 205210328f8bSStefan Eßercontents=$(replace "$contents" "BC_ALL_TESTS" "$bc_test") 2053d43fa8efSStefan Eßercontents=$(replace "$contents" "BC_ALL_TESTS_NP" "$bc_test_np") 205410328f8bSStefan Eßercontents=$(replace "$contents" "BC_TESTS" "$bc_tests") 205510328f8bSStefan Eßercontents=$(replace "$contents" "BC_SCRIPT_TESTS" "$bc_script_tests") 2056d43fa8efSStefan Eßercontents=$(replace "$contents" "BC_ERROR_TESTS" "$bc_err_tests") 205710328f8bSStefan Eßercontents=$(replace "$contents" "BC_TEST_EXEC" "$bc_test_exec") 205810328f8bSStefan Eßercontents=$(replace "$contents" "TIMECONST_ALL_TESTS" "$timeconst") 205910328f8bSStefan Eßer 206010328f8bSStefan Eßercontents=$(replace "$contents" "DC_ALL_TESTS" "$dc_test") 2061d43fa8efSStefan Eßercontents=$(replace "$contents" "DC_ALL_TESTS_NP" "$dc_test_np") 206210328f8bSStefan Eßercontents=$(replace "$contents" "DC_TESTS" "$dc_tests") 206310328f8bSStefan Eßercontents=$(replace "$contents" "DC_SCRIPT_TESTS" "$dc_script_tests") 2064d43fa8efSStefan Eßercontents=$(replace "$contents" "DC_ERROR_TESTS" "$dc_err_tests") 206510328f8bSStefan Eßercontents=$(replace "$contents" "DC_TEST_EXEC" "$dc_test_exec") 20663aa99676SStefan Eßer 2067d101cdd6SStefan Eßercontents=$(replace "$contents" "BCL_TEST_EXEC" "$bcl_test_exec") 2068d101cdd6SStefan Eßer 20697e5c51e5SStefan Eßercontents=$(replace "$contents" "BUILD_TYPE" "$manpage_args") 207078bc019dSStefan Eßercontents=$(replace "$contents" "EXCLUDE_EXTRA_MATH" "$exclude_extra_math") 20717e5c51e5SStefan Eßer 207250696a6eSStefan Eßercontents=$(replace "$contents" "LIBRARY" "$library") 20733aa99676SStefan Eßercontents=$(replace "$contents" "HISTORY" "$hist") 20743aa99676SStefan Eßercontents=$(replace "$contents" "EXTRA_MATH" "$extra_math") 20753aa99676SStefan Eßercontents=$(replace "$contents" "NLS" "$nls") 207610328f8bSStefan Eßercontents=$(replace "$contents" "FUZZ" "$fuzz") 2077*12e0d316SStefan Eßercontents=$(replace "$contents" "OSSFUZZ" "$ossfuzz") 207810328f8bSStefan Eßercontents=$(replace "$contents" "MEMCHECK" "$memcheck") 2079*12e0d316SStefan Eßercontents=$(replace "$contents" "LIB_FUZZING_ENGINE" "$LIB_FUZZING_ENGINE") 208010328f8bSStefan Eßer 20813aa99676SStefan Eßercontents=$(replace "$contents" "BC_LIB_O" "$bc_lib") 20823aa99676SStefan Eßercontents=$(replace "$contents" "BC_HELP_O" "$bc_help") 20833aa99676SStefan Eßercontents=$(replace "$contents" "DC_HELP_O" "$dc_help") 20843aa99676SStefan Eßercontents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O") 20853aa99676SStefan Eßercontents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len") 20863aa99676SStefan Eßer 20873aa99676SStefan Eßercontents=$(replace "$contents" "NLSPATH" "$NLSPATH") 20883aa99676SStefan Eßercontents=$(replace "$contents" "DESTDIR" "$destdir") 20893aa99676SStefan Eßercontents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX") 20903aa99676SStefan Eßercontents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX") 20913aa99676SStefan Eßercontents=$(replace "$contents" "BINDIR" "$BINDIR") 209250696a6eSStefan Eßercontents=$(replace "$contents" "INCLUDEDIR" "$INCLUDEDIR") 209350696a6eSStefan Eßercontents=$(replace "$contents" "LIBDIR" "$LIBDIR") 20943aa99676SStefan Eßercontents=$(replace "$contents" "MAN1DIR" "$MAN1DIR") 209550696a6eSStefan Eßercontents=$(replace "$contents" "MAN3DIR" "$MAN3DIR") 20963aa99676SStefan Eßercontents=$(replace "$contents" "CFLAGS" "$CFLAGS") 20973aa99676SStefan Eßercontents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS") 20983aa99676SStefan Eßercontents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS") 20993aa99676SStefan Eßercontents=$(replace "$contents" "LDFLAGS" "$LDFLAGS") 21003aa99676SStefan Eßercontents=$(replace "$contents" "CC" "$CC") 21013aa99676SStefan Eßercontents=$(replace "$contents" "HOSTCC" "$HOSTCC") 21023aa99676SStefan Eßercontents=$(replace "$contents" "COVERAGE_OUTPUT" "$COVERAGE_OUTPUT") 21033aa99676SStefan Eßercontents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS") 21043aa99676SStefan Eßercontents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs") 210550696a6eSStefan Eßercontents=$(replace "$contents" "INSTALL_MAN_PREREQS" "$install_man_prereqs") 2106cf7becd2SStefan Eßercontents=$(replace "$contents" "INSTALL_LOCALES" "$install_locales") 21073aa99676SStefan Eßercontents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs") 21083aa99676SStefan Eßercontents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs") 21093aa99676SStefan Eßercontents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs") 21103aa99676SStefan Eßercontents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs") 21113aa99676SStefan Eßer 211210041e99SStefan Eßercontents=$(replace "$contents" "PC_PATH" "$PC_PATH") 211310041e99SStefan Eßercontents=$(replace "$contents" "PKG_CONFIG_INSTALL" "$pkg_config_install") 211410041e99SStefan Eßercontents=$(replace "$contents" "PKG_CONFIG_UNINSTALL" "$pkg_config_uninstall") 211510041e99SStefan Eßer 211610328f8bSStefan Eßercontents=$(replace "$contents" "DEFAULT_TARGET" "$default_target") 211710328f8bSStefan Eßercontents=$(replace "$contents" "DEFAULT_TARGET_PREREQS" "$default_target_prereqs") 211810328f8bSStefan Eßercontents=$(replace "$contents" "DEFAULT_TARGET_CMD" "$default_target_cmd") 211910328f8bSStefan Eßercontents=$(replace "$contents" "SECOND_TARGET" "$second_target") 212010328f8bSStefan Eßercontents=$(replace "$contents" "SECOND_TARGET_PREREQS" "$second_target_prereqs") 212110328f8bSStefan Eßercontents=$(replace "$contents" "SECOND_TARGET_CMD" "$second_target_cmd") 212210328f8bSStefan Eßer 212350696a6eSStefan Eßercontents=$(replace "$contents" "ALL_PREREQ" "$ALL_PREREQ") 212410328f8bSStefan Eßercontents=$(replace "$contents" "BC_EXEC_PREREQ" "$bc_exec_prereq") 212510328f8bSStefan Eßercontents=$(replace "$contents" "BC_EXEC_CMD" "$bc_exec_cmd") 212610328f8bSStefan Eßercontents=$(replace "$contents" "DC_EXEC_PREREQ" "$dc_exec_prereq") 212710328f8bSStefan Eßercontents=$(replace "$contents" "DC_EXEC_CMD" "$dc_exec_cmd") 212850696a6eSStefan Eßer 21293aa99676SStefan Eßercontents=$(replace "$contents" "EXECUTABLES" "$executables") 21303aa99676SStefan Eßercontents=$(replace "$contents" "MAIN_EXEC" "$main_exec") 21313aa99676SStefan Eßercontents=$(replace "$contents" "EXEC" "$executable") 213250696a6eSStefan Eßercontents=$(replace "$contents" "TESTS" "$tests") 21333aa99676SStefan Eßer 213444d4804dSStefan Eßercontents=$(replace "$contents" "BC_HISTORY_TEST_PREREQS" "$test_bc_history_prereqs") 213544d4804dSStefan Eßercontents=$(replace "$contents" "DC_HISTORY_TEST_PREREQS" "$test_dc_history_prereqs") 213644d4804dSStefan Eßercontents=$(replace "$contents" "HISTORY_TESTS" "$history_tests") 21373aa99676SStefan Eßer 21383aa99676SStefan Eßercontents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test") 21393aa99676SStefan Eßercontents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test") 21403aa99676SStefan Eßer 21413aa99676SStefan Eßercontents=$(replace "$contents" "TIMECONST" "$timeconst") 21423aa99676SStefan Eßer 21433aa99676SStefan Eßercontents=$(replace "$contents" "KARATSUBA" "$karatsuba") 21443aa99676SStefan Eßercontents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test") 21453aa99676SStefan Eßer 21463aa99676SStefan Eßercontents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE") 21473aa99676SStefan Eßer 2148d101cdd6SStefan Eßercontents=$(replace "$contents" "GEN_DIR" "$GEN_DIR") 21493aa99676SStefan Eßercontents=$(replace "$contents" "GEN" "$GEN") 21503aa99676SStefan Eßercontents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET") 21513aa99676SStefan Eßercontents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS") 21523aa99676SStefan Eßercontents=$(replace "$contents" "GEN_EMU" "$GEN_EMU") 21533aa99676SStefan Eßer 215444d4804dSStefan Eßercontents=$(replace "$contents" "BSD" "$bsd") 215576238846SStefan Eßercontents=$(replace "$contents" "APPLE" "$apple") 215644d4804dSStefan Eßer 215744d4804dSStefan Eßercontents=$(replace "$contents" "BC_DEFAULT_BANNER" "$bc_default_banner") 215844d4804dSStefan Eßercontents=$(replace "$contents" "BC_DEFAULT_SIGINT_RESET" "$bc_default_sigint_reset") 215944d4804dSStefan Eßercontents=$(replace "$contents" "DC_DEFAULT_SIGINT_RESET" "$dc_default_sigint_reset") 216044d4804dSStefan Eßercontents=$(replace "$contents" "BC_DEFAULT_TTY_MODE" "$bc_default_tty_mode") 216144d4804dSStefan Eßercontents=$(replace "$contents" "DC_DEFAULT_TTY_MODE" "$dc_default_tty_mode") 216244d4804dSStefan Eßercontents=$(replace "$contents" "BC_DEFAULT_PROMPT" "$bc_default_prompt") 216344d4804dSStefan Eßercontents=$(replace "$contents" "DC_DEFAULT_PROMPT" "$dc_default_prompt") 216410041e99SStefan Eßercontents=$(replace "$contents" "BC_DEFAULT_EXPR_EXIT" "$bc_default_expr_exit") 216510041e99SStefan Eßercontents=$(replace "$contents" "DC_DEFAULT_EXPR_EXIT" "$dc_default_expr_exit") 2166d101cdd6SStefan Eßercontents=$(replace "$contents" "BC_DEFAULT_DIGIT_CLAMP" "$bc_default_digit_clamp") 2167d101cdd6SStefan Eßercontents=$(replace "$contents" "DC_DEFAULT_DIGIT_CLAMP" "$dc_default_digit_clamp") 216844d4804dSStefan Eßer 216944d4804dSStefan Eßer# Do the first print to the Makefile. 217010041e99SStefan Eßerprintf '%s\n%s\n\n' "$contents" "$SRC_TARGETS" > "Makefile" 217110328f8bSStefan Eßer 217244d4804dSStefan Eßer# Generate the individual test targets. 217310328f8bSStefan Eßerif [ "$bc" -ne 0 ]; then 2174d43fa8efSStefan Eßer gen_std_tests bc "$extra_math" "$time_tests" $bc_test_exec 217510328f8bSStefan Eßer gen_script_tests bc "$extra_math" "$generate_tests" "$time_tests" $bc_test_exec 2176d43fa8efSStefan Eßer gen_err_tests bc $bc_test_exec 217710328f8bSStefan Eßerfi 217810328f8bSStefan Eßer 217910328f8bSStefan Eßerif [ "$dc" -ne 0 ]; then 2180d43fa8efSStefan Eßer gen_std_tests dc "$extra_math" "$time_tests" $dc_test_exec 218110328f8bSStefan Eßer gen_script_tests dc "$extra_math" "$generate_tests" "$time_tests" $dc_test_exec 2182d43fa8efSStefan Eßer gen_err_tests dc $dc_test_exec 218310328f8bSStefan Eßerfi 21843aa99676SStefan Eßer 2185*12e0d316SStefan Eßerif [ "$ossfuzz" -ne 0 ]; then 2186*12e0d316SStefan Eßer 2187*12e0d316SStefan Eßer printf 'bc_fuzzer_c: $(BC_FUZZER)\n\tln -sf $(BC_FUZZER) bc_fuzzer_c\n' >> Makefile 2188*12e0d316SStefan Eßer printf 'bc_fuzzer_C: $(BC_FUZZER)\n\tln -sf $(BC_FUZZER) bc_fuzzer_C\n' >> Makefile 2189*12e0d316SStefan Eßer printf 'dc_fuzzer_c: $(DC_FUZZER)\n\tln -sf $(DC_FUZZER) dc_fuzzer_c\n' >> Makefile 2190*12e0d316SStefan Eßer printf 'dc_fuzzer_C: $(DC_FUZZER)\n\tln -sf $(DC_FUZZER) dc_fuzzer_C\n' >> Makefile 2191*12e0d316SStefan Eßer 2192*12e0d316SStefan Eßerfi 2193*12e0d316SStefan Eßer 219444d4804dSStefan Eßer# Copy the correct manuals to the expected places. 219510041e99SStefan Eßermkdir -p manuals 219610041e99SStefan Eßercp -f "$scriptdir/manuals/bc/$manpage_args.1.md" manuals/bc.1.md 219710041e99SStefan Eßercp -f "$scriptdir/manuals/bc/$manpage_args.1" manuals/bc.1 219810041e99SStefan Eßercp -f "$scriptdir/manuals/dc/$manpage_args.1.md" manuals/dc.1.md 219910041e99SStefan Eßercp -f "$scriptdir/manuals/dc/$manpage_args.1" manuals/dc.1 22003aa99676SStefan Eßer 22013aa99676SStefan Eßermake clean > /dev/null 2202