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"
49 printf ' %s -h\n' "$script"
50 printf ' %s --help\n' "$script"
51 printf ' %s [-a|-bD|-dB|-c] [-EfgGHlMNPT] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\n' "$script"
52 printf ' %s \\\n' "$script"
53 printf ' [--library|--bc-only --disable-dc|--dc-only --disable-bc|--coverage]\\\n'
54 printf ' [--force --debug --disable-extra-math --disable-generated-tests] \\\n'
55 printf ' [--disable-history --disable-man-pages --disable-nls] \\\n'
56 printf ' [--disable-prompt --disable-strip] [--install-all-locales] \\\n'
57 printf ' [--opt=OPT_LEVEL] [--karatsuba-len=KARATSUBA_LEN] \\\n'
58 printf ' [--prefix=PREFIX] [--bindir=BINDIR] [--datarootdir=DATAROOTDIR] \\\n'
59 printf ' [--datadir=DATADIR] [--mandir=MANDIR] [--man1dir=MAN1DIR] \\\n'
61 printf ' -a, --library\n'
62 printf ' Build the libbc instead of the programs. This is meant to be used with\n'
63 printf ' Other software like programming languages that want to make use of the\n'
64 printf ' parsing and math capabilities. This option will install headers using\n'
65 printf ' `make install`.\n'
66 printf ' -b, --bc-only\n'
67 printf ' Build bc only. It is an error if "-d", "--dc-only", "-B", or\n'
68 printf ' "--disable-bc" are specified too.\n'
69 printf ' -B, --disable-bc\n'
70 printf ' Disable bc. It is an error if "-b", "--bc-only", "-D", or "--disable-dc"\n'
71 printf ' are specified too.\n'
72 printf ' -c, --coverage\n'
73 printf ' Generate test coverage code. Requires gcov and regcovr.\n'
74 printf ' It is an error if either "-b" ("-D") or "-d" ("-B") is specified.\n'
75 printf ' Requires a compiler that use gcc-compatible coverage options\n'
76 printf ' -d, --dc-only\n'
77 printf ' Build dc only. It is an error if "-b", "--bc-only", "-D", or\n'
78 printf ' "--disable-dc" are specified too.\n'
79 printf ' -D, --disable-dc\n'
80 printf ' Disable dc. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"\n'
81 printf ' are specified too.\n'
82 printf ' -E, --disable-extra-math\n'
83 printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n'
84 printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n'
85 printf ' function). Additionally, this option disables the extra printing\n'
86 printf ' functions in the math library.\n'
87 printf ' -f, --force\n'
88 printf ' Force use of all enabled options, even if they do not work. This\n'
89 printf ' option is to allow the maintainer a way to test that certain options\n'
90 printf ' are not failing invisibly. (Development only.)'
91 printf ' -g, --debug\n'
92 printf ' Build in debug mode. Adds the "-g" flag, and if there are no\n'
93 printf ' other CFLAGS, and "-O" was not given, this also adds the "-O0"\n'
94 printf ' flag. If this flag is *not* given, "-DNDEBUG" is added to CPPFLAGS\n'
95 printf ' and a strip flag is added to the link stage.\n'
96 printf ' -G, --disable-generated-tests\n'
97 printf ' Disable generating tests. This is for platforms that do not have a\n'
98 printf ' GNU bc-compatible bc to generate tests.\n'
99 printf ' -h, --help\n'
100 printf ' Print this help message and exit.\n'
101 printf ' -H, --disable-history\n'
102 printf ' Disable history.\n'
103 printf ' -k KARATSUBA_LEN, --karatsuba-len KARATSUBA_LEN\n'
104 printf ' Set the karatsuba length to KARATSUBA_LEN (default is 64).\n'
105 printf ' It is an error if KARATSUBA_LEN is not a number or is less than 16.\n'
106 printf ' -l, --install-all-locales\n'
107 printf ' Installs all locales, regardless of how many are on the system. This\n'
108 printf ' option is useful for package maintainers who want to make sure that\n'
109 printf ' a package contains all of the locales that end users might need.\n'
110 printf ' -M, --disable-man-pages\n'
111 printf ' Disable installing manpages.\n'
112 printf ' -N, --disable-nls\n'
113 printf ' Disable POSIX locale (NLS) support.\n'
114 printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n'
115 printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
116 printf ' but it is provided, so maintainers can build optimized debug builds.\n'
117 printf ' This is passed through to the compiler, so it must be supported.\n'
118 printf ' -P, --disable-prompt\n'
119 printf ' Disables the prompt in the built bc. The prompt will never show up,\n'
120 printf ' or in other words, it will be permanently disabled and cannot be\n'
122 printf ' -T, --disable-strip\n'
123 printf ' Disable stripping symbols from the compiled binary or binaries.\n'
124 printf ' Stripping symbols only happens when debug mode is off.\n'
125 printf ' --prefix PREFIX\n'
126 printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n'
127 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
128 printf ' Default is "/usr/local".\n'
129 printf ' --bindir BINDIR\n'
130 printf ' The directory to install binaries in. Overrides "$BINDIR" if it exists.\n'
131 printf ' Default is "$PREFIX/bin".\n'
132 printf ' --includedir INCLUDEDIR\n'
133 printf ' The directory to install headers in. Overrides "$INCLUDEDIR" if it\n'
134 printf ' exists. Default is "$PREFIX/include".\n'
135 printf ' --libdir LIBDIR\n'
136 printf ' The directory to install libraries in. Overrides "$LIBDIR" if it exists.\n'
137 printf ' Default is "$PREFIX/lib".\n'
138 printf ' --datarootdir DATAROOTDIR\n'
139 printf ' The root location for data files. Overrides "$DATAROOTDIR" if it exists.\n'
140 printf ' Default is "$PREFIX/share".\n'
141 printf ' --datadir DATADIR\n'
142 printf ' The location for data files. Overrides "$DATADIR" if it exists.\n'
143 printf ' Default is "$DATAROOTDIR".\n'
144 printf ' --mandir MANDIR\n'
145 printf ' The location to install manpages to. Overrides "$MANDIR" if it exists.\n'
146 printf ' Default is "$DATADIR/man".\n'
147 printf ' --man1dir MAN1DIR\n'
148 printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n'
149 printf ' it exists. Default is "$MANDIR/man1".\n'
150 printf ' --man3dir MAN3DIR\n'
151 printf ' The location to install Section 3 manpages to. Overrides "$MAN3DIR" if\n'
152 printf ' it exists. Default is "$MANDIR/man3".\n'
154 printf 'In addition, the following environment variables are used:\n'
156 printf ' CC C compiler. Must be compatible with POSIX c99. If there is a\n'
157 printf ' space in the basename of the compiler, the items after the\n'
158 printf ' first space are assumed to be compiler flags, and in that case,\n'
159 printf ' the flags are automatically moved into CFLAGS. Default is\n'
161 printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99. If there is\n'
162 printf ' a space in the basename of the compiler, the items after the\n'
163 printf ' first space are assumed to be compiler flags, and in the case,\n'
164 printf ' the flags are automatically moved into HOSTCFLAGS. Default is\n'
166 printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n'
167 printf ' CFLAGS C compiler flags.\n'
168 printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n'
169 printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n'
170 printf ' CPPFLAGS C preprocessor flags. Default is "".\n'
171 printf ' LDFLAGS Linker flags. Default is "".\n'
172 printf ' PREFIX The prefix to install to. Default is "/usr/local".\n'
173 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
174 printf ' BINDIR The directory to install binaries in. Default is "$PREFIX/bin".\n'
175 printf ' INCLUDEDIR The directory to install header files in. Default is\n'
176 printf ' "$PREFIX/include".\n'
177 printf ' LIBDIR The directory to install libraries in. Default is\n'
178 printf ' "$PREFIX/lib".\n'
179 printf ' DATAROOTDIR The root location for data files. Default is "$PREFIX/share".\n'
180 printf ' DATADIR The location for data files. Default is "$DATAROOTDIR".\n'
181 printf ' MANDIR The location to install manpages to. Default is "$DATADIR/man".\n'
182 printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n'
183 printf ' "$MANDIR/man1".\n'
184 printf ' MAN3DIR The location to install Section 3 manpages to. Default is\n'
185 printf ' "$MANDIR/man3".\n'
186 printf ' NLSPATH The location to install locale catalogs to. Must be an absolute\n'
187 printf ' path (or contain one). This is treated the same as the POSIX\n'
188 printf ' definition of $NLSPATH (see POSIX environment variables for\n'
189 printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n'
190 printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n'
191 printf ' interfere with other installed bc executables. Default is "".\n'
192 printf ' EXECPREFIX The prefix to append to the executable names, used to not\n'
193 printf ' interfere with other installed bc executables. Default is "".\n'
194 printf ' DESTDIR For package creation. Default is "". If it is empty when\n'
195 printf ' `%s` is run, it can also be passed to `make install`\n' "$script"
196 printf ' later as an environment variable. If both are specified,\n'
197 printf ' the one given to `%s` takes precedence.\n' "$script"
198 printf ' LONG_BIT The number of bits in a C `long` type. This is mostly for the\n'
199 printf ' embedded space since this `bc` uses `long`s internally for\n'
200 printf ' overflow checking. In C99, a `long` is required to be 32 bits.\n'
201 printf ' For most normal desktop systems, setting this is unnecessary,\n'
202 printf ' except that 32-bit platforms with 64-bit longs may want to set\n'
203 printf ' it to `32`. Default is the default of `LONG_BIT` for the target\n'
204 printf ' platform. Minimum allowed is `32`. It is a build time error if\n'
205 printf ' the specified value of `LONG_BIT` is greater than the default\n'
206 printf ' value of `LONG_BIT` for the target platform.\n'
207 printf ' GEN_HOST Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to\n'
208 printf ' produce the C files that contain the help texts as well as the\n'
209 printf ' math libraries. By default, `gen/strgen.c` is used, compiled by\n'
210 printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
211 printf ' removes the need to compile and run an executable on the host\n'
212 printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
213 printf ' `gen/lib2.bc` is perilously close to 4095 characters, the max\n'
214 printf ' supported length of a string literal in C99 (and it could be\n'
215 printf ' added to in the future), and `gen/strgen.sh` generates a string\n'
216 printf ' literal instead of an array, as `gen/strgen.c` does. For most\n'
217 printf ' production-ready compilers, this limit probably is not\n'
218 printf ' enforced, but it could be. Both options are still available for\n'
219 printf ' this reason. If you are sure your compiler does not have the\n'
220 printf ' limit and do not want to compile and run a binary on the host\n'
221 printf ' machine, set this variable to "0". Any other value, or a\n'
222 printf ' non-existent value, will cause the build system to compile and\n'
223 printf ' run `gen/strgen.c`. Default is "".\n'
224 printf ' GEN_EMU Emulator to run string generator code under (leave empty if not\n'
225 printf ' necessary). This is not necessary when using `gen/strgen.sh`.\n'
226 printf ' Default is "".\n'
228 printf 'WARNING: even though `configure.sh` supports both option types, short and\n'
229 printf 'long, it does not support handling both at the same time. Use only one type.\n'
236 if [ "$#" -ne 3 ]; then
237 err_exit "Invalid number of args to $0"
240 _replace_ext_file="$1"
241 _replace_ext_ext1="$2"
242 _replace_ext_ext2="$3"
244 _replace_ext_result=${_replace_ext_file%.$_replace_ext_ext1}.$_replace_ext_ext2
246 printf '%s\n' "$_replace_ext_result"
251 if [ "$#" -ne 3 ]; then
252 err_exit "Invalid number of args to $0"
255 _replace_exts_files="$1"
256 _replace_exts_ext1="$2"
257 _replace_exts_ext2="$3"
259 for _replace_exts_file in $_replace_exts_files; do
260 _replace_exts_new_name=$(replace_ext "$_replace_exts_file" "$_replace_exts_ext1" "$_replace_exts_ext2")
261 _replace_exts_result="$_replace_exts_result $_replace_exts_new_name"
264 printf '%s\n' "$_replace_exts_result"
269 if [ "$#" -ne 3 ]; then
270 err_exit "Invalid number of args to $0"
275 _replace_replacement="$3"
277 substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement"
282 if [ "$#" -lt 1 ]; then
283 err_exit "Invalid number of args to $0"
286 _gen_file_list_contents="$1"
293 if [ "$#" -ge 1 ]; then
295 while [ "$#" -ge 1 ]; do
298 args="$args ! -wholename src/${a}"
305 _gen_file_list_needle_src="SRC"
306 _gen_file_list_needle_obj="OBJ"
307 _gen_file_list_needle_gcda="GCDA"
308 _gen_file_list_needle_gcno="GCNO"
310 _gen_file_list_replacement=$(find src/ -depth -name "*.c" $args | tr '\n' ' ')
311 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
312 "$_gen_file_list_needle_src" "$_gen_file_list_replacement")
314 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "c" "o")
315 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
316 "$_gen_file_list_needle_obj" "$_gen_file_list_replacement")
318 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "o" "gcda")
319 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
320 "$_gen_file_list_needle_gcda" "$_gen_file_list_replacement")
322 _gen_file_list_replacement=$(replace_exts "$_gen_file_list_replacement" "gcda" "gcno")
323 _gen_file_list_contents=$(replace "$_gen_file_list_contents" \
324 "$_gen_file_list_needle_gcno" "$_gen_file_list_replacement")
328 printf '%s\n' "$_gen_file_list_contents"
348 while getopts "abBcdDEfgGhHk:lMNO:PST-" opt; do
360 G) generate_tests=0 ;;
363 k) karatsuba_len="$OPTARG" ;;
365 M) install_manpages=0 ;;
367 O) optimization="$OPTARG" ;;
373 LONG_OPTARG="${arg#*=}"
376 library) library=1 ;;
377 bc-only) bc_only=1 ;;
378 dc-only) dc_only=1 ;;
379 coverage) coverage=1 ;;
382 prefix=?*) PREFIX="$LONG_OPTARG" ;;
384 if [ "$#" -lt 2 ]; then
385 usage "No argument given for '--$arg' option"
389 bindir=?*) BINDIR="$LONG_OPTARG" ;;
391 if [ "$#" -lt 2 ]; then
392 usage "No argument given for '--$arg' option"
396 includedir=?*) INCLUDEDIR="$LONG_OPTARG" ;;
398 if [ "$#" -lt 2 ]; then
399 usage "No argument given for '--$arg' option"
403 libdir=?*) LIBDIR="$LONG_OPTARG" ;;
405 if [ "$#" -lt 2 ]; then
406 usage "No argument given for '--$arg' option"
410 datarootdir=?*) DATAROOTDIR="$LONG_OPTARG" ;;
412 if [ "$#" -lt 2 ]; then
413 usage "No argument given for '--$arg' option"
417 datadir=?*) DATADIR="$LONG_OPTARG" ;;
419 if [ "$#" -lt 2 ]; then
420 usage "No argument given for '--$arg' option"
424 mandir=?*) MANDIR="$LONG_OPTARG" ;;
426 if [ "$#" -lt 2 ]; then
427 usage "No argument given for '--$arg' option"
431 man1dir=?*) MAN1DIR="$LONG_OPTARG" ;;
433 if [ "$#" -lt 2 ]; then
434 usage "No argument given for '--$arg' option"
438 man3dir=?*) MAN3DIR="$LONG_OPTARG" ;;
440 if [ "$#" -lt 2 ]; then
441 usage "No argument given for '--$arg' option"
445 localedir=?*) LOCALEDIR="$LONG_OPTARG" ;;
447 if [ "$#" -lt 2 ]; then
448 usage "No argument given for '--$arg' option"
452 karatsuba-len=?*) karatsuba_len="$LONG_OPTARG" ;;
454 if [ "$#" -lt 2 ]; then
455 usage "No argument given for '--$arg' option"
459 opt=?*) optimization="$LONG_OPTARG" ;;
461 if [ "$#" -lt 2 ]; then
462 usage "No argument given for '--$arg' option"
466 disable-bc) dc_only=1 ;;
467 disable-dc) bc_only=1 ;;
468 disable-extra-math) extra_math=0 ;;
469 disable-generated-tests) generate_tests=0 ;;
470 disable-history) hist=0 ;;
471 disable-man-pages) install_manpages=0 ;;
472 disable-nls) nls=0 ;;
473 disable-prompt) prompt=0 ;;
474 disable-strip) strip_bin=0 ;;
475 install-all-locales) all_locales=1 ;;
476 help* | bc-only* | dc-only* | coverage* | debug*)
477 usage "No arg allowed for --$arg option" ;;
478 disable-bc* | disable-dc* | disable-extra-math*)
479 usage "No arg allowed for --$arg option" ;;
480 disable-generated-tests* | disable-history*)
481 usage "No arg allowed for --$arg option" ;;
482 disable-man-pages* | disable-nls* | disable-strip*)
483 usage "No arg allowed for --$arg option" ;;
484 install-all-locales*)
485 usage "No arg allowed for --$arg option" ;;
486 '') break ;; # "--" terminates argument processing
487 * ) usage "Invalid option $LONG_OPTARG" ;;
491 ?) usage "Invalid option $opt" ;;
496 if [ "$bc_only" -eq 1 ] && [ "$dc_only" -eq 1 ]; then
497 usage "Can only specify one of -b(-D) or -d(-B)"
500 if [ "$library" -ne 0 ]; then
501 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
502 usage "Must not specify -b(-D) or -d(-B) when building the library"
506 case $karatsuba_len in
507 (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;;
511 if [ "$karatsuba_len" -lt 16 ]; then
512 usage "KARATSUBA_LEN is less than 16"
517 if [ -z "${LONG_BIT+set}" ]; then
519 elif [ "$LONG_BIT" -lt 32 ]; then
520 usage "LONG_BIT is less than 32"
522 LONG_BIT_DEFINE="-DBC_LONG_BIT=\$(BC_LONG_BIT)"
525 if [ -z "$CC" ]; then
528 ccbase=$(basename "$CC")
532 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
533 ccflags="${ccbase#$prefix}"
534 cc="${ccbase%%$suffix}"
535 ccdir=$(dirname "$CC")
536 if [ "$ccdir" = "." ] && [ "${CC#.}" = "$CC" ]; then
542 CFLAGS="$CFLAGS $ccflags"
546 if [ -z "$HOSTCC" ] && [ -z "$HOST_CC" ]; then
548 elif [ -z "$HOSTCC" ]; then
552 if [ "$HOSTCC" != "$CC" ]; then
553 ccbase=$(basename "$HOSTCC")
557 if [ "${ccbase%%$suffix}" != "$ccbase" ]; then
558 ccflags="${ccbase#$prefix}"
559 cc="${ccbase%%$suffix}"
560 ccdir=$(dirname "$HOSTCC")
561 if [ "$ccdir" = "." ] && [ "${HOSTCC#.}" = "$HOSTCC" ]; then
566 HOSTCC="${ccdir}${cc}"
567 HOSTCFLAGS="$HOSTCFLAGS $ccflags"
571 if [ -z "${HOSTCFLAGS+set}" ] && [ -z "${HOST_CFLAGS+set}" ]; then
573 elif [ -z "${HOSTCFLAGS+set}" ]; then
574 HOSTCFLAGS="$HOST_CFLAGS"
577 link="@printf 'No link necessary\\\\n'"
581 tests="test_bc timeconst test_dc"
583 bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 \$(BC_EXEC)"
584 bc_time_test="@tests/all.sh bc $extra_math 1 $generate_tests 1 \$(BC_EXEC)"
586 dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 \$(DC_EXEC)"
587 dc_time_test="@tests/all.sh dc $extra_math 1 $generate_tests 1 \$(DC_EXEC)"
589 timeconst="@tests/bc/timeconst.sh tests/bc/scripts/timeconst.bc \$(BC_EXEC)"
591 # In order to have cleanup at exit, we need to be in
592 # debug mode, so don't run valgrind without that.
593 if [ "$debug" -ne 0 ]; then
594 vg_bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(BC_EXEC)"
595 vg_dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(DC_EXEC)"
597 vg_bc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
598 vg_dc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
601 karatsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
602 karatsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
604 bc_lib="\$(GEN_DIR)/lib.o"
605 bc_help="\$(GEN_DIR)/bc_help.o"
606 dc_help="\$(GEN_DIR)/dc_help.o"
608 if [ "$bc_only" -eq 1 ]; then
617 dc_test="@printf 'No dc tests to run\\\\n'"
618 dc_time_test="@printf 'No dc tests to run\\\\n'"
619 vg_dc_test="@printf 'No dc tests to run\\\\n'"
621 install_prereqs=" install_execs"
622 install_man_prereqs=" install_bc_manpage"
623 uninstall_prereqs=" uninstall_bc"
624 uninstall_man_prereqs=" uninstall_bc_manpage"
626 elif [ "$dc_only" -eq 1 ]; then
639 bc_test="@printf 'No bc tests to run\\\\n'"
640 bc_time_test="@printf 'No bc tests to run\\\\n'"
641 vg_bc_test="@printf 'No bc tests to run\\\\n'"
643 timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'"
645 install_prereqs=" install_execs"
646 install_man_prereqs=" install_dc_manpage"
647 uninstall_prereqs=" uninstall_dc"
648 uninstall_man_prereqs=" uninstall_dc_manpage"
655 executables="bc and dc"
657 link="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)"
659 karatsuba="@\$(KARATSUBA) 30 0 \$(BC_EXEC)"
660 karatsuba_test="@\$(KARATSUBA) 1 100 \$(BC_EXEC)"
662 if [ "$library" -eq 0 ]; then
663 install_prereqs=" install_execs"
664 install_man_prereqs=" install_bc_manpage install_dc_manpage"
665 uninstall_prereqs=" uninstall_bc uninstall_dc"
666 uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage"
668 install_prereqs=" install_library install_bcl_header"
669 install_man_prereqs=" install_bcl_manpage"
670 uninstall_prereqs=" uninstall_library uninstall_bcl_header"
671 uninstall_man_prereqs=" uninstall_bcl_manpage"
677 if [ "$debug" -eq 1 ]; then
679 if [ -z "$CFLAGS" ] && [ -z "$optimization" ]; then
686 CPPFLAGS="-DNDEBUG $CPPFLAGS"
687 if [ "$strip_bin" -ne 0 ]; then
688 LDFLAGS="-s $LDFLAGS"
692 if [ -n "$optimization" ]; then
693 CFLAGS="-O$optimization $CFLAGS"
696 if [ "$coverage" -eq 1 ]; then
698 if [ "$bc_only" -eq 1 ] || [ "$dc_only" -eq 1 ]; then
699 usage "Can only specify -c without -b or -d"
702 CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS"
703 CPPFLAGS="-DNDEBUG $CPPFLAGS"
705 COVERAGE_OUTPUT="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA) \$(HISTORY_GCDA) \$(RAND_GCDA)"
706 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;\$(RM) -f \$(GEN)*.gc*"
707 COVERAGE_OUTPUT="$COVERAGE_OUTPUT;gcovr --html-details --output index.html"
708 COVERAGE_PREREQS=" test coverage_output"
711 COVERAGE_OUTPUT="@printf 'Coverage not generated\\\\n'"
715 if [ -z "${DESTDIR+set}" ]; then
718 destdir="DESTDIR = $DESTDIR"
721 if [ -z "${PREFIX+set}" ]; then
725 if [ -z "${BINDIR+set}" ]; then
729 if [ -z "${INCLUDEDIR+set}" ]; then
730 INCLUDEDIR="$PREFIX/include"
733 if [ -z "${LIBDIR+set}" ]; then
737 if [ "$install_manpages" -ne 0 ] || [ "$nls" -ne 0 ]; then
738 if [ -z "${DATAROOTDIR+set}" ]; then
739 DATAROOTDIR="$PREFIX/share"
743 if [ "$install_manpages" -ne 0 ]; then
745 if [ -z "${DATADIR+set}" ]; then
746 DATADIR="$DATAROOTDIR"
749 if [ -z "${MANDIR+set}" ]; then
750 MANDIR="$DATADIR/man"
753 if [ -z "${MAN1DIR+set}" ]; then
754 MAN1DIR="$MANDIR/man1"
757 if [ -z "${MAN3DIR+set}" ]; then
758 MAN3DIR="$MANDIR/man3"
762 install_man_prereqs=""
763 uninstall_man_prereqs=""
766 if [ "$library" -ne 0 ]; then
776 if [ "$nls" -ne 0 ]; then
780 printf 'Testing NLS...\n'
782 flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
783 flags="$flags -DBC_ENABLE_HISTORY=$hist"
784 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
785 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
787 "$CC" $CPPFLAGS $CFLAGS $flags -c "src/vm.c" -o "$scriptdir/vm.o" > /dev/null 2>&1
791 rm -rf "$scriptdir/vm.o"
793 # If this errors, it is probably because of building on Windows,
794 # and NLS is not supported on Windows, so disable it.
795 if [ "$err" -ne 0 ]; then
796 printf 'NLS does not work.\n'
797 if [ $force -eq 0 ]; then
798 printf 'Disabling NLS...\n\n'
801 printf 'Forcing NLS...\n\n'
804 printf 'NLS works.\n\n'
806 printf 'Testing gencat...\n'
807 gencat "$scriptdir/en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
811 rm -rf "$scriptdir/en_US.cat"
813 if [ "$err" -ne 0 ]; then
814 printf 'gencat does not work.\n'
815 if [ $force -eq 0 ]; then
816 printf 'Disabling NLS...\n\n'
819 printf 'Forcing NLS...\n\n'
823 printf 'gencat works.\n\n'
825 if [ "$HOSTCC" != "$CC" ]; then
826 printf 'Cross-compile detected.\n\n'
827 printf 'WARNING: Catalog files generated with gencat may not be portable\n'
828 printf ' across different architectures.\n\n'
831 if [ -z "$NLSPATH" ]; then
832 NLSPATH="/usr/share/locale/%L/%N"
835 install_locales_prereqs=" install_locales"
836 uninstall_locales_prereqs=" uninstall_locales"
845 install_locales_prereqs=""
846 uninstall_locales_prereqs=""
850 if [ "$nls" -ne 0 ] && [ "$all_locales" -ne 0 ]; then
851 install_locales="\$(LOCALE_INSTALL) -l \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
853 install_locales="\$(LOCALE_INSTALL) \$(NLSPATH) \$(MAIN_EXEC) \$(DESTDIR)"
856 if [ "$hist" -eq 1 ]; then
860 printf 'Testing history...\n'
862 flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
863 flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0"
864 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
865 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
867 "$CC" $CPPFLAGS $CFLAGS $flags -c "src/history.c" -o "$scriptdir/history.o" > /dev/null 2>&1
871 rm -rf "$scriptdir/history.o"
873 # If this errors, it is probably because of building on Windows,
874 # and history is not supported on Windows, so disable it.
875 if [ "$err" -ne 0 ]; then
876 printf 'History does not work.\n'
877 if [ $force -eq 0 ]; then
878 printf 'Disabling history...\n\n'
881 printf 'Forcing history...\n\n'
884 printf 'History works.\n\n'
891 if [ "$library" -eq 1 ]; then
895 if [ "$extra_math" -eq 1 ] && [ "$bc" -ne 0 ] && [ "$library" -eq 0 ]; then
896 BC_LIB2_O="\$(GEN_DIR)/lib2.o"
902 GEN_EXEC_TARGET="\$(HOSTCC) \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
903 CLEAN_PREREQS=" clean_gen"
905 if [ -z "${GEN_HOST+set}" ]; then
908 if [ "$GEN_HOST" -eq 0 ]; then
910 GEN_EXEC_TARGET="@printf 'Do not need to build gen/strgen.c\\\\n'"
917 if [ "$extra_math" -eq 0 ]; then
921 if [ "$hist" -eq 0 ]; then
922 manpage_args="${manpage_args}H"
925 if [ "$nls" -eq 0 ]; then
926 manpage_args="${manpage_args}N"
929 if [ "$prompt" -eq 0 ]; then
930 manpage_args="${manpage_args}P"
933 if [ "$manpage_args" = "" ]; then
939 if [ "$hist" -eq 0 ]; then
940 unneeded="$unneeded history.c"
943 if [ "$bc" -eq 0 ]; then
944 unneeded="$unneeded bc.c bc_lex.c bc_parse.c"
947 if [ "$dc" -eq 0 ]; then
948 unneeded="$unneeded dc.c dc_lex.c dc_parse.c"
951 if [ "$extra_math" -eq 0 ]; then
952 unneeded="$unneeded rand.c"
955 if [ "$library" -ne 0 ]; then
956 unneeded="$unneeded args.c opt.c read.c file.c main.c"
957 unneeded="$unneeded lang.c lex.c parse.c program.c"
958 unneeded="$unneeded bc.c bc_lex.c bc_parse.c"
959 unneeded="$unneeded dc.c dc_lex.c dc_parse.c"
961 unneeded="$unneeded library.c"
964 # Print out the values; this is for debugging.
965 if [ "$bc" -ne 0 ]; then
966 printf 'Building bc\n'
968 printf 'Not building bc\n'
970 if [ "$dc" -ne 0 ]; then
971 printf 'Building dc\n'
973 printf 'Not building dc\n'
976 printf 'BC_ENABLE_LIBRARY=%s\n\n' "$library"
977 printf 'BC_ENABLE_HISTORY=%s\n' "$hist"
978 printf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math"
979 printf 'BC_ENABLE_NLS=%s\n' "$nls"
980 printf 'BC_ENABLE_PROMPT=%s\n' "$prompt"
982 printf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len"
984 printf 'CC=%s\n' "$CC"
985 printf 'CFLAGS=%s\n' "$CFLAGS"
986 printf 'HOSTCC=%s\n' "$HOSTCC"
987 printf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS"
988 printf 'CPPFLAGS=%s\n' "$CPPFLAGS"
989 printf 'LDFLAGS=%s\n' "$LDFLAGS"
990 printf 'PREFIX=%s\n' "$PREFIX"
991 printf 'BINDIR=%s\n' "$BINDIR"
992 printf 'INCLUDEDIR=%s\n' "$INCLUDEDIR"
993 printf 'LIBDIR=%s\n' "$LIBDIR"
994 printf 'DATAROOTDIR=%s\n' "$DATAROOTDIR"
995 printf 'DATADIR=%s\n' "$DATADIR"
996 printf 'MANDIR=%s\n' "$MANDIR"
997 printf 'MAN1DIR=%s\n' "$MAN1DIR"
998 printf 'MAN3DIR=%s\n' "$MAN3DIR"
999 printf 'NLSPATH=%s\n' "$NLSPATH"
1000 printf 'EXECSUFFIX=%s\n' "$EXECSUFFIX"
1001 printf 'EXECPREFIX=%s\n' "$EXECPREFIX"
1002 printf 'DESTDIR=%s\n' "$DESTDIR"
1003 printf 'LONG_BIT=%s\n' "$LONG_BIT"
1004 printf 'GEN_HOST=%s\n' "$GEN_HOST"
1005 printf 'GEN_EMU=%s\n' "$GEN_EMU"
1007 contents=$(cat "$scriptdir/Makefile.in")
1010 replacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***'
1012 contents=$(replace "$contents" "$needle" "$replacement")
1014 if [ "$unneeded" = "" ]; then
1015 contents=$(gen_file_list "$contents" "library.c")
1017 contents=$(gen_file_list "$contents" $unneeded)
1020 contents=$(replace "$contents" "BC_ENABLED" "$bc")
1021 contents=$(replace "$contents" "DC_ENABLED" "$dc")
1022 contents=$(replace "$contents" "LINK" "$link")
1024 contents=$(replace "$contents" "LIBRARY" "$library")
1025 contents=$(replace "$contents" "HISTORY" "$hist")
1026 contents=$(replace "$contents" "EXTRA_MATH" "$extra_math")
1027 contents=$(replace "$contents" "NLS" "$nls")
1028 contents=$(replace "$contents" "PROMPT" "$prompt")
1029 contents=$(replace "$contents" "BC_LIB_O" "$bc_lib")
1030 contents=$(replace "$contents" "BC_HELP_O" "$bc_help")
1031 contents=$(replace "$contents" "DC_HELP_O" "$dc_help")
1032 contents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O")
1033 contents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len")
1035 contents=$(replace "$contents" "NLSPATH" "$NLSPATH")
1036 contents=$(replace "$contents" "DESTDIR" "$destdir")
1037 contents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX")
1038 contents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX")
1039 contents=$(replace "$contents" "BINDIR" "$BINDIR")
1040 contents=$(replace "$contents" "INCLUDEDIR" "$INCLUDEDIR")
1041 contents=$(replace "$contents" "LIBDIR" "$LIBDIR")
1042 contents=$(replace "$contents" "MAN1DIR" "$MAN1DIR")
1043 contents=$(replace "$contents" "MAN3DIR" "$MAN3DIR")
1044 contents=$(replace "$contents" "CFLAGS" "$CFLAGS")
1045 contents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS")
1046 contents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS")
1047 contents=$(replace "$contents" "LDFLAGS" "$LDFLAGS")
1048 contents=$(replace "$contents" "CC" "$CC")
1049 contents=$(replace "$contents" "HOSTCC" "$HOSTCC")
1050 contents=$(replace "$contents" "COVERAGE_OUTPUT" "$COVERAGE_OUTPUT")
1051 contents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS")
1052 contents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs")
1053 contents=$(replace "$contents" "INSTALL_MAN_PREREQS" "$install_man_prereqs")
1054 contents=$(replace "$contents" "INSTALL_LOCALES" "$install_locales")
1055 contents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs")
1056 contents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs")
1057 contents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs")
1058 contents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs")
1060 contents=$(replace "$contents" "ALL_PREREQ" "$ALL_PREREQ")
1062 contents=$(replace "$contents" "EXECUTABLES" "$executables")
1063 contents=$(replace "$contents" "MAIN_EXEC" "$main_exec")
1064 contents=$(replace "$contents" "EXEC" "$executable")
1065 contents=$(replace "$contents" "TESTS" "$tests")
1067 contents=$(replace "$contents" "BC_TEST" "$bc_test")
1068 contents=$(replace "$contents" "BC_TIME_TEST" "$bc_time_test")
1070 contents=$(replace "$contents" "DC_TEST" "$dc_test")
1071 contents=$(replace "$contents" "DC_TIME_TEST" "$dc_time_test")
1073 contents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test")
1074 contents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test")
1076 contents=$(replace "$contents" "TIMECONST" "$timeconst")
1078 contents=$(replace "$contents" "KARATSUBA" "$karatsuba")
1079 contents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test")
1081 contents=$(replace "$contents" "LONG_BIT" "$LONG_BIT")
1082 contents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE")
1084 contents=$(replace "$contents" "GEN" "$GEN")
1085 contents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET")
1086 contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS")
1087 contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU")
1089 printf '%s\n' "$contents" > "$scriptdir/Makefile"
1093 cp -f manuals/bc/$manpage_args.1.md manuals/bc.1.md
1094 cp -f manuals/bc/$manpage_args.1 manuals/bc.1
1095 cp -f manuals/dc/$manpage_args.1.md manuals/dc.1.md
1096 cp -f manuals/dc/$manpage_args.1 manuals/dc.1
1098 make clean > /dev/null