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] [-EfgGHMNPT] [-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] \\\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 ' -M, --disable-man-pages\n'
102 printf ' Disable installing manpages.\n'
103 printf ' -N, --disable-nls\n'
104 printf ' Disable POSIX locale (NLS) support.\n'
105 printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n'
106 printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
107 printf ' but it is provided, so maintainers can build optimized debug builds.\n'
108 printf ' This is passed through to the compiler, so it must be supported.\n'
109 printf ' -P, --disable-prompt\n'
110 printf ' Disables the prompt in the built bc. The prompt will never show up,\n'
111 printf ' or in other words, it will be permanently disabled and cannot be\n'
113 printf ' -T, --disable-strip\n'
114 printf ' Disable stripping symbols from the compiled binary or binaries.\n'
115 printf ' Stripping symbols only happens when debug mode is off.\n'
116 printf ' --prefix PREFIX\n'
117 printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n'
118 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
119 printf ' Default is "/usr/local".\n'
120 printf ' --bindir BINDIR\n'
121 printf ' The directory to install binaries. Overrides "$BINDIR" if it exists.\n'
122 printf ' Default is "$PREFIX/bin".\n'
123 printf ' --datarootdir DATAROOTDIR\n'
124 printf ' The root location for data files. Overrides "$DATAROOTDIR" if it exists.\n'
125 printf ' Default is "$PREFIX/share".\n'
126 printf ' --datadir DATADIR\n'
127 printf ' The location for data files. Overrides "$DATADIR" if it exists.\n'
128 printf ' Default is "$DATAROOTDIR".\n'
129 printf ' --mandir MANDIR\n'
130 printf ' The location to install manpages to. Overrides "$MANDIR" if it exists.\n'
131 printf ' Default is "$DATADIR/man".\n'
132 printf ' --man1dir MAN1DIR\n'
133 printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n'
134 printf ' it exists. Default is "$MANDIR/man1".\n'
136 printf 'In addition, the following environment variables are used:\n'
138 printf ' CC C compiler. Must be compatible with POSIX c99. If there is a\n'
139 printf ' space in the basename of the compiler, the items after the\n'
140 printf ' first space are assumed to be compiler flags, and in that case,\n'
141 printf ' the flags are automatically moved into CFLAGS. Default is\n'
143 printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99. If there is\n'
144 printf ' a space in the basename of the compiler, the items after the\n'
145 printf ' first space are assumed to be compiler flags, and in the case,\n'
146 printf ' the flags are automatically moved into HOSTCFLAGS. Default is\n'
148 printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n'
149 printf ' CFLAGS C compiler flags.\n'
150 printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n'
151 printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n'
152 printf ' CPPFLAGS C preprocessor flags. Default is "".\n'
153 printf ' LDFLAGS Linker flags. Default is "".\n'
154 printf ' PREFIX The prefix to install to. Default is "/usr/local".\n'
155 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
156 printf ' BINDIR The directory to install binaries. Default is "$PREFIX/bin".\n'
157 printf ' DATAROOTDIR The root location for data files. Default is "$PREFIX/share".\n'
158 printf ' DATADIR The location for data files. Default is "$DATAROOTDIR".\n'
159 printf ' MANDIR The location to install manpages to. Default is "$DATADIR/man".\n'
160 printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n'
161 printf ' "$MANDIR/man1".\n'
162 printf ' NLSPATH The location to install locale catalogs to. Must be an absolute\n'
163 printf ' path (or contain one). This is treated the same as the POSIX\n'
164 printf ' definition of $NLSPATH (see POSIX environment variables for\n'
165 printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n'
166 printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n'
167 printf ' interfere with other installed bc executables. Default is "".\n'
168 printf ' EXECPREFIX The prefix to append to the executable names, used to not\n'
169 printf ' interfere with other installed bc executables. Default is "".\n'
170 printf ' DESTDIR For package creation. Default is "". If it is empty when\n'
171 printf ' `%s` is run, it can also be passed to `make install`\n' "$script"
172 printf ' later as an environment variable. If both are specified,\n'
173 printf ' the one given to `%s` takes precedence.\n' "$script"
174 printf ' LONG_BIT The number of bits in a C `long` type. This is mostly for the\n'
175 printf ' embedded space since this `bc` uses `long`s internally for\n'
176 printf ' overflow checking. In C99, a `long` is required to be 32 bits.\n'
177 printf ' For most normal desktop systems, setting this is unnecessary,\n'
178 printf ' except that 32-bit platforms with 64-bit longs may want to set\n'
179 printf ' it to `32`. Default is the default of `LONG_BIT` for the target\n'
180 printf ' platform. Minimum allowed is `32`. It is a build time error if\n'
181 printf ' the specified value of `LONG_BIT` is greater than the default\n'
182 printf ' value of `LONG_BIT` for the target platform.\n'
183 printf ' GEN_HOST Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to\n'
184 printf ' produce the C files that contain the help texts as well as the\n'
185 printf ' math libraries. By default, `gen/strgen.c` is used, compiled by\n'
186 printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
187 printf ' removes the need to compile and run an executable on the host\n'
188 printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
189 printf ' `gen/lib2.bc` is perilously close to 4095 characters, the max\n'
190 printf ' supported length of a string literal in C99 (and it could be\n'
191 printf ' added to in the future), and `gen/strgen.sh` generates a string\n'
192 printf ' literal instead of an array, as `gen/strgen.c` does. For most\n'
193 printf ' production-ready compilers, this limit probably is not\n'
194 printf ' enforced, but it could be. Both options are still available for\n'
195 printf ' this reason. If you are sure your compiler does not have the\n'
196 printf ' limit and do not want to compile and run a binary on the host\n'
197 printf ' machine, set this variable to "0". Any other value, or a\n'
198 printf ' non-existent value, will cause the build system to compile and\n'
199 printf ' run `gen/strgen.c`. Default is "".\n'
200 printf ' GEN_EMU Emulator to run string generator code under (leave empty if not\n'
201 printf ' necessary). This is not necessary when using `gen/strgen.sh`.\n'
202 printf ' Default is "".\n'
204 printf 'WARNING: even though `configure.sh` supports both option types, short and\n'
205 printf 'long, it does not support handling both at the same time. Use only one type.\n'
212 if [ "$#" -ne 3 ]; then
213 err_exit "Invalid number of args to $0"
216 _replace_ext_file="$1"
217 _replace_ext_ext1="$2"
218 _replace_ext_ext2="$3"
220 _replace_ext_result=${_replace_ext_file%.$_replace_ext_ext1}.$_replace_ext_ext2
222 printf '%s\n' "$_replace_ext_result"
227 if [ "$#" -ne 3 ]; then
228 err_exit "Invalid number of args to $0"
231 _replace_exts_files="$1"
232 _replace_exts_ext1="$2"
233 _replace_exts_ext2="$3"
235 for _replace_exts_file in $_replace_exts_files; do
236 _replace_exts_new_name=$(replace_ext "$_replace_exts_file" "$_replace_exts_ext1" "$_replace_exts_ext2")
237 _replace_exts_result="$_replace_exts_result $_replace_exts_new_name"
240 printf '%s\n' "$_replace_exts_result"
245 if [ "$#" -ne 3 ]; then
246 err_exit "Invalid number of args to $0"
251 _replace_replacement="$3"
253 substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement"
258 if [ "$#" -lt 3 ]; then
259 err_exit "Invalid number of args to $0"
262 _gen_file_lists_contents="$1"
265 _gen_file_lists_filedir="$1"
268 _gen_file_lists_typ="$1"
271 # If there is an extra argument, and it
272 # is zero, we keep the file lists empty.
273 if [ "$#" -gt 0 ]; then
274 _gen_file_lists_use="$1"
276 _gen_file_lists_use="1"
279 _gen_file_lists_needle_src="${_gen_file_lists_typ}SRC"
280 _gen_file_lists_needle_obj="${_gen_file_lists_typ}OBJ"
281 _gen_file_lists_needle_gcda="${_gen_file_lists_typ}GCDA"
282 _gen_file_lists_needle_gcno="${_gen_file_lists_typ}GCNO"
284 if [ "$_gen_file_lists_use" -ne 0 ]; then
286 _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' ' ')
287 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_src" "$_gen_file_lists_replacement")
289 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "c" "o")
290 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_obj" "$_gen_file_lists_replacement")
292 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "o" "gcda")
293 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcda" "$_gen_file_lists_replacement")
295 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "gcda" "gcno")
296 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcno" "$_gen_file_lists_replacement")
299 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_src" "")
300 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_obj" "")
301 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcda" "")
302 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcno" "")
305 printf '%s\n' "$_gen_file_lists_contents"
323 while getopts "bBcdDEfgGhHk:MNO:PST-" opt; do
334 G) generate_tests=0 ;;
337 k) karatsuba_len="$OPTARG" ;;
338 M) install_manpages=0 ;;
340 O) optimization="$OPTARG" ;;
346 LONG_OPTARG="${arg#*=}"
349 bc-only) bc_only=1 ;;
350 dc-only) dc_only=1 ;;
351 coverage) coverage=1 ;;
354 prefix=?*) PREFIX="$LONG_OPTARG" ;;
356 if [ "$#" -lt 2 ]; then
357 usage "No argument given for '--$arg' option"
361 bindir=?*) BINDIR="$LONG_OPTARG" ;;
363 if [ "$#" -lt 2 ]; then
364 usage "No argument given for '--$arg' option"
368 datarootdir=?*) DATAROOTDIR="$LONG_OPTARG" ;;
370 if [ "$#" -lt 2 ]; then
371 usage "No argument given for '--$arg' option"
375 datadir=?*) DATADIR="$LONG_OPTARG" ;;
377 if [ "$#" -lt 2 ]; then
378 usage "No argument given for '--$arg' option"
382 mandir=?*) MANDIR="$LONG_OPTARG" ;;
384 if [ "$#" -lt 2 ]; then
385 usage "No argument given for '--$arg' option"
389 man1dir=?*) MAN1DIR="$LONG_OPTARG" ;;
391 if [ "$#" -lt 2 ]; then
392 usage "No argument given for '--$arg' option"
396 localedir=?*) LOCALEDIR="$LONG_OPTARG" ;;
398 if [ "$#" -lt 2 ]; then
399 usage "No argument given for '--$arg' option"
403 karatsuba-len=?*) karatsuba_len="$LONG_OPTARG" ;;
405 if [ "$#" -lt 2 ]; then
406 usage "No argument given for '--$arg' option"
410 opt=?*) optimization="$LONG_OPTARG" ;;
412 if [ "$#" -lt 2 ]; then
413 usage "No argument given for '--$arg' option"
417 disable-bc) dc_only=1 ;;
418 disable-dc) bc_only=1 ;;
419 disable-extra-math) extra_math=0 ;;
420 disable-generated-tests) generate_tests=0 ;;
421 disable-history) hist=0 ;;
422 disable-man-pages) install_manpages=0 ;;
423 disable-nls) nls=0 ;;
424 disable-prompt) prompt=0 ;;
425 disable-strip) strip_bin=0 ;;
426 help* | bc-only* | dc-only* | coverage* | debug*)
427 usage "No arg allowed for --$arg option" ;;
428 disable-bc* | disable-dc* | disable-extra-math*)
429 usage "No arg allowed for --$arg option" ;;
430 disable-generated-tests* | disable-history*)
431 usage "No arg allowed for --$arg option" ;;
432 disable-man-pages* | disable-nls* | disable-strip*)
433 usage "No arg allowed for --$arg option" ;;
434 '') break ;; # "--" terminates argument processing
435 * ) usage "Invalid option $LONG_OPTARG" ;;
439 ?) usage "Invalid option $opt" ;;
444 if [ "$bc_only" -eq 1 ] && [ "$dc_only" -eq 1 ]; then
445 usage "Can only specify one of -b(-D) or -d(-B)"
448 case $karatsuba_len in
449 (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;;
453 if [ "$karatsuba_len" -lt 16 ]; then
454 usage "KARATSUBA_LEN is less than 16"
459 if [ -z "${LONG_BIT+set}" ]; then
461 elif [ "$LONG_BIT" -lt 32 ]; then
462 usage "LONG_BIT is less than 32"
464 LONG_BIT_DEFINE="-DBC_LONG_BIT=\$(BC_LONG_BIT)"
467 if [ -z "$CC" ]; then
470 ccbase=$(basename "$CC")
474 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
475 ccflags="${ccbase#$prefix}"
476 cc="${ccbase%%$suffix}"
477 ccdir=$(dirname "$CC")
478 if [ "$ccdir" = "." ] && [ "${CC#.}" = "$CC" ]; then
484 CFLAGS="$CFLAGS $ccflags"
488 if [ -z "$HOSTCC" ] && [ -z "$HOST_CC" ]; then
490 elif [ -z "$HOSTCC" ]; then
494 if [ "$HOSTCC" != "$CC" ]; then
495 ccbase=$(basename "$HOSTCC")
499 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
500 ccflags="${ccbase#$prefix}"
501 cc="${ccbase%%$suffix}"
502 ccdir=$(dirname "$HOSTCC")
503 if [ "$ccdir" = "." ] && [ "${HOSTCC#.}" = "$HOSTCC" ]; then
508 HOSTCC="${ccdir}${cc}"
509 HOSTCFLAGS="$HOSTCFLAGS $ccflags"
513 if [ -z "${HOSTCFLAGS+set}" ] && [ -z "${HOST_CFLAGS+set}" ]; then
515 elif [ -z "${HOSTCFLAGS+set}" ]; then
516 HOSTCFLAGS="$HOST_CFLAGS"
519 link="@printf 'No link necessary\\\\n'"
523 bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 \$(BC_EXEC)"
524 bc_time_test="@tests/all.sh bc $extra_math 1 $generate_tests 1 \$(BC_EXEC)"
526 dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 \$(DC_EXEC)"
527 dc_time_test="@tests/all.sh dc $extra_math 1 $generate_tests 1 \$(DC_EXEC)"
529 timeconst="@tests/bc/timeconst.sh tests/bc/scripts/timeconst.bc \$(BC_EXEC)"
531 # In order to have cleanup at exit, we need to be in
532 # debug mode, so don't run valgrind without that.
533 if [ "$debug" -ne 0 ]; then
534 vg_bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(BC_EXEC)"
535 vg_dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(DC_EXEC)"
537 vg_bc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
538 vg_dc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
541 karatsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
542 karatsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
544 bc_lib="\$(GEN_DIR)/lib.o"
545 bc_help="\$(GEN_DIR)/bc_help.o"
546 dc_help="\$(GEN_DIR)/dc_help.o"
548 if [ "$bc_only" -eq 1 ]; then
557 dc_test="@printf 'No dc tests to run\\\\n'"
558 dc_time_test="@printf 'No dc tests to run\\\\n'"
559 vg_dc_test="@printf 'No dc tests to run\\\\n'"
561 install_prereqs=" install_bc_manpage"
562 uninstall_prereqs=" uninstall_bc"
563 uninstall_man_prereqs=" uninstall_bc_manpage"
565 elif [ "$dc_only" -eq 1 ]; then
578 bc_test="@printf 'No bc tests to run\\\\n'"
579 bc_time_test="@printf 'No bc tests to run\\\\n'"
580 vg_bc_test="@printf 'No bc tests to run\\\\n'"
582 timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'"
584 install_prereqs=" install_dc_manpage"
585 uninstall_prereqs=" uninstall_dc"
586 uninstall_man_prereqs=" uninstall_dc_manpage"
593 executables="bc and dc"
595 link="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)"
597 karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)"
598 karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)"
600 install_prereqs=" install_bc_manpage install_dc_manpage"
601 uninstall_prereqs=" uninstall_bc uninstall_dc"
602 uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage"
606 if [ "$debug" -eq 1 ]; then
608 if [ -z "$CFLAGS" ] && [ -z "$optimization" ]; then
615 CPPFLAGS="-DNDEBUG $CPPFLAGS"
616 if [ "$strip_bin" -ne 0 ]; then
617 LDFLAGS="-s $LDFLAGS"
621 if [ -n "$optimization" ]; then
622 CFLAGS="-O$optimization $CFLAGS"
625 if [ "$coverage" -eq 1 ]; then
627 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
628 usage "Can only specify -c without -b or -d"
631 CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS"
632 CPPFLAGS="-DNDEBUG $CPPFLAGS"
634 COVERAGE_OUTPUT="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA) \$(HISTORY_GCDA) \$(RAND_GCDA)"
635 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;\$(RM) -f \$(GEN)*.gc*"
636 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;gcovr --html-details --output index.html"
637 COVERAGE_PREREQS=" test coverage_output"
640 COVERAGE_OUTPUT="@printf 'Coverage not generated\\\\n'"
644 if [ -z "${DESTDIR+set}" ]; then
647 destdir="DESTDIR = $DESTDIR"
650 if [ -z "${PREFIX+set}" ]; then
654 if [ -z "${BINDIR+set}" ]; then
658 if [ "$install_manpages" -ne 0 ] || [ "$nls" -ne 0 ]; then
659 if [ -z "${DATAROOTDIR+set}" ]; then
660 DATAROOTDIR="$PREFIX/share"
664 if [ "$install_manpages" -ne 0 ]; then
666 if [ -z "${DATADIR+set}" ]; then
667 DATADIR="$DATAROOTDIR"
670 if [ -z "${MANDIR+set}" ]; then
671 MANDIR="$DATADIR/man"
674 if [ -z "${MAN1DIR+set}" ]; then
675 MAN1DIR="$MANDIR/man1"
680 uninstall_man_prereqs=""
683 if [ "$nls" -ne 0 ]; then
687 printf 'Testing NLS...\n'
689 flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
690 flags="$flags -DBC_ENABLE_HISTORY=$hist"
691 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
692 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
694 "$CC" $CPPFLAGS $CFLAGS $flags -c "src/vm.c" -o "$scriptdir/vm.o" > /dev/null 2>&1
698 rm -rf "$scriptdir/vm.o"
700 # If this errors, it is probably because of building on Windows,
701 # and NLS is not supported on Windows, so disable it.
702 if [ "$err" -ne 0 ]; then
703 printf 'NLS does not work.\n'
704 if [ $force -eq 0 ]; then
705 printf 'Disabling NLS...\n\n'
708 printf 'Forcing NLS...\n\n'
711 printf 'NLS works.\n\n'
713 printf 'Testing gencat...\n'
714 gencat "$scriptdir/en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
718 rm -rf "$scriptdir/en_US.cat"
720 if [ "$err" -ne 0 ]; then
721 printf 'gencat does not work.\n'
722 if [ $force -eq 0 ]; then
723 printf 'Disabling NLS...\n\n'
726 printf 'Forcing NLS...\n\n'
730 printf 'gencat works.\n\n'
732 if [ "$HOSTCC" != "$CC" ]; then
733 printf 'Cross-compile detected.\n\n'
734 printf 'WARNING: Catalog files generated with gencat may not be portable\n'
735 printf ' across different architectures.\n\n'
738 if [ -z "$NLSPATH" ]; then
739 NLSPATH="/usr/share/locale/%L/%N"
742 install_locales_prereqs=" install_locales"
743 uninstall_locales_prereqs=" uninstall_locales"
752 install_locales_prereqs=""
753 uninstall_locales_prereqs=""
756 if [ "$hist" -eq 1 ]; then
760 printf 'Testing history...\n'
762 flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
763 flags="$flags -DBC_ENABLE_NLS=$nls"
764 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
765 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
767 "$CC" $CPPFLAGS $CFLAGS $flags -c "src/history/history.c" -o "$scriptdir/history.o" > /dev/null 2>&1
771 rm -rf "$scriptdir/history.o"
773 # If this errors, it is probably because of building on Windows,
774 # and history is not supported on Windows, so disable it.
775 if [ "$err" -ne 0 ]; then
776 printf 'History does not work.\n'
777 if [ $force -eq 0 ]; then
778 printf 'Disabling history...\n\n'
781 printf 'Forcing history...\n\n'
784 printf 'History works.\n\n'
791 if [ "$extra_math" -eq 1 ] && [ "$bc" -ne 0 ]; then
792 BC_LIB2_O="\$(GEN_DIR)/lib2.o"
798 GEN_EXEC_TARGET="\$(HOSTCC) \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
799 CLEAN_PREREQS=" clean_gen"
801 if [ -z "${GEN_HOST+set}" ]; then
804 if [ "$GEN_HOST" -eq 0 ]; then
806 GEN_EXEC_TARGET="@printf 'Do not need to build gen/strgen.c\\\\n'"
813 if [ "$extra_math" -eq 0 ]; then
817 if [ "$hist" -eq 0 ]; then
818 manpage_args="${manpage_args}H"
821 if [ "$nls" -eq 0 ]; then
822 manpage_args="${manpage_args}N"
825 if [ "$prompt" -eq 0 ]; then
826 manpage_args="${manpage_args}P"
829 if [ "$manpage_args" = "" ]; then
833 # Print out the values; this is for debugging.
834 if [ "$bc" -ne 0 ]; then
835 printf 'Building bc\n'
837 printf 'Not building bc\n'
839 if [ "$dc" -ne 0 ]; then
840 printf 'Building dc\n'
842 printf 'Not building dc\n'
845 printf 'BC_ENABLE_HISTORY=%s\n' "$hist"
846 printf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math"
847 printf 'BC_ENABLE_NLS=%s\n' "$nls"
848 printf 'BC_ENABLE_PROMPT=%s\n' "$prompt"
850 printf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len"
852 printf 'CC=%s\n' "$CC"
853 printf 'CFLAGS=%s\n' "$CFLAGS"
854 printf 'HOSTCC=%s\n' "$HOSTCC"
855 printf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS"
856 printf 'CPPFLAGS=%s\n' "$CPPFLAGS"
857 printf 'LDFLAGS=%s\n' "$LDFLAGS"
858 printf 'PREFIX=%s\n' "$PREFIX"
859 printf 'BINDIR=%s\n' "$BINDIR"
860 printf 'DATAROOTDIR=%s\n' "$DATAROOTDIR"
861 printf 'DATADIR=%s\n' "$DATADIR"
862 printf 'MANDIR=%s\n' "$MANDIR"
863 printf 'MAN1DIR=%s\n' "$MAN1DIR"
864 printf 'NLSPATH=%s\n' "$NLSPATH"
865 printf 'EXECSUFFIX=%s\n' "$EXECSUFFIX"
866 printf 'EXECPREFIX=%s\n' "$EXECPREFIX"
867 printf 'DESTDIR=%s\n' "$DESTDIR"
868 printf 'LONG_BIT=%s\n' "$LONG_BIT"
869 printf 'GEN_HOST=%s\n' "$GEN_HOST"
870 printf 'GEN_EMU=%s\n' "$GEN_EMU"
872 contents=$(cat "$scriptdir/Makefile.in")
875 replacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***'
877 contents=$(replace "$contents" "$needle" "$replacement")
879 contents=$(gen_file_lists "$contents" "$scriptdir/src" "")
880 contents=$(gen_file_lists "$contents" "$scriptdir/src/bc" "BC_" "$bc")
881 contents=$(gen_file_lists "$contents" "$scriptdir/src/dc" "DC_" "$dc")
882 contents=$(gen_file_lists "$contents" "$scriptdir/src/history" "HISTORY_" "$hist")
883 contents=$(gen_file_lists "$contents" "$scriptdir/src/rand" "RAND_" "$extra_math")
885 contents=$(replace "$contents" "BC_ENABLED" "$bc")
886 contents=$(replace "$contents" "DC_ENABLED" "$dc")
887 contents=$(replace "$contents" "LINK" "$link")
889 contents=$(replace "$contents" "HISTORY" "$hist")
890 contents=$(replace "$contents" "EXTRA_MATH" "$extra_math")
891 contents=$(replace "$contents" "NLS" "$nls")
892 contents=$(replace "$contents" "PROMPT" "$prompt")
893 contents=$(replace "$contents" "BC_LIB_O" "$bc_lib")
894 contents=$(replace "$contents" "BC_HELP_O" "$bc_help")
895 contents=$(replace "$contents" "DC_HELP_O" "$dc_help")
896 contents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O")
897 contents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len")
899 contents=$(replace "$contents" "NLSPATH" "$NLSPATH")
900 contents=$(replace "$contents" "DESTDIR" "$destdir")
901 contents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX")
902 contents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX")
903 contents=$(replace "$contents" "BINDIR" "$BINDIR")
904 contents=$(replace "$contents" "MAN1DIR" "$MAN1DIR")
905 contents=$(replace "$contents" "CFLAGS" "$CFLAGS")
906 contents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS")
907 contents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS")
908 contents=$(replace "$contents" "LDFLAGS" "$LDFLAGS")
909 contents=$(replace "$contents" "CC" "$CC")
910 contents=$(replace "$contents" "HOSTCC" "$HOSTCC")
911 contents=$(replace "$contents" "COVERAGE_OUTPUT" "$COVERAGE_OUTPUT")
912 contents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS")
913 contents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs")
914 contents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs")
915 contents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs")
916 contents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs")
917 contents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs")
919 contents=$(replace "$contents" "EXECUTABLES" "$executables")
920 contents=$(replace "$contents" "MAIN_EXEC" "$main_exec")
921 contents=$(replace "$contents" "EXEC" "$executable")
923 contents=$(replace "$contents" "BC_TEST" "$bc_test")
924 contents=$(replace "$contents" "BC_TIME_TEST" "$bc_time_test")
926 contents=$(replace "$contents" "DC_TEST" "$dc_test")
927 contents=$(replace "$contents" "DC_TIME_TEST" "$dc_time_test")
929 contents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test")
930 contents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test")
932 contents=$(replace "$contents" "TIMECONST" "$timeconst")
934 contents=$(replace "$contents" "KARATSUBA" "$karatsuba")
935 contents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test")
937 contents=$(replace "$contents" "LONG_BIT" "$LONG_BIT")
938 contents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE")
940 contents=$(replace "$contents" "GEN" "$GEN")
941 contents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET")
942 contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS")
943 contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU")
945 printf '%s\n' "$contents" > "$scriptdir/Makefile"
949 cp -f manuals/bc/$manpage_args.1.md manuals/bc.1.md
950 cp -f manuals/bc/$manpage_args.1 manuals/bc.1
951 cp -f manuals/dc/$manpage_args.1.md manuals/dc.1.md
952 cp -f manuals/dc/$manpage_args.1 manuals/dc.1
954 make clean > /dev/null