blob: 46e37bfc252748bf5f7de70eae354f5bde0b9d25 [file] [log] [blame]
Gavin Howard27fa9cd2018-12-12 02:52:52 -07001#! /bin/sh
2#
Gavin Howard7345cb92019-04-08 14:13:43 -06003# Copyright (c) 2018-2019 Gavin D. Howard and contributors.
Gavin Howard27fa9cd2018-12-12 02:52:52 -07004#
Gavin Howard7345cb92019-04-08 14:13:43 -06005# All rights reserved.
Gavin Howard27fa9cd2018-12-12 02:52:52 -07006#
Gavin Howard7345cb92019-04-08 14:13:43 -06007# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9#
10# * Redistributions of source code must retain the above copyright notice, this
11# list of conditions and the following disclaimer.
12#
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.
16#
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.
Gavin Howard27fa9cd2018-12-12 02:52:52 -070028#
29
Gavin Howard2425bf22019-04-08 17:05:45 -060030script="$0"
31scriptdir=$(dirname "$script")
32script=$(basename "$script")
33
34. "$scriptdir/functions.sh"
35
Gavin Howard27fa9cd2018-12-12 02:52:52 -070036usage() {
Gavin Howard629b5c02018-12-12 03:21:01 -070037
38 if [ $# -gt 0 ]; then
39
Gavin Howard65c0bbc2019-10-11 22:17:22 -060040 _usage_val=1
Gavin Howard629b5c02018-12-12 03:21:01 -070041
Gavin Howardd15e01d2018-12-19 12:49:02 -070042 printf "%s\n\n" "$1"
Gavin Howard629b5c02018-12-12 03:21:01 -070043
44 else
Gavin Howard65c0bbc2019-10-11 22:17:22 -060045 _usage_val=0
Gavin Howard629b5c02018-12-12 03:21:01 -070046 fi
47
Gavin Howard9a679742019-04-06 09:44:57 -060048 printf 'usage: %s -h\n' "$script"
49 printf ' %s --help\n' "$script"
Gavin Howard96ac4272019-11-27 22:16:26 -070050 printf ' %s [-bD|-dB|-c] [-EfgGHMNPST] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\n' "$script"
Gavin Howard9a679742019-04-06 09:44:57 -060051 printf ' %s \\\n' "$script"
Gavin Howard96ac4272019-11-27 22:16:26 -070052 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-signal-handling --disable-strip] \\\n'
56 printf ' [--opt=OPT_LEVEL] [--karatsuba-len=KARATSUBA_LEN] \\\n'
57 printf ' [--prefix=PREFIX] [--bindir=BINDIR] \\\n'
58 printf ' [--datarootdir=DATAROOTDIR] [--datadir=DATADIR] \\\n'
59 printf ' [--mandir=MANDIR] [--man1dir=MAN1DIR] \\\n'
60 printf ' [--force] \\\n'
Gavin Howardd15e01d2018-12-19 12:49:02 -070061 printf '\n'
Gavin Howard9a679742019-04-06 09:44:57 -060062 printf ' -b, --bc-only\n'
Gavin Howard2f061342018-12-24 14:15:44 -070063 printf ' Build bc only. It is an error if "-d" or "-B" are specified too.\n'
Gavin Howard9a679742019-04-06 09:44:57 -060064 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'
Gavin Howardd15e01d2018-12-19 12:49:02 -070068 printf ' Generate test coverage code. Requires gcov and regcovr.\n'
Gavin Howard995d0612018-12-25 11:37:52 -070069 printf ' It is an error if either "-b" ("-D") or "-d" ("-B") is specified.\n'
Gavin Howardd366bb12018-12-19 14:05:13 -070070 printf ' Requires a compiler that use gcc-compatible coverage options\n'
Gavin Howard9a679742019-04-06 09:44:57 -060071 printf ' -d, --dc-only\n'
Gavin Howardd15e01d2018-12-19 12:49:02 -070072 printf ' Build dc only. It is an error if "-b" is specified too.\n'
Gavin Howard9a679742019-04-06 09:44:57 -060073 printf ' -D, --disable-dc\n'
74 printf ' Disable dc. It is an error if "-d", "--dc-only" "-B", or "--disable-bc"\n'
75 printf ' are specified too.\n'
76 printf ' -E, --disable-extra-math\n'
Gavin Howard6fcb5042018-12-26 17:44:06 -070077 printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n'
Gavin Howard87250702018-12-31 15:49:33 -070078 printf ' "@" operator (set number of decimal places), and r(x, p) (rounding\n'
79 printf ' function). Additionally, this option disables the extra printing\n'
80 printf ' functions in the math library.\n'
Gavin Howarde2d185f2019-08-03 12:13:46 -060081 printf ' -f, --force\n'
82 printf ' Force use of all enabled options, even if they do not work. This\n'
83 printf ' option is to allow the maintainer a way to test that certain options\n'
84 printf ' are not failing invisibly. (Development only.)'
Gavin Howard9a679742019-04-06 09:44:57 -060085 printf ' -g, --debug\n'
Gavin Howardd366bb12018-12-19 14:05:13 -070086 printf ' Build in debug mode. Adds the "-g" flag, and if there are no\n'
Gavin Howard24f942f2018-12-20 10:08:49 -070087 printf ' other CFLAGS, and "-O" was not given, this also adds the "-O0"\n'
Gavin Howarda9468b52018-12-25 16:43:27 -070088 printf ' flag. If this flag is *not* given, "-DNDEBUG" is added to CPPFLAGS\n'
89 printf ' and a strip flag is added to the link stage.\n'
Gavin Howard9a679742019-04-06 09:44:57 -060090 printf ' -G, --disable-generated-tests\n'
Gavin Howard78fa2972019-01-08 10:10:47 -070091 printf ' Disable generating tests. This is for platforms that do not have a\n'
92 printf ' GNU bc-compatible bc to generate tests.\n'
Gavin Howard9a679742019-04-06 09:44:57 -060093 printf ' -h, --help\n'
Gavin Howardd15e01d2018-12-19 12:49:02 -070094 printf ' Print this help message and exit.\n'
Gavin Howard9a679742019-04-06 09:44:57 -060095 printf ' -H, --disable-history\n'
Gavin Howard995d0612018-12-25 11:37:52 -070096 printf ' Disable history.\n'
Gavin Howardab6ba682019-05-10 08:42:15 -060097 printf ' -k KARATSUBA_LEN, --karatsuba-len KARATSUBA_LEN\n'
98 printf ' Set the karatsuba length to KARATSUBA_LEN (default is 64).\n'
99 printf ' It is an error if KARATSUBA_LEN is not a number or is less than 16.\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600100 printf ' -M, --disable-man-pages\n'
Gavin Howarded9b6c22019-01-23 12:02:43 -0700101 printf ' Disable installing manpages.\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600102 printf ' -N, --disable-nls\n'
Gavin Howard50080252019-02-20 15:27:43 -0700103 printf ' Disable POSIX locale (NLS) support.\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600104 printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n'
Gavin Howard24f942f2018-12-20 10:08:49 -0700105 printf ' Set the optimization level. This can also be included in the CFLAGS,\n'
106 printf ' but it is provided, so maintainers can build optimized debug builds.\n'
107 printf ' This is passed through to the compiler, so it must be supported.\n'
Gavin Howard1444c9f2019-06-21 21:16:11 -0600108 printf ' -P, --disable-prompt\n'
Gavin Howardca8f9a42019-06-25 07:01:20 -0600109 printf ' Disables the prompt in the built bc. The prompt will never show up,\n'
110 printf ' or in other words, it will be permanently disabled and cannot be\n'
111 printf ' enabled.\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600112 printf ' -S, --disable-signal-handling\n'
Gavin Howardd15e01d2018-12-19 12:49:02 -0700113 printf ' Disable signal handling. On by default.\n'
Gavin Howard96ac4272019-11-27 22:16:26 -0700114 printf ' -T, --disable-strip\n'
115 printf ' Disable stripping symbols from the compiled binary or binaries.\n'
116 printf ' Stripping symbols only happens when debug mode is off.\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600117 printf ' --prefix PREFIX\n'
118 printf ' The prefix to install to. Overrides "$PREFIX" if it exists.\n'
119 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
120 printf ' Default is "/usr/local".\n'
121 printf ' --bindir BINDIR\n'
Gavin Howard9d47b6f2019-05-09 14:41:41 -0600122 printf ' The directory to install binaries. Overrides "$BINDIR" if it exists.\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600123 printf ' Default is "$PREFIX/bin".\n'
124 printf ' --datarootdir DATAROOTDIR\n'
125 printf ' The root location for data files. Overrides "$DATAROOTDIR" if it exists.\n'
126 printf ' Default is "$PREFIX/share".\n'
127 printf ' --datadir DATADIR\n'
128 printf ' The location for data files. Overrides "$DATADIR" if it exists.\n'
129 printf ' Default is "$DATAROOTDIR".\n'
130 printf ' --mandir MANDIR\n'
131 printf ' The location to install manpages to. Overrides "$MANDIR" if it exists.\n'
132 printf ' Default is "$DATADIR/man".\n'
133 printf ' --man1dir MAN1DIR\n'
Gavin Howard9d47b6f2019-05-09 14:41:41 -0600134 printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n'
135 printf ' it exists. Default is "$MANDIR/man1".\n'
Gavin Howardd15e01d2018-12-19 12:49:02 -0700136 printf '\n'
137 printf 'In addition, the following environment variables are used:\n'
138 printf '\n'
Gavin Howard593a5182019-01-17 10:22:45 -0700139 printf ' CC C compiler. Must be compatible with POSIX c99.\n'
Gavin Howarded910222019-01-17 11:16:18 -0700140 printf ' Default is "c99".\n'
Gavin Howard593a5182019-01-17 10:22:45 -0700141 printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99.\n'
Gavin Howard2469a222019-01-23 15:36:33 -0700142 printf ' Default is "$CC".\n'
Gavin Howard593a5182019-01-17 10:22:45 -0700143 printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n'
144 printf ' CFLAGS C compiler flags.\n'
Gavin Howard471b6c02019-01-17 14:25:07 -0700145 printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n'
Gavin Howard593a5182019-01-17 10:22:45 -0700146 printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n'
Gavin Howard2469a222019-01-23 15:36:33 -0700147 printf ' CPPFLAGS C preprocessor flags. Default is "".\n'
148 printf ' LDFLAGS Linker flags. Default is "".\n'
Gavin Howarded910222019-01-17 11:16:18 -0700149 printf ' PREFIX The prefix to install to. Default is "/usr/local".\n'
150 printf ' If PREFIX is "/usr", install path will be "/usr/bin".\n'
Gavin Howard2469a222019-01-23 15:36:33 -0700151 printf ' BINDIR The directory to install binaries. Default is "$PREFIX/bin".\n'
Gavin Howard32cf7422019-01-17 14:36:35 -0700152 printf ' DATAROOTDIR The root location for data files. Default is "$PREFIX/share".\n'
153 printf ' DATADIR The location for data files. Default is "$DATAROOTDIR".\n'
154 printf ' MANDIR The location to install manpages to. Default is "$DATADIR/man".\n'
Gavin Howard471b6c02019-01-17 14:25:07 -0700155 printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n'
156 printf ' "$MANDIR/man1".\n'
Gavin Howardbc021292019-04-09 10:04:01 -0600157 printf ' NLSPATH The location to install locale catalogs to. Must be an absolute\n'
158 printf ' path (or contain one). This is treated the same as the POSIX\n'
Gavin Howarda5132242019-04-22 08:34:28 -0600159 printf ' definition of $NLSPATH (see POSIX environment variables for\n'
160 printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n'
Gavin Howard5d057152019-01-29 10:31:40 -0700161 printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n'
Gavin Howard36ae6292019-04-01 07:30:27 -0600162 printf ' interfere with other installed bc executables. Default is "".\n'
163 printf ' EXECPREFIX The prefix to append to the executable names, used to not\n'
164 printf ' interfere with other installed bc executables. Default is "".\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600165 printf ' DESTDIR For package creation. Default is "". If it is empty when\n'
Gavin Howarda5132242019-04-22 08:34:28 -0600166 printf ' `%s` is run, it can also be passed to `make install`\n' "$script"
Gavin Howard3dd8ad82019-04-06 23:36:57 -0600167 printf ' later as an environment variable. If both are specified,\n'
Gavin Howarda5132242019-04-22 08:34:28 -0600168 printf ' the one given to `%s` takes precedence.\n' "$script"
Gavin Howard277b5142019-05-10 10:58:57 -0600169 printf ' LONG_BIT The number of bits in a C `long` type. This is mostly for the\n'
170 printf ' embedded space since this `bc` uses `long`s internally for\n'
171 printf ' overflow checking. In C99, a `long` is required to be 32 bits.\n'
Gavin Howard3d59ce72019-05-25 11:19:44 -0600172 printf ' For most normal desktop systems, setting this is unnecessary,\n'
173 printf ' except that 32-bit platforms with 64-bit longs may want to set\n'
174 printf ' it to `32`. Default is the default of `LONG_BIT` for the target\n'
175 printf ' platform. Minimum allowed is `32`. It is a build time error if\n'
176 printf ' the specified value of `LONG_BIT` is greater than the default\n'
177 printf ' value of `LONG_BIT` for the target platform.\n'
Gavin Howarda5132242019-04-22 08:34:28 -0600178 printf ' GEN_HOST Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to\n'
179 printf ' produce the C files that contain the help texts as well as the\n'
180 printf ' math libraries. By default, `gen/strgen.c` is used, compiled by\n'
181 printf ' "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`\n'
182 printf ' removes the need to compile and run an executable on the host\n'
Gavin Howard277b5142019-05-10 10:58:57 -0600183 printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n'
Gavin Howarda5132242019-04-22 08:34:28 -0600184 printf ' `gen/lib2.bc` is perilously close to 4095 characters, the max\n'
185 printf ' supported length of a string literal in C99 (and it could be\n'
186 printf ' added to in the future), and `gen/strgen.sh` generates a string\n'
187 printf ' literal instead of an array, as `gen/strgen.c` does. For most\n'
188 printf ' production-ready compilers, this limit probably is not\n'
189 printf ' enforced, but it could be. Both options are still available for\n'
190 printf ' this reason. If you are sure your compiler does not have the\n'
191 printf ' limit and do not want to compile and run a binary on the host\n'
192 printf ' machine, set this variable to "0". Any other value, or a\n'
193 printf ' non-existent value, will cause the build system to compile and\n'
194 printf ' run `gen/strgen.c`. Default is "".\n'
195 printf ' GEN_EMU Emulator to run string generator code under (leave empty if not\n'
196 printf ' necessary). This is not necessary when using `gen/strgen.sh`.\n'
197 printf ' Default is "".\n'
Gavin Howard3d59ce72019-05-25 11:19:44 -0600198 printf '\n'
199 printf 'WARNING: even though `configure.sh` supports both option types, short and\n'
200 printf 'long, it does not support handling both at the same time. Use only one type.\n'
Gavin Howard954f9b62018-12-19 15:22:20 -0700201
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600202 exit "$_usage_val"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700203}
204
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700205replace_ext() {
206
207 if [ "$#" -ne 3 ]; then
208 err_exit "Invalid number of args to $0"
209 fi
210
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600211 _replace_ext_file="$1"
212 _replace_ext_ext1="$2"
213 _replace_ext_ext2="$3"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700214
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600215 _replace_ext_result=$(printf "$_replace_ext_file" | sed -e "s@\.$_replace_ext_ext1@\.$_replace_ext_ext2@")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700216
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600217 printf '%s\n' "$_replace_ext_result"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700218}
219
220replace_exts() {
221
222 if [ "$#" -ne 3 ]; then
223 err_exit "Invalid number of args to $0"
224 fi
225
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600226 _replace_exts_files="$1"
227 _replace_exts_ext1="$2"
228 _replace_exts_ext2="$3"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700229
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600230 for _replace_exts_file in $_replace_exts_files; do
231 _replace_exts_new_name=$(replace_ext "$_replace_exts_file" "$_replace_exts_ext1" "$_replace_exts_ext2")
232 _replace_exts_result="$_replace_exts_result $_replace_exts_new_name"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700233 done
234
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600235 printf '%s\n' "$_replace_exts_result"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700236}
237
238replace() {
239
240 if [ "$#" -ne 3 ]; then
241 err_exit "Invalid number of args to $0"
242 fi
243
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600244 _replace_str="$1"
245 _replace_needle="$2"
246 _replace_replacement="$3"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700247
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600248 substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700249}
250
251gen_file_lists() {
252
Gavin Howard6a94fd72018-12-20 10:28:42 -0700253 if [ "$#" -lt 3 ]; then
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700254 err_exit "Invalid number of args to $0"
255 fi
256
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600257 _gen_file_lists_contents="$1"
Gavin Howard6a94fd72018-12-20 10:28:42 -0700258 shift
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700259
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600260 _gen_file_lists_filedir="$1"
Gavin Howard6a94fd72018-12-20 10:28:42 -0700261 shift
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700262
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600263 _gen_file_lists_typ="$1"
Gavin Howard6a94fd72018-12-20 10:28:42 -0700264 shift
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700265
Gavin Howard6a94fd72018-12-20 10:28:42 -0700266 # If there is an extra argument, and it
267 # is zero, we keep the file lists empty.
268 if [ "$#" -gt 0 ]; then
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600269 _gen_file_lists_use="$1"
Gavin Howard6a94fd72018-12-20 10:28:42 -0700270 else
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600271 _gen_file_lists_use="1"
Gavin Howard6a94fd72018-12-20 10:28:42 -0700272 fi
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700273
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600274 _gen_file_lists_needle_src="${_gen_file_lists_typ}SRC"
275 _gen_file_lists_needle_obj="${_gen_file_lists_typ}OBJ"
276 _gen_file_lists_needle_gcda="${_gen_file_lists_typ}GCDA"
277 _gen_file_lists_needle_gcno="${_gen_file_lists_typ}GCNO"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700278
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600279 if [ "$_gen_file_lists_use" -ne 0 ]; then
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700280
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600281 _gen_file_lists_replacement=$(ls $_gen_file_lists_filedir/*.c | tr '\n' ' ')
282 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_src" "$_gen_file_lists_replacement")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700283
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600284 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "c" "o")
285 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_obj" "$_gen_file_lists_replacement")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700286
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600287 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "o" "gcda")
288 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcda" "$_gen_file_lists_replacement")
Gavin Howard6a94fd72018-12-20 10:28:42 -0700289
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600290 _gen_file_lists_replacement=$(replace_exts "$_gen_file_lists_replacement" "gcda" "gcno")
291 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcno" "$_gen_file_lists_replacement")
Gavin Howard6a94fd72018-12-20 10:28:42 -0700292
293 else
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600294 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_src" "")
295 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_obj" "")
296 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcda" "")
297 _gen_file_lists_contents=$(replace "$_gen_file_lists_contents" "$_gen_file_lists_needle_gcno" "")
Gavin Howard6a94fd72018-12-20 10:28:42 -0700298 fi
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700299
Gavin Howard65c0bbc2019-10-11 22:17:22 -0600300 printf '%s\n' "$_gen_file_lists_contents"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700301}
302
303bc_only=0
304dc_only=0
305coverage=0
Gavin Howarddf9b2a62019-05-10 18:39:01 -0600306karatsuba_len=64
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700307debug=0
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700308signals=1
Gavin Howard629b5c02018-12-12 03:21:01 -0700309hist=1
Gavin Howard6fcb5042018-12-26 17:44:06 -0700310extra_math=1
Gavin Howardb5fd5062018-12-20 13:53:02 -0700311optimization=""
Gavin Howard78fa2972019-01-08 10:10:47 -0700312generate_tests=1
Gavin Howarded9b6c22019-01-23 12:02:43 -0700313install_manpages=1
Gavin Howard50080252019-02-20 15:27:43 -0700314nls=1
Gavin Howard1444c9f2019-06-21 21:16:11 -0600315prompt=1
Gavin Howarde2d185f2019-08-03 12:13:46 -0600316force=0
Gavin Howard96ac4272019-11-27 22:16:26 -0700317strip_bin=1
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700318
Gavin Howard96ac4272019-11-27 22:16:26 -0700319while getopts "bBcdDEfgGhHk:MNO:PST-" opt; do
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700320
321 case "$opt" in
322 b) bc_only=1 ;;
Gavin Howard2f061342018-12-24 14:15:44 -0700323 B) dc_only=1 ;;
Gavin Howard5a295152018-12-24 14:20:22 -0700324 c) coverage=1 ;;
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700325 d) dc_only=1 ;;
Gavin Howard2f061342018-12-24 14:15:44 -0700326 D) bc_only=1 ;;
Gavin Howard6fcb5042018-12-26 17:44:06 -0700327 E) extra_math=0 ;;
Gavin Howarde2d185f2019-08-03 12:13:46 -0600328 f) force=1 ;;
Gavin Howard629b5c02018-12-12 03:21:01 -0700329 g) debug=1 ;;
Gavin Howard78fa2972019-01-08 10:10:47 -0700330 G) generate_tests=0 ;;
Gavin Howard629b5c02018-12-12 03:21:01 -0700331 h) usage ;;
332 H) hist=0 ;;
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700333 k) karatsuba_len="$OPTARG" ;;
Gavin Howarded9b6c22019-01-23 12:02:43 -0700334 M) install_manpages=0 ;;
Gavin Howard50080252019-02-20 15:27:43 -0700335 N) nls=0 ;;
Gavin Howardb5fd5062018-12-20 13:53:02 -0700336 O) optimization="$OPTARG" ;;
Gavin Howard1444c9f2019-06-21 21:16:11 -0600337 P) prompt=0 ;;
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700338 S) signals=0 ;;
Gavin Howard96ac4272019-11-27 22:16:26 -0700339 T) strip_bin=0 ;;
Gavin Howard9a679742019-04-06 09:44:57 -0600340 -)
341 arg="$1"
342 arg="${arg#--}"
343 LONG_OPTARG="${arg#*=}"
344 case $arg in
345 help) usage ;;
346 bc-only) bc_only=1 ;;
347 dc-only) dc_only=1 ;;
348 coverage) coverage=1 ;;
349 debug) debug=1 ;;
Gavin Howarde2d185f2019-08-03 12:13:46 -0600350 force) force=1 ;;
Gavin Howard9a679742019-04-06 09:44:57 -0600351 prefix=?*) PREFIX="$LONG_OPTARG" ;;
352 prefix)
353 if [ "$#" -lt 2 ]; then
354 usage "No argument given for '--$arg' option"
355 fi
356 PREFIX="$2"
357 shift ;;
358 bindir=?*) BINDIR="$LONG_OPTARG" ;;
359 bindir)
360 if [ "$#" -lt 2 ]; then
361 usage "No argument given for '--$arg' option"
362 fi
363 BINDIR="$2"
364 shift ;;
365 datarootdir=?*) DATAROOTDIR="$LONG_OPTARG" ;;
366 datarootdir)
367 if [ "$#" -lt 2 ]; then
368 usage "No argument given for '--$arg' option"
369 fi
370 DATAROOTDIR="$2"
371 shift ;;
372 datadir=?*) DATADIR="$LONG_OPTARG" ;;
373 datadir)
374 if [ "$#" -lt 2 ]; then
375 usage "No argument given for '--$arg' option"
376 fi
377 DATADIR="$2"
378 shift ;;
379 mandir=?*) MANDIR="$LONG_OPTARG" ;;
380 mandir)
381 if [ "$#" -lt 2 ]; then
382 usage "No argument given for '--$arg' option"
383 fi
384 MANDIR="$2"
385 shift ;;
386 man1dir=?*) MAN1DIR="$LONG_OPTARG" ;;
387 man1dir)
388 if [ "$#" -lt 2 ]; then
389 usage "No argument given for '--$arg' option"
390 fi
391 MAN1DIR="$2"
392 shift ;;
393 localedir=?*) LOCALEDIR="$LONG_OPTARG" ;;
394 localedir)
395 if [ "$#" -lt 2 ]; then
396 usage "No argument given for '--$arg' option"
397 fi
398 LOCALEDIR="$2"
399 shift ;;
400 karatsuba-len=?*) karatsuba_len="$LONG_OPTARG" ;;
401 karatsuba-len)
402 if [ "$#" -lt 2 ]; then
403 usage "No argument given for '--$arg' option"
404 fi
405 karatsuba_len="$1"
406 shift ;;
407 opt=?*) optimization="$LONG_OPTARG" ;;
408 opt)
409 if [ "$#" -lt 2 ]; then
410 usage "No argument given for '--$arg' option"
411 fi
412 optimization="$1"
413 shift ;;
414 disable-bc) dc_only=1 ;;
415 disable-dc) bc_only=1 ;;
416 disable-extra-math) extra_math=0 ;;
417 disable-generated-tests) generate_tests=0 ;;
418 disable-history) hist=0 ;;
419 disable-man-pages) install_manpages=0 ;;
420 disable-nls) nls=0 ;;
Gavin Howard1444c9f2019-06-21 21:16:11 -0600421 disable-prompt) prompt=0 ;;
Gavin Howard9a679742019-04-06 09:44:57 -0600422 disable-signal-handling) signals=0 ;;
Gavin Howard96ac4272019-11-27 22:16:26 -0700423 disable-strip) strip_bin=0 ;;
Gavin Howard9a679742019-04-06 09:44:57 -0600424 help* | bc-only* | dc-only* | coverage* | debug*)
425 usage "No arg allowed for --$arg option" ;;
426 disable-bc* | disable-dc* | disable-extra-math*)
427 usage "No arg allowed for --$arg option" ;;
428 disable-generated-tests* | disable-history*)
429 usage "No arg allowed for --$arg option" ;;
430 disable-man-pages* | disable-nls* | disable-signal-handling*)
431 usage "No arg allowed for --$arg option" ;;
Gavin Howard96ac4272019-11-27 22:16:26 -0700432 disable-strip*)
433 usage "No arg allowed for --$arg option" ;;
Gavin Howard9a679742019-04-06 09:44:57 -0600434 '') break ;; # "--" terminates argument processing
Gavin Howarda0a1df42019-04-15 17:00:39 -0600435 * ) usage "Invalid option $LONG_OPTARG" ;;
Gavin Howard8931a772019-04-09 10:24:55 -0600436 esac
Gavin Howardb7fbdab2019-08-12 14:56:26 -0600437 shift
438 OPTIND=1 ;;
Gavin Howard4e615482019-04-15 17:18:30 -0600439 ?) usage "Invalid option $opt" ;;
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700440 esac
441
442done
443
444if [ "$bc_only" -eq 1 -a "$dc_only" -eq 1 ]; then
Gavin Howard2f061342018-12-24 14:15:44 -0700445 usage "Can only specify one of -b(-D) or -d(-B)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700446fi
447
448case $karatsuba_len in
Gavin Howardab6ba682019-05-10 08:42:15 -0600449 (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;;
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700450 (*) ;;
451esac
452
Gavin Howarddf9b2a62019-05-10 18:39:01 -0600453if [ "$karatsuba_len" -lt 16 ]; then
454 usage "KARATSUBA_LEN is less than 16"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700455fi
456
Gavin Howardddff7092019-03-30 14:58:24 -0600457set -e
458
Gavin Howard00e0eef2019-01-05 20:11:43 -0700459link="@printf 'No link necessary\\\\n'"
Gavin Howard50080252019-02-20 15:27:43 -0700460main_exec="BC"
461executable="BC_EXEC"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700462
Gavin Howard2fbbf252019-05-10 11:34:24 -0600463bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 \$(BC_EXEC)"
464bc_time_test="@tests/all.sh bc $extra_math 1 $generate_tests 1 \$(BC_EXEC)"
465dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 \$(DC_EXEC)"
466dc_time_test="@tests/all.sh dc $extra_math 1 $generate_tests 1 \$(DC_EXEC)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700467
Gavin Howard36ae6292019-04-01 07:30:27 -0600468timeconst="@tests/bc/timeconst.sh tests/bc/scripts/timeconst.bc \$(BC_EXEC)"
Gavin Howarda3af22f2018-12-13 16:53:58 -0700469
470# In order to have cleanup at exit, we need to be in
471# debug mode, so don't run valgrind without that.
472if [ "$debug" -ne 0 ]; then
Gavin Howard2fbbf252019-05-10 11:34:24 -0600473 vg_bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(BC_EXEC)"
474 vg_dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 valgrind \$(VALGRIND_ARGS) \$(DC_EXEC)"
Gavin Howarda3af22f2018-12-13 16:53:58 -0700475else
Gavin Howard6686f6b2019-01-05 20:35:26 -0700476 vg_bc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
477 vg_dc_test="@printf 'Cannot run valgrind without debug flags\\\\n'"
Gavin Howarda3af22f2018-12-13 16:53:58 -0700478fi
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700479
Gavin Howard6686f6b2019-01-05 20:35:26 -0700480karatsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
481karatsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700482
Gavin Howard1fe45452018-12-20 10:34:05 -0700483bc_lib="\$(GEN_DIR)/lib.o"
Gavin Howarda1cd1222019-01-02 14:40:46 -0700484bc_help="\$(GEN_DIR)/bc_help.o"
485dc_help="\$(GEN_DIR)/dc_help.o"
Gavin Howard1fe45452018-12-20 10:34:05 -0700486
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700487if [ "$bc_only" -eq 1 ]; then
488
489 bc=1
490 dc=0
491
Gavin Howarda1cd1222019-01-02 14:40:46 -0700492 dc_help=""
Gavin Howard1fe45452018-12-20 10:34:05 -0700493
Gavin Howardf1a04042018-12-13 14:07:33 -0700494 executables="bc"
495
Gavin Howard6686f6b2019-01-05 20:35:26 -0700496 dc_test="@printf 'No dc tests to run\\\\n'"
Gavin Howard2fbbf252019-05-10 11:34:24 -0600497 dc_time_test="@printf 'No dc tests to run\\\\n'"
Gavin Howard6686f6b2019-01-05 20:35:26 -0700498 vg_dc_test="@printf 'No dc tests to run\\\\n'"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700499
Gavin Howard074b38a2019-01-17 11:15:59 -0700500 install_prereqs=" install_bc_manpage"
Gavin Howard98fcceb2019-01-23 12:12:26 -0700501 uninstall_prereqs=" uninstall_bc"
502 uninstall_man_prereqs=" uninstall_bc_manpage"
Gavin Howard074b38a2019-01-17 11:15:59 -0700503
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700504elif [ "$dc_only" -eq 1 ]; then
505
506 bc=0
507 dc=1
508
Gavin Howard1fe45452018-12-20 10:34:05 -0700509 bc_lib=""
Gavin Howarda1cd1222019-01-02 14:40:46 -0700510 bc_help=""
Gavin Howard87250702018-12-31 15:49:33 -0700511
Gavin Howardf1a04042018-12-13 14:07:33 -0700512 executables="dc"
513
Gavin Howard50080252019-02-20 15:27:43 -0700514 main_exec="DC"
515 executable="DC_EXEC"
Gavin Howard4f3cf8d2018-12-13 11:33:19 -0700516
Gavin Howard6686f6b2019-01-05 20:35:26 -0700517 bc_test="@printf 'No bc tests to run\\\\n'"
Gavin Howard2fbbf252019-05-10 11:34:24 -0600518 bc_time_test="@printf 'No bc tests to run\\\\n'"
Gavin Howard6686f6b2019-01-05 20:35:26 -0700519 vg_bc_test="@printf 'No bc tests to run\\\\n'"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700520
Gavin Howard6686f6b2019-01-05 20:35:26 -0700521 timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700522
Gavin Howard074b38a2019-01-17 11:15:59 -0700523 install_prereqs=" install_dc_manpage"
Gavin Howard98fcceb2019-01-23 12:12:26 -0700524 uninstall_prereqs=" uninstall_dc"
525 uninstall_man_prereqs=" uninstall_dc_manpage"
Gavin Howard074b38a2019-01-17 11:15:59 -0700526
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700527else
528
529 bc=1
530 dc=1
531
Gavin Howardf1a04042018-12-13 14:07:33 -0700532 executables="bc and dc"
533
Gavin Howard36ae6292019-04-01 07:30:27 -0600534 link="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700535
Gavin Howard36ae6292019-04-01 07:30:27 -0600536 karatsuba="@\$(KARATSUBA) 0 \$(BC_EXEC)"
Gavin Howard233cf1d2018-12-27 12:32:09 -0700537 karatsuba_test="@\$(KARATSUBA) 100 \$(BC_EXEC)"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700538
Gavin Howard074b38a2019-01-17 11:15:59 -0700539 install_prereqs=" install_bc_manpage install_dc_manpage"
Gavin Howard98fcceb2019-01-23 12:12:26 -0700540 uninstall_prereqs=" uninstall_bc uninstall_dc"
541 uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage"
Gavin Howard074b38a2019-01-17 11:15:59 -0700542
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700543fi
544
Gavin Howard277b5142019-05-10 10:58:57 -0600545if [ -z "${LONG_BIT+set}" ]; then
Gavin Howard51a87e92019-05-14 09:59:50 -0600546 LONG_BIT_DEFINE=""
Gavin Howardbed30022019-05-18 23:56:26 -0600547elif [ "$LONG_BIT" -lt 32 ]; then
548 usage "LONG_BIT is less than 32"
Gavin Howard51a87e92019-05-14 09:59:50 -0600549else
550 LONG_BIT_DEFINE="-DBC_LONG_BIT=\$(BC_LONG_BIT)"
Gavin Howard277b5142019-05-10 10:58:57 -0600551fi
552
Gavin Howard05ae38d2019-04-08 09:48:19 -0600553if [ -z "${HOSTCFLAGS+set}" -a -z "${HOST_CFLAGS+set}" ]; then
Gavin Howard593a5182019-01-17 10:22:45 -0700554 HOSTCFLAGS="$CFLAGS"
Gavin Howard05ae38d2019-04-08 09:48:19 -0600555elif [ -z "${HOSTCFLAGS+set}" ]; then
Gavin Howard593a5182019-01-17 10:22:45 -0700556 HOSTCFLAGS="$HOST_CFLAGS"
557fi
558
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700559if [ "$debug" -eq 1 ]; then
560
Gavin Howard9a679742019-04-06 09:44:57 -0600561 if [ -z "$CFLAGS" -a -z "$optimization" ]; then
Gavin Howard5cfc8dc2019-02-20 11:18:35 -0700562 CFLAGS="-O0"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700563 fi
Gavin Howardd366bb12018-12-19 14:05:13 -0700564
Gavin Howard73c77ff2019-11-09 12:03:48 -0700565 CFLAGS="-g $CFLAGS"
Gavin Howard87250702018-12-31 15:49:33 -0700566
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700567else
Gavin Howard73c77ff2019-11-09 12:03:48 -0700568 CPPFLAGS="-DNDEBUG $CPPFLAGS"
Gavin Howard96ac4272019-11-27 22:16:26 -0700569 if [ "$strip_bin" -ne 0 ]; then
570 LDFLAGS="-s $LDFLAGS"
571 fi
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700572fi
573
Gavin Howard9a679742019-04-06 09:44:57 -0600574if [ -n "$optimization" ]; then
Gavin Howard73c77ff2019-11-09 12:03:48 -0700575 CFLAGS="-O$optimization $CFLAGS"
Gavin Howard24f942f2018-12-20 10:08:49 -0700576fi
577
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700578if [ "$coverage" -eq 1 ]; then
579
580 if [ "$bc_only" -eq 1 -o "$dc_only" -eq 1 ]; then
Gavin Howard629b5c02018-12-12 03:21:01 -0700581 usage "Can only specify -c without -b or -d"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700582 fi
583
Gavin Howard73c77ff2019-11-09 12:03:48 -0700584 CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS"
585 CPPFLAGS="-DNDEBUG $CPPFLAGS"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700586
Gavin Howardf01c1382018-12-27 13:22:55 -0700587 COVERAGE="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA)"
Gavin Howard62cf3ca2018-12-13 13:30:29 -0700588 COVERAGE="$COVERAGE;\$(RM) -f \$(GEN)*.gc*"
Gavin Howard573259c2018-12-28 00:11:28 -0700589 COVERAGE="$COVERAGE;gcovr --html-details --output index.html"
Gavin Howardce513f72019-02-15 08:52:57 -0700590 COVERAGE_PREREQS=" test"
Gavin Howard62cf3ca2018-12-13 13:30:29 -0700591
592else
Gavin Howard6686f6b2019-01-05 20:35:26 -0700593 COVERAGE="@printf 'Coverage not generated\\\\n'"
Gavin Howard62cf3ca2018-12-13 13:30:29 -0700594 COVERAGE_PREREQS=""
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700595fi
596
Gavin Howard9a679742019-04-06 09:44:57 -0600597if [ -z "${DESTDIR+set}" ]; then
598 destdir=""
599else
600 destdir="DESTDIR = $DESTDIR"
601fi
602
Gavin Howard05ae38d2019-04-08 09:48:19 -0600603if [ -z "${PREFIX+set}" ]; then
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700604 PREFIX="/usr/local"
605fi
606
Gavin Howard05ae38d2019-04-08 09:48:19 -0600607if [ -z "${BINDIR+set}" ]; then
Gavin Howard471b6c02019-01-17 14:25:07 -0700608 BINDIR="$PREFIX/bin"
609fi
610
Gavin Howard50080252019-02-20 15:27:43 -0700611if [ "$install_manpages" -ne 0 -o "$nls" -ne 0 ]; then
Gavin Howard05ae38d2019-04-08 09:48:19 -0600612 if [ -z "${DATAROOTDIR+set}" ]; then
Gavin Howarded9b6c22019-01-23 12:02:43 -0700613 DATAROOTDIR="$PREFIX/share"
614 fi
Gavin Howard50080252019-02-20 15:27:43 -0700615fi
616
Gavin Howard50080252019-02-20 15:27:43 -0700617if [ "$install_manpages" -ne 0 ]; then
Gavin Howard471b6c02019-01-17 14:25:07 -0700618
Gavin Howard05ae38d2019-04-08 09:48:19 -0600619 if [ -z "${DATADIR+set}" ]; then
Gavin Howarded9b6c22019-01-23 12:02:43 -0700620 DATADIR="$DATAROOTDIR"
621 fi
Gavin Howard471b6c02019-01-17 14:25:07 -0700622
Gavin Howard05ae38d2019-04-08 09:48:19 -0600623 if [ -z "${MANDIR+set}" ]; then
Gavin Howarded9b6c22019-01-23 12:02:43 -0700624 MANDIR="$DATADIR/man"
625 fi
626
Gavin Howard05ae38d2019-04-08 09:48:19 -0600627 if [ -z "${MAN1DIR+set}" ]; then
Gavin Howarded9b6c22019-01-23 12:02:43 -0700628 MAN1DIR="$MANDIR/man1"
629 fi
630
631else
632 install_prereqs=""
Gavin Howard98fcceb2019-01-23 12:12:26 -0700633 uninstall_man_prereqs=""
Gavin Howard074b38a2019-01-17 11:15:59 -0700634fi
635
Gavin Howard9a679742019-04-06 09:44:57 -0600636if [ -z "$CC" ]; then
Gavin Howard67222d32018-12-14 12:38:10 -0700637 CC="c99"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700638fi
639
Gavin Howard9a679742019-04-06 09:44:57 -0600640if [ -z "$HOSTCC" -a -z "$HOST_CC" ]; then
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700641 HOSTCC="$CC"
Gavin Howard9a679742019-04-06 09:44:57 -0600642elif [ -z "$HOSTCC" ]; then
Gavin Howard593a5182019-01-17 10:22:45 -0700643 HOSTCC="$HOST_CC"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700644fi
645
Gavin Howard91c38012019-04-09 14:42:22 -0600646if [ "$nls" -ne 0 ]; then
Gavin Howard54dfdc62019-03-27 11:09:10 -0600647
648 set +e
649
650 printf 'Testing NLS...\n'
651
652 flags="-DBC_ENABLE_NLS=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc -DBC_ENABLE_SIGNALS=$signals"
653 flags="$flags -DBC_ENABLE_HISTORY=$hist"
654 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
Gavin Howardd8dced32019-03-30 14:58:59 -0600655 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
Gavin Howard54dfdc62019-03-27 11:09:10 -0600656
Gavin Howard73c77ff2019-11-09 12:03:48 -0700657 "$HOSTCC" $HOSTCFLAGS $flags -c "src/vm.c" -o "$scriptdir/vm.o" > /dev/null 2>&1
Gavin Howard54dfdc62019-03-27 11:09:10 -0600658
659 err="$?"
660
661 rm -rf "$scriptdir/vm.o"
662
663 # If this errors, it is probably because of building on Windows,
664 # and NLS is not supported on Windows, so disable it.
665 if [ "$err" -ne 0 ]; then
666 printf 'NLS does not work.\n'
Gavin Howarde2d185f2019-08-03 12:13:46 -0600667 if [ $force -eq 0 ]; then
668 printf 'Disabling NLS...\n'
669 nls=0
670 else
671 printf 'Forcing NLS...\n'
672 fi
Gavin Howard54dfdc62019-03-27 11:09:10 -0600673 else
Gavin Howard5d0d10e2019-04-05 13:53:50 -0600674 printf 'NLS works.\n\n'
675
Gavin Howardf8a5d392019-04-05 14:07:57 -0600676 printf 'Testing gencat...\n'
Gavin Howardea73c8c2019-04-09 07:21:38 -0600677 gencat "$scriptdir/en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1
Gavin Howardf8a5d392019-04-05 14:07:57 -0600678
679 err="$?"
680
Gavin Howardea73c8c2019-04-09 07:21:38 -0600681 rm -rf "$scriptdir/en_US.cat"
Gavin Howardf8a5d392019-04-05 14:07:57 -0600682
683 if [ "$err" -ne 0 ]; then
684 printf 'gencat does not work.\n'
Gavin Howarde2d185f2019-08-03 12:13:46 -0600685 if [ $force -eq 0 ]; then
686 printf 'Disabling NLS...\n\n'
687 nls=0
688 else
689 printf 'Forcing NLS...\n\n'
690 fi
Gavin Howard5d0d10e2019-04-05 13:53:50 -0600691 else
Gavin Howard91c38012019-04-09 14:42:22 -0600692
Gavin Howardf8a5d392019-04-05 14:07:57 -0600693 printf 'gencat works.\n\n'
Gavin Howard91c38012019-04-09 14:42:22 -0600694
Gavin Howard8752b262019-04-09 14:54:52 -0600695 if [ "$HOSTCC" != "$CC" ]; then
696 printf 'Cross-compile detected.\n\n'
697 printf 'WARNING: Catalog files generated with gencat may not be portable\n'
698 printf ' across different architectures.\n\n'
699 fi
700
Gavin Howard91c38012019-04-09 14:42:22 -0600701 if [ -z "$NLSPATH" ]; then
702 NLSPATH="/usr/share/locale/%L/%N"
703 fi
704
705 install_locales_prereqs=" install_locales"
706 uninstall_locales_prereqs=" uninstall_locales"
707
Gavin Howard5d0d10e2019-04-05 13:53:50 -0600708 fi
709
Gavin Howard54dfdc62019-03-27 11:09:10 -0600710 fi
711
712 set -e
713
Gavin Howard91c38012019-04-09 14:42:22 -0600714else
715 install_locales_prereqs=""
716 uninstall_locales_prereqs=""
Gavin Howard54dfdc62019-03-27 11:09:10 -0600717fi
718
Gavin Howard2a669ea2018-12-24 12:19:20 -0700719if [ "$hist" -eq 1 ]; then
720
721 set +e
722
Gavin Howard4fe954e2018-12-24 14:06:18 -0700723 printf 'Testing history...\n'
724
Gavin Howard401954f2019-02-19 11:56:04 -0700725 flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc -DBC_ENABLE_SIGNALS=$signals"
Gavin Howardefa34952019-02-21 11:44:58 -0700726 flags="$flags -DBC_ENABLE_NLS=$nls"
Gavin Howarda2e5bb02019-02-23 12:34:05 -0700727 flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
Gavin Howardd8dced32019-03-30 14:58:59 -0600728 flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
Gavin Howard2a669ea2018-12-24 12:19:20 -0700729
Gavin Howard73c77ff2019-11-09 12:03:48 -0700730 "$HOSTCC" $HOSTCFLAGS $flags -c "src/history/history.c" -o "$scriptdir/history.o" > /dev/null 2>&1
Gavin Howard2a669ea2018-12-24 12:19:20 -0700731
732 err="$?"
733
Gavin Howard26c7b192018-12-25 11:25:01 -0700734 rm -rf "$scriptdir/history.o"
735
Gavin Howard2a669ea2018-12-24 12:19:20 -0700736 # If this errors, it is probably because of building on Windows,
737 # and history is not supported on Windows, so disable it.
738 if [ "$err" -ne 0 ]; then
Gavin Howard959375c2018-12-24 14:07:02 -0700739 printf 'History does not work.\n'
Gavin Howarde2d185f2019-08-03 12:13:46 -0600740 if [ $force -eq 0 ]; then
741 printf 'Disabling history...\n'
742 hist=0
743 else
744 printf 'Forcing history...\n'
745 fi
Gavin Howard57ef47e2018-12-24 14:08:35 -0700746 else
747 printf 'History works.\n'
Gavin Howard2a669ea2018-12-24 12:19:20 -0700748 fi
749
750 set -e
751
752fi
753
Gavin Howarda1cd1222019-01-02 14:40:46 -0700754if [ "$extra_math" -eq 1 -a "$bc" -ne 0 ]; then
Gavin Howard6fcb5042018-12-26 17:44:06 -0700755 BC_LIB2_O="\$(GEN_DIR)/lib2.o"
756else
757 BC_LIB2_O=""
758fi
759
Gavin Howarda5132242019-04-22 08:34:28 -0600760GEN="strgen"
761GEN_EXEC_TARGET="\$(HOSTCC) \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)"
762CLEAN_PREREQS=" clean_gen"
763
764if [ -z "${GEN_HOST+set}" ]; then
765 GEN_HOST=1
766else
767 if [ "$GEN_HOST" -eq 0 ]; then
768 GEN="strgen.sh"
769 GEN_EXEC_TARGET="@printf 'Do not need to build gen/strgen.c\\\\n'"
770 CLEAN_PREREQS=""
771 fi
772fi
773
Gavin Howard50080252019-02-20 15:27:43 -0700774# Print out the values; this is for debugging.
775printf '\n'
Gavin Howard9a679742019-04-06 09:44:57 -0600776if [ "$bc" -ne 0 ]; then
777 printf 'Building bc\n'
778else
779 printf 'Not building bc\n'
780fi
781if [ "$dc" -ne 0 ]; then
782 printf 'Building dc\n'
783else
784 printf 'Not building dc\n'
785fi
786printf '\n'
Gavin Howard50080252019-02-20 15:27:43 -0700787printf 'BC_ENABLE_SIGNALS=%s\n' "$signals"
788printf 'BC_ENABLE_HISTORY=%s\n' "$hist"
Gavin Howard50080252019-02-20 15:27:43 -0700789printf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math"
790printf 'BC_ENABLE_NLS=%s\n' "$nls"
Gavin Howard1444c9f2019-06-21 21:16:11 -0600791printf 'BC_ENABLE_PROMPT=%s\n' "$prompt"
Gavin Howard64005c42019-01-29 10:32:52 -0700792printf '\n'
Gavin Howarddf9b2a62019-05-10 18:39:01 -0600793printf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len"
794printf '\n'
Gavin Howard64005c42019-01-29 10:32:52 -0700795printf 'CC=%s\n' "$CC"
796printf 'CFLAGS=%s\n' "$CFLAGS"
797printf 'HOSTCC=%s\n' "$HOSTCC"
798printf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS"
799printf 'CPPFLAGS=%s\n' "$CPPFLAGS"
800printf 'LDFLAGS=%s\n' "$LDFLAGS"
801printf 'PREFIX=%s\n' "$PREFIX"
802printf 'BINDIR=%s\n' "$BINDIR"
803printf 'DATAROOTDIR=%s\n' "$DATAROOTDIR"
804printf 'DATADIR=%s\n' "$DATADIR"
805printf 'MANDIR=%s\n' "$MANDIR"
806printf 'MAN1DIR=%s\n' "$MAN1DIR"
Gavin Howardbc021292019-04-09 10:04:01 -0600807printf 'NLSPATH=%s\n' "$NLSPATH"
Gavin Howard64005c42019-01-29 10:32:52 -0700808printf 'EXECSUFFIX=%s\n' "$EXECSUFFIX"
Gavin Howard36ae6292019-04-01 07:30:27 -0600809printf 'EXECPREFIX=%s\n' "$EXECPREFIX"
Gavin Howard64005c42019-01-29 10:32:52 -0700810printf 'DESTDIR=%s\n' "$DESTDIR"
Gavin Howard277b5142019-05-10 10:58:57 -0600811printf 'LONG_BIT=%s\n' "$LONG_BIT"
Gavin Howarda5132242019-04-22 08:34:28 -0600812printf 'GEN_HOST=%s\n' "$GEN_HOST"
Gavin Howard64005c42019-01-29 10:32:52 -0700813printf 'GEN_EMU=%s\n' "$GEN_EMU"
814
Gavin Howard6a94fd72018-12-20 10:28:42 -0700815contents=$(cat "$scriptdir/Makefile.in")
816
817needle="WARNING"
Gavin Howardb55ad002018-12-20 16:59:23 -0700818replacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***'
Gavin Howard6a94fd72018-12-20 10:28:42 -0700819
820contents=$(replace "$contents" "$needle" "$replacement")
821
822contents=$(gen_file_lists "$contents" "$scriptdir/src" "")
Gavin Howarde18c2482018-12-20 11:15:28 -0700823contents=$(gen_file_lists "$contents" "$scriptdir/src/bc" "BC_" "$bc")
824contents=$(gen_file_lists "$contents" "$scriptdir/src/dc" "DC_" "$dc")
825contents=$(gen_file_lists "$contents" "$scriptdir/src/history" "HISTORY_" "$hist")
Gavin Howard6a94fd72018-12-20 10:28:42 -0700826
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700827contents=$(replace "$contents" "BC_ENABLED" "$bc")
828contents=$(replace "$contents" "DC_ENABLED" "$dc")
829contents=$(replace "$contents" "LINK" "$link")
830
831contents=$(replace "$contents" "SIGNALS" "$signals")
832contents=$(replace "$contents" "HISTORY" "$hist")
Gavin Howard6fcb5042018-12-26 17:44:06 -0700833contents=$(replace "$contents" "EXTRA_MATH" "$extra_math")
Gavin Howard50080252019-02-20 15:27:43 -0700834contents=$(replace "$contents" "NLS" "$nls")
Gavin Howard1444c9f2019-06-21 21:16:11 -0600835contents=$(replace "$contents" "PROMPT" "$prompt")
Gavin Howarda1cd1222019-01-02 14:40:46 -0700836contents=$(replace "$contents" "BC_LIB_O" "$bc_lib")
837contents=$(replace "$contents" "BC_HELP_O" "$bc_help")
838contents=$(replace "$contents" "DC_HELP_O" "$dc_help")
Gavin Howard6fcb5042018-12-26 17:44:06 -0700839contents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700840contents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len")
841
Gavin Howardbc021292019-04-09 10:04:01 -0600842contents=$(replace "$contents" "NLSPATH" "$NLSPATH")
Gavin Howard9a679742019-04-06 09:44:57 -0600843contents=$(replace "$contents" "DESTDIR" "$destdir")
Gavin Howard5d057152019-01-29 10:31:40 -0700844contents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX")
Gavin Howard36ae6292019-04-01 07:30:27 -0600845contents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX")
Gavin Howard471b6c02019-01-17 14:25:07 -0700846contents=$(replace "$contents" "BINDIR" "$BINDIR")
847contents=$(replace "$contents" "MAN1DIR" "$MAN1DIR")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700848contents=$(replace "$contents" "CFLAGS" "$CFLAGS")
Gavin Howard593a5182019-01-17 10:22:45 -0700849contents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700850contents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS")
851contents=$(replace "$contents" "LDFLAGS" "$LDFLAGS")
852contents=$(replace "$contents" "CC" "$CC")
853contents=$(replace "$contents" "HOSTCC" "$HOSTCC")
854contents=$(replace "$contents" "COVERAGE" "$COVERAGE")
Gavin Howard62cf3ca2018-12-13 13:30:29 -0700855contents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS")
Gavin Howard074b38a2019-01-17 11:15:59 -0700856contents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs")
Gavin Howard50080252019-02-20 15:27:43 -0700857contents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs")
Gavin Howard98fcceb2019-01-23 12:12:26 -0700858contents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs")
Gavin Howarded9b6c22019-01-23 12:02:43 -0700859contents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs")
Gavin Howard50080252019-02-20 15:27:43 -0700860contents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700861
Gavin Howardf1a04042018-12-13 14:07:33 -0700862contents=$(replace "$contents" "EXECUTABLES" "$executables")
Gavin Howard4f3cf8d2018-12-13 11:33:19 -0700863contents=$(replace "$contents" "MAIN_EXEC" "$main_exec")
Gavin Howard50080252019-02-20 15:27:43 -0700864contents=$(replace "$contents" "EXEC" "$executable")
Gavin Howard4f3cf8d2018-12-13 11:33:19 -0700865
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700866contents=$(replace "$contents" "BC_TEST" "$bc_test")
Gavin Howard2fbbf252019-05-10 11:34:24 -0600867contents=$(replace "$contents" "BC_TIME_TEST" "$bc_time_test")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700868contents=$(replace "$contents" "DC_TEST" "$dc_test")
Gavin Howard2fbbf252019-05-10 11:34:24 -0600869contents=$(replace "$contents" "DC_TIME_TEST" "$dc_time_test")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700870
871contents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test")
872contents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test")
873
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700874contents=$(replace "$contents" "TIMECONST" "$timeconst")
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700875
876contents=$(replace "$contents" "KARATSUBA" "$karatsuba")
877contents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test")
878
Gavin Howard277b5142019-05-10 10:58:57 -0600879contents=$(replace "$contents" "LONG_BIT" "$LONG_BIT")
Gavin Howard51a87e92019-05-14 09:59:50 -0600880contents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE")
Gavin Howard277b5142019-05-10 10:58:57 -0600881
Gavin Howarda5132242019-04-22 08:34:28 -0600882contents=$(replace "$contents" "GEN" "$GEN")
883contents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET")
884contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS")
Gavin Howard4dff5452018-12-20 10:06:58 -0700885contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU")
886
Gavin Howardd15e01d2018-12-19 12:49:02 -0700887printf '%s\n' "$contents" > "$scriptdir/Makefile"
Gavin Howard27fa9cd2018-12-12 02:52:52 -0700888
889cd "$scriptdir"
890
891make clean > /dev/null