3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2018-2021 Gavin D. Howard and contributors.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
10 # * Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
31 scriptdir=$(dirname "$script")
32 script=$(basename "$script")
36 . "$scriptdir/scripts/functions.sh"
38 # Simply prints the help message and quits based on the argument.
39 # @param msg The help message to print.
53 printf ' %s -h\n' "$script"
54 printf ' %s --help\n' "$script"
55 printf ' %s [-a|-bD|-dB|-c] [-CeEfgGHlmMNrtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script"
56 printf ' [-s SETTING] [-S SETTING]\n'
57 printf ' %s \\\n' "$script"
58 printf ' [--library|--bc-only --disable-dc|--dc-only --disable-bc|--coverage] \\\n'
59 printf ' [--force --debug --disable-extra-math --disable-generated-tests] \\\n'
60 printf ' [--disable-history --disable-man-pages --disable-nls --disable-strip] \\\n'
61 printf ' [--enable-editline] [--enable-readline] \\\n'
62 printf ' [--install-all-locales] [--opt=OPT_LEVEL] \\\n'
63 printf ' [--karatsuba-len=KARATSUBA_LEN] \\\n'
64 printf ' [--set-default-on=SETTING] [--set-default-off=SETTING] \\\n'
65 printf ' [--prefix=PREFIX] [--bindir=BINDIR] [--datarootdir=DATAROOTDIR] \\\n'
66 printf ' [--datadir=DATADIR] [--mandir=MANDIR] [--man1dir=MAN1DIR] \\\n'
68 printf ' -a, --library\n'
69 printf ' Build the libbcl instead of the programs. This is meant to be used with\n'
70 printf ' Other software like programming languages that want to make use of the\n'
71 printf ' parsing and math capabilities. This option will install headers using\n'
72 printf ' `make install`.\n'
73 printf ' -b, --bc-only\n'
74 printf ' Build bc only. It is an error if "-d", "--dc-only", "-B", or\n'
75 printf ' "--disable-bc" are specified too.\n'
76 printf ' -B, --disable-bc\n'
77 printf ' Disable bc. It is an error if "-b", "--bc-only", "-D", or "--disable-dc"\n'
78 printf ' are specified too.\n'
79 printf ' -c, --coverage\n'
80 printf ' Generate test coverage code. Requires gcov and gcovr.\n'
81 printf ' It is an error if either "-b" ("-D") or "-d" ("-B") is specified.\n'
82 printf ' Requires a compiler that use gcc-compatible coverage options\n'
83 printf ' -C, --disable-clean\n'
84 printf ' Disable the clean that configure.sh does before configure.\n'
85 printf ' -d, --dc-only\n'
86 printf ' Build dc only. It is an error if "-b", "--bc-only", "-D", or\n'
87 printf ' "--disable-dc" are specified too.\n'
88 printf ' -D, --disable-dc\n'
89 printf ' Disable dc. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"\n'
90 printf ' are specified too.\n'
91 printf ' -e, --enable-editline\n'
92 printf ' Enable the use of libedit/editline. This is meant for those users that\n'
93 printf ' want vi-like or Emacs-like behavior in history.This option is ignored if\n'
94 printf ' history is disabled. It is an error if this option is enabled when the\n'
95 printf ' -r/--enable-readline option is enabled.\n'
96 printf ' -E, --disable-extra-math\n'
97 printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n'
98 printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n'
99 printf ' function). Additionally, this option disables the extra printing\n'
100 printf ' functions in the math library.\n'
101 printf ' -f, --force\n'
102 printf ' Force use of all enabled options, even if they do not work. This\n'
103 printf ' option is to allow the maintainer a way to test that certain options\n'
104 printf ' are not failing invisibly. (Development only.)\n'
105 printf ' -g, --debug\n'
106 printf ' Build in debug mode. Adds the "-g" flag, and if there are no\n'
107 printf ' other CFLAGS, and "-O" was not given, this also adds the "-O0"\n'
108 printf ' flag. If this flag is *not* given, "-DNDEBUG" is added to CPPFLAGS\n'
109 printf ' and a strip flag is added to the link stage.\n'
110 printf ' -G, --disable-generated-tests\n'
111 printf ' Disable generating tests. This is for platforms that do not have a\n'
112 printf ' GNU bc-compatible bc to generate tests.\n'
113 printf ' -h, --help\n'
114 printf ' Print this help message and exit.\n'
115 printf ' -H, --disable-history\n'
116 printf ' Disable history.\n'
117 printf ' -k KARATSUBA_LEN, --karatsuba-len KARATSUBA_LEN\n'
118 printf ' Set the karatsuba length to KARATSUBA_LEN (default is 64).\n'
119 printf ' It is an error if KARATSUBA_LEN is not a number or is less than 16.\n'
120 printf ' -l, --install-all-locales\n'
121 printf ' Installs all locales, regardless of how many are on the system. This\n'
122 printf ' option is useful for package maintainers who want to make sure that\n'
123 printf ' a package contains all of the locales that end users might need.\n'
124 printf ' -m, --enable-memcheck\n'
125 printf ' Enable memcheck mode, to ensure no memory leaks. For development only.\n'
126 printf ' -M, --disable-man-pages\n'
127 printf ' Disable installing manpages.\n'
128 printf ' -N, --disable-nls\n'
129 printf ' Disable POSIX locale (NLS) support.\n'
130 printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n'
131 printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
132 printf ' but it is provided, so maintainers can build optimized debug builds.\n'
133 printf ' This is passed through to the compiler, so it must be supported.\n'
134 printf ' -r, --enable-readline\n'
135 printf ' Enable the use of libreadline/readline. This is meant for those users\n'
136 printf ' that want vi-like or Emacs-like behavior in history.This option is\n'
137 printf ' ignored if history is disabled. It is an error if this option is\n'
138 printf ' enabled when the -e/--enable-editline option is enabled.\n'
139 printf ' -s SETTING, --set-default-on SETTING\n'
140 printf ' Set the default named by SETTING to on. See below for possible values\n'
141 printf ' for SETTING. For multiple instances of the -s or -S for the the same\n'
142 printf ' setting, the last one is used.\n'
143 printf ' -S SETTING, --set-default-off SETTING\n'
144 printf ' Set the default named by SETTING to off. See below for possible values\n'
145 printf ' for SETTING. For multiple instances of the -s or -S for the the same\n'
146 printf ' setting, the last one is used.\n'
147 printf ' -t, --enable-test-timing\n'
148 printf ' Enable the timing of tests. This is for development only.\n'
149 printf ' -T, --disable-strip\n'
150 printf ' Disable stripping symbols from the compiled binary or binaries.\n'
151 printf ' Stripping symbols only happens when debug mode is off.\n'
152 printf ' -v, --enable-valgrind\n'
153 printf ' Enable a build appropriate for valgrind. For development only.\n'
154 printf ' -z, --enable-fuzz-mode\n'
155 printf ' Enable fuzzing mode. THIS IS FOR DEVELOPMENT ONLY.\n'
156 printf ' --prefix PREFIX\n'
157 printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n'
158 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
159 printf ' Default is "/usr/local".\n'
160 printf ' --bindir BINDIR\n'
161 printf ' The directory to install binaries in. Overrides "$BINDIR" if it exists.\n'
162 printf ' Default is "$PREFIX/bin".\n'
163 printf ' --includedir INCLUDEDIR\n'
164 printf ' The directory to install headers in. Overrides "$INCLUDEDIR" if it\n'
165 printf ' exists. Default is "$PREFIX/include".\n'
166 printf ' --libdir LIBDIR\n'
167 printf ' The directory to install libraries in. Overrides "$LIBDIR" if it exists.\n'
168 printf ' Default is "$PREFIX/lib".\n'
169 printf ' --datarootdir DATAROOTDIR\n'
170 printf ' The root location for data files. Overrides "$DATAROOTDIR" if it exists.\n'
171 printf ' Default is "$PREFIX/share".\n'
172 printf ' --datadir DATADIR\n'
173 printf ' The location for data files. Overrides "$DATADIR" if it exists.\n'
174 printf ' Default is "$DATAROOTDIR".\n'
175 printf ' --mandir MANDIR\n'
176 printf ' The location to install manpages to. Overrides "$MANDIR" if it exists.\n'
177 printf ' Default is "$DATADIR/man".\n'
178 printf ' --man1dir MAN1DIR\n'
179 printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n'
180 printf ' it exists. Default is "$MANDIR/man1".\n'
181 printf ' --man3dir MAN3DIR\n'
182 printf ' The location to install Section 3 manpages to. Overrides "$MAN3DIR" if\n'
183 printf ' it exists. Default is "$MANDIR/man3".\n'
185 printf 'In addition, the following environment variables are used:\n'
187 printf ' CC C compiler. Must be compatible with POSIX c99. If there is a\n'
188 printf ' space in the basename of the compiler, the items after the\n'
189 printf ' first space are assumed to be compiler flags, and in that case,\n'
190 printf ' the flags are automatically moved into CFLAGS. Default is\n'
192 printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99. If there is\n'
193 printf ' a space in the basename of the compiler, the items after the\n'
194 printf ' first space are assumed to be compiler flags, and in the case,\n'
195 printf ' the flags are automatically moved into HOSTCFLAGS. Default is\n'
197 printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n'
198 printf ' CFLAGS C compiler flags.\n'
199 printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n'
200 printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n'
201 printf ' CPPFLAGS C preprocessor flags. Default is "".\n'
202 printf ' LDFLAGS Linker flags. Default is "".\n'
203 printf ' PREFIX The prefix to install to. Default is "/usr/local".\n'
204 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
205 printf ' BINDIR The directory to install binaries in. Default is "$PREFIX/bin".\n'
206 printf ' INCLUDEDIR The directory to install header files in. Default is\n'
207 printf ' "$PREFIX/include".\n'
208 printf ' LIBDIR The directory to install libraries in. Default is\n'
209 printf ' "$PREFIX/lib".\n'
210 printf ' DATAROOTDIR The root location for data files. Default is "$PREFIX/share".\n'
211 printf ' DATADIR The location for data files. Default is "$DATAROOTDIR".\n'
212 printf ' MANDIR The location to install manpages to. Default is "$DATADIR/man".\n'
213 printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n'
214 printf ' "$MANDIR/man1".\n'
215 printf ' MAN3DIR The location to install Section 3 manpages to. Default is\n'
216 printf ' "$MANDIR/man3".\n'
217 printf ' NLSPATH The location to install locale catalogs to. Must be an absolute\n'
218 printf ' path (or contain one). This is treated the same as the POSIX\n'
219 printf ' definition of $NLSPATH (see POSIX environment variables for\n'
220 printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n'
221 printf ' PC_PATH The location to install pkg-config files to. Must be an\n'
222 printf ' path or contain one. Default is the first path given by the\n'
223 printf ' output of `pkg-config --variable=pc_path pkg-config`.\n'
224 printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n'
225 printf ' interfere with other installed bc executables. Default is "".\n'
226 printf ' EXECPREFIX The prefix to append to the executable names, used to not\n'
227 printf ' interfere with other installed bc executables. Default is "".\n'
228 printf ' DESTDIR For package creation. Default is "". If it is empty when\n'
229 printf ' `%s` is run, it can also be passed to `make install`\n' "$script"
230 printf ' later as an environment variable. If both are specified,\n'
231 printf ' the one given to `%s` takes precedence.\n' "$script"
232 printf ' LONG_BIT The number of bits in a C `long` type. This is mostly for the\n'
233 printf ' embedded space since this `bc` uses `long`s internally for\n'
234 printf ' overflow checking. In C99, a `long` is required to be 32 bits.\n'
235 printf ' For most normal desktop systems, setting this is unnecessary,\n'
236 printf ' except that 32-bit platforms with 64-bit longs may want to set\n'
237 printf ' it to `32`. Default is the default of `LONG_BIT` for the target\n'
238 printf ' platform. Minimum allowed is `32`. It is a build time error if\n'
239 printf ' the specified value of `LONG_BIT` is greater than the default\n'
240 printf ' value of `LONG_BIT` for the target platform.\n'
241 printf ' GEN_HOST Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to\n'
242 printf ' produce the C files that contain the help texts as well as the\n'
243 printf ' math libraries. By default, `gen/strgen.c` is used, compiled by\n'
244 printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
245 printf ' removes the need to compile and run an executable on the host\n'
246 printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
247 printf ' `gen/lib2.bc` is over 4095 characters, the max supported length\n'
248 printf ' of a string literal in C99, and `gen/strgen.sh` generates a\n'
249 printf ' string literal instead of an array, as `gen/strgen.c` does. For\n'
250 printf ' most production-ready compilers, this limit probably is not\n'
251 printf ' enforced, but it could be. Both options are still available for\n'
252 printf ' this reason. If you are sure your compiler does not have the\n'
253 printf ' limit and do not want to compile and run a binary on the host\n'
254 printf ' machine, set this variable to "0". Any other value, or a\n'
255 printf ' non-existent value, will cause the build system to compile and\n'
256 printf ' run `gen/strgen.c`. Default is "".\n'
257 printf ' GEN_EMU Emulator to run string generator code under (leave empty if not\n'
258 printf ' necessary). This is not necessary when using `gen/strgen.sh`.\n'
259 printf ' Default is "".\n'
261 printf 'WARNING: even though `configure.sh` supports both option types, short and\n'
262 printf 'long, it does not support handling both at the same time. Use only one type.\n'
267 printf 'bc and dc have some settings that, while they cannot be removed by build time\n'
268 printf 'options, can have their defaults changed at build time by packagers. Users are\n'
269 printf 'also able to change each setting with environment variables.\n'
271 printf 'The following is a table of settings, along with their default values and the\n'
272 printf 'environment variables users can use to change them. (For the defaults, non-zero\n'
273 printf 'means on, and zero means off.)\n'
275 printf '| Setting | Description | Default | Env Variable |\n'
276 printf '| =============== | ==================== | ============ | ==================== |\n'
277 printf '| bc.banner | Whether to display | 0 | BC_BANNER |\n'
278 printf '| | the bc version | | |\n'
279 printf '| | banner when in | | |\n'
280 printf '| | interactive mode. | | |\n'
281 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
282 printf '| bc.sigint_reset | Whether SIGINT will | 1 | BC_SIGINT_RESET |\n'
283 printf '| | reset bc, instead of | | |\n'
284 printf '| | exiting, when in | | |\n'
285 printf '| | interactive mode. | | |\n'
286 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
287 printf '| dc.sigint_reset | Whether SIGINT will | 1 | DC_SIGINT_RESET |\n'
288 printf '| | reset dc, instead of | | |\n'
289 printf '| | exiting, when in | | |\n'
290 printf '| | interactive mode. | | |\n'
291 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
292 printf '| bc.tty_mode | Whether TTY mode for | 1 | BC_TTY_MODE |\n'
293 printf '| | bc should be on when | | |\n'
294 printf '| | available. | | |\n'
295 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
296 printf '| dc.tty_mode | Whether TTY mode for | 0 | BC_TTY_MODE |\n'
297 printf '| | dc should be on when | | |\n'
298 printf '| | available. | | |\n'
299 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
300 printf '| bc.prompt | Whether the prompt | $BC_TTY_MODE | BC_PROMPT |\n'
301 printf '| | for bc should be on | | |\n'
302 printf '| | in tty mode. | | |\n'
303 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
304 printf '| dc.prompt | Whether the prompt | $DC_TTY_MODE | DC_PROMPT |\n'
305 printf '| | for dc should be on | | |\n'
306 printf '| | in tty mode. | | |\n'
307 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
308 printf '| bc.expr_exit | Whether to exit bc | 1 | BC_EXPR_EXIT |\n'
309 printf '| | if an expression or | | |\n'
310 printf '| | expression file is | | |\n'
311 printf '| | given with the -e or | | |\n'
312 printf '| | -f options. | | |\n'
313 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
314 printf '| dc.expr_exit | Whether to exit dc | 1 | DC_EXPR_EXIT |\n'
315 printf '| | if an expression or | | |\n'
316 printf '| | expression file is | | |\n'
317 printf '| | given with the -e or | | |\n'
318 printf '| | -f options. | | |\n'
319 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
321 printf 'These settings are not meant to be changed on a whim. They are meant to ensure\n'
322 printf 'that this bc and dc will conform to the expectations of the user on each\n'
328 # Replaces a file extension in a filename. This is used mostly to turn filenames
329 # like `src/num.c` into `src/num.o`. In other words, it helps to link targets to
330 # the files they depend on.
332 # @param file The filename.
333 # @param ext1 The extension to replace.
334 # @param ext2 The new extension.
337 if [ "$#" -ne 3 ]; then
338 err_exit "Invalid number of args to $0"
341 _replace_ext_file="$1"
342 _replace_ext_ext1="$2"
343 _replace_ext_ext2="$3"
345 _replace_ext_result="${_replace_ext_file%.$_replace_ext_ext1}.$_replace_ext_ext2"
347 printf '%s\n' "$_replace_ext_result"
350 # Replaces a file extension in every filename given in a list. The list is just
351 # a space-separated list of words, so filenames are expected to *not* have
352 # spaces in them. See the documentation for `replace_ext()`.
354 # @param files The list of space-separated filenames to replace extensions for.
355 # @param ext1 The extension to replace.
356 # @param ext2 The new extension.
359 if [ "$#" -ne 3 ]; then
360 err_exit "Invalid number of args to $0"
363 _replace_exts_files="$1"
364 _replace_exts_ext1="$2"
365 _replace_exts_ext2="$3"
367 for _replace_exts_file in $_replace_exts_files; do
368 _replace_exts_new_name=$(replace_ext "$_replace_exts_file" "$_replace_exts_ext1" "$_replace_exts_ext2")
369 _replace_exts_result="$_replace_exts_result $_replace_exts_new_name"
372 printf '%s\n' "$_replace_exts_result"
375 # Finds a placeholder in @a str and replaces it. This is the workhorse of
376 # configure.sh. It's what replaces placeholders in Makefile.in with the data
377 # needed for the chosen build. Below, you will see a lot of calls to this
380 # Note that needle can never contain an exclamation point. For more information,
381 # see substring_replace() in scripts/functions.sh.
383 # @param str The string to find and replace placeholders in.
384 # @param needle The placeholder name.
385 # @param replacement The string to use to replace the placeholder.
388 if [ "$#" -ne 3 ]; then
389 err_exit "Invalid number of args to $0"
394 _replace_replacement="$3"
396 substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement"
399 # This function finds all the source files that need to be built. If there is
400 # only one argument and it is empty, then all source files are built. Otherwise,
401 # the arguments are all assumed to be source files that should *not* be built.
404 _find_src_files_args=""
406 if [ "$#" -ge 1 ] && [ "$1" != "" ]; then
408 while [ "$#" -ge 1 ]; do
409 _find_src_files_a="${1## }"
411 _find_src_files_args=$(printf '%s\n%s/src/%s\n' "$_find_src_files_args" "$scriptdir" "${_find_src_files_a}")
416 _find_src_files_files=$(find "$scriptdir/src/" -depth -name "*.c" -print)
418 _find_src_files_result=""
420 for _find_src_files_f in $_find_src_files_files; do
422 # If this is true, the file is part of args, and therefore, unneeded.
423 if [ "${_find_src_files_args##*$_find_src_files_f}" != "${_find_src_files_args}" ]; then
427 _find_src_files_result=$(printf '%s\n%s\n' "$_find_src_files_result" "$_find_src_files_f")
431 printf '%s\n' "$_find_src_files_result"
434 # This function generates a list of files to go into the Makefile. It generates
435 # the list of object files, as well as the list of test coverage files.
437 # @param contents The contents of the Makefile template to put the list of
441 if [ "$#" -lt 1 ]; then
442 err_exit "Invalid number of args to $0"
445 _gen_file_list_contents="$1"
448 if [ "$#" -ge 1 ]; then
449 _gen_file_list_unneeded="$@"
451 _gen_file_list_unneeded=""
454 _gen_file_list_needle_src="SRC"
455 _gen_file_list_needle_obj="OBJ"
456 _gen_file_list_needle_gcda="GCDA"
457 _gen_file_list_needle_gcno="GCNO"
459 _gen_file_list_replacement=$(find_src_files $_gen_file_list_unneeded | tr '\n' ' ')
460 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
461 "$_gen_file_list_needle_src" "$_gen_file_list_replacement")
463 _gen_file_list_cbases=""
465 for _gen_file_list_f in $_gen_file_list_replacement; do
466 _gen_file_list_b=$(basename "$_gen_file_list_f")
467 _gen_file_list_cbases="$_gen_file_list_cbases src/$_gen_file_list_b"
470 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_cbases" "c" "o")
471 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
472 "$_gen_file_list_needle_obj" "$_gen_file_list_replacement")
474 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "o" "gcda")
475 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
476 "$_gen_file_list_needle_gcda" "$_gen_file_list_replacement")
478 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "gcda" "gcno")
479 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
480 "$_gen_file_list_needle_gcno" "$_gen_file_list_replacement")
482 printf '%s\n' "$_gen_file_list_contents"
485 # Generates the proper test targets for each test to have its own target. This
486 # allows `make test` to run in parallel.
488 # @param name Which calculator to generate tests for.
489 # @param extra_math An integer that, if non-zero, activates extra math tests.
490 # @param time_tests An integer that, if non-zero, tells the test suite to time
491 # the execution of each test.
494 _gen_std_tests_name="$1"
497 _gen_std_tests_extra_math="$1"
500 _gen_std_tests_time_tests="$1"
503 _gen_std_tests_extra_required=$(cat "$scriptdir/tests/extra_required.txt")
505 for _gen_std_tests_t in $(cat "$scriptdir/tests/$_gen_std_tests_name/all.txt"); do
507 if [ "$_gen_std_tests_extra_math" -eq 0 ]; then
509 if [ -z "${_gen_std_tests_extra_required##*$_gen_std_tests_t*}" ]; then
510 printf 'test_%s_%s:\n\t@printf "Skipping %s %s\\n"\n\n' \
511 "$_gen_std_tests_name" "$_gen_std_tests_t" "$_gen_std_tests_name" \
512 "$_gen_std_tests_t" >> "Makefile"
518 printf 'test_%s_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh \$(TESTSDIR)/test.sh %s %s %s %s %s\n\n' \
519 "$_gen_std_tests_name" "$_gen_std_tests_t" "$builddir" "$_gen_std_tests_name" \
520 "$_gen_std_tests_t" "$generate_tests" "$time_tests" \
526 # Generates a list of test targets that will be used as prerequisites for other
529 # @param name The name of the calculator to generate test targets for.
530 gen_std_test_targets() {
532 _gen_std_test_targets_name="$1"
535 _gen_std_test_targets_tests=$(cat "$scriptdir/tests/${_gen_std_test_targets_name}/all.txt")
537 for _gen_std_test_targets_t in $_gen_std_test_targets_tests; do
538 printf ' test_%s_%s' "$_gen_std_test_targets_name" "$_gen_std_test_targets_t"
544 # Generates the proper test targets for each error test to have its own target.
545 # This allows `make test_bc_errors` and `make test_dc_errors` to run in
548 # @param name Which calculator to generate tests for.
551 _gen_err_tests_name="$1"
554 _gen_err_tests_fs=$(ls "$scriptdir/tests/$_gen_err_tests_name/errors/")
556 for _gen_err_tests_t in $_gen_err_tests_fs; do
558 printf 'test_%s_error_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh \$(TESTSDIR)/error.sh %s %s %s\n\n' \
559 "$_gen_err_tests_name" "$_gen_err_tests_t" "$builddir" "$_gen_err_tests_name" \
560 "$_gen_err_tests_t" "$*" >> "Makefile"
566 # Generates a list of error test targets that will be used as prerequisites for
569 # @param name The name of the calculator to generate test targets for.
570 gen_err_test_targets() {
572 _gen_err_test_targets_name="$1"
575 _gen_err_test_targets_tests=$(ls "$scriptdir/tests/$_gen_err_test_targets_name/errors/")
577 for _gen_err_test_targets_t in $_gen_err_test_targets_tests; do
578 printf ' test_%s_error_%s' "$_gen_err_test_targets_name" "$_gen_err_test_targets_t"
584 # Generates the proper script test targets for each script test to have its own
585 # target. This allows `make test` to run in parallel.
587 # @param name Which calculator to generate tests for.
588 # @param extra_math An integer that, if non-zero, activates extra math tests.
589 # @param generate An integer that, if non-zero, activates generated tests.
590 # @param time_tests An integer that, if non-zero, tells the test suite to time
591 # the execution of each test.
594 _gen_script_tests_name="$1"
597 _gen_script_tests_extra_math="$1"
600 _gen_script_tests_generate="$1"
603 _gen_script_tests_time="$1"
606 _gen_script_tests_tests=$(cat "$scriptdir/tests/$_gen_script_tests_name/scripts/all.txt")
608 for _gen_script_tests_f in $_gen_script_tests_tests; do
610 _gen_script_tests_b=$(basename "$_gen_script_tests_f" ".${_gen_script_tests_name}")
612 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' \
613 "$_gen_script_tests_name" "$_gen_script_tests_b" "$builddir" "$_gen_script_tests_name" \
614 "$_gen_script_tests_f" "$_gen_script_tests_extra_math" "$_gen_script_tests_generate" \
615 "$_gen_script_tests_time" "$*" >> "Makefile"
624 _set_default_name="$1"
627 # The reason that the variables that are being set do not have the same
628 # non-collision avoidance that the other variables do is that we *do* want
629 # the settings of these variables to leak out of the function. They adjust
630 # the settings outside of the function.
631 case "$_set_default_name" in
633 bc.banner) bc_default_banner="$_set_default_on" ;;
634 bc.sigint_reset) bc_default_sigint_reset="$_set_default_on" ;;
635 dc.sigint_reset) dc_default_sigint_reset="$_set_default_on" ;;
636 bc.tty_mode) bc_default_tty_mode="$_set_default_on" ;;
637 dc.tty_mode) dc_default_tty_mode="$_set_default_on" ;;
638 bc.prompt) bc_default_prompt="$_set_default_on" ;;
639 dc.prompt) dc_default_prompt="$_set_default_on" ;;
640 bc.expr_exit) bc_default_expr_exit="$_set_default_on";;
641 dc.expr_exit) dc_default_expr_exit="$_set_default_on";;
642 ?) usage "Invalid setting: $_set_default_name" ;;
647 # Generates a list of script test targets that will be used as prerequisites for
650 # @param name The name of the calculator to generate script test targets for.
651 gen_script_test_targets() {
653 _gen_script_test_targets_name="$1"
656 _gen_script_test_targets_tests=$(cat "$scriptdir/tests/$_gen_script_test_targets_name/scripts/all.txt")
658 for _gen_script_test_targets_f in $_gen_script_test_targets_tests; do
659 _gen_script_test_targets_b=$(basename "$_gen_script_test_targets_f" \
660 ".$_gen_script_test_targets_name")
661 printf ' test_%s_script_%s' "$_gen_script_test_targets_name" \
662 "$_gen_script_test_targets_b"
668 # This is a list of defaults, but it is also the list of possible options for
671 # The development options are: force (force options even if they fail), valgrind
672 # (build in a way suitable for valgrind testing), memcheck (same as valgrind),
673 # and fuzzing (build in a way suitable for fuzzing).
697 # The empty strings are because they depend on TTY mode. If they are directly
698 # set, though, they will be integers. We test for empty strings later.
700 bc_default_sigint_reset=1
701 dc_default_sigint_reset=1
702 bc_default_tty_mode=1
703 dc_default_tty_mode=0
706 bc_default_expr_exit=1
707 dc_default_expr_exit=1
709 # getopts is a POSIX utility, but it cannot handle long options. Thus, the
710 # handling of long options is done by hand, and that's the reason that short and
711 # long options cannot be mixed.
712 while getopts "abBcdDeEfgGhHk:lMmNO:rS:s:tTvz-" opt; do
726 G) generate_tests=0 ;;
729 k) karatsuba_len="$OPTARG" ;;
732 M) install_manpages=0 ;;
734 O) optimization="$OPTARG" ;;
736 S) set_default 0 "$OPTARG" ;;
737 s) set_default 1 "$OPTARG" ;;
745 LONG_OPTARG="${arg#*=}"
748 library) library=1 ;;
749 bc-only) bc_only=1 ;;
750 dc-only) dc_only=1 ;;
751 coverage) coverage=1 ;;
754 prefix=?*) PREFIX="$LONG_OPTARG" ;;
756 if [ "$#" -lt 2 ]; then
757 usage "No argument given for '--$arg' option"
761 bindir=?*) BINDIR="$LONG_OPTARG" ;;
763 if [ "$#" -lt 2 ]; then
764 usage "No argument given for '--$arg' option"
768 includedir=?*) INCLUDEDIR="$LONG_OPTARG" ;;
770 if [ "$#" -lt 2 ]; then
771 usage "No argument given for '--$arg' option"
775 libdir=?*) LIBDIR="$LONG_OPTARG" ;;
777 if [ "$#" -lt 2 ]; then
778 usage "No argument given for '--$arg' option"
782 datarootdir=?*) DATAROOTDIR="$LONG_OPTARG" ;;
784 if [ "$#" -lt 2 ]; then
785 usage "No argument given for '--$arg' option"
789 datadir=?*) DATADIR="$LONG_OPTARG" ;;
791 if [ "$#" -lt 2 ]; then
792 usage "No argument given for '--$arg' option"
796 mandir=?*) MANDIR="$LONG_OPTARG" ;;
798 if [ "$#" -lt 2 ]; then
799 usage "No argument given for '--$arg' option"
803 man1dir=?*) MAN1DIR="$LONG_OPTARG" ;;
805 if [ "$#" -lt 2 ]; then
806 usage "No argument given for '--$arg' option"
810 man3dir=?*) MAN3DIR="$LONG_OPTARG" ;;
812 if [ "$#" -lt 2 ]; then
813 usage "No argument given for '--$arg' option"
817 localedir=?*) LOCALEDIR="$LONG_OPTARG" ;;
819 if [ "$#" -lt 2 ]; then
820 usage "No argument given for '--$arg' option"
824 karatsuba-len=?*) karatsuba_len="$LONG_OPTARG" ;;
826 if [ "$#" -lt 2 ]; then
827 usage "No argument given for '--$arg' option"
831 opt=?*) optimization="$LONG_OPTARG" ;;
833 if [ "$#" -lt 2 ]; then
834 usage "No argument given for '--$arg' option"
838 set-default-on=?*) set_default 1 "$LONG_OPTARG" ;;
840 if [ "$#" -lt 2 ]; then
841 usage "No argument given for '--$arg' option"
845 set-default-off=?*) set_default 0 "$LONG_OPTARG" ;;
847 if [ "$#" -lt 2 ]; then
848 usage "No argument given for '--$arg' option"
852 disable-bc) dc_only=1 ;;
853 disable-dc) bc_only=1 ;;
854 disable-clean) clean=0 ;;
855 disable-extra-math) extra_math=0 ;;
856 disable-generated-tests) generate_tests=0 ;;
857 disable-history) hist=0 ;;
858 disable-man-pages) install_manpages=0 ;;
859 disable-nls) nls=0 ;;
860 disable-strip) strip_bin=0 ;;
861 enable-editline) editline=1 ;;
862 enable-readline) readline=1 ;;
863 enable-test-timing) time_tests=1 ;;
864 enable-valgrind) vg=1 ;;
865 enable-fuzz-mode) fuzz=1 ;;
866 enable-memcheck) memcheck=1 ;;
867 install-all-locales) all_locales=1 ;;
868 help* | bc-only* | dc-only* | coverage* | debug*)
869 usage "No arg allowed for --$arg option" ;;
870 disable-bc* | disable-dc* | disable-clean*)
871 usage "No arg allowed for --$arg option" ;;
873 usage "No arg allowed for --$arg option" ;;
874 disable-generated-tests* | disable-history*)
875 usage "No arg allowed for --$arg option" ;;
876 disable-man-pages* | disable-nls* | disable-strip*)
877 usage "No arg allowed for --$arg option" ;;
878 enable-fuzz-mode* | enable-test-timing* | enable-valgrind*)
879 usage "No arg allowed for --$arg option" ;;
880 enable-memcheck* | install-all-locales*)
881 usage "No arg allowed for --$arg option" ;;
882 enable-editline* | enable-readline*)
883 usage "No arg allowed for --$arg option" ;;
884 '') break ;; # "--" terminates argument processing
885 * ) usage "Invalid option $LONG_OPTARG" ;;
889 ?) usage "Invalid option: $opt" ;;
894 # Sometimes, developers don't want configure.sh to do a config clean. But
896 if [ "$clean" -ne 0 ]; then
897 if [ -f ./Makefile ]; then
898 make clean_config > /dev/null
902 # It is an error to say that bc only should be built and likewise for dc.
903 if [ "$bc_only" -eq 1 ] && [ "$dc_only" -eq 1 ]; then
904 usage "Can only specify one of -b(-D) or -d(-B)"
907 # The library is mutually exclusive to the calculators, so it's an error to
908 # give an option for either of them.
909 if [ "$library" -ne 0 ]; then
910 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
911 usage "Must not specify -b(-D) or -d(-B) when building the library"
915 # KARATSUBA_LEN must be an integer and must be 16 or greater.
916 case $karatsuba_len in
917 (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;;
921 if [ "$karatsuba_len" -lt 16 ]; then
922 usage "KARATSUBA_LEN is less than 16"
927 if [ -z "${LONG_BIT+set}" ]; then
929 elif [ "$LONG_BIT" -lt 32 ]; then
930 usage "LONG_BIT is less than 32"
932 LONG_BIT_DEFINE="-DBC_LONG_BIT=\$(BC_LONG_BIT)"
935 if [ -z "$CC" ]; then
939 # I had users complain that, if they gave CFLAGS as part of CC, which
940 # autotools allows in its braindead way, the build would fail with an error.
941 # I don't like adjusting for autotools, but oh well. These lines puts the
942 # stuff after the first space into CFLAGS.
943 ccbase=$(basename "$CC")
947 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
948 ccflags="${ccbase#$prefix}"
949 cc="${ccbase%%$suffix}"
950 ccdir=$(dirname "$CC")
951 if [ "$ccdir" = "." ] && [ "${CC#.}" = "$CC" ]; then
957 CFLAGS="$CFLAGS $ccflags"
961 if [ -z "$HOSTCC" ] && [ -z "$HOST_CC" ]; then
963 elif [ -z "$HOSTCC" ]; then
967 if [ "$HOSTCC" != "$CC" ]; then
969 # Like above, this splits HOSTCC and HOSTCFLAGS.
970 ccbase=$(basename "$HOSTCC")
974 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
975 ccflags="${ccbase#$prefix}"
976 cc="${ccbase%%$suffix}"
977 ccdir=$(dirname "$HOSTCC")
978 if [ "$ccdir" = "." ] && [ "${HOSTCC#.}" = "$HOSTCC" ]; then
983 HOSTCC="${ccdir}${cc}"
984 HOSTCFLAGS="$HOSTCFLAGS $ccflags"
988 if [ -z "${HOSTCFLAGS+set}" ] && [ -z "${HOST_CFLAGS+set}" ]; then
990 elif [ -z "${HOSTCFLAGS+set}" ]; then
991 HOSTCFLAGS="$HOST_CFLAGS"
994 # Store these for the cross compilation detection later.
996 OLDHOSTCFLAGS="$HOSTCFLAGS"
998 link="@printf 'No link necessary\\\\n'"
1000 executable="BC_EXEC"
1002 tests="test_bc timeconst test_dc"
1004 bc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh bc $extra_math 1 $generate_tests $time_tests \$(BC_EXEC)"
1005 bc_test_np="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh -n bc $extra_math 1 $generate_tests $time_tests \$(BC_EXEC)"
1006 dc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh dc $extra_math 1 $generate_tests $time_tests \$(DC_EXEC)"
1007 dc_test_np="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh -n dc $extra_math 1 $generate_tests $time_tests \$(DC_EXEC)"
1009 timeconst="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/bc/timeconst.sh \$(TESTSDIR)/bc/scripts/timeconst.bc \$(BC_EXEC)"
1011 # In order to have cleanup at exit, we need to be in
1012 # debug mode, so don't run valgrind without that.
1013 if [ "$vg" -ne 0 ]; then
1015 bc_test_exec='valgrind $(VALGRIND_ARGS) $(BC_EXEC)'
1016 dc_test_exec='valgrind $(VALGRIND_ARGS) $(DC_EXEC)'
1018 bc_test_exec='$(BC_EXEC)'
1019 dc_test_exec='$(DC_EXEC)'
1022 test_bc_history_prereqs="test_bc_history_all"
1023 test_dc_history_prereqs="test_dc_history_all"
1025 karatsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
1026 karatsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
1028 bc_lib="\$(GEN_DIR)/lib.o"
1029 bc_help="\$(GEN_DIR)/bc_help.o"
1030 dc_help="\$(GEN_DIR)/dc_help.o"
1032 default_target_prereqs="\$(BIN) \$(OBJS)"
1033 default_target_cmd="\$(CC) \$(CFLAGS) \$(OBJS) \$(LDFLAGS) -o \$(EXEC)"
1034 default_target="\$(DC_EXEC)"
1036 second_target_prereqs=""
1037 second_target_cmd="$default_target_cmd"
1038 second_target="\$(BC_EXEC)"
1040 # This if/else if chain is for setting the defaults that change based on whether
1041 # the library is being built, bc only, dc only, or both calculators.
1042 if [ "$library" -ne 0 ]; then
1050 default_target_prereqs="\$(BIN) \$(OBJ)"
1051 default_target_cmd="ar -r -cu \$(LIBBC) \$(OBJ)"
1052 default_target="\$(LIBBC)"
1053 tests="test_library"
1054 test_bc_history_prereqs=" test_bc_history_skip"
1055 test_dc_history_prereqs=" test_dc_history_skip"
1057 install_prereqs=" install_library"
1058 uninstall_prereqs=" uninstall_library"
1059 install_man_prereqs=" install_bcl_manpage"
1060 uninstall_man_prereqs=" uninstall_bcl_manpage"
1062 elif [ "$bc_only" -eq 1 ]; then
1071 dc_test="@printf 'No dc tests to run\\\\n'"
1072 dc_test_np="@printf 'No dc tests to run\\\\n'"
1073 test_dc_history_prereqs=" test_dc_history_skip"
1075 install_prereqs=" install_execs"
1076 install_man_prereqs=" install_bc_manpage"
1077 uninstall_prereqs=" uninstall_bc"
1078 uninstall_man_prereqs=" uninstall_bc_manpage"
1080 default_target="\$(BC_EXEC)"
1081 second_target="\$(DC_EXEC)"
1082 tests="test_bc timeconst"
1084 elif [ "$dc_only" -eq 1 ]; then
1095 executable="DC_EXEC"
1097 bc_test="@printf 'No bc tests to run\\\\n'"
1098 bc_test_np="@printf 'No bc tests to run\\\\n'"
1099 test_bc_history_prereqs=" test_bc_history_skip"
1101 timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'"
1103 install_prereqs=" install_execs"
1104 install_man_prereqs=" install_dc_manpage"
1105 uninstall_prereqs=" uninstall_dc"
1106 uninstall_man_prereqs=" uninstall_dc_manpage"
1115 executables="bc and dc"
1117 karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)"
1118 karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)"
1120 if [ "$library" -eq 0 ]; then
1121 install_prereqs=" install_execs"
1122 install_man_prereqs=" install_bc_manpage install_dc_manpage"
1123 uninstall_prereqs=" uninstall_bc uninstall_dc"
1124 uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage"
1126 install_prereqs=" install_library install_bcl_header"
1127 install_man_prereqs=" install_bcl_manpage"
1128 uninstall_prereqs=" uninstall_library uninstall_bcl_header"
1129 uninstall_man_prereqs=" uninstall_bcl_manpage"
1130 tests="test_library"
1133 second_target_prereqs="$default_target_prereqs"
1134 default_target_prereqs="$second_target"
1135 default_target_cmd="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)"
1139 # We need specific stuff for fuzzing.
1140 if [ "$fuzz" -ne 0 ]; then
1147 # This sets some necessary things for debug mode.
1148 if [ "$debug" -eq 1 ]; then
1150 if [ -z "$CFLAGS" ] && [ -z "$optimization" ]; then
1158 CPPFLAGS="-DNDEBUG $CPPFLAGS"
1160 if [ "$strip_bin" -ne 0 ]; then
1161 LDFLAGS="-s $LDFLAGS"
1165 # Set optimization CFLAGS.
1166 if [ -n "$optimization" ]; then
1167 CFLAGS="-O$optimization $CFLAGS"
1170 # Set test coverage defaults.
1171 if [ "$coverage" -eq 1 ]; then
1173 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
1174 usage "Can only specify -c without -b or -d"
1177 CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS"
1178 CPPFLAGS="-DNDEBUG $CPPFLAGS"
1180 COVERAGE_OUTPUT="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA) \$(HISTORY_GCDA) \$(RAND_GCDA)"
1181 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;\$(RM) -f \$(GEN)*.gc*"
1182 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;gcovr --exclude-unreachable-branches --exclude-throw-branches --html-details --output index.html"
1183 COVERAGE_PREREQS=" test coverage_output"
1186 COVERAGE_OUTPUT="@printf 'Coverage not generated\\\\n'"
1191 # Set some defaults.
1192 if [ -z "${DESTDIR+set}" ]; then
1195 destdir="DESTDIR = $DESTDIR"
1198 if [ -z "${PREFIX+set}" ]; then
1202 if [ -z "${BINDIR+set}" ]; then
1203 BINDIR="$PREFIX/bin"
1206 if [ -z "${INCLUDEDIR+set}" ]; then
1207 INCLUDEDIR="$PREFIX/include"
1210 if [ -z "${LIBDIR+set}" ]; then
1211 LIBDIR="$PREFIX/lib"
1214 if [ -z "${PC_PATH+set}" ]; then
1218 command -v pkg-config > /dev/null
1223 if [ "$err" -eq 0 ]; then
1224 PC_PATH=$(pkg-config --variable=pc_path pkg-config)
1225 PC_PATH="${PC_PATH%%:*}"
1232 # Set a default for the DATAROOTDIR. This is done if either manpages will be
1233 # installed, or locales are enabled because that's probably where NLS_PATH
1235 if [ "$install_manpages" -ne 0 ] || [ "$nls" -ne 0 ]; then
1236 if [ -z "${DATAROOTDIR+set}" ]; then
1237 DATAROOTDIR="$PREFIX/share"
1241 # Set defaults for manpage environment variables.
1242 if [ "$install_manpages" -ne 0 ]; then
1244 if [ -z "${DATADIR+set}" ]; then
1245 DATADIR="$DATAROOTDIR"
1248 if [ -z "${MANDIR+set}" ]; then
1249 MANDIR="$DATADIR/man"
1252 if [ -z "${MAN1DIR+set}" ]; then
1253 MAN1DIR="$MANDIR/man1"
1256 if [ -z "${MAN3DIR+set}" ]; then
1257 MAN3DIR="$MANDIR/man3"
1261 install_man_prereqs=""
1262 uninstall_man_prereqs=""
1265 # Here is where we test NLS (the locale system). This is done by trying to
1266 # compile src/vm.c, which has the relevant code. If it fails, then it is
1268 if [ "$nls" -ne 0 ]; then
1272 printf 'Testing NLS...\n'
1274 flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
1275 flags="$flags -DBC_ENABLE_HISTORY=$hist -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
1276 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
1277 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
1279 "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/vm.c" -o "./vm.o" > /dev/null 2>&1
1285 # If this errors, it is probably because of building on Windows,
1286 # and NLS is not supported on Windows, so disable it.
1287 if [ "$err" -ne 0 ]; then
1288 printf 'NLS does not work.\n'
1289 if [ $force -eq 0 ]; then
1290 printf 'Disabling NLS...\n\n'
1293 printf 'Forcing NLS...\n\n'
1296 printf 'NLS works.\n\n'
1298 printf 'Testing gencat...\n'
1299 gencat "./en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
1303 rm -rf "./en_US.cat"
1305 if [ "$err" -ne 0 ]; then
1306 printf 'gencat does not work.\n'
1307 if [ $force -eq 0 ]; then
1308 printf 'Disabling NLS...\n\n'
1311 printf 'Forcing NLS...\n\n'
1315 printf 'gencat works.\n\n'
1317 # It turns out that POSIX locales are really terrible, and running
1318 # gencat on one machine is not guaranteed to make those cat files
1319 # portable to another machine, so we had better warn the user here.
1320 if [ "$HOSTCC" != "$CC" ] || [ "$OLDHOSTCFLAGS" != "$OLDCFLAGS" ]; then
1321 printf 'Cross-compile detected.\n\n'
1322 printf 'WARNING: Catalog files generated with gencat may not be portable\n'
1323 printf ' across different architectures.\n\n'
1326 if [ -z "$NLSPATH" ]; then
1327 NLSPATH="/usr/share/locale/%L/%N"
1330 install_locales_prereqs=" install_locales"
1331 uninstall_locales_prereqs=" uninstall_locales"
1340 install_locales_prereqs=""
1341 uninstall_locales_prereqs=""
1345 if [ "$nls" -ne 0 ] && [ "$all_locales" -ne 0 ]; then
1346 install_locales="\$(LOCALE_INSTALL) -l \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
1348 install_locales="\$(LOCALE_INSTALL) \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
1351 # Like the above tested locale support, this tests history.
1352 if [ "$hist" -eq 1 ]; then
1354 if [ "$editline" -ne 0 ] && [ "$readline" -ne 0 ]; then
1355 usage "Must only enable one of readline or editline"
1360 printf 'Testing history...\n'
1362 flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
1363 flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
1364 flags="$flags -DBC_ENABLE_EDITLINE=$editline -DBC_ENABLE_READLINE=$readline"
1365 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
1366 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
1368 "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/history.c" -o "./history.o" > /dev/null 2>&1
1372 rm -rf "./history.o"
1374 # If this errors, it is probably because of building on Windows,
1375 # and history is not supported on Windows, so disable it.
1376 if [ "$err" -ne 0 ]; then
1377 printf 'History does not work.\n'
1378 if [ $force -eq 0 ]; then
1379 printf 'Disabling history...\n\n'
1382 printf 'Forcing history...\n\n'
1385 printf 'History works.\n\n'
1392 # We have to disable the history tests if it is disabled or valgrind is on. Or
1393 # if we are using editline or readline.
1394 if [ "$hist" -eq 0 ] || [ "$vg" -ne 0 ]; then
1395 test_bc_history_prereqs=" test_bc_history_skip"
1396 test_dc_history_prereqs=" test_dc_history_skip"
1397 history_tests="@printf 'Skipping history tests...\\\\n'"
1398 CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
1401 if [ "$editline" -eq 0 ] && [ "$readline" -eq 0 ]; then
1402 history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n'"
1403 history_tests="$history_tests \&\& \$(TESTSDIR)/history.sh bc -a \&\&"
1404 history_tests="$history_tests \$(TESTSDIR)/history.sh dc -a \&\& printf"
1405 history_tests="$history_tests '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
1407 test_bc_history_prereqs=" test_bc_history_skip"
1408 test_dc_history_prereqs=" test_dc_history_skip"
1409 history_tests="@printf 'Skipping history tests...\\\\n'"
1412 # We are also setting the CFLAGS and LDFLAGS here.
1413 if [ "$editline" -ne 0 ]; then
1414 LDFLAGS="$LDFLAGS -ledit"
1415 CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=1 -DBC_ENABLE_READLINE=0"
1416 elif [ "$readline" -ne 0 ]; then
1417 LDFLAGS="$LDFLAGS -lreadline"
1418 CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=1"
1420 CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
1425 # Test FreeBSD. This is not in an if statement because regardless of whatever
1426 # the user says, we need to know if we are on FreeBSD. If we are, we cannot set
1427 # _POSIX_C_SOURCE and _XOPEN_SOURCE. The FreeBSD headers turn *off* stuff when
1430 printf 'Testing for FreeBSD...\n'
1432 flags="-DBC_TEST_FREEBSD -DBC_ENABLE_AFL=0"
1433 "$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/include/status.h" > /dev/null 2>&1
1437 if [ "$err" -ne 0 ]; then
1438 printf 'On FreeBSD. Not using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
1440 printf 'Not on FreeBSD. Using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
1441 CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
1444 # Test OpenBSD. This is not in an if statement because regardless of whatever
1445 # the user says, we need to know if we are on OpenBSD to activate _BSD_SOURCE.
1446 # No, I cannot `#define _BSD_SOURCE` in a header because OpenBSD's patched GCC
1447 # and Clang complain that that is only allowed for system headers. Sigh....So we
1448 # have to check at configure time and set it on the compiler command-line. And
1449 # we have to set it because we also set _POSIX_C_SOURCE, which OpenBSD headers
1450 # detect, and when they detect it, they turn off _BSD_SOURCE unless it is
1451 # specifically requested.
1453 printf 'Testing for OpenBSD...\n'
1455 flags="-DBC_TEST_OPENBSD -DBC_ENABLE_AFL=0"
1456 "$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/include/status.h" > /dev/null 2>&1
1460 if [ "$err" -ne 0 ]; then
1461 printf 'On OpenBSD. Using _BSD_SOURCE.\n\n'
1464 printf 'Not on OpenBSD.\n\n'
1468 if [ "$library" -eq 1 ]; then
1472 if [ "$extra_math" -eq 1 ] && [ "$bc" -ne 0 ] && [ "$library" -eq 0 ]; then
1473 BC_LIB2_O="\$(GEN_DIR)/lib2.o"
1478 # These lines set the appropriate targets based on whether `gen/strgen.c` or
1479 # `gen/strgen.sh` is used.
1481 GEN_EXEC_TARGET="\$(HOSTCC) \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
1482 CLEAN_PREREQS=" clean_gen clean_coverage"
1484 if [ -z "${GEN_HOST+set}" ]; then
1487 if [ "$GEN_HOST" -eq 0 ]; then
1489 GEN_EXEC_TARGET="@printf 'Do not need to build gen/strgen.c\\\\n'"
1490 CLEAN_PREREQS=" clean_coverage"
1496 headers="\$(HEADERS)"
1498 # This series of if statements figure out what source files are *not* needed.
1499 if [ "$extra_math" -eq 0 ]; then
1500 exclude_extra_math=1
1502 unneeded="$unneeded rand.c"
1504 exclude_extra_math=0
1505 headers="$headers \$(EXTRA_MATH_HEADERS)"
1508 # All of these next if statements set the build type and mark certain source
1509 # files as unneeded so that they won't have targets generated for them.
1511 if [ "$hist" -eq 0 ]; then
1512 manpage_args="${manpage_args}H"
1513 unneeded="$unneeded history.c"
1515 headers="$headers \$(HISTORY_HEADERS)"
1518 if [ "$nls" -eq 0 ]; then
1519 manpage_args="${manpage_args}N"
1522 if [ "$bc" -eq 0 ]; then
1523 unneeded="$unneeded bc.c bc_lex.c bc_parse.c"
1525 headers="$headers \$(BC_HEADERS)"
1528 if [ "$dc" -eq 0 ]; then
1529 unneeded="$unneeded dc.c dc_lex.c dc_parse.c"
1531 headers="$headers \$(DC_HEADERS)"
1534 # This convoluted mess does pull the version out. If you change the format of
1535 # include/version.h, you may have to change this line.
1536 version=$(cat "$scriptdir/include/version.h" | grep "VERSION " - | awk '{ print $3 }' -)
1538 if [ "$library" -ne 0 ]; then
1540 unneeded="$unneeded args.c opt.c read.c file.c main.c"
1541 unneeded="$unneeded lang.c lex.c parse.c program.c"
1542 unneeded="$unneeded bc.c bc_lex.c bc_parse.c"
1543 unneeded="$unneeded dc.c dc_lex.c dc_parse.c"
1544 headers="$headers \$(LIBRARY_HEADERS)"
1546 if [ "$PC_PATH" != "" ]; then
1548 contents=$(cat "$scriptdir/bcl.pc.in")
1550 contents=$(replace "$contents" "INCLUDEDIR" "$INCLUDEDIR")
1551 contents=$(replace "$contents" "LIBDIR" "$LIBDIR")
1552 contents=$(replace "$contents" "VERSION" "$version")
1554 printf '%s\n' "$contents" > "./bcl.pc"
1556 pkg_config_install="\$(SAFE_INSTALL) \$(PC_INSTALL_ARGS) \"\$(BCL_PC)\" \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\""
1557 pkg_config_uninstall="\$(RM) -f \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\""
1561 pkg_config_install=""
1562 pkg_config_uninstall=""
1568 unneeded="$unneeded library.c"
1571 pkg_config_install=""
1572 pkg_config_uninstall=""
1576 # library.c is not needed under normal circumstances.
1577 if [ "$unneeded" = "" ]; then
1578 unneeded="library.c"
1581 # This sets the appropriate manpage for a full build.
1582 if [ "$manpage_args" = "" ]; then
1586 if [ "$vg" -ne 0 ]; then
1590 if [ "$bc_default_prompt" = "" ]; then
1591 bc_default_prompt="$bc_default_tty_mode"
1594 if [ "$dc_default_prompt" = "" ]; then
1595 dc_default_prompt="$dc_default_tty_mode"
1598 # Generate the test targets and prerequisites.
1599 bc_tests=$(gen_std_test_targets bc)
1600 bc_script_tests=$(gen_script_test_targets bc)
1601 bc_err_tests=$(gen_err_test_targets bc)
1602 dc_tests=$(gen_std_test_targets dc)
1603 dc_script_tests=$(gen_script_test_targets dc)
1604 dc_err_tests=$(gen_err_test_targets dc)
1606 # Print out the values; this is for debugging.
1607 printf 'Version: %s\n' "$version"
1609 if [ "$bc" -ne 0 ]; then
1610 printf 'Building bc\n'
1612 printf 'Not building bc\n'
1614 if [ "$dc" -ne 0 ]; then
1615 printf 'Building dc\n'
1617 printf 'Not building dc\n'
1620 printf 'BC_ENABLE_LIBRARY=%s\n\n' "$library"
1621 printf 'BC_ENABLE_HISTORY=%s\n' "$hist"
1622 printf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math"
1623 printf 'BC_ENABLE_NLS=%s\n' "$nls"
1624 printf 'BC_ENABLE_AFL=%s\n' "$fuzz"
1626 printf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len"
1628 printf 'CC=%s\n' "$CC"
1629 printf 'CFLAGS=%s\n' "$CFLAGS"
1630 printf 'HOSTCC=%s\n' "$HOSTCC"
1631 printf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS"
1632 printf 'CPPFLAGS=%s\n' "$CPPFLAGS"
1633 printf 'LDFLAGS=%s\n' "$LDFLAGS"
1634 printf 'PREFIX=%s\n' "$PREFIX"
1635 printf 'BINDIR=%s\n' "$BINDIR"
1636 printf 'INCLUDEDIR=%s\n' "$INCLUDEDIR"
1637 printf 'LIBDIR=%s\n' "$LIBDIR"
1638 printf 'DATAROOTDIR=%s\n' "$DATAROOTDIR"
1639 printf 'DATADIR=%s\n' "$DATADIR"
1640 printf 'MANDIR=%s\n' "$MANDIR"
1641 printf 'MAN1DIR=%s\n' "$MAN1DIR"
1642 printf 'MAN3DIR=%s\n' "$MAN3DIR"
1643 printf 'NLSPATH=%s\n' "$NLSPATH"
1644 printf 'PC_PATH=%s\n' "$PC_PATH"
1645 printf 'EXECSUFFIX=%s\n' "$EXECSUFFIX"
1646 printf 'EXECPREFIX=%s\n' "$EXECPREFIX"
1647 printf 'DESTDIR=%s\n' "$DESTDIR"
1648 printf 'LONG_BIT=%s\n' "$LONG_BIT"
1649 printf 'GEN_HOST=%s\n' "$GEN_HOST"
1650 printf 'GEN_EMU=%s\n' "$GEN_EMU"
1652 printf 'Setting Defaults\n'
1653 printf '================\n'
1654 printf 'bc.banner=%s\n' "$bc_default_banner"
1655 printf 'bc.sigint_reset=%s\n' "$bc_default_sigint_reset"
1656 printf 'dc.sigint_reset=%s\n' "$dc_default_sigint_reset"
1657 printf 'bc.tty_mode=%s\n' "$bc_default_tty_mode"
1658 printf 'dc.tty_mode=%s\n' "$dc_default_tty_mode"
1659 printf 'bc.prompt=%s\n' "$bc_default_prompt"
1660 printf 'dc.prompt=%s\n' "$dc_default_prompt"
1661 printf 'bc.expr_exit=%s\n' "$bc_default_expr_exit"
1662 printf 'dc.expr_exit=%s\n' "$dc_default_expr_exit"
1664 # This is where the real work begins. This is the point at which the Makefile.in
1665 # template is edited and output to the Makefile.
1667 contents=$(cat "$scriptdir/Makefile.in")
1670 replacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***'
1672 contents=$(replace "$contents" "$needle" "$replacement")
1674 # The contents are edited to have the list of files to build.
1675 contents=$(gen_file_list "$contents" $unneeded)
1679 # This line and loop generates the individual targets for source files. I used
1680 # to just use an implicit target, but that was found to be inadequate when I
1681 # added the library.
1682 src_files=$(find_src_files $unneeded)
1684 for f in $src_files; do
1685 o=$(replace_ext "$f" "c" "o")
1687 SRC_TARGETS=$(printf '%s\n\nsrc/%s: src %s %s\n\t$(CC) $(CFLAGS) -o src/%s -c %s\n' \
1688 "$SRC_TARGETS" "$o" "$headers" "$f" "$o" "$f")
1691 # Replace all the placeholders.
1692 contents=$(replace "$contents" "ROOTDIR" "$scriptdir")
1693 contents=$(replace "$contents" "BUILDDIR" "$builddir")
1695 contents=$(replace "$contents" "HEADERS" "$headers")
1697 contents=$(replace "$contents" "BC_ENABLED" "$bc")
1698 contents=$(replace "$contents" "DC_ENABLED" "$dc")
1700 contents=$(replace "$contents" "BC_ALL_TESTS" "$bc_test")
1701 contents=$(replace "$contents" "BC_ALL_TESTS_NP" "$bc_test_np")
1702 contents=$(replace "$contents" "BC_TESTS" "$bc_tests")
1703 contents=$(replace "$contents" "BC_SCRIPT_TESTS" "$bc_script_tests")
1704 contents=$(replace "$contents" "BC_ERROR_TESTS" "$bc_err_tests")
1705 contents=$(replace "$contents" "BC_TEST_EXEC" "$bc_test_exec")
1706 contents=$(replace "$contents" "TIMECONST_ALL_TESTS" "$timeconst")
1708 contents=$(replace "$contents" "DC_ALL_TESTS" "$dc_test")
1709 contents=$(replace "$contents" "DC_ALL_TESTS_NP" "$dc_test_np")
1710 contents=$(replace "$contents" "DC_TESTS" "$dc_tests")
1711 contents=$(replace "$contents" "DC_SCRIPT_TESTS" "$dc_script_tests")
1712 contents=$(replace "$contents" "DC_ERROR_TESTS" "$dc_err_tests")
1713 contents=$(replace "$contents" "DC_TEST_EXEC" "$dc_test_exec")
1715 contents=$(replace "$contents" "BUILD_TYPE" "$manpage_args")
1716 contents=$(replace "$contents" "EXCLUDE_EXTRA_MATH" "$exclude_extra_math")
1718 contents=$(replace "$contents" "LIBRARY" "$library")
1719 contents=$(replace "$contents" "HISTORY" "$hist")
1720 contents=$(replace "$contents" "EXTRA_MATH" "$extra_math")
1721 contents=$(replace "$contents" "NLS" "$nls")
1722 contents=$(replace "$contents" "FUZZ" "$fuzz")
1723 contents=$(replace "$contents" "MEMCHECK" "$memcheck")
1725 contents=$(replace "$contents" "BC_LIB_O" "$bc_lib")
1726 contents=$(replace "$contents" "BC_HELP_O" "$bc_help")
1727 contents=$(replace "$contents" "DC_HELP_O" "$dc_help")
1728 contents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O")
1729 contents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len")
1731 contents=$(replace "$contents" "NLSPATH" "$NLSPATH")
1732 contents=$(replace "$contents" "DESTDIR" "$destdir")
1733 contents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX")
1734 contents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX")
1735 contents=$(replace "$contents" "BINDIR" "$BINDIR")
1736 contents=$(replace "$contents" "INCLUDEDIR" "$INCLUDEDIR")
1737 contents=$(replace "$contents" "LIBDIR" "$LIBDIR")
1738 contents=$(replace "$contents" "MAN1DIR" "$MAN1DIR")
1739 contents=$(replace "$contents" "MAN3DIR" "$MAN3DIR")
1740 contents=$(replace "$contents" "CFLAGS" "$CFLAGS")
1741 contents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS")
1742 contents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS")
1743 contents=$(replace "$contents" "LDFLAGS" "$LDFLAGS")
1744 contents=$(replace "$contents" "CC" "$CC")
1745 contents=$(replace "$contents" "HOSTCC" "$HOSTCC")
1746 contents=$(replace "$contents" "COVERAGE_OUTPUT" "$COVERAGE_OUTPUT")
1747 contents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS")
1748 contents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs")
1749 contents=$(replace "$contents" "INSTALL_MAN_PREREQS" "$install_man_prereqs")
1750 contents=$(replace "$contents" "INSTALL_LOCALES" "$install_locales")
1751 contents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs")
1752 contents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs")
1753 contents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs")
1754 contents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs")
1756 contents=$(replace "$contents" "PC_PATH" "$PC_PATH")
1757 contents=$(replace "$contents" "PKG_CONFIG_INSTALL" "$pkg_config_install")
1758 contents=$(replace "$contents" "PKG_CONFIG_UNINSTALL" "$pkg_config_uninstall")
1760 contents=$(replace "$contents" "DEFAULT_TARGET" "$default_target")
1761 contents=$(replace "$contents" "DEFAULT_TARGET_PREREQS" "$default_target_prereqs")
1762 contents=$(replace "$contents" "DEFAULT_TARGET_CMD" "$default_target_cmd")
1763 contents=$(replace "$contents" "SECOND_TARGET" "$second_target")
1764 contents=$(replace "$contents" "SECOND_TARGET_PREREQS" "$second_target_prereqs")
1765 contents=$(replace "$contents" "SECOND_TARGET_CMD" "$second_target_cmd")
1767 contents=$(replace "$contents" "ALL_PREREQ" "$ALL_PREREQ")
1768 contents=$(replace "$contents" "BC_EXEC_PREREQ" "$bc_exec_prereq")
1769 contents=$(replace "$contents" "BC_EXEC_CMD" "$bc_exec_cmd")
1770 contents=$(replace "$contents" "DC_EXEC_PREREQ" "$dc_exec_prereq")
1771 contents=$(replace "$contents" "DC_EXEC_CMD" "$dc_exec_cmd")
1773 contents=$(replace "$contents" "EXECUTABLES" "$executables")
1774 contents=$(replace "$contents" "MAIN_EXEC" "$main_exec")
1775 contents=$(replace "$contents" "EXEC" "$executable")
1776 contents=$(replace "$contents" "TESTS" "$tests")
1778 contents=$(replace "$contents" "BC_HISTORY_TEST_PREREQS" "$test_bc_history_prereqs")
1779 contents=$(replace "$contents" "DC_HISTORY_TEST_PREREQS" "$test_dc_history_prereqs")
1780 contents=$(replace "$contents" "HISTORY_TESTS" "$history_tests")
1782 contents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test")
1783 contents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test")
1785 contents=$(replace "$contents" "TIMECONST" "$timeconst")
1787 contents=$(replace "$contents" "KARATSUBA" "$karatsuba")
1788 contents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test")
1790 contents=$(replace "$contents" "LONG_BIT" "$LONG_BIT")
1791 contents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE")
1793 contents=$(replace "$contents" "GEN" "$GEN")
1794 contents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET")
1795 contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS")
1796 contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU")
1798 contents=$(replace "$contents" "BSD" "$bsd")
1800 contents=$(replace "$contents" "BC_DEFAULT_BANNER" "$bc_default_banner")
1801 contents=$(replace "$contents" "BC_DEFAULT_SIGINT_RESET" "$bc_default_sigint_reset")
1802 contents=$(replace "$contents" "DC_DEFAULT_SIGINT_RESET" "$dc_default_sigint_reset")
1803 contents=$(replace "$contents" "BC_DEFAULT_TTY_MODE" "$bc_default_tty_mode")
1804 contents=$(replace "$contents" "DC_DEFAULT_TTY_MODE" "$dc_default_tty_mode")
1805 contents=$(replace "$contents" "BC_DEFAULT_PROMPT" "$bc_default_prompt")
1806 contents=$(replace "$contents" "DC_DEFAULT_PROMPT" "$dc_default_prompt")
1807 contents=$(replace "$contents" "BC_DEFAULT_EXPR_EXIT" "$bc_default_expr_exit")
1808 contents=$(replace "$contents" "DC_DEFAULT_EXPR_EXIT" "$dc_default_expr_exit")
1810 # Do the first print to the Makefile.
1811 printf '%s\n%s\n\n' "$contents" "$SRC_TARGETS" > "Makefile"
1813 # Generate the individual test targets.
1814 if [ "$bc" -ne 0 ]; then
1815 gen_std_tests bc "$extra_math" "$time_tests" $bc_test_exec
1816 gen_script_tests bc "$extra_math" "$generate_tests" "$time_tests" $bc_test_exec
1817 gen_err_tests bc $bc_test_exec
1820 if [ "$dc" -ne 0 ]; then
1821 gen_std_tests dc "$extra_math" "$time_tests" $dc_test_exec
1822 gen_script_tests dc "$extra_math" "$generate_tests" "$time_tests" $dc_test_exec
1823 gen_err_tests dc $dc_test_exec
1826 # Copy the correct manuals to the expected places.
1828 cp -f "$scriptdir/manuals/bc/$manpage_args.1.md" manuals/bc.1.md
1829 cp -f "$scriptdir/manuals/bc/$manpage_args.1" manuals/bc.1
1830 cp -f "$scriptdir/manuals/dc/$manpage_args.1.md" manuals/dc.1.md
1831 cp -f "$scriptdir/manuals/dc/$manpage_args.1" manuals/dc.1
1833 make clean > /dev/null