3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2018-2023 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] [-CeEfgGHilmMNPrtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\\\n' "$script"
56 printf ' [-s SETTING] [-S SETTING] [-p TYPE]\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] [--enable-internal-history] \\\n'
62 printf ' [--disable-problematic-tests] [--install-all-locales] \\\n'
63 printf ' [--opt=OPT_LEVEL] [--karatsuba-len=KARATSUBA_LEN] \\\n'
64 printf ' [--set-default-on=SETTING] [--set-default-off=SETTING] \\\n'
65 printf ' [--predefined-build-type=TYPE] \\\n'
66 printf ' [--prefix=PREFIX] [--bindir=BINDIR] [--datarootdir=DATAROOTDIR] \\\n'
67 printf ' [--datadir=DATADIR] [--mandir=MANDIR] [--man1dir=MAN1DIR] \\\n'
68 printf ' [--man3dir=MAN3DIR]\n'
70 if [ "$_usage_val" -ne 0 ]; then
75 printf ' -a, --library\n'
76 printf ' Build the libbcl instead of the programs. This is meant to be used with\n'
77 printf ' Other software like programming languages that want to make use of the\n'
78 printf ' parsing and math capabilities. This option will install headers using\n'
79 printf ' `make install`.\n'
80 printf ' -b, --bc-only\n'
81 printf ' Build bc only. It is an error if "-d", "--dc-only", "-B", or\n'
82 printf ' "--disable-bc" are specified too.\n'
83 printf ' -B, --disable-bc\n'
84 printf ' Disable bc. It is an error if "-b", "--bc-only", "-D", or "--disable-dc"\n'
85 printf ' are specified too.\n'
86 printf ' -c, --coverage\n'
87 printf ' Generate test coverage code. Requires gcov and gcovr.\n'
88 printf ' It is an error if either "-b" ("-D") or "-d" ("-B") is specified.\n'
89 printf ' Requires a compiler that use gcc-compatible coverage options\n'
90 printf ' -C, --disable-clean\n'
91 printf ' Disable the clean that configure.sh does before configure.\n'
92 printf ' -d, --dc-only\n'
93 printf ' Build dc only. It is an error if "-b", "--bc-only", "-D", or\n'
94 printf ' "--disable-dc" are specified too.\n'
95 printf ' -D, --disable-dc\n'
96 printf ' Disable dc. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"\n'
97 printf ' are specified too.\n'
98 printf ' -e, --enable-editline\n'
99 printf ' Enable the use of libedit/editline. This is meant for those users that\n'
100 printf ' want vi-like or Emacs-like behavior in history. This option is ignored\n'
101 printf ' if history is disabled. If the -r or -i options are given with this\n'
102 printf ' option, the last occurrence of all of the three is used.\n'
103 printf ' -E, --disable-extra-math\n'
104 printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n'
105 printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n'
106 printf ' function). Additionally, this option disables the extra printing\n'
107 printf ' functions in the math library.\n'
108 printf ' -f, --force\n'
109 printf ' Force use of all enabled options, even if they do not work. This\n'
110 printf ' option is to allow the maintainer a way to test that certain options\n'
111 printf ' are not failing invisibly. (Development only.)\n'
112 printf ' -g, --debug\n'
113 printf ' Build in debug mode. Adds the "-g" flag, and if there are no\n'
114 printf ' other CFLAGS, and "-O" was not given, this also adds the "-O0"\n'
115 printf ' flag. If this flag is *not* given, "-DNDEBUG" is added to CPPFLAGS\n'
116 printf ' and a strip flag is added to the link stage.\n'
117 printf ' -G, --disable-generated-tests\n'
118 printf ' Disable generating tests. This is for platforms that do not have a\n'
119 printf ' GNU bc-compatible bc to generate tests.\n'
120 printf ' -h, --help\n'
121 printf ' Print this help message and exit.\n'
122 printf ' -H, --disable-history\n'
123 printf ' Disable history.\n'
124 printf ' -i, --enable-internal-history\n'
125 printf ' Enable the internal history implementation and do not depend on either\n'
126 printf ' editline or readline. This option is ignored if history is disabled.\n'
127 printf ' If this option is given along with -e and -r, the last occurrence of\n'
128 printf ' all of the three is used.\n'
129 printf ' -k KARATSUBA_LEN, --karatsuba-len KARATSUBA_LEN\n'
130 printf ' Set the karatsuba length to KARATSUBA_LEN (default is 64).\n'
131 printf ' It is an error if KARATSUBA_LEN is not a number or is less than 16.\n'
132 printf ' -l, --install-all-locales\n'
133 printf ' Installs all locales, regardless of how many are on the system. This\n'
134 printf ' option is useful for package maintainers who want to make sure that\n'
135 printf ' a package contains all of the locales that end users might need.\n'
136 printf ' -m, --enable-memcheck\n'
137 printf ' Enable memcheck mode, to ensure no memory leaks. For development only.\n'
138 printf ' -M, --disable-man-pages\n'
139 printf ' Disable installing manpages.\n'
140 printf ' -N, --disable-nls\n'
141 printf ' Disable POSIX locale (NLS) support.\n'
142 printf ' ***WARNING***: Locales ignore the prefix because they *must* be\n'
143 printf ' installed at a fixed location to work at all. If you do not want that\n'
144 printf ' to happen, you must disable locales (NLS) completely.\n'
145 printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n'
146 printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
147 printf ' but it is provided, so maintainers can build optimized debug builds.\n'
148 printf ' This is passed through to the compiler, so it must be supported.\n'
149 printf ' -p TYPE, --predefined-build-type=TYPE\n'
150 printf ' Sets a given predefined build type with specific defaults. This is for\n'
151 printf ' easy setting of predefined builds. For example, to get a build that\n'
152 printf ' acts like the GNU bc by default, TYPE should be "GNU" (without the\n'
153 printf ' quotes) This option *must* come before any others that might change the\n'
154 printf ' build options. Currently supported values for TYPE include: "BSD" (for\n'
155 printf ' matching the BSD bc and BSD dc), "GNU" (for matching the GNU bc and\n'
156 printf ' dc), "GDH" (for the preferred build of the author, Gavin D. Howard),\n'
157 printf ' and "DBG" (for the preferred debug build of the author). This will\n'
158 printf ' also automatically enable a release build (except for "DBG").\n'
159 printf ' -P, --disable-problematic-tests\n'
160 printf ' Disables problematic tests. These tests usually include tests that\n'
161 printf ' can cause a SIGKILL because of too much memory usage.\n'
162 printf ' -r, --enable-readline\n'
163 printf ' Enable the use of libreadline/readline. This is meant for those users\n'
164 printf ' that want vi-like or Emacs-like behavior in history. This option is\n'
165 printf ' ignored if history is disabled. If this option is given along with -e\n'
166 printf ' and -r, the last occurrence of all of the three is used.\n'
167 printf ' -s SETTING, --set-default-on SETTING\n'
168 printf ' Set the default named by SETTING to on. See below for possible values\n'
169 printf ' for SETTING. For multiple instances of the -s or -S for the the same\n'
170 printf ' setting, the last one is used.\n'
171 printf ' -S SETTING, --set-default-off SETTING\n'
172 printf ' Set the default named by SETTING to off. See below for possible values\n'
173 printf ' for SETTING. For multiple instances of the -s or -S for the the same\n'
174 printf ' setting, the last one is used.\n'
175 printf ' -t, --enable-test-timing\n'
176 printf ' Enable the timing of tests. This is for development only.\n'
177 printf ' -T, --disable-strip\n'
178 printf ' Disable stripping symbols from the compiled binary or binaries.\n'
179 printf ' Stripping symbols only happens when debug mode is off.\n'
180 printf ' -v, --enable-valgrind\n'
181 printf ' Enable a build appropriate for valgrind. For development only.\n'
182 printf ' -z, --enable-fuzz-mode\n'
183 printf ' Enable fuzzing mode. THIS IS FOR DEVELOPMENT ONLY.\n'
184 printf ' --prefix PREFIX\n'
185 printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n'
186 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
187 printf ' Default is "/usr/local".\n'
188 printf ' ***WARNING***: Locales ignore the prefix because they *must* be\n'
189 printf ' installed at a fixed location to work at all. If you do not want that to\n'
190 printf ' happen, you must disable locales (NLS) completely.\n'
191 printf ' --bindir BINDIR\n'
192 printf ' The directory to install binaries in. Overrides "$BINDIR" if it exists.\n'
193 printf ' Default is "$PREFIX/bin".\n'
194 printf ' --includedir INCLUDEDIR\n'
195 printf ' The directory to install headers in. Overrides "$INCLUDEDIR" if it\n'
196 printf ' exists. Default is "$PREFIX/include".\n'
197 printf ' --libdir LIBDIR\n'
198 printf ' The directory to install libraries in. Overrides "$LIBDIR" if it exists.\n'
199 printf ' Default is "$PREFIX/lib".\n'
200 printf ' --datarootdir DATAROOTDIR\n'
201 printf ' The root location for data files. Overrides "$DATAROOTDIR" if it exists.\n'
202 printf ' Default is "$PREFIX/share".\n'
203 printf ' --datadir DATADIR\n'
204 printf ' The location for data files. Overrides "$DATADIR" if it exists.\n'
205 printf ' Default is "$DATAROOTDIR".\n'
206 printf ' --mandir MANDIR\n'
207 printf ' The location to install manpages to. Overrides "$MANDIR" if it exists.\n'
208 printf ' Default is "$DATADIR/man".\n'
209 printf ' --man1dir MAN1DIR\n'
210 printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n'
211 printf ' it exists. Default is "$MANDIR/man1".\n'
212 printf ' --man3dir MAN3DIR\n'
213 printf ' The location to install Section 3 manpages to. Overrides "$MAN3DIR" if\n'
214 printf ' it exists. Default is "$MANDIR/man3".\n'
216 printf 'In addition, the following environment variables are used:\n'
218 printf ' CC C compiler. Must be compatible with POSIX c99. If there is a\n'
219 printf ' space in the basename of the compiler, the items after the\n'
220 printf ' first space are assumed to be compiler flags, and in that case,\n'
221 printf ' the flags are automatically moved into CFLAGS. Default is\n'
223 printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99. If there is\n'
224 printf ' a space in the basename of the compiler, the items after the\n'
225 printf ' first space are assumed to be compiler flags, and in the case,\n'
226 printf ' the flags are automatically moved into HOSTCFLAGS. Default is\n'
228 printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n'
229 printf ' CFLAGS C compiler flags.\n'
230 printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n'
231 printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n'
232 printf ' CPPFLAGS C preprocessor flags. Default is "".\n'
233 printf ' LDFLAGS Linker flags. Default is "".\n'
234 printf ' PREFIX The prefix to install to. Default is "/usr/local".\n'
235 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
236 printf ' ***WARNING***: Locales ignore the prefix because they *must* be\n'
237 printf ' installed at a fixed location to work at all. If you do not\n'
238 printf ' want that to happen, you must disable locales (NLS) completely.\n'
239 printf ' BINDIR The directory to install binaries in. Default is "$PREFIX/bin".\n'
240 printf ' INCLUDEDIR The directory to install header files in. Default is\n'
241 printf ' "$PREFIX/include".\n'
242 printf ' LIBDIR The directory to install libraries in. Default is\n'
243 printf ' "$PREFIX/lib".\n'
244 printf ' DATAROOTDIR The root location for data files. Default is "$PREFIX/share".\n'
245 printf ' DATADIR The location for data files. Default is "$DATAROOTDIR".\n'
246 printf ' MANDIR The location to install manpages to. Default is "$DATADIR/man".\n'
247 printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n'
248 printf ' "$MANDIR/man1".\n'
249 printf ' MAN3DIR The location to install Section 3 manpages to. Default is\n'
250 printf ' "$MANDIR/man3".\n'
251 printf ' NLSPATH The location to install locale catalogs to. Must be an absolute\n'
252 printf ' path (or contain one). This is treated the same as the POSIX\n'
253 printf ' definition of $NLSPATH (see POSIX environment variables for\n'
254 printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n'
255 printf ' PC_PATH The location to install pkg-config files to. Must be an\n'
256 printf ' path or contain one. Default is the first path given by the\n'
257 printf ' output of `pkg-config --variable=pc_path pkg-config`.\n'
258 printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n'
259 printf ' interfere with other installed bc executables. Default is "".\n'
260 printf ' EXECPREFIX The prefix to append to the executable names, used to not\n'
261 printf ' interfere with other installed bc executables. Default is "".\n'
262 printf ' DESTDIR For package creation. Default is "". If it is empty when\n'
263 printf ' `%s` is run, it can also be passed to `make install`\n' "$script"
264 printf ' later as an environment variable. If both are specified,\n'
265 printf ' the one given to `%s` takes precedence.\n' "$script"
266 printf ' LONG_BIT The number of bits in a C `long` type. This is mostly for the\n'
267 printf ' embedded space since this `bc` uses `long`s internally for\n'
268 printf ' overflow checking. In C99, a `long` is required to be 32 bits.\n'
269 printf ' For most normal desktop systems, setting this is unnecessary,\n'
270 printf ' except that 32-bit platforms with 64-bit longs may want to set\n'
271 printf ' it to `32`. Default is the default of `LONG_BIT` for the target\n'
272 printf ' platform. Minimum allowed is `32`. It is a build time error if\n'
273 printf ' the specified value of `LONG_BIT` is greater than the default\n'
274 printf ' value of `LONG_BIT` for the target platform.\n'
275 printf ' GEN_HOST Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to\n'
276 printf ' produce the C files that contain the help texts as well as the\n'
277 printf ' math libraries. By default, `gen/strgen.c` is used, compiled by\n'
278 printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
279 printf ' removes the need to compile and run an executable on the host\n'
280 printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
281 printf ' `gen/lib2.bc` is over 4095 characters, the max supported length\n'
282 printf ' of a string literal in C99, and `gen/strgen.sh` generates a\n'
283 printf ' string literal instead of an array, as `gen/strgen.c` does. For\n'
284 printf ' most production-ready compilers, this limit probably is not\n'
285 printf ' enforced, but it could be. Both options are still available for\n'
286 printf ' this reason. If you are sure your compiler does not have the\n'
287 printf ' limit and do not want to compile and run a binary on the host\n'
288 printf ' machine, set this variable to "0". Any other value, or a\n'
289 printf ' non-existent value, will cause the build system to compile and\n'
290 printf ' run `gen/strgen.c`. Default is "".\n'
291 printf ' GEN_EMU Emulator to run string generator code under (leave empty if not\n'
292 printf ' necessary). This is not necessary when using `gen/strgen.sh`.\n'
293 printf ' Default is "".\n'
295 printf 'WARNING: even though `configure.sh` supports both option types, short and\n'
296 printf 'long, it does not support handling both at the same time. Use only one type.\n'
301 printf 'bc and dc have some settings that, while they cannot be removed by build time\n'
302 printf 'options, can have their defaults changed at build time by packagers. Users are\n'
303 printf 'also able to change each setting with environment variables.\n'
305 printf 'The following is a table of settings, along with their default values and the\n'
306 printf 'environment variables users can use to change them. (For the defaults, non-zero\n'
307 printf 'means on, and zero means off.)\n'
309 printf '| Setting | Description | Default | Env Variable |\n'
310 printf '| =============== | ==================== | ============ | ==================== |\n'
311 printf '| bc.banner | Whether to display | 0 | BC_BANNER |\n'
312 printf '| | the bc version | | |\n'
313 printf '| | banner when in | | |\n'
314 printf '| | interactive mode. | | |\n'
315 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
316 printf '| bc.sigint_reset | Whether SIGINT will | 1 | BC_SIGINT_RESET |\n'
317 printf '| | reset bc, instead of | | |\n'
318 printf '| | exiting, when in | | |\n'
319 printf '| | interactive mode. | | |\n'
320 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
321 printf '| dc.sigint_reset | Whether SIGINT will | 1 | DC_SIGINT_RESET |\n'
322 printf '| | reset dc, instead of | | |\n'
323 printf '| | exiting, when in | | |\n'
324 printf '| | interactive mode. | | |\n'
325 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
326 printf '| bc.tty_mode | Whether TTY mode for | 1 | BC_TTY_MODE |\n'
327 printf '| | bc should be on when | | |\n'
328 printf '| | available. | | |\n'
329 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
330 printf '| dc.tty_mode | Whether TTY mode for | 0 | BC_TTY_MODE |\n'
331 printf '| | dc should be on when | | |\n'
332 printf '| | available. | | |\n'
333 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
334 printf '| bc.prompt | Whether the prompt | $BC_TTY_MODE | BC_PROMPT |\n'
335 printf '| | for bc should be on | | |\n'
336 printf '| | in tty mode. | | |\n'
337 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
338 printf '| dc.prompt | Whether the prompt | $DC_TTY_MODE | DC_PROMPT |\n'
339 printf '| | for dc should be on | | |\n'
340 printf '| | in tty mode. | | |\n'
341 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
342 printf '| bc.expr_exit | Whether to exit bc | 1 | BC_EXPR_EXIT |\n'
343 printf '| | if an expression or | | |\n'
344 printf '| | expression file is | | |\n'
345 printf '| | given with the -e or | | |\n'
346 printf '| | -f options. | | |\n'
347 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
348 printf '| dc.expr_exit | Whether to exit dc | 1 | DC_EXPR_EXIT |\n'
349 printf '| | if an expression or | | |\n'
350 printf '| | expression file is | | |\n'
351 printf '| | given with the -e or | | |\n'
352 printf '| | -f options. | | |\n'
353 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
354 printf '| bc.digit_clamp | Whether to have bc | 0 | BC_DIGIT_CLAMP |\n'
355 printf '| | clamp digits that | | |\n'
356 printf '| | are greater than or | | |\n'
357 printf '| | equal to the current | | |\n'
358 printf '| | ibase when parsing | | |\n'
359 printf '| | numbers. | | |\n'
360 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
361 printf '| dc.digit_clamp | Whether to have dc | 0 | DC_DIGIT_CLAMP |\n'
362 printf '| | clamp digits that | | |\n'
363 printf '| | are greater than or | | |\n'
364 printf '| | equal to the current | | |\n'
365 printf '| | ibase when parsing | | |\n'
366 printf '| | numbers. | | |\n'
367 printf '| --------------- | -------------------- | ------------ | -------------------- |\n'
369 printf 'These settings are not meant to be changed on a whim. They are meant to ensure\n'
370 printf 'that this bc and dc will conform to the expectations of the user on each\n'
376 # Replaces a file extension in a filename. This is used mostly to turn filenames
377 # like `src/num.c` into `src/num.o`. In other words, it helps to link targets to
378 # the files they depend on.
380 # @param file The filename.
381 # @param ext1 The extension to replace.
382 # @param ext2 The new extension.
385 if [ "$#" -ne 3 ]; then
386 err_exit "Invalid number of args to $0"
389 _replace_ext_file="$1"
390 _replace_ext_ext1="$2"
391 _replace_ext_ext2="$3"
393 _replace_ext_result="${_replace_ext_file%.$_replace_ext_ext1}.$_replace_ext_ext2"
395 printf '%s\n' "$_replace_ext_result"
398 # Replaces a file extension in every filename given in a list. The list is just
399 # a space-separated list of words, so filenames are expected to *not* have
400 # spaces in them. See the documentation for `replace_ext()`.
402 # @param files The list of space-separated filenames to replace extensions for.
403 # @param ext1 The extension to replace.
404 # @param ext2 The new extension.
407 if [ "$#" -ne 3 ]; then
408 err_exit "Invalid number of args to $0"
411 _replace_exts_files="$1"
412 _replace_exts_ext1="$2"
413 _replace_exts_ext2="$3"
415 for _replace_exts_file in $_replace_exts_files; do
416 _replace_exts_new_name=$(replace_ext "$_replace_exts_file" "$_replace_exts_ext1" "$_replace_exts_ext2")
417 _replace_exts_result="$_replace_exts_result $_replace_exts_new_name"
420 printf '%s\n' "$_replace_exts_result"
423 # Finds a placeholder in @a str and replaces it. This is the workhorse of
424 # configure.sh. It's what replaces placeholders in Makefile.in with the data
425 # needed for the chosen build. Below, you will see a lot of calls to this
428 # Note that needle can never contain an exclamation point. For more information,
429 # see substring_replace() in scripts/functions.sh.
431 # @param str The string to find and replace placeholders in.
432 # @param needle The placeholder name.
433 # @param replacement The string to use to replace the placeholder.
436 if [ "$#" -ne 3 ]; then
437 err_exit "Invalid number of args to $0"
442 _replace_replacement="$3"
444 substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement"
447 # This function finds all the source files that need to be built. If there is
448 # only one argument and it is empty, then all source files are built. Otherwise,
449 # the arguments are all assumed to be source files that should *not* be built.
452 _find_src_files_args=""
454 if [ "$#" -ge 1 ] && [ "$1" != "" ]; then
456 while [ "$#" -ge 1 ]; do
457 _find_src_files_a="${1## }"
459 _find_src_files_args=$(printf '%s\n%s/src/%s\n' "$_find_src_files_args" "$scriptdir" "${_find_src_files_a}")
464 _find_src_files_files=$(find "$scriptdir/src/" -depth -name "*.c" -print | LC_ALL=C sort)
466 _find_src_files_result=""
468 for _find_src_files_f in $_find_src_files_files; do
470 # If this is true, the file is part of args, and therefore, unneeded.
471 if [ "${_find_src_files_args##*$_find_src_files_f}" != "${_find_src_files_args}" ]; then
475 _find_src_files_result=$(printf '%s\n%s\n' "$_find_src_files_result" "$_find_src_files_f")
479 printf '%s\n' "$_find_src_files_result"
482 # This function generates a list of files to go into the Makefile. It generates
483 # the list of object files, as well as the list of test coverage files.
485 # @param contents The contents of the Makefile template to put the list of
489 if [ "$#" -lt 1 ]; then
490 err_exit "Invalid number of args to $0"
493 _gen_file_list_contents="$1"
496 if [ "$#" -ge 1 ]; then
497 _gen_file_list_unneeded="$@"
499 _gen_file_list_unneeded=""
502 _gen_file_list_needle_src="SRC"
503 _gen_file_list_needle_obj="OBJ"
504 _gen_file_list_needle_gcda="GCDA"
505 _gen_file_list_needle_gcno="GCNO"
507 _gen_file_list_replacement=$(find_src_files $_gen_file_list_unneeded | tr '\n' ' ')
508 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
509 "$_gen_file_list_needle_src" "$_gen_file_list_replacement")
511 _gen_file_list_cbases=""
513 for _gen_file_list_f in $_gen_file_list_replacement; do
514 _gen_file_list_b=$(basename "$_gen_file_list_f")
515 _gen_file_list_cbases="$_gen_file_list_cbases src/$_gen_file_list_b"
518 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_cbases" "c" "o")
519 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
520 "$_gen_file_list_needle_obj" "$_gen_file_list_replacement")
522 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "o" "gcda")
523 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
524 "$_gen_file_list_needle_gcda" "$_gen_file_list_replacement")
526 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "gcda" "gcno")
527 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
528 "$_gen_file_list_needle_gcno" "$_gen_file_list_replacement")
530 printf '%s\n' "$_gen_file_list_contents"
533 # Generates the proper test targets for each test to have its own target. This
534 # allows `make test` to run in parallel.
536 # @param name Which calculator to generate tests for.
537 # @param extra_math An integer that, if non-zero, activates extra math tests.
538 # @param time_tests An integer that, if non-zero, tells the test suite to time
539 # the execution of each test.
542 _gen_std_tests_name="$1"
545 _gen_std_tests_extra_math="$1"
548 _gen_std_tests_time_tests="$1"
551 _gen_std_tests_extra_required=$(cat "$scriptdir/tests/extra_required.txt")
553 for _gen_std_tests_t in $(cat "$scriptdir/tests/$_gen_std_tests_name/all.txt"); do
555 if [ "$_gen_std_tests_extra_math" -eq 0 ]; then
557 if [ -z "${_gen_std_tests_extra_required##*$_gen_std_tests_t*}" ]; then
558 printf 'test_%s_%s:\n\t@printf "Skipping %s %s\\n"\n\n' \
559 "$_gen_std_tests_name" "$_gen_std_tests_t" "$_gen_std_tests_name" \
560 "$_gen_std_tests_t" >> "Makefile"
566 printf 'test_%s_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh $(TESTSDIR)/test.sh %s %s %s %s %s\n\n' \
567 "$_gen_std_tests_name" "$_gen_std_tests_t" "$builddir" "$_gen_std_tests_name" \
568 "$_gen_std_tests_t" "$generate_tests" "$time_tests" \
574 # Generates a list of test targets that will be used as prerequisites for other
577 # @param name The name of the calculator to generate test targets for.
578 gen_std_test_targets() {
580 _gen_std_test_targets_name="$1"
583 _gen_std_test_targets_tests=$(cat "$scriptdir/tests/${_gen_std_test_targets_name}/all.txt")
585 for _gen_std_test_targets_t in $_gen_std_test_targets_tests; do
586 printf ' test_%s_%s' "$_gen_std_test_targets_name" "$_gen_std_test_targets_t"
592 # Generates the proper test targets for each error test to have its own target.
593 # This allows `make test_bc_errors` and `make test_dc_errors` to run in
596 # @param name Which calculator to generate tests for.
599 _gen_err_tests_name="$1"
602 _gen_err_tests_fs=$(ls "$scriptdir/tests/$_gen_err_tests_name/errors/")
604 for _gen_err_tests_t in $_gen_err_tests_fs; do
606 printf 'test_%s_error_%s:\n\t@export BC_TEST_OUTPUT_DIR="%s/tests"; sh $(TESTSDIR)/error.sh %s %s %s %s\n\n' \
607 "$_gen_err_tests_name" "$_gen_err_tests_t" "$builddir" "$_gen_err_tests_name" \
608 "$_gen_err_tests_t" "$problematic_tests" "$*" >> "Makefile"
614 # Generates a list of error test targets that will be used as prerequisites for
617 # @param name The name of the calculator to generate test targets for.
618 gen_err_test_targets() {
620 _gen_err_test_targets_name="$1"
623 _gen_err_test_targets_tests=$(ls "$scriptdir/tests/$_gen_err_test_targets_name/errors/")
625 for _gen_err_test_targets_t in $_gen_err_test_targets_tests; do
626 printf ' test_%s_error_%s' "$_gen_err_test_targets_name" "$_gen_err_test_targets_t"
632 # Generates the proper script test targets for each script test to have its own
633 # target. This allows `make test` to run in parallel.
635 # @param name Which calculator to generate tests for.
636 # @param extra_math An integer that, if non-zero, activates extra math tests.
637 # @param generate An integer that, if non-zero, activates generated tests.
638 # @param time_tests An integer that, if non-zero, tells the test suite to time
639 # the execution of each test.
642 _gen_script_tests_name="$1"
645 _gen_script_tests_extra_math="$1"
648 _gen_script_tests_generate="$1"
651 _gen_script_tests_time="$1"
654 _gen_script_tests_tests=$(cat "$scriptdir/tests/$_gen_script_tests_name/scripts/all.txt")
656 for _gen_script_tests_f in $_gen_script_tests_tests; do
658 _gen_script_tests_b=$(basename "$_gen_script_tests_f" ".${_gen_script_tests_name}")
660 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' \
661 "$_gen_script_tests_name" "$_gen_script_tests_b" "$builddir" "$_gen_script_tests_name" \
662 "$_gen_script_tests_f" "$_gen_script_tests_extra_math" "$_gen_script_tests_generate" \
663 "$_gen_script_tests_time" "$*" >> "Makefile"
672 _set_default_name="$1"
675 # The reason that the variables that are being set do not have the same
676 # non-collision avoidance that the other variables do is that we *do* want
677 # the settings of these variables to leak out of the function. They adjust
678 # the settings outside of the function.
679 case "$_set_default_name" in
681 bc.banner) bc_default_banner="$_set_default_on" ;;
682 bc.sigint_reset) bc_default_sigint_reset="$_set_default_on" ;;
683 dc.sigint_reset) dc_default_sigint_reset="$_set_default_on" ;;
684 bc.tty_mode) bc_default_tty_mode="$_set_default_on" ;;
685 dc.tty_mode) dc_default_tty_mode="$_set_default_on" ;;
686 bc.prompt) bc_default_prompt="$_set_default_on" ;;
687 dc.prompt) dc_default_prompt="$_set_default_on" ;;
688 bc.expr_exit) bc_default_expr_exit="$_set_default_on";;
689 dc.expr_exit) dc_default_expr_exit="$_set_default_on";;
690 bc.digit_clamp) bc_default_digit_clamp="$_set_default_on";;
691 dc.digit_clamp) dc_default_digit_clamp="$_set_default_on";;
692 ?) usage "Invalid setting: $_set_default_name" ;;
699 _predefined_build_type="$1"
702 # The reason that the variables that are being set do not have the same
703 # non-collision avoidance that the other variables do is that we *do* want
704 # the settings of these variables to leak out of the function. They adjust
705 # the settings outside of the function.
706 case "$_predefined_build_type" in
717 generate_tests=$generate_tests
730 bc_default_sigint_reset=1
731 dc_default_sigint_reset=1
732 bc_default_tty_mode=1
733 dc_default_tty_mode=0
736 bc_default_expr_exit=1
737 dc_default_expr_exit=1
738 bc_default_digit_clamp=0
739 dc_default_digit_clamp=0;;
750 generate_tests=$generate_tests
763 bc_default_sigint_reset=1
764 dc_default_sigint_reset=0
765 bc_default_tty_mode=1
766 dc_default_tty_mode=0
769 bc_default_expr_exit=1
770 dc_default_expr_exit=1
771 bc_default_digit_clamp=1
772 dc_default_digit_clamp=0;;
775 CFLAGS="-flto -Weverything -Wno-padded -Wno-unsafe-buffer-usage -Werror -pedantic -std=c11"
797 bc_default_sigint_reset=1
798 dc_default_sigint_reset=1
799 bc_default_tty_mode=1
800 dc_default_tty_mode=1
803 bc_default_expr_exit=0
804 dc_default_expr_exit=0
805 bc_default_digit_clamp=1
806 dc_default_digit_clamp=1;;
809 CFLAGS="-Weverything -Wno-padded -Wno-unsafe-buffer-usage -Werror -pedantic -std=c11"
831 bc_default_sigint_reset=1
832 dc_default_sigint_reset=1
833 bc_default_tty_mode=1
834 dc_default_tty_mode=1
837 bc_default_expr_exit=0
838 dc_default_expr_exit=0
839 bc_default_digit_clamp=1
840 dc_default_digit_clamp=1;;
842 ?|'') usage "Invalid user build: \"$_predefined_build_type\". Accepted types are BSD, GNU, GDH, DBG.";;
847 # Generates a list of script test targets that will be used as prerequisites for
850 # @param name The name of the calculator to generate script test targets for.
851 gen_script_test_targets() {
853 _gen_script_test_targets_name="$1"
856 _gen_script_test_targets_tests=$(cat "$scriptdir/tests/$_gen_script_test_targets_name/scripts/all.txt")
858 for _gen_script_test_targets_f in $_gen_script_test_targets_tests; do
859 _gen_script_test_targets_b=$(basename "$_gen_script_test_targets_f" \
860 ".$_gen_script_test_targets_name")
861 printf ' test_%s_script_%s' "$_gen_script_test_targets_name" \
862 "$_gen_script_test_targets_b"
868 # This is a list of defaults, but it is also the list of possible options for
871 # The development options are: force (force options even if they fail), valgrind
872 # (build in a way suitable for valgrind testing), memcheck (same as valgrind),
873 # and fuzzing (build in a way suitable for fuzzing).
897 # The empty strings are because they depend on TTY mode. If they are directly
898 # set, though, they will be integers. We test for empty strings later.
900 bc_default_sigint_reset=1
901 dc_default_sigint_reset=1
902 bc_default_tty_mode=1
903 dc_default_tty_mode=0
906 bc_default_expr_exit=1
907 dc_default_expr_exit=1
908 bc_default_digit_clamp=0
909 dc_default_digit_clamp=0
911 # getopts is a POSIX utility, but it cannot handle long options. Thus, the
912 # handling of long options is done by hand, and that's the reason that short and
913 # long options cannot be mixed.
914 while getopts "abBcdDeEfgGhHik:lMmNO:p:PrS:s:tTvz-" opt; do
924 e) hist_impl="editline" ;;
928 G) generate_tests=0 ;;
931 i) hist_impl="internal" ;;
932 k) karatsuba_len="$OPTARG" ;;
935 M) install_manpages=0 ;;
937 O) optimization="$OPTARG" ;;
938 p) predefined_build "$OPTARG" ;;
939 P) problematic_tests=0 ;;
940 r) hist_impl="readline" ;;
941 S) set_default 0 "$OPTARG" ;;
942 s) set_default 1 "$OPTARG" ;;
950 LONG_OPTARG="${arg#*=}"
953 library) library=1 ;;
954 bc-only) bc_only=1 ;;
955 dc-only) dc_only=1 ;;
956 coverage) coverage=1 ;;
959 prefix=?*) PREFIX="$LONG_OPTARG" ;;
961 if [ "$#" -lt 2 ]; then
962 usage "No argument given for '--$arg' option"
966 bindir=?*) BINDIR="$LONG_OPTARG" ;;
968 if [ "$#" -lt 2 ]; then
969 usage "No argument given for '--$arg' option"
973 includedir=?*) INCLUDEDIR="$LONG_OPTARG" ;;
975 if [ "$#" -lt 2 ]; then
976 usage "No argument given for '--$arg' option"
980 libdir=?*) LIBDIR="$LONG_OPTARG" ;;
982 if [ "$#" -lt 2 ]; then
983 usage "No argument given for '--$arg' option"
987 datarootdir=?*) DATAROOTDIR="$LONG_OPTARG" ;;
989 if [ "$#" -lt 2 ]; then
990 usage "No argument given for '--$arg' option"
994 datadir=?*) DATADIR="$LONG_OPTARG" ;;
996 if [ "$#" -lt 2 ]; then
997 usage "No argument given for '--$arg' option"
1001 mandir=?*) MANDIR="$LONG_OPTARG" ;;
1003 if [ "$#" -lt 2 ]; then
1004 usage "No argument given for '--$arg' option"
1008 man1dir=?*) MAN1DIR="$LONG_OPTARG" ;;
1010 if [ "$#" -lt 2 ]; then
1011 usage "No argument given for '--$arg' option"
1015 man3dir=?*) MAN3DIR="$LONG_OPTARG" ;;
1017 if [ "$#" -lt 2 ]; then
1018 usage "No argument given for '--$arg' option"
1022 karatsuba-len=?*) karatsuba_len="$LONG_OPTARG" ;;
1024 if [ "$#" -lt 2 ]; then
1025 usage "No argument given for '--$arg' option"
1029 opt=?*) optimization="$LONG_OPTARG" ;;
1031 if [ "$#" -lt 2 ]; then
1032 usage "No argument given for '--$arg' option"
1036 set-default-on=?*) set_default 1 "$LONG_OPTARG" ;;
1038 if [ "$#" -lt 2 ]; then
1039 usage "No argument given for '--$arg' option"
1043 set-default-off=?*) set_default 0 "$LONG_OPTARG" ;;
1045 if [ "$#" -lt 2 ]; then
1046 usage "No argument given for '--$arg' option"
1050 predefined-build-type=?*) predefined_build "$LONG_OPTARG" ;;
1051 predefined-build-type)
1052 if [ "$#" -lt 2 ]; then
1053 usage "No argument given for '--$arg' option"
1055 predefined_build "$1"
1057 disable-bc) dc_only=1 ;;
1058 disable-dc) bc_only=1 ;;
1059 disable-clean) clean=0 ;;
1060 disable-extra-math) extra_math=0 ;;
1061 disable-generated-tests) generate_tests=0 ;;
1062 disable-history) hist=0 ;;
1063 disable-man-pages) install_manpages=0 ;;
1064 disable-nls) nls=0 ;;
1065 disable-strip) strip_bin=0 ;;
1066 disable-problematic-tests) problematic_tests=0 ;;
1067 enable-editline) hist_impl="editline" ;;
1068 enable-readline) hist_impl="readline" ;;
1069 enable-internal-history) hist_impl="internal" ;;
1070 enable-test-timing) time_tests=1 ;;
1071 enable-valgrind) vg=1 ;;
1072 enable-fuzz-mode) fuzz=1 ;;
1073 enable-memcheck) memcheck=1 ;;
1074 install-all-locales) all_locales=1 ;;
1075 help* | bc-only* | dc-only* | coverage* | debug*)
1076 usage "No arg allowed for --$arg option" ;;
1077 disable-bc* | disable-dc* | disable-clean*)
1078 usage "No arg allowed for --$arg option" ;;
1079 disable-extra-math*)
1080 usage "No arg allowed for --$arg option" ;;
1081 disable-generated-tests* | disable-history*)
1082 usage "No arg allowed for --$arg option" ;;
1083 disable-man-pages* | disable-nls* | disable-strip*)
1084 usage "No arg allowed for --$arg option" ;;
1085 disable-problematic-tests*)
1086 usage "No arg allowed for --$arg option" ;;
1087 enable-fuzz-mode* | enable-test-timing* | enable-valgrind*)
1088 usage "No arg allowed for --$arg option" ;;
1089 enable-memcheck* | install-all-locales*)
1090 usage "No arg allowed for --$arg option" ;;
1091 enable-editline* | enable-readline*)
1092 usage "No arg allowed for --$arg option" ;;
1093 enable-internal-history*)
1094 usage "No arg allowed for --$arg option" ;;
1095 '') break ;; # "--" terminates argument processing
1096 * ) usage "Invalid option $LONG_OPTARG" ;;
1100 ?) usage "Invalid option: $opt" ;;
1105 # Sometimes, developers don't want configure.sh to do a config clean. But
1106 # sometimes they do.
1107 if [ "$clean" -ne 0 ]; then
1108 if [ -f ./Makefile ]; then
1109 make clean_config > /dev/null
1113 # It is an error to say that bc only should be built and likewise for dc.
1114 if [ "$bc_only" -eq 1 ] && [ "$dc_only" -eq 1 ]; then
1115 usage "Can only specify one of -b(-D) or -d(-B)"
1118 # The library is mutually exclusive to the calculators, so it's an error to
1119 # give an option for either of them.
1120 if [ "$library" -ne 0 ]; then
1121 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
1122 usage "Must not specify -b(-D) or -d(-B) when building the library"
1126 # KARATSUBA_LEN must be an integer and must be 16 or greater.
1127 case $karatsuba_len in
1128 (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;;
1132 if [ "$karatsuba_len" -lt 16 ]; then
1133 usage "KARATSUBA_LEN is less than 16"
1138 if [ -z "${LONG_BIT+set}" ]; then
1140 elif [ "$LONG_BIT" -lt 32 ]; then
1141 usage "LONG_BIT is less than 32"
1143 LONG_BIT_DEFINE="-DBC_LONG_BIT=$LONG_BIT"
1146 if [ -z "$CC" ]; then
1150 # I had users complain that, if they gave CFLAGS as part of CC, which
1151 # autotools allows in its braindead way, the build would fail with an error.
1152 # I don't like adjusting for autotools, but oh well. These lines puts the
1153 # stuff after the first space into CFLAGS.
1154 ccbase=$(basename "$CC")
1158 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
1159 ccflags="${ccbase#$prefix}"
1160 cc="${ccbase%%$suffix}"
1161 ccdir=$(dirname "$CC")
1162 if [ "$ccdir" = "." ] && [ "${CC#.}" = "$CC" ]; then
1168 CFLAGS="$CFLAGS $ccflags"
1172 if [ -z "$HOSTCC" ] && [ -z "$HOST_CC" ]; then
1174 elif [ -z "$HOSTCC" ]; then
1178 if [ "$HOSTCC" != "$CC" ]; then
1180 # Like above, this splits HOSTCC and HOSTCFLAGS.
1181 ccbase=$(basename "$HOSTCC")
1185 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
1186 ccflags="${ccbase#$prefix}"
1187 cc="${ccbase%%$suffix}"
1188 ccdir=$(dirname "$HOSTCC")
1189 if [ "$ccdir" = "." ] && [ "${HOSTCC#.}" = "$HOSTCC" ]; then
1194 HOSTCC="${ccdir}${cc}"
1195 HOSTCFLAGS="$HOSTCFLAGS $ccflags"
1199 if [ -z "${HOSTCFLAGS+set}" ] && [ -z "${HOST_CFLAGS+set}" ]; then
1200 HOSTCFLAGS="$CFLAGS"
1201 elif [ -z "${HOSTCFLAGS+set}" ]; then
1202 HOSTCFLAGS="$HOST_CFLAGS"
1205 # Store these for the cross compilation detection later.
1207 OLDHOSTCFLAGS="$HOSTCFLAGS"
1209 link="@printf 'No link necessary\\\\n'"
1211 executable="BC_EXEC"
1213 tests="test_bc timeconst test_dc"
1215 bc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh bc $extra_math 1 $generate_tests $problematic_tests $time_tests \$(BC_EXEC)"
1216 bc_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)"
1217 dc_test="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/all.sh dc $extra_math 1 $generate_tests $problematic_tests $time_tests \$(DC_EXEC)"
1218 dc_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)"
1220 timeconst="@export BC_TEST_OUTPUT_DIR=\"$builddir/tests\"; \$(TESTSDIR)/bc/timeconst.sh \$(TESTSDIR)/bc/scripts/timeconst.bc \$(BC_EXEC)"
1222 # In order to have cleanup at exit, we need to be in
1223 # debug mode, so don't run valgrind without that.
1224 if [ "$vg" -ne 0 ]; then
1226 bc_test_exec='valgrind $(VALGRIND_ARGS) $(BC_EXEC)'
1227 dc_test_exec='valgrind $(VALGRIND_ARGS) $(DC_EXEC)'
1228 bcl_test_exec='valgrind $(VALGRIND_ARGS) $(BCL_TEST)'
1230 bc_test_exec='$(BC_EXEC)'
1231 dc_test_exec='$(DC_EXEC)'
1232 bcl_test_exec='$(BCL_TEST)'
1235 test_bc_history_prereqs="test_bc_history_all"
1236 test_dc_history_prereqs="test_dc_history_all"
1238 karatsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
1239 karatsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
1241 bc_lib="\$(GEN_DIR)/lib.o"
1242 bc_help="\$(GEN_DIR)/bc_help.o"
1243 dc_help="\$(GEN_DIR)/dc_help.o"
1245 default_target_prereqs="\$(BIN) \$(OBJS)"
1246 default_target_cmd="\$(CC) \$(CFLAGS) \$(OBJS) \$(LDFLAGS) -o \$(EXEC)"
1247 default_target="\$(DC_EXEC)"
1249 second_target_prereqs=""
1250 second_target_cmd="$default_target_cmd"
1251 second_target="\$(BC_EXEC)"
1253 # This if/else if chain is for setting the defaults that change based on whether
1254 # the library is being built, bc only, dc only, or both calculators.
1255 if [ "$library" -ne 0 ]; then
1263 default_target_prereqs="\$(BIN) \$(OBJ)"
1264 default_target_cmd="ar -r -cu \$(LIBBC) \$(OBJ)"
1265 default_target="\$(LIBBC)"
1266 tests="test_library"
1267 test_bc_history_prereqs=" test_bc_history_skip"
1268 test_dc_history_prereqs=" test_dc_history_skip"
1270 install_prereqs=" install_library"
1271 uninstall_prereqs=" uninstall_library"
1272 install_man_prereqs=" install_bcl_manpage"
1273 uninstall_man_prereqs=" uninstall_bcl_manpage"
1275 elif [ "$bc_only" -eq 1 ]; then
1284 dc_test="@printf 'No dc tests to run\\\\n'"
1285 dc_test_np="@printf 'No dc tests to run\\\\n'"
1286 test_dc_history_prereqs=" test_dc_history_skip"
1288 install_prereqs=" install_execs"
1289 install_man_prereqs=" install_bc_manpage"
1290 uninstall_prereqs=" uninstall_bc"
1291 uninstall_man_prereqs=" uninstall_bc_manpage"
1293 default_target="\$(BC_EXEC)"
1294 second_target="\$(DC_EXEC)"
1295 tests="test_bc timeconst"
1297 elif [ "$dc_only" -eq 1 ]; then
1308 executable="DC_EXEC"
1310 bc_test="@printf 'No bc tests to run\\\\n'"
1311 bc_test_np="@printf 'No bc tests to run\\\\n'"
1312 test_bc_history_prereqs=" test_bc_history_skip"
1314 timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'"
1316 install_prereqs=" install_execs"
1317 install_man_prereqs=" install_dc_manpage"
1318 uninstall_prereqs=" uninstall_dc"
1319 uninstall_man_prereqs=" uninstall_dc_manpage"
1328 executables="bc and dc"
1330 karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)"
1331 karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)"
1333 if [ "$library" -eq 0 ]; then
1334 install_prereqs=" install_execs"
1335 install_man_prereqs=" install_bc_manpage install_dc_manpage"
1336 uninstall_prereqs=" uninstall_bc uninstall_dc"
1337 uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage"
1339 install_prereqs=" install_library install_bcl_header"
1340 install_man_prereqs=" install_bcl_manpage"
1341 uninstall_prereqs=" uninstall_library uninstall_bcl_header"
1342 uninstall_man_prereqs=" uninstall_bcl_manpage"
1343 tests="test_library"
1346 second_target_prereqs="$default_target_prereqs"
1347 default_target_prereqs="$second_target"
1348 default_target_cmd="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)"
1352 # We need specific stuff for fuzzing.
1353 if [ "$fuzz" -ne 0 ]; then
1360 # This sets some necessary things for debug mode.
1361 if [ "$debug" -eq 1 ]; then
1363 if [ -z "$CFLAGS" ] && [ -z "$optimization" ]; then
1367 ccbase=$(basename "$CC")
1369 if [ "$ccbase" = "clang" ]; then
1370 CFLAGS="-gdwarf-4 $CFLAGS"
1377 CPPFLAGS="-DNDEBUG $CPPFLAGS"
1379 if [ "$strip_bin" -ne 0 ]; then
1380 LDFLAGS="-s $LDFLAGS"
1384 # Set optimization CFLAGS.
1385 if [ -n "$optimization" ]; then
1386 CFLAGS="-O$optimization $CFLAGS"
1389 # Set test coverage defaults.
1390 if [ "$coverage" -eq 1 ]; then
1392 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
1393 usage "Can only specify -c without -b or -d"
1396 CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS"
1397 CPPFLAGS="-DNDEBUG $CPPFLAGS"
1399 COVERAGE_OUTPUT="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA) \$(HISTORY_GCDA) \$(RAND_GCDA)"
1400 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;\$(RM) -f \$(GEN)*.gc*"
1401 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;gcovr --exclude-unreachable-branches --exclude-throw-branches --html-details --output index.html"
1402 COVERAGE_PREREQS=" test coverage_output"
1405 COVERAGE_OUTPUT="@printf 'Coverage not generated\\\\n'"
1410 # Set some defaults.
1411 if [ -z "${DESTDIR+set}" ]; then
1414 destdir="DESTDIR = $DESTDIR"
1417 # defprefix is for a warning about locales later.
1418 if [ -z "${PREFIX+set}" ]; then
1425 if [ -z "${BINDIR+set}" ]; then
1426 BINDIR="$PREFIX/bin"
1429 if [ -z "${INCLUDEDIR+set}" ]; then
1430 INCLUDEDIR="$PREFIX/include"
1433 if [ -z "${LIBDIR+set}" ]; then
1434 LIBDIR="$PREFIX/lib"
1437 if [ -z "${PC_PATH+set}" ]; then
1441 command -v pkg-config > /dev/null
1446 if [ "$err" -eq 0 ]; then
1447 PC_PATH=$(pkg-config --variable=pc_path pkg-config)
1448 PC_PATH="${PC_PATH%%:*}"
1455 # Set a default for the DATAROOTDIR. This is done if either manpages will be
1456 # installed, or locales are enabled because that's probably where NLSPATH
1458 if [ "$install_manpages" -ne 0 ] || [ "$nls" -ne 0 ]; then
1459 if [ -z "${DATAROOTDIR+set}" ]; then
1460 DATAROOTDIR="$PREFIX/share"
1464 # Set defaults for manpage environment variables.
1465 if [ "$install_manpages" -ne 0 ]; then
1467 if [ -z "${DATADIR+set}" ]; then
1468 DATADIR="$DATAROOTDIR"
1471 if [ -z "${MANDIR+set}" ]; then
1472 MANDIR="$DATADIR/man"
1475 if [ -z "${MAN1DIR+set}" ]; then
1476 MAN1DIR="$MANDIR/man1"
1479 if [ -z "${MAN3DIR+set}" ]; then
1480 MAN3DIR="$MANDIR/man3"
1484 install_man_prereqs=""
1485 uninstall_man_prereqs=""
1488 # Here is where we test NLS (the locale system). This is done by trying to
1489 # compile src/vm.c, which has the relevant code. If it fails, then it is
1491 if [ "$nls" -ne 0 ]; then
1495 printf 'Testing NLS...\n'
1497 flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
1498 flags="$flags -DBC_ENABLE_HISTORY=$hist -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
1499 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
1500 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
1502 ccbase=$(basename "$CC")
1504 if [ "$ccbase" = "clang" ]; then
1505 flags="$flags -Wno-unreachable-code"
1508 "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/vm.c" -o "./vm.o" > /dev/null 2>&1
1514 # If this errors, it is probably because of building on Windows,
1515 # and NLS is not supported on Windows, so disable it.
1516 if [ "$err" -ne 0 ]; then
1517 printf 'NLS does not work.\n'
1518 if [ $force -eq 0 ]; then
1519 printf 'Disabling NLS...\n\n'
1522 printf 'Forcing NLS...\n\n'
1525 printf 'NLS works.\n\n'
1527 printf 'Testing gencat...\n'
1528 gencat "./en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
1532 rm -rf "./en_US.cat"
1534 if [ "$err" -ne 0 ]; then
1535 printf 'gencat does not work.\n'
1536 if [ $force -eq 0 ]; then
1537 printf 'Disabling NLS...\n\n'
1540 printf 'Forcing NLS...\n\n'
1544 printf 'gencat works.\n\n'
1546 # It turns out that POSIX locales are really terrible, and running
1547 # gencat on one machine is not guaranteed to make those cat files
1548 # portable to another machine, so we had better warn the user here.
1549 if [ "$HOSTCC" != "$CC" ] || [ "$OLDHOSTCFLAGS" != "$OLDCFLAGS" ]; then
1550 printf 'Cross-compile detected.\n\n'
1551 printf 'WARNING: Catalog files generated with gencat may not be portable\n'
1552 printf ' across different architectures.\n\n'
1555 if [ -z "$NLSPATH" ]; then
1556 NLSPATH="/usr/share/locale/%L/%N"
1559 install_locales_prereqs=" install_locales"
1560 uninstall_locales_prereqs=" uninstall_locales"
1569 install_locales_prereqs=""
1570 uninstall_locales_prereqs=""
1574 if [ "$nls" -ne 0 ] && [ "$all_locales" -ne 0 ]; then
1575 install_locales="\$(LOCALE_INSTALL) -l \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
1577 install_locales="\$(LOCALE_INSTALL) \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
1580 # Like the above tested locale support, this tests history.
1581 if [ "$hist" -eq 1 ]; then
1583 if [ "$hist_impl" = "editline" ]; then
1586 elif [ "$hist_impl" = "readline" ]; then
1596 printf 'Testing history...\n'
1598 flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
1599 flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0 -DBC_ENABLE_AFL=0"
1600 flags="$flags -DBC_ENABLE_EDITLINE=$editline -DBC_ENABLE_READLINE=$readline"
1601 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I$scriptdir/include/"
1602 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
1604 "$CC" $CPPFLAGS $CFLAGS $flags -c "$scriptdir/src/history.c" -o "./history.o" > /dev/null 2>&1
1608 rm -rf "./history.o"
1610 # If this errors, it is probably because of building on Windows,
1611 # and history is not supported on Windows, so disable it.
1612 if [ "$err" -ne 0 ]; then
1613 printf 'History does not work.\n'
1614 if [ $force -eq 0 ]; then
1615 printf 'Disabling history...\n\n'
1618 printf 'Forcing history...\n\n'
1621 printf 'History works.\n\n'
1633 # We have to disable the history tests if it is disabled or valgrind is on. Or
1634 # if we are using editline or readline.
1635 if [ "$hist" -eq 0 ] || [ "$vg" -ne 0 ]; then
1636 test_bc_history_prereqs=" test_bc_history_skip"
1637 test_dc_history_prereqs=" test_dc_history_skip"
1638 history_tests="@printf 'Skipping history tests...\\\\n'"
1639 CFLAGS="$CFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
1642 if [ "$editline" -eq 0 ] && [ "$readline" -eq 0 ]; then
1643 history_tests="@printf '\$(TEST_STARS)\\\\n\\\\nRunning history tests...\\\\n\\\\n'"
1644 history_tests="$history_tests \&\& \$(TESTSDIR)/history.sh bc -a \&\&"
1645 history_tests="$history_tests \$(TESTSDIR)/history.sh dc -a \&\& printf"
1646 history_tests="$history_tests '\\\\nAll history tests passed.\\\\n\\\\n\$(TEST_STARS)\\\\n'"
1648 test_bc_history_prereqs=" test_bc_history_skip"
1649 test_dc_history_prereqs=" test_dc_history_skip"
1650 history_tests="@printf 'Skipping history tests...\\\\n'"
1653 # We are also setting the CFLAGS and LDFLAGS here.
1654 if [ "$editline" -ne 0 ]; then
1655 LDFLAGS="$LDFLAGS -ledit"
1656 CPPFLAGS="$CPPFLAGS -DBC_ENABLE_EDITLINE=1 -DBC_ENABLE_READLINE=0"
1657 elif [ "$readline" -ne 0 ]; then
1658 LDFLAGS="$LDFLAGS -lreadline"
1659 CPPFLAGS="$CPPFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=1"
1661 CPPFLAGS="$CPPFLAGS -DBC_ENABLE_EDITLINE=0 -DBC_ENABLE_READLINE=0"
1666 # Test FreeBSD. This is not in an if statement because regardless of whatever
1667 # the user says, we need to know if we are on FreeBSD. If we are, we cannot set
1668 # _POSIX_C_SOURCE and _XOPEN_SOURCE. The FreeBSD headers turn *off* stuff when
1671 printf 'Testing for FreeBSD...\n'
1673 flags="-DBC_TEST_FREEBSD -DBC_ENABLE_AFL=0"
1674 "$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/src/vm.c" > /dev/null 2>&1
1678 if [ "$err" -ne 0 ]; then
1679 printf 'On FreeBSD. Not using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
1681 printf 'Not on FreeBSD. Using _POSIX_C_SOURCE and _XOPEN_SOURCE.\n\n'
1682 CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
1685 # Test Mac OSX. This is not in an if statement because regardless of whatever
1686 # the user says, we need to know if we are on Mac OSX. If we are, we have to set
1688 printf 'Testing for Mac OSX...\n'
1690 flags="-DBC_TEST_APPLE -DBC_ENABLE_AFL=0"
1691 "$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/src/vm.c" > /dev/null 2>&1
1695 if [ "$err" -ne 0 ]; then
1696 printf 'On Mac OSX. Using _DARWIN_C_SOURCE.\n\n'
1697 apple="-D_DARWIN_C_SOURCE"
1699 printf 'Not on Mac OSX.\n\n'
1703 # Test OpenBSD. This is not in an if statement because regardless of whatever
1704 # the user says, we need to know if we are on OpenBSD to activate _BSD_SOURCE.
1705 # No, I cannot `#define _BSD_SOURCE` in a header because OpenBSD's patched GCC
1706 # and Clang complain that that is only allowed for system headers. Sigh....So we
1707 # have to check at configure time and set it on the compiler command-line. And
1708 # we have to set it because we also set _POSIX_C_SOURCE, which OpenBSD headers
1709 # detect, and when they detect it, they turn off _BSD_SOURCE unless it is
1710 # specifically requested.
1711 printf 'Testing for OpenBSD...\n'
1713 flags="-DBC_TEST_OPENBSD -DBC_ENABLE_AFL=0"
1714 "$CC" $CPPFLAGS $CFLAGS $flags "-I$scriptdir/include" -E "$scriptdir/src/vm.c" > /dev/null 2>&1
1718 if [ "$err" -ne 0 ]; then
1720 printf 'On OpenBSD. Using _BSD_SOURCE.\n\n'
1723 # Readline errors on OpenBSD, for some weird reason.
1724 if [ "$readline" -ne 0 ]; then
1725 usage "Cannot use readline on OpenBSD"
1729 printf 'Not on OpenBSD.\n\n'
1735 if [ "$library" -eq 1 ]; then
1739 if [ "$extra_math" -eq 1 ] && [ "$bc" -ne 0 ] && [ "$library" -eq 0 ]; then
1740 BC_LIB2_O="\$(GEN_DIR)/lib2.o"
1745 GEN_DIR="$scriptdir/gen"
1747 # These lines set the appropriate targets based on whether `gen/strgen.c` or
1748 # `gen/strgen.sh` is used.
1750 GEN_EXEC_TARGET="\$(HOSTCC) -DBC_ENABLE_AFL=0 -I$scriptdir/include/ \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
1751 CLEAN_PREREQS=" clean_gen clean_coverage"
1753 if [ -z "${GEN_HOST+set}" ]; then
1756 if [ "$GEN_HOST" -eq 0 ]; then
1758 GEN_EXEC_TARGET="@printf 'Do not need to build gen/strgen.c\\\\n'"
1759 CLEAN_PREREQS=" clean_coverage"
1765 headers="\$(HEADERS)"
1767 # This series of if statements figure out what source files are *not* needed.
1768 if [ "$extra_math" -eq 0 ]; then
1769 exclude_extra_math=1
1771 unneeded="$unneeded rand.c"
1773 exclude_extra_math=0
1774 headers="$headers \$(EXTRA_MATH_HEADERS)"
1777 # All of these next if statements set the build type and mark certain source
1778 # files as unneeded so that they won't have targets generated for them.
1780 if [ "$hist" -eq 0 ]; then
1781 manpage_args="${manpage_args}H"
1782 unneeded="$unneeded history.c"
1784 headers="$headers \$(HISTORY_HEADERS)"
1787 if [ "$nls" -eq 0 ]; then
1788 manpage_args="${manpage_args}N"
1791 if [ "$bc" -eq 0 ]; then
1792 unneeded="$unneeded bc.c bc_lex.c bc_parse.c"
1794 headers="$headers \$(BC_HEADERS)"
1797 if [ "$dc" -eq 0 ]; then
1798 unneeded="$unneeded dc.c dc_lex.c dc_parse.c"
1800 headers="$headers \$(DC_HEADERS)"
1803 # This convoluted mess does pull the version out. If you change the format of
1804 # include/version.h, you may have to change this line.
1805 version=$(cat "$scriptdir/include/version.h" | grep "VERSION " - | awk '{ print $3 }' -)
1807 if [ "$library" -ne 0 ]; then
1809 unneeded="$unneeded args.c opt.c read.c file.c main.c"
1810 unneeded="$unneeded lang.c lex.c parse.c program.c"
1811 unneeded="$unneeded bc.c bc_lex.c bc_parse.c"
1812 unneeded="$unneeded dc.c dc_lex.c dc_parse.c"
1813 headers="$headers \$(LIBRARY_HEADERS)"
1815 if [ "$PC_PATH" != "" ]; then
1817 contents=$(cat "$scriptdir/bcl.pc.in")
1819 contents=$(replace "$contents" "INCLUDEDIR" "$INCLUDEDIR")
1820 contents=$(replace "$contents" "LIBDIR" "$LIBDIR")
1821 contents=$(replace "$contents" "VERSION" "$version")
1823 printf '%s\n' "$contents" > "$scriptdir/bcl.pc"
1825 pkg_config_install="\$(SAFE_INSTALL) \$(PC_INSTALL_ARGS) \"\$(BCL_PC)\" \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\""
1826 pkg_config_uninstall="\$(RM) -f \"\$(DESTDIR)\$(PC_PATH)/\$(BCL_PC)\""
1830 pkg_config_install=""
1831 pkg_config_uninstall=""
1837 unneeded="$unneeded library.c"
1840 pkg_config_install=""
1841 pkg_config_uninstall=""
1845 # library.c is not needed under normal circumstances.
1846 if [ "$unneeded" = "" ]; then
1847 unneeded="library.c"
1850 # This sets the appropriate manpage for a full build.
1851 if [ "$manpage_args" = "" ]; then
1855 if [ "$vg" -ne 0 ]; then
1859 if [ "$bc_default_prompt" = "" ]; then
1860 bc_default_prompt="$bc_default_tty_mode"
1863 if [ "$dc_default_prompt" = "" ]; then
1864 dc_default_prompt="$dc_default_tty_mode"
1867 # Generate the test targets and prerequisites.
1868 bc_tests=$(gen_std_test_targets bc)
1869 bc_script_tests=$(gen_script_test_targets bc)
1870 bc_err_tests=$(gen_err_test_targets bc)
1871 dc_tests=$(gen_std_test_targets dc)
1872 dc_script_tests=$(gen_script_test_targets dc)
1873 dc_err_tests=$(gen_err_test_targets dc)
1875 # Print out the values; this is for debugging.
1876 printf 'Version: %s\n' "$version"
1878 if [ "$bc" -ne 0 ]; then
1879 printf 'Building bc\n'
1881 printf 'Not building bc\n'
1883 if [ "$dc" -ne 0 ]; then
1884 printf 'Building dc\n'
1886 printf 'Not building dc\n'
1889 printf 'BC_ENABLE_LIBRARY=%s\n\n' "$library"
1890 printf 'BC_ENABLE_HISTORY=%s\n' "$hist"
1891 printf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math"
1892 printf 'BC_ENABLE_NLS=%s\n\n' "$nls"
1893 printf 'BC_ENABLE_AFL=%s\n' "$fuzz"
1895 printf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len"
1897 printf 'CC=%s\n' "$CC"
1898 printf 'CFLAGS=%s\n' "$CFLAGS"
1899 printf 'HOSTCC=%s\n' "$HOSTCC"
1900 printf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS"
1901 printf 'CPPFLAGS=%s\n' "$CPPFLAGS"
1902 printf 'LDFLAGS=%s\n' "$LDFLAGS"
1903 printf 'PREFIX=%s\n' "$PREFIX"
1904 printf 'BINDIR=%s\n' "$BINDIR"
1905 printf 'INCLUDEDIR=%s\n' "$INCLUDEDIR"
1906 printf 'LIBDIR=%s\n' "$LIBDIR"
1907 printf 'DATAROOTDIR=%s\n' "$DATAROOTDIR"
1908 printf 'DATADIR=%s\n' "$DATADIR"
1909 printf 'MANDIR=%s\n' "$MANDIR"
1910 printf 'MAN1DIR=%s\n' "$MAN1DIR"
1911 printf 'MAN3DIR=%s\n' "$MAN3DIR"
1912 printf 'NLSPATH=%s\n' "$NLSPATH"
1913 printf 'PC_PATH=%s\n' "$PC_PATH"
1914 printf 'EXECSUFFIX=%s\n' "$EXECSUFFIX"
1915 printf 'EXECPREFIX=%s\n' "$EXECPREFIX"
1916 printf 'DESTDIR=%s\n' "$DESTDIR"
1917 printf 'LONG_BIT=%s\n' "$LONG_BIT"
1918 printf 'GEN_HOST=%s\n' "$GEN_HOST"
1919 printf 'GEN_EMU=%s\n' "$GEN_EMU"
1921 printf 'Setting Defaults\n'
1922 printf '================\n'
1923 printf 'bc.banner=%s\n' "$bc_default_banner"
1924 printf 'bc.sigint_reset=%s\n' "$bc_default_sigint_reset"
1925 printf 'dc.sigint_reset=%s\n' "$dc_default_sigint_reset"
1926 printf 'bc.tty_mode=%s\n' "$bc_default_tty_mode"
1927 printf 'dc.tty_mode=%s\n' "$dc_default_tty_mode"
1928 printf 'bc.prompt=%s\n' "$bc_default_prompt"
1929 printf 'dc.prompt=%s\n' "$dc_default_prompt"
1930 printf 'bc.expr_exit=%s\n' "$bc_default_expr_exit"
1931 printf 'dc.expr_exit=%s\n' "$dc_default_expr_exit"
1932 printf 'bc.digit_clamp=%s\n' "$bc_default_digit_clamp"
1933 printf 'dc.digit_clamp=%s\n' "$dc_default_digit_clamp"
1935 # This code outputs a warning. The warning is to not surprise users when locales
1936 # are installed outside of the prefix. This warning is suppressed when the
1937 # default prefix is used, as well, so as not to panic users just installing by
1938 # hand. I believe this will be okay because NLSPATH is usually in /usr and the
1939 # default prefix is /usr/local, so they'll be close that way.
1940 if [ "$nls" -ne 0 ] && [ "${NLSPATH#$PREFIX}" = "${NLSPATH}" ] && [ "$defprefix" -eq 0 ]; then
1941 printf '\n********************************************************************************\n\n'
1942 printf 'WARNING: Locales will *NOT* be installed in $PREFIX (%s).\n' "$PREFIX"
1944 printf ' This is because they *MUST* be installed at a fixed location to even\n'
1945 printf ' work, and that fixed location is $NLSPATH (%s).\n' "$NLSPATH"
1947 printf ' This location is *outside* of $PREFIX. If you do not wish to install\n'
1948 printf ' locales outside of $PREFIX, you must disable NLS with the -N or the\n'
1949 printf ' --disable-nls options.\n'
1951 printf ' The author apologizes for the inconvenience, but the need to install\n'
1952 printf ' the locales at a fixed location is mandated by POSIX, and it is not\n'
1953 printf ' possible for the author to change that requirement.\n'
1954 printf '\n********************************************************************************\n'
1957 # This is where the real work begins. This is the point at which the Makefile.in
1958 # template is edited and output to the Makefile.
1960 contents=$(cat "$scriptdir/Makefile.in")
1963 replacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***'
1965 contents=$(replace "$contents" "$needle" "$replacement")
1967 # The contents are edited to have the list of files to build.
1968 contents=$(gen_file_list "$contents" $unneeded)
1972 # This line and loop generates the individual targets for source files. I used
1973 # to just use an implicit target, but that was found to be inadequate when I
1974 # added the library.
1975 src_files=$(find_src_files $unneeded)
1977 for f in $src_files; do
1978 o=$(replace_ext "$f" "c" "o")
1980 SRC_TARGETS=$(printf '%s\n\nsrc/%s: src %s %s\n\t$(CC) $(CFLAGS) -o src/%s -c %s\n' \
1981 "$SRC_TARGETS" "$o" "$headers" "$f" "$o" "$f")
1984 # Replace all the placeholders.
1985 contents=$(replace "$contents" "ROOTDIR" "$scriptdir")
1986 contents=$(replace "$contents" "BUILDDIR" "$builddir")
1988 contents=$(replace "$contents" "HEADERS" "$headers")
1990 contents=$(replace "$contents" "BC_ENABLED" "$bc")
1991 contents=$(replace "$contents" "DC_ENABLED" "$dc")
1993 contents=$(replace "$contents" "BC_ALL_TESTS" "$bc_test")
1994 contents=$(replace "$contents" "BC_ALL_TESTS_NP" "$bc_test_np")
1995 contents=$(replace "$contents" "BC_TESTS" "$bc_tests")
1996 contents=$(replace "$contents" "BC_SCRIPT_TESTS" "$bc_script_tests")
1997 contents=$(replace "$contents" "BC_ERROR_TESTS" "$bc_err_tests")
1998 contents=$(replace "$contents" "BC_TEST_EXEC" "$bc_test_exec")
1999 contents=$(replace "$contents" "TIMECONST_ALL_TESTS" "$timeconst")
2001 contents=$(replace "$contents" "DC_ALL_TESTS" "$dc_test")
2002 contents=$(replace "$contents" "DC_ALL_TESTS_NP" "$dc_test_np")
2003 contents=$(replace "$contents" "DC_TESTS" "$dc_tests")
2004 contents=$(replace "$contents" "DC_SCRIPT_TESTS" "$dc_script_tests")
2005 contents=$(replace "$contents" "DC_ERROR_TESTS" "$dc_err_tests")
2006 contents=$(replace "$contents" "DC_TEST_EXEC" "$dc_test_exec")
2008 contents=$(replace "$contents" "BCL_TEST_EXEC" "$bcl_test_exec")
2010 contents=$(replace "$contents" "BUILD_TYPE" "$manpage_args")
2011 contents=$(replace "$contents" "EXCLUDE_EXTRA_MATH" "$exclude_extra_math")
2013 contents=$(replace "$contents" "LIBRARY" "$library")
2014 contents=$(replace "$contents" "HISTORY" "$hist")
2015 contents=$(replace "$contents" "EXTRA_MATH" "$extra_math")
2016 contents=$(replace "$contents" "NLS" "$nls")
2017 contents=$(replace "$contents" "FUZZ" "$fuzz")
2018 contents=$(replace "$contents" "MEMCHECK" "$memcheck")
2020 contents=$(replace "$contents" "BC_LIB_O" "$bc_lib")
2021 contents=$(replace "$contents" "BC_HELP_O" "$bc_help")
2022 contents=$(replace "$contents" "DC_HELP_O" "$dc_help")
2023 contents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O")
2024 contents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len")
2026 contents=$(replace "$contents" "NLSPATH" "$NLSPATH")
2027 contents=$(replace "$contents" "DESTDIR" "$destdir")
2028 contents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX")
2029 contents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX")
2030 contents=$(replace "$contents" "BINDIR" "$BINDIR")
2031 contents=$(replace "$contents" "INCLUDEDIR" "$INCLUDEDIR")
2032 contents=$(replace "$contents" "LIBDIR" "$LIBDIR")
2033 contents=$(replace "$contents" "MAN1DIR" "$MAN1DIR")
2034 contents=$(replace "$contents" "MAN3DIR" "$MAN3DIR")
2035 contents=$(replace "$contents" "CFLAGS" "$CFLAGS")
2036 contents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS")
2037 contents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS")
2038 contents=$(replace "$contents" "LDFLAGS" "$LDFLAGS")
2039 contents=$(replace "$contents" "CC" "$CC")
2040 contents=$(replace "$contents" "HOSTCC" "$HOSTCC")
2041 contents=$(replace "$contents" "COVERAGE_OUTPUT" "$COVERAGE_OUTPUT")
2042 contents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS")
2043 contents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs")
2044 contents=$(replace "$contents" "INSTALL_MAN_PREREQS" "$install_man_prereqs")
2045 contents=$(replace "$contents" "INSTALL_LOCALES" "$install_locales")
2046 contents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs")
2047 contents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs")
2048 contents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs")
2049 contents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs")
2051 contents=$(replace "$contents" "PC_PATH" "$PC_PATH")
2052 contents=$(replace "$contents" "PKG_CONFIG_INSTALL" "$pkg_config_install")
2053 contents=$(replace "$contents" "PKG_CONFIG_UNINSTALL" "$pkg_config_uninstall")
2055 contents=$(replace "$contents" "DEFAULT_TARGET" "$default_target")
2056 contents=$(replace "$contents" "DEFAULT_TARGET_PREREQS" "$default_target_prereqs")
2057 contents=$(replace "$contents" "DEFAULT_TARGET_CMD" "$default_target_cmd")
2058 contents=$(replace "$contents" "SECOND_TARGET" "$second_target")
2059 contents=$(replace "$contents" "SECOND_TARGET_PREREQS" "$second_target_prereqs")
2060 contents=$(replace "$contents" "SECOND_TARGET_CMD" "$second_target_cmd")
2062 contents=$(replace "$contents" "ALL_PREREQ" "$ALL_PREREQ")
2063 contents=$(replace "$contents" "BC_EXEC_PREREQ" "$bc_exec_prereq")
2064 contents=$(replace "$contents" "BC_EXEC_CMD" "$bc_exec_cmd")
2065 contents=$(replace "$contents" "DC_EXEC_PREREQ" "$dc_exec_prereq")
2066 contents=$(replace "$contents" "DC_EXEC_CMD" "$dc_exec_cmd")
2068 contents=$(replace "$contents" "EXECUTABLES" "$executables")
2069 contents=$(replace "$contents" "MAIN_EXEC" "$main_exec")
2070 contents=$(replace "$contents" "EXEC" "$executable")
2071 contents=$(replace "$contents" "TESTS" "$tests")
2073 contents=$(replace "$contents" "BC_HISTORY_TEST_PREREQS" "$test_bc_history_prereqs")
2074 contents=$(replace "$contents" "DC_HISTORY_TEST_PREREQS" "$test_dc_history_prereqs")
2075 contents=$(replace "$contents" "HISTORY_TESTS" "$history_tests")
2077 contents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test")
2078 contents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test")
2080 contents=$(replace "$contents" "TIMECONST" "$timeconst")
2082 contents=$(replace "$contents" "KARATSUBA" "$karatsuba")
2083 contents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test")
2085 contents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE")
2087 contents=$(replace "$contents" "GEN_DIR" "$GEN_DIR")
2088 contents=$(replace "$contents" "GEN" "$GEN")
2089 contents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET")
2090 contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS")
2091 contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU")
2093 contents=$(replace "$contents" "BSD" "$bsd")
2094 contents=$(replace "$contents" "APPLE" "$apple")
2096 contents=$(replace "$contents" "BC_DEFAULT_BANNER" "$bc_default_banner")
2097 contents=$(replace "$contents" "BC_DEFAULT_SIGINT_RESET" "$bc_default_sigint_reset")
2098 contents=$(replace "$contents" "DC_DEFAULT_SIGINT_RESET" "$dc_default_sigint_reset")
2099 contents=$(replace "$contents" "BC_DEFAULT_TTY_MODE" "$bc_default_tty_mode")
2100 contents=$(replace "$contents" "DC_DEFAULT_TTY_MODE" "$dc_default_tty_mode")
2101 contents=$(replace "$contents" "BC_DEFAULT_PROMPT" "$bc_default_prompt")
2102 contents=$(replace "$contents" "DC_DEFAULT_PROMPT" "$dc_default_prompt")
2103 contents=$(replace "$contents" "BC_DEFAULT_EXPR_EXIT" "$bc_default_expr_exit")
2104 contents=$(replace "$contents" "DC_DEFAULT_EXPR_EXIT" "$dc_default_expr_exit")
2105 contents=$(replace "$contents" "BC_DEFAULT_DIGIT_CLAMP" "$bc_default_digit_clamp")
2106 contents=$(replace "$contents" "DC_DEFAULT_DIGIT_CLAMP" "$dc_default_digit_clamp")
2108 # Do the first print to the Makefile.
2109 printf '%s\n%s\n\n' "$contents" "$SRC_TARGETS" > "Makefile"
2111 # Generate the individual test targets.
2112 if [ "$bc" -ne 0 ]; then
2113 gen_std_tests bc "$extra_math" "$time_tests" $bc_test_exec
2114 gen_script_tests bc "$extra_math" "$generate_tests" "$time_tests" $bc_test_exec
2115 gen_err_tests bc $bc_test_exec
2118 if [ "$dc" -ne 0 ]; then
2119 gen_std_tests dc "$extra_math" "$time_tests" $dc_test_exec
2120 gen_script_tests dc "$extra_math" "$generate_tests" "$time_tests" $dc_test_exec
2121 gen_err_tests dc $dc_test_exec
2124 # Copy the correct manuals to the expected places.
2126 cp -f "$scriptdir/manuals/bc/$manpage_args.1.md" manuals/bc.1.md
2127 cp -f "$scriptdir/manuals/bc/$manpage_args.1" manuals/bc.1
2128 cp -f "$scriptdir/manuals/dc/$manpage_args.1.md" manuals/dc.1.md
2129 cp -f "$scriptdir/manuals/dc/$manpage_args.1" manuals/dc.1
2131 make clean > /dev/null