3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2018-2020 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")
34 . "$scriptdir/functions.sh"
48 printf 'usage: %s -h\n' "$script"
49 printf ' %s --help\n' "$script"
50 printf ' %s [-bD|-dB|-c] [-EfgGHlMNPT] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\n' "$script"
51 printf ' %s \\\n' "$script"
52 printf ' [--bc-only --disable-dc|--dc-only --disable-bc|--coverage] \\\n'
53 printf ' [--debug --disable-extra-math --disable-generated-tests] \\\n'
54 printf ' [--disable-history --disable-man-pages --disable-nls] \\\n'
55 printf ' [--disable-prompt --disable-strip] [--install-all-locales] \\\n'
56 printf ' [--opt=OPT_LEVEL] [--karatsuba-len=KARATSUBA_LEN] \\\n'
57 printf ' [--prefix=PREFIX] [--bindir=BINDIR] [--datarootdir=DATAROOTDIR] \\\n'
58 printf ' [--datadir=DATADIR] [--mandir=MANDIR] [--man1dir=MAN1DIR] \\\n'
59 printf ' [--force] \\\n'
61 printf ' -b, --bc-only\n'
62 printf ' Build bc only. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"\n'
63 printf ' are specified too.\n'
64 printf ' -B, --disable-bc\n'
65 printf ' Disable bc. It is an error if "-b", "--bc-only", "-D", or "--disable-dc"\n'
66 printf ' are specified too.\n'
67 printf ' -c, --coverage\n'
68 printf ' Generate test coverage code. Requires gcov and regcovr.\n'
69 printf ' It is an error if either "-b" ("-D") or "-d" ("-B") is specified.\n'
70 printf ' Requires a compiler that use gcc-compatible coverage options\n'
71 printf ' -d, --dc-only\n'
72 printf ' Build dc only. It is an error if "-b", "--bc-only", "-D", or "--disable-dc"\n'
73 printf ' are specified too.\n'
74 printf ' -D, --disable-dc\n'
75 printf ' Disable dc. It is an error if "-d", "--dc-only" "-B", or "--disable-bc"\n'
76 printf ' are specified too.\n'
77 printf ' -E, --disable-extra-math\n'
78 printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n'
79 printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n'
80 printf ' function). Additionally, this option disables the extra printing\n'
81 printf ' functions in the math library.\n'
82 printf ' -f, --force\n'
83 printf ' Force use of all enabled options, even if they do not work. This\n'
84 printf ' option is to allow the maintainer a way to test that certain options\n'
85 printf ' are not failing invisibly. (Development only.)'
86 printf ' -g, --debug\n'
87 printf ' Build in debug mode. Adds the "-g" flag, and if there are no\n'
88 printf ' other CFLAGS, and "-O" was not given, this also adds the "-O0"\n'
89 printf ' flag. If this flag is *not* given, "-DNDEBUG" is added to CPPFLAGS\n'
90 printf ' and a strip flag is added to the link stage.\n'
91 printf ' -G, --disable-generated-tests\n'
92 printf ' Disable generating tests. This is for platforms that do not have a\n'
93 printf ' GNU bc-compatible bc to generate tests.\n'
94 printf ' -h, --help\n'
95 printf ' Print this help message and exit.\n'
96 printf ' -H, --disable-history\n'
97 printf ' Disable history.\n'
98 printf ' -k KARATSUBA_LEN, --karatsuba-len KARATSUBA_LEN\n'
99 printf ' Set the karatsuba length to KARATSUBA_LEN (default is 64).\n'
100 printf ' It is an error if KARATSUBA_LEN is not a number or is less than 16.\n'
101 printf ' -l, --install-all-locales\n'
102 printf ' Installs all locales, regardless of how many are on the system. This\n'
103 printf ' option is useful for package maintainers who want to make sure that\n'
104 printf ' a package contains all of the locales that end users might need.\n'
105 printf ' -M, --disable-man-pages\n'
106 printf ' Disable installing manpages.\n'
107 printf ' -N, --disable-nls\n'
108 printf ' Disable POSIX locale (NLS) support.\n'
109 printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n'
110 printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
111 printf ' but it is provided, so maintainers can build optimized debug builds.\n'
112 printf ' This is passed through to the compiler, so it must be supported.\n'
113 printf ' -P, --disable-prompt\n'
114 printf ' Disables the prompt in the built bc. The prompt will never show up,\n'
115 printf ' or in other words, it will be permanently disabled and cannot be\n'
117 printf ' -T, --disable-strip\n'
118 printf ' Disable stripping symbols from the compiled binary or binaries.\n'
119 printf ' Stripping symbols only happens when debug mode is off.\n'
120 printf ' --prefix PREFIX\n'
121 printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n'
122 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
123 printf ' Default is "/usr/local".\n'
124 printf ' --bindir BINDIR\n'
125 printf ' The directory to install binaries. Overrides "$BINDIR" if it exists.\n'
126 printf ' Default is "$PREFIX/bin".\n'
127 printf ' --datarootdir DATAROOTDIR\n'
128 printf ' The root location for data files. Overrides "$DATAROOTDIR" if it exists.\n'
129 printf ' Default is "$PREFIX/share".\n'
130 printf ' --datadir DATADIR\n'
131 printf ' The location for data files. Overrides "$DATADIR" if it exists.\n'
132 printf ' Default is "$DATAROOTDIR".\n'
133 printf ' --mandir MANDIR\n'
134 printf ' The location to install manpages to. Overrides "$MANDIR" if it exists.\n'
135 printf ' Default is "$DATADIR/man".\n'
136 printf ' --man1dir MAN1DIR\n'
137 printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n'
138 printf ' it exists. Default is "$MANDIR/man1".\n'
140 printf 'In addition, the following environment variables are used:\n'
142 printf ' CC C compiler. Must be compatible with POSIX c99. If there is a\n'
143 printf ' space in the basename of the compiler, the items after the\n'
144 printf ' first space are assumed to be compiler flags, and in that case,\n'
145 printf ' the flags are automatically moved into CFLAGS. Default is\n'
147 printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99. If there is\n'
148 printf ' a space in the basename of the compiler, the items after the\n'
149 printf ' first space are assumed to be compiler flags, and in the case,\n'
150 printf ' the flags are automatically moved into HOSTCFLAGS. Default is\n'
152 printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n'
153 printf ' CFLAGS C compiler flags.\n'
154 printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n'
155 printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n'
156 printf ' CPPFLAGS C preprocessor flags. Default is "".\n'
157 printf ' LDFLAGS Linker flags. Default is "".\n'
158 printf ' PREFIX The prefix to install to. Default is "/usr/local".\n'
159 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
160 printf ' BINDIR The directory to install binaries. Default is "$PREFIX/bin".\n'
161 printf ' DATAROOTDIR The root location for data files. Default is "$PREFIX/share".\n'
162 printf ' DATADIR The location for data files. Default is "$DATAROOTDIR".\n'
163 printf ' MANDIR The location to install manpages to. Default is "$DATADIR/man".\n'
164 printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n'
165 printf ' "$MANDIR/man1".\n'
166 printf ' NLSPATH The location to install locale catalogs to. Must be an absolute\n'
167 printf ' path (or contain one). This is treated the same as the POSIX\n'
168 printf ' definition of $NLSPATH (see POSIX environment variables for\n'
169 printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n'
170 printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n'
171 printf ' interfere with other installed bc executables. Default is "".\n'
172 printf ' EXECPREFIX The prefix to append to the executable names, used to not\n'
173 printf ' interfere with other installed bc executables. Default is "".\n'
174 printf ' DESTDIR For package creation. Default is "". If it is empty when\n'
175 printf ' `%s` is run, it can also be passed to `make install`\n' "$script"
176 printf ' later as an environment variable. If both are specified,\n'
177 printf ' the one given to `%s` takes precedence.\n' "$script"
178 printf ' LONG_BIT The number of bits in a C `long` type. This is mostly for the\n'
179 printf ' embedded space since this `bc` uses `long`s internally for\n'
180 printf ' overflow checking. In C99, a `long` is required to be 32 bits.\n'
181 printf ' For most normal desktop systems, setting this is unnecessary,\n'
182 printf ' except that 32-bit platforms with 64-bit longs may want to set\n'
183 printf ' it to `32`. Default is the default of `LONG_BIT` for the target\n'
184 printf ' platform. Minimum allowed is `32`. It is a build time error if\n'
185 printf ' the specified value of `LONG_BIT` is greater than the default\n'
186 printf ' value of `LONG_BIT` for the target platform.\n'
187 printf ' GEN_HOST Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to\n'
188 printf ' produce the C files that contain the help texts as well as the\n'
189 printf ' math libraries. By default, `gen/strgen.c` is used, compiled by\n'
190 printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
191 printf ' removes the need to compile and run an executable on the host\n'
192 printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
193 printf ' `gen/lib2.bc` is perilously close to 4095 characters, the max\n'
194 printf ' supported length of a string literal in C99 (and it could be\n'
195 printf ' added to in the future), and `gen/strgen.sh` generates a string\n'
196 printf ' literal instead of an array, as `gen/strgen.c` does. For most\n'
197 printf ' production-ready compilers, this limit probably is not\n'
198 printf ' enforced, but it could be. Both options are still available for\n'
199 printf ' this reason. If you are sure your compiler does not have the\n'
200 printf ' limit and do not want to compile and run a binary on the host\n'
201 printf ' machine, set this variable to "0". Any other value, or a\n'
202 printf ' non-existent value, will cause the build system to compile and\n'
203 printf ' run `gen/strgen.c`. Default is "".\n'
204 printf ' GEN_EMU Emulator to run string generator code under (leave empty if not\n'
205 printf ' necessary). This is not necessary when using `gen/strgen.sh`.\n'
206 printf ' Default is "".\n'
208 printf 'WARNING: even though `configure.sh` supports both option types, short and\n'
209 printf 'long, it does not support handling both at the same time. Use only one type.\n'
216 if [ "$#" -ne 3 ]; then
217 err_exit "Invalid number of args to $0"
220 _replace_ext_file="$1"
221 _replace_ext_ext1="$2"
222 _replace_ext_ext2="$3"
224 _replace_ext_result=${_replace_ext_file%.$_replace_ext_ext1}.$_replace_ext_ext2
226 printf '%s\n' "$_replace_ext_result"
231 if [ "$#" -ne 3 ]; then
232 err_exit "Invalid number of args to $0"
235 _replace_exts_files="$1"
236 _replace_exts_ext1="$2"
237 _replace_exts_ext2="$3"
239 for _replace_exts_file in $_replace_exts_files; do
240 _replace_exts_new_name=$(replace_ext "$_replace_exts_file" "$_replace_exts_ext1" "$_replace_exts_ext2")
241 _replace_exts_result="$_replace_exts_result $_replace_exts_new_name"
244 printf '%s\n' "$_replace_exts_result"
249 if [ "$#" -ne 3 ]; then
250 err_exit "Invalid number of args to $0"
255 _replace_replacement="$3"
257 substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement"
262 if [ "$#" -lt 3 ]; then
263 err_exit "Invalid number of args to $0"
266 _gen_file_lists_contents="$1"
269 _gen_file_lists_filedir="$1"
272 _gen_file_lists_typ="$1"
275 # If there is an extra argument, and it
276 # is zero, we keep the file lists empty.
277 if [ "$#" -gt 0 ]; then
278 _gen_file_lists_use="$1"
280 _gen_file_lists_use="1"
283 _gen_file_lists_needle_src="${_gen_file_lists_typ}SRC"
284 _gen_file_lists_needle_obj="${_gen_file_lists_typ}OBJ"
285 _gen_file_lists_needle_gcda="${_gen_file_lists_typ}GCDA"
286 _gen_file_lists_needle_gcno="${_gen_file_lists_typ}GCNO"
288 if [ "$_gen_file_lists_use" -ne 0 ]; then
290 _gen_file_lists_replacement=$(cd "$_gen_file_lists_filedir" && find . ! -name . -prune -name "*.c" | cut -d/ -f2 | sed "s@^@$_gen_file_lists_filedir/@g" | tr '\n' ' ')
291 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_src" "$_gen_file_lists_replacement")
293 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "c" "o")
294 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_obj" "$_gen_file_lists_replacement")
296 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "o" "gcda")
297 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcda" "$_gen_file_lists_replacement")
299 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "gcda" "gcno")
300 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcno" "$_gen_file_lists_replacement")
303 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_src" "")
304 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_obj" "")
305 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcda" "")
306 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcno" "")
309 printf '%s\n' "$_gen_file_lists_contents"
328 while getopts "bBcdDEfgGhHk:lMNO:PST-" opt; do
339 G) generate_tests=0 ;;
342 k) karatsuba_len="$OPTARG" ;;
344 M) install_manpages=0 ;;
346 O) optimization="$OPTARG" ;;
352 LONG_OPTARG="${arg#*=}"
355 bc-only) bc_only=1 ;;
356 dc-only) dc_only=1 ;;
357 coverage) coverage=1 ;;
360 prefix=?*) PREFIX="$LONG_OPTARG" ;;
362 if [ "$#" -lt 2 ]; then
363 usage "No argument given for '--$arg' option"
367 bindir=?*) BINDIR="$LONG_OPTARG" ;;
369 if [ "$#" -lt 2 ]; then
370 usage "No argument given for '--$arg' option"
374 datarootdir=?*) DATAROOTDIR="$LONG_OPTARG" ;;
376 if [ "$#" -lt 2 ]; then
377 usage "No argument given for '--$arg' option"
381 datadir=?*) DATADIR="$LONG_OPTARG" ;;
383 if [ "$#" -lt 2 ]; then
384 usage "No argument given for '--$arg' option"
388 mandir=?*) MANDIR="$LONG_OPTARG" ;;
390 if [ "$#" -lt 2 ]; then
391 usage "No argument given for '--$arg' option"
395 man1dir=?*) MAN1DIR="$LONG_OPTARG" ;;
397 if [ "$#" -lt 2 ]; then
398 usage "No argument given for '--$arg' option"
402 localedir=?*) LOCALEDIR="$LONG_OPTARG" ;;
404 if [ "$#" -lt 2 ]; then
405 usage "No argument given for '--$arg' option"
409 karatsuba-len=?*) karatsuba_len="$LONG_OPTARG" ;;
411 if [ "$#" -lt 2 ]; then
412 usage "No argument given for '--$arg' option"
416 opt=?*) optimization="$LONG_OPTARG" ;;
418 if [ "$#" -lt 2 ]; then
419 usage "No argument given for '--$arg' option"
423 disable-bc) dc_only=1 ;;
424 disable-dc) bc_only=1 ;;
425 disable-extra-math) extra_math=0 ;;
426 disable-generated-tests) generate_tests=0 ;;
427 disable-history) hist=0 ;;
428 disable-man-pages) install_manpages=0 ;;
429 disable-nls) nls=0 ;;
430 disable-prompt) prompt=0 ;;
431 disable-strip) strip_bin=0 ;;
432 install-all-locales) all_locales=1 ;;
433 help* | bc-only* | dc-only* | coverage* | debug*)
434 usage "No arg allowed for --$arg option" ;;
435 disable-bc* | disable-dc* | disable-extra-math*)
436 usage "No arg allowed for --$arg option" ;;
437 disable-generated-tests* | disable-history*)
438 usage "No arg allowed for --$arg option" ;;
439 disable-man-pages* | disable-nls* | disable-strip*)
440 usage "No arg allowed for --$arg option" ;;
441 install-all-locales*)
442 usage "No arg allowed for --$arg option" ;;
443 '') break ;; # "--" terminates argument processing
444 * ) usage "Invalid option $LONG_OPTARG" ;;
448 ?) usage "Invalid option $opt" ;;
453 if [ "$bc_only" -eq 1 ] && [ "$dc_only" -eq 1 ]; then
454 usage "Can only specify one of -b(-D) or -d(-B)"
457 case $karatsuba_len in
458 (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;;
462 if [ "$karatsuba_len" -lt 16 ]; then
463 usage "KARATSUBA_LEN is less than 16"
468 if [ -z "${LONG_BIT+set}" ]; then
470 elif [ "$LONG_BIT" -lt 32 ]; then
471 usage "LONG_BIT is less than 32"
473 LONG_BIT_DEFINE="-DBC_LONG_BIT=\$(BC_LONG_BIT)"
476 if [ -z "$CC" ]; then
479 ccbase=$(basename "$CC")
483 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
484 ccflags="${ccbase#$prefix}"
485 cc="${ccbase%%$suffix}"
486 ccdir=$(dirname "$CC")
487 if [ "$ccdir" = "." ] && [ "${CC#.}" = "$CC" ]; then
493 CFLAGS="$CFLAGS $ccflags"
497 if [ -z "$HOSTCC" ] && [ -z "$HOST_CC" ]; then
499 elif [ -z "$HOSTCC" ]; then
503 if [ "$HOSTCC" != "$CC" ]; then
504 ccbase=$(basename "$HOSTCC")
508 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
509 ccflags="${ccbase#$prefix}"
510 cc="${ccbase%%$suffix}"
511 ccdir=$(dirname "$HOSTCC")
512 if [ "$ccdir" = "." ] && [ "${HOSTCC#.}" = "$HOSTCC" ]; then
517 HOSTCC="${ccdir}${cc}"
518 HOSTCFLAGS="$HOSTCFLAGS $ccflags"
522 if [ -z "${HOSTCFLAGS+set}" ] && [ -z "${HOST_CFLAGS+set}" ]; then
524 elif [ -z "${HOSTCFLAGS+set}" ]; then
525 HOSTCFLAGS="$HOST_CFLAGS"
528 link="@printf 'No link necessary\\\\n'"
532 bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 \$(BC_EXEC)"
533 bc_time_test="@tests/all.sh bc $extra_math 1 $generate_tests 1 \$(BC_EXEC)"
535 dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 \$(DC_EXEC)"
536 dc_time_test="@tests/all.sh dc $extra_math 1 $generate_tests 1 \$(DC_EXEC)"
538 timeconst="@tests/bc/timeconst.sh tests/bc/scripts/timeconst.bc \$(BC_EXEC)"
540 # In order to have cleanup at exit, we need to be in
541 # debug mode, so don't run valgrind without that.
542 if [ "$debug" -ne 0 ]; then
543 vg_bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(BC_EXEC)"
544 vg_dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(DC_EXEC)"
546 vg_bc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
547 vg_dc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
550 karatsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
551 karatsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
553 bc_lib="\$(GEN_DIR)/lib.o"
554 bc_help="\$(GEN_DIR)/bc_help.o"
555 dc_help="\$(GEN_DIR)/dc_help.o"
557 if [ "$bc_only" -eq 1 ]; then
566 dc_test="@printf 'No dc tests to run\\\\n'"
567 dc_time_test="@printf 'No dc tests to run\\\\n'"
568 vg_dc_test="@printf 'No dc tests to run\\\\n'"
570 install_prereqs=" install_bc_manpage"
571 uninstall_prereqs=" uninstall_bc"
572 uninstall_man_prereqs=" uninstall_bc_manpage"
574 elif [ "$dc_only" -eq 1 ]; then
587 bc_test="@printf 'No bc tests to run\\\\n'"
588 bc_time_test="@printf 'No bc tests to run\\\\n'"
589 vg_bc_test="@printf 'No bc tests to run\\\\n'"
591 timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'"
593 install_prereqs=" install_dc_manpage"
594 uninstall_prereqs=" uninstall_dc"
595 uninstall_man_prereqs=" uninstall_dc_manpage"
602 executables="bc and dc"
604 link="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)"
606 karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)"
607 karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)"
609 install_prereqs=" install_bc_manpage install_dc_manpage"
610 uninstall_prereqs=" uninstall_bc uninstall_dc"
611 uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage"
615 if [ "$debug" -eq 1 ]; then
617 if [ -z "$CFLAGS" ] && [ -z "$optimization" ]; then
624 CPPFLAGS="-DNDEBUG $CPPFLAGS"
625 if [ "$strip_bin" -ne 0 ]; then
626 LDFLAGS="-s $LDFLAGS"
630 if [ -n "$optimization" ]; then
631 CFLAGS="-O$optimization $CFLAGS"
634 if [ "$coverage" -eq 1 ]; then
636 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
637 usage "Can only specify -c without -b or -d"
640 CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS"
641 CPPFLAGS="-DNDEBUG $CPPFLAGS"
643 COVERAGE_OUTPUT="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA) \$(HISTORY_GCDA) \$(RAND_GCDA)"
644 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;\$(RM) -f \$(GEN)*.gc*"
645 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;gcovr --html-details --output index.html"
646 COVERAGE_PREREQS=" test coverage_output"
649 COVERAGE_OUTPUT="@printf 'Coverage not generated\\\\n'"
653 if [ -z "${DESTDIR+set}" ]; then
656 destdir="DESTDIR = $DESTDIR"
659 if [ -z "${PREFIX+set}" ]; then
663 if [ -z "${BINDIR+set}" ]; then
667 if [ "$install_manpages" -ne 0 ] || [ "$nls" -ne 0 ]; then
668 if [ -z "${DATAROOTDIR+set}" ]; then
669 DATAROOTDIR="$PREFIX/share"
673 if [ "$install_manpages" -ne 0 ]; then
675 if [ -z "${DATADIR+set}" ]; then
676 DATADIR="$DATAROOTDIR"
679 if [ -z "${MANDIR+set}" ]; then
680 MANDIR="$DATADIR/man"
683 if [ -z "${MAN1DIR+set}" ]; then
684 MAN1DIR="$MANDIR/man1"
689 uninstall_man_prereqs=""
692 if [ "$nls" -ne 0 ]; then
696 printf 'Testing NLS...\n'
698 flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
699 flags="$flags -DBC_ENABLE_HISTORY=$hist"
700 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
701 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
703 "$CC" $CPPFLAGS $CFLAGS $flags -c "src/vm.c" -o "$scriptdir/vm.o" > /dev/null 2>&1
707 rm -rf "$scriptdir/vm.o"
709 # If this errors, it is probably because of building on Windows,
710 # and NLS is not supported on Windows, so disable it.
711 if [ "$err" -ne 0 ]; then
712 printf 'NLS does not work.\n'
713 if [ $force -eq 0 ]; then
714 printf 'Disabling NLS...\n\n'
717 printf 'Forcing NLS...\n\n'
720 printf 'NLS works.\n\n'
722 printf 'Testing gencat...\n'
723 gencat "$scriptdir/en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
727 rm -rf "$scriptdir/en_US.cat"
729 if [ "$err" -ne 0 ]; then
730 printf 'gencat does not work.\n'
731 if [ $force -eq 0 ]; then
732 printf 'Disabling NLS...\n\n'
735 printf 'Forcing NLS...\n\n'
739 printf 'gencat works.\n\n'
741 if [ "$HOSTCC" != "$CC" ]; then
742 printf 'Cross-compile detected.\n\n'
743 printf 'WARNING: Catalog files generated with gencat may not be portable\n'
744 printf ' across different architectures.\n\n'
747 if [ -z "$NLSPATH" ]; then
748 NLSPATH="/usr/share/locale/%L/%N"
751 install_locales_prereqs=" install_locales"
752 uninstall_locales_prereqs=" uninstall_locales"
761 install_locales_prereqs=""
762 uninstall_locales_prereqs=""
766 if [ "$nls" -ne 0 ] && [ "$all_locales" -ne 0 ]; then
767 install_locales="\$(LOCALE_INSTALL) -l \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
769 install_locales="\$(LOCALE_INSTALL) \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
772 if [ "$hist" -eq 1 ]; then
776 printf 'Testing history...\n'
778 flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
779 flags="$flags -DBC_ENABLE_NLS=$nls"
780 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
781 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
783 "$CC" $CPPFLAGS $CFLAGS $flags -c "src/history/history.c" -o "$scriptdir/history.o" > /dev/null 2>&1
787 rm -rf "$scriptdir/history.o"
789 # If this errors, it is probably because of building on Windows,
790 # and history is not supported on Windows, so disable it.
791 if [ "$err" -ne 0 ]; then
792 printf 'History does not work.\n'
793 if [ $force -eq 0 ]; then
794 printf 'Disabling history...\n\n'
797 printf 'Forcing history...\n\n'
800 printf 'History works.\n\n'
807 if [ "$extra_math" -eq 1 ] && [ "$bc" -ne 0 ]; then
808 BC_LIB2_O="\$(GEN_DIR)/lib2.o"
814 GEN_EXEC_TARGET="\$(HOSTCC) \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
815 CLEAN_PREREQS=" clean_gen"
817 if [ -z "${GEN_HOST+set}" ]; then
820 if [ "$GEN_HOST" -eq 0 ]; then
822 GEN_EXEC_TARGET="@printf 'Do not need to build gen/strgen.c\\\\n'"
829 if [ "$extra_math" -eq 0 ]; then
833 if [ "$hist" -eq 0 ]; then
834 manpage_args="${manpage_args}H"
837 if [ "$nls" -eq 0 ]; then
838 manpage_args="${manpage_args}N"
841 if [ "$prompt" -eq 0 ]; then
842 manpage_args="${manpage_args}P"
845 if [ "$manpage_args" = "" ]; then
849 # Print out the values; this is for debugging.
850 if [ "$bc" -ne 0 ]; then
851 printf 'Building bc\n'
853 printf 'Not building bc\n'
855 if [ "$dc" -ne 0 ]; then
856 printf 'Building dc\n'
858 printf 'Not building dc\n'
861 printf 'BC_ENABLE_HISTORY=%s\n' "$hist"
862 printf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math"
863 printf 'BC_ENABLE_NLS=%s\n' "$nls"
864 printf 'BC_ENABLE_PROMPT=%s\n' "$prompt"
866 printf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len"
868 printf 'CC=%s\n' "$CC"
869 printf 'CFLAGS=%s\n' "$CFLAGS"
870 printf 'HOSTCC=%s\n' "$HOSTCC"
871 printf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS"
872 printf 'CPPFLAGS=%s\n' "$CPPFLAGS"
873 printf 'LDFLAGS=%s\n' "$LDFLAGS"
874 printf 'PREFIX=%s\n' "$PREFIX"
875 printf 'BINDIR=%s\n' "$BINDIR"
876 printf 'DATAROOTDIR=%s\n' "$DATAROOTDIR"
877 printf 'DATADIR=%s\n' "$DATADIR"
878 printf 'MANDIR=%s\n' "$MANDIR"
879 printf 'MAN1DIR=%s\n' "$MAN1DIR"
880 printf 'NLSPATH=%s\n' "$NLSPATH"
881 printf 'EXECSUFFIX=%s\n' "$EXECSUFFIX"
882 printf 'EXECPREFIX=%s\n' "$EXECPREFIX"
883 printf 'DESTDIR=%s\n' "$DESTDIR"
884 printf 'LONG_BIT=%s\n' "$LONG_BIT"
885 printf 'GEN_HOST=%s\n' "$GEN_HOST"
886 printf 'GEN_EMU=%s\n' "$GEN_EMU"
888 contents=$(cat "$scriptdir/Makefile.in")
891 replacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***'
893 contents=$(replace "$contents" "$needle" "$replacement")
895 contents=$(gen_file_lists "$contents" "$scriptdir/src" "")
896 contents=$(gen_file_lists "$contents" "$scriptdir/src/bc" "BC_" "$bc")
897 contents=$(gen_file_lists "$contents" "$scriptdir/src/dc" "DC_" "$dc")
898 contents=$(gen_file_lists "$contents" "$scriptdir/src/history" "HISTORY_" "$hist")
899 contents=$(gen_file_lists "$contents" "$scriptdir/src/rand" "RAND_" "$extra_math")
901 contents=$(replace "$contents" "BC_ENABLED" "$bc")
902 contents=$(replace "$contents" "DC_ENABLED" "$dc")
903 contents=$(replace "$contents" "LINK" "$link")
905 contents=$(replace "$contents" "HISTORY" "$hist")
906 contents=$(replace "$contents" "EXTRA_MATH" "$extra_math")
907 contents=$(replace "$contents" "NLS" "$nls")
908 contents=$(replace "$contents" "PROMPT" "$prompt")
909 contents=$(replace "$contents" "BC_LIB_O" "$bc_lib")
910 contents=$(replace "$contents" "BC_HELP_O" "$bc_help")
911 contents=$(replace "$contents" "DC_HELP_O" "$dc_help")
912 contents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O")
913 contents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len")
915 contents=$(replace "$contents" "NLSPATH" "$NLSPATH")
916 contents=$(replace "$contents" "DESTDIR" "$destdir")
917 contents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX")
918 contents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX")
919 contents=$(replace "$contents" "BINDIR" "$BINDIR")
920 contents=$(replace "$contents" "MAN1DIR" "$MAN1DIR")
921 contents=$(replace "$contents" "CFLAGS" "$CFLAGS")
922 contents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS")
923 contents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS")
924 contents=$(replace "$contents" "LDFLAGS" "$LDFLAGS")
925 contents=$(replace "$contents" "CC" "$CC")
926 contents=$(replace "$contents" "HOSTCC" "$HOSTCC")
927 contents=$(replace "$contents" "COVERAGE_OUTPUT" "$COVERAGE_OUTPUT")
928 contents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS")
929 contents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs")
930 contents=$(replace "$contents" "INSTALL_LOCALES" "$install_locales")
931 contents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs")
932 contents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs")
933 contents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs")
934 contents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs")
936 contents=$(replace "$contents" "EXECUTABLES" "$executables")
937 contents=$(replace "$contents" "MAIN_EXEC" "$main_exec")
938 contents=$(replace "$contents" "EXEC" "$executable")
940 contents=$(replace "$contents" "BC_TEST" "$bc_test")
941 contents=$(replace "$contents" "BC_TIME_TEST" "$bc_time_test")
943 contents=$(replace "$contents" "DC_TEST" "$dc_test")
944 contents=$(replace "$contents" "DC_TIME_TEST" "$dc_time_test")
946 contents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test")
947 contents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test")
949 contents=$(replace "$contents" "TIMECONST" "$timeconst")
951 contents=$(replace "$contents" "KARATSUBA" "$karatsuba")
952 contents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test")
954 contents=$(replace "$contents" "LONG_BIT" "$LONG_BIT")
955 contents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE")
957 contents=$(replace "$contents" "GEN" "$GEN")
958 contents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET")
959 contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS")
960 contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU")
962 printf '%s\n' "$contents" > "$scriptdir/Makefile"
966 cp -f manuals/bc/$manpage_args.1.md manuals/bc.1.md
967 cp -f manuals/bc/$manpage_args.1 manuals/bc.1
968 cp -f manuals/dc/$manpage_args.1.md manuals/dc.1.md
969 cp -f manuals/dc/$manpage_args.1 manuals/dc.1
971 make clean > /dev/null