Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | # |
Gavin Howard | 7345cb9 | 2019-04-08 14:13:43 -0600 | [diff] [blame] | 3 | # Copyright (c) 2018-2019 Gavin D. Howard and contributors. |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 4 | # |
Gavin Howard | 7345cb9 | 2019-04-08 14:13:43 -0600 | [diff] [blame] | 5 | # All rights reserved. |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 6 | # |
Gavin Howard | 7345cb9 | 2019-04-08 14:13:43 -0600 | [diff] [blame] | 7 | # 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 Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 28 | # |
| 29 | |
Gavin Howard | 2425bf2 | 2019-04-08 17:05:45 -0600 | [diff] [blame] | 30 | script="$0" |
| 31 | scriptdir=$(dirname "$script") |
| 32 | script=$(basename "$script") |
| 33 | |
| 34 | . "$scriptdir/functions.sh" |
| 35 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 36 | usage() { |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 37 | |
| 38 | if [ $# -gt 0 ]; then |
| 39 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 40 | _usage_val=1 |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 41 | |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 42 | printf "%s\n\n" "$1" |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 43 | |
| 44 | else |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 45 | _usage_val=0 |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 46 | fi |
| 47 | |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 48 | printf 'usage: %s -h\n' "$script" |
| 49 | printf ' %s --help\n' "$script" |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 50 | printf ' %s [-bD|-dB|-c] [-EfgGHMNPST] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\n' "$script" |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 51 | printf ' %s \\\n' "$script" |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 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-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 Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 61 | printf '\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 62 | printf ' -b, --bc-only\n' |
Gavin Howard | 2f06134 | 2018-12-24 14:15:44 -0700 | [diff] [blame] | 63 | printf ' Build bc only. It is an error if "-d" or "-B" are specified too.\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 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' |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 68 | printf ' Generate test coverage code. Requires gcov and regcovr.\n' |
Gavin Howard | 995d061 | 2018-12-25 11:37:52 -0700 | [diff] [blame] | 69 | printf ' It is an error if either "-b" ("-D") or "-d" ("-B") is specified.\n' |
Gavin Howard | d366bb1 | 2018-12-19 14:05:13 -0700 | [diff] [blame] | 70 | printf ' Requires a compiler that use gcc-compatible coverage options\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 71 | printf ' -d, --dc-only\n' |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 72 | printf ' Build dc only. It is an error if "-b" is specified too.\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 73 | 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 Howard | 6fcb504 | 2018-12-26 17:44:06 -0700 | [diff] [blame] | 77 | printf ' Disable extra math. This includes: "$" operator (truncate to integer),\n' |
Gavin Howard | 8725070 | 2018-12-31 15:49:33 -0700 | [diff] [blame] | 78 | 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 Howard | e2d185f | 2019-08-03 12:13:46 -0600 | [diff] [blame] | 81 | 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 Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 85 | printf ' -g, --debug\n' |
Gavin Howard | d366bb1 | 2018-12-19 14:05:13 -0700 | [diff] [blame] | 86 | printf ' Build in debug mode. Adds the "-g" flag, and if there are no\n' |
Gavin Howard | 24f942f | 2018-12-20 10:08:49 -0700 | [diff] [blame] | 87 | printf ' other CFLAGS, and "-O" was not given, this also adds the "-O0"\n' |
Gavin Howard | a9468b5 | 2018-12-25 16:43:27 -0700 | [diff] [blame] | 88 | 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 Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 90 | printf ' -G, --disable-generated-tests\n' |
Gavin Howard | 78fa297 | 2019-01-08 10:10:47 -0700 | [diff] [blame] | 91 | 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 Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 93 | printf ' -h, --help\n' |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 94 | printf ' Print this help message and exit.\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 95 | printf ' -H, --disable-history\n' |
Gavin Howard | 995d061 | 2018-12-25 11:37:52 -0700 | [diff] [blame] | 96 | printf ' Disable history.\n' |
Gavin Howard | ab6ba68 | 2019-05-10 08:42:15 -0600 | [diff] [blame] | 97 | 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 Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 100 | printf ' -M, --disable-man-pages\n' |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 101 | printf ' Disable installing manpages.\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 102 | printf ' -N, --disable-nls\n' |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 103 | printf ' Disable POSIX locale (NLS) support.\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 104 | printf ' -O OPT_LEVEL, --opt OPT_LEVEL\n' |
Gavin Howard | 24f942f | 2018-12-20 10:08:49 -0700 | [diff] [blame] | 105 | 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 Howard | 1444c9f | 2019-06-21 21:16:11 -0600 | [diff] [blame] | 108 | printf ' -P, --disable-prompt\n' |
Gavin Howard | ca8f9a4 | 2019-06-25 07:01:20 -0600 | [diff] [blame] | 109 | 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 Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 112 | printf ' -S, --disable-signal-handling\n' |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 113 | printf ' Disable signal handling. On by default.\n' |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 114 | 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 Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 117 | 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 Howard | 9d47b6f | 2019-05-09 14:41:41 -0600 | [diff] [blame] | 122 | printf ' The directory to install binaries. Overrides "$BINDIR" if it exists.\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 123 | 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 Howard | 9d47b6f | 2019-05-09 14:41:41 -0600 | [diff] [blame] | 134 | printf ' The location to install Section 1 manpages to. Overrides "$MAN1DIR" if\n' |
| 135 | printf ' it exists. Default is "$MANDIR/man1".\n' |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 136 | printf '\n' |
| 137 | printf 'In addition, the following environment variables are used:\n' |
| 138 | printf '\n' |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 139 | printf ' CC C compiler. Must be compatible with POSIX c99.\n' |
Gavin Howard | ed91022 | 2019-01-17 11:16:18 -0700 | [diff] [blame] | 140 | printf ' Default is "c99".\n' |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 141 | printf ' HOSTCC Host C compiler. Must be compatible with POSIX c99.\n' |
Gavin Howard | 2469a22 | 2019-01-23 15:36:33 -0700 | [diff] [blame] | 142 | printf ' Default is "$CC".\n' |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 143 | printf ' HOST_CC Same as HOSTCC. If HOSTCC also exists, it is used.\n' |
| 144 | printf ' CFLAGS C compiler flags.\n' |
Gavin Howard | 471b6c0 | 2019-01-17 14:25:07 -0700 | [diff] [blame] | 145 | printf ' HOSTCFLAGS CFLAGS for HOSTCC. Default is "$CFLAGS".\n' |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 146 | printf ' HOST_CFLAGS Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.\n' |
Gavin Howard | 2469a22 | 2019-01-23 15:36:33 -0700 | [diff] [blame] | 147 | printf ' CPPFLAGS C preprocessor flags. Default is "".\n' |
| 148 | printf ' LDFLAGS Linker flags. Default is "".\n' |
Gavin Howard | ed91022 | 2019-01-17 11:16:18 -0700 | [diff] [blame] | 149 | 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 Howard | 2469a22 | 2019-01-23 15:36:33 -0700 | [diff] [blame] | 151 | printf ' BINDIR The directory to install binaries. Default is "$PREFIX/bin".\n' |
Gavin Howard | 32cf742 | 2019-01-17 14:36:35 -0700 | [diff] [blame] | 152 | 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 Howard | 471b6c0 | 2019-01-17 14:25:07 -0700 | [diff] [blame] | 155 | printf ' MAN1DIR The location to install Section 1 manpages to. Default is\n' |
| 156 | printf ' "$MANDIR/man1".\n' |
Gavin Howard | bc02129 | 2019-04-09 10:04:01 -0600 | [diff] [blame] | 157 | 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 Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 159 | printf ' definition of $NLSPATH (see POSIX environment variables for\n' |
| 160 | printf ' more information). Default is "/usr/share/locale/%%L/%%N".\n' |
Gavin Howard | 5d05715 | 2019-01-29 10:31:40 -0700 | [diff] [blame] | 161 | printf ' EXECSUFFIX The suffix to append to the executable names, used to not\n' |
Gavin Howard | 36ae629 | 2019-04-01 07:30:27 -0600 | [diff] [blame] | 162 | 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 Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 165 | printf ' DESTDIR For package creation. Default is "". If it is empty when\n' |
Gavin Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 166 | printf ' `%s` is run, it can also be passed to `make install`\n' "$script" |
Gavin Howard | 3dd8ad8 | 2019-04-06 23:36:57 -0600 | [diff] [blame] | 167 | printf ' later as an environment variable. If both are specified,\n' |
Gavin Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 168 | printf ' the one given to `%s` takes precedence.\n' "$script" |
Gavin Howard | 277b514 | 2019-05-10 10:58:57 -0600 | [diff] [blame] | 169 | 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 Howard | 3d59ce7 | 2019-05-25 11:19:44 -0600 | [diff] [blame] | 172 | 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 Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 178 | 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 Howard | 277b514 | 2019-05-10 10:58:57 -0600 | [diff] [blame] | 183 | printf ' machine since `gen/strgen.sh` is a POSIX shell script. However,\n' |
Gavin Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 184 | 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 Howard | 3d59ce7 | 2019-05-25 11:19:44 -0600 | [diff] [blame] | 198 | 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 Howard | 954f9b6 | 2018-12-19 15:22:20 -0700 | [diff] [blame] | 201 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 202 | exit "$_usage_val" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 205 | replace_ext() { |
| 206 | |
| 207 | if [ "$#" -ne 3 ]; then |
| 208 | err_exit "Invalid number of args to $0" |
| 209 | fi |
| 210 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 211 | _replace_ext_file="$1" |
| 212 | _replace_ext_ext1="$2" |
| 213 | _replace_ext_ext2="$3" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 214 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 215 | _replace_ext_result=$(printf "$_replace_ext_file" | sed -e "s@\.$_replace_ext_ext1@\.$_replace_ext_ext2@") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 216 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 217 | printf '%s\n' "$_replace_ext_result" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | replace_exts() { |
| 221 | |
| 222 | if [ "$#" -ne 3 ]; then |
| 223 | err_exit "Invalid number of args to $0" |
| 224 | fi |
| 225 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 226 | _replace_exts_files="$1" |
| 227 | _replace_exts_ext1="$2" |
| 228 | _replace_exts_ext2="$3" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 229 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 230 | 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 Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 233 | done |
| 234 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 235 | printf '%s\n' "$_replace_exts_result" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | replace() { |
| 239 | |
| 240 | if [ "$#" -ne 3 ]; then |
| 241 | err_exit "Invalid number of args to $0" |
| 242 | fi |
| 243 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 244 | _replace_str="$1" |
| 245 | _replace_needle="$2" |
| 246 | _replace_replacement="$3" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 247 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 248 | substring_replace "$_replace_str" "%%$_replace_needle%%" "$_replace_replacement" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | gen_file_lists() { |
| 252 | |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 253 | if [ "$#" -lt 3 ]; then |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 254 | err_exit "Invalid number of args to $0" |
| 255 | fi |
| 256 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 257 | _gen_file_lists_contents="$1" |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 258 | shift |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 259 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 260 | _gen_file_lists_filedir="$1" |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 261 | shift |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 262 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 263 | _gen_file_lists_typ="$1" |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 264 | shift |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 265 | |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 266 | # If there is an extra argument, and it |
| 267 | # is zero, we keep the file lists empty. |
| 268 | if [ "$#" -gt 0 ]; then |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 269 | _gen_file_lists_use="$1" |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 270 | else |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 271 | _gen_file_lists_use="1" |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 272 | fi |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 273 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 274 | _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 Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 278 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 279 | if [ "$_gen_file_lists_use" -ne 0 ]; then |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 280 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 281 | _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 Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 283 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 284 | _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 Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 286 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 287 | _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 Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 289 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 290 | _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 Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 292 | |
| 293 | else |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 294 | _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 Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 298 | fi |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 299 | |
Gavin Howard | 65c0bbc | 2019-10-11 22:17:22 -0600 | [diff] [blame] | 300 | printf '%s\n' "$_gen_file_lists_contents" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | bc_only=0 |
| 304 | dc_only=0 |
| 305 | coverage=0 |
Gavin Howard | df9b2a6 | 2019-05-10 18:39:01 -0600 | [diff] [blame] | 306 | karatsuba_len=64 |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 307 | debug=0 |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 308 | signals=1 |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 309 | hist=1 |
Gavin Howard | 6fcb504 | 2018-12-26 17:44:06 -0700 | [diff] [blame] | 310 | extra_math=1 |
Gavin Howard | b5fd506 | 2018-12-20 13:53:02 -0700 | [diff] [blame] | 311 | optimization="" |
Gavin Howard | 78fa297 | 2019-01-08 10:10:47 -0700 | [diff] [blame] | 312 | generate_tests=1 |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 313 | install_manpages=1 |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 314 | nls=1 |
Gavin Howard | 1444c9f | 2019-06-21 21:16:11 -0600 | [diff] [blame] | 315 | prompt=1 |
Gavin Howard | e2d185f | 2019-08-03 12:13:46 -0600 | [diff] [blame] | 316 | force=0 |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 317 | strip_bin=1 |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 318 | |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 319 | while getopts "bBcdDEfgGhHk:MNO:PST-" opt; do |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 320 | |
| 321 | case "$opt" in |
| 322 | b) bc_only=1 ;; |
Gavin Howard | 2f06134 | 2018-12-24 14:15:44 -0700 | [diff] [blame] | 323 | B) dc_only=1 ;; |
Gavin Howard | 5a29515 | 2018-12-24 14:20:22 -0700 | [diff] [blame] | 324 | c) coverage=1 ;; |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 325 | d) dc_only=1 ;; |
Gavin Howard | 2f06134 | 2018-12-24 14:15:44 -0700 | [diff] [blame] | 326 | D) bc_only=1 ;; |
Gavin Howard | 6fcb504 | 2018-12-26 17:44:06 -0700 | [diff] [blame] | 327 | E) extra_math=0 ;; |
Gavin Howard | e2d185f | 2019-08-03 12:13:46 -0600 | [diff] [blame] | 328 | f) force=1 ;; |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 329 | g) debug=1 ;; |
Gavin Howard | 78fa297 | 2019-01-08 10:10:47 -0700 | [diff] [blame] | 330 | G) generate_tests=0 ;; |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 331 | h) usage ;; |
| 332 | H) hist=0 ;; |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 333 | k) karatsuba_len="$OPTARG" ;; |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 334 | M) install_manpages=0 ;; |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 335 | N) nls=0 ;; |
Gavin Howard | b5fd506 | 2018-12-20 13:53:02 -0700 | [diff] [blame] | 336 | O) optimization="$OPTARG" ;; |
Gavin Howard | 1444c9f | 2019-06-21 21:16:11 -0600 | [diff] [blame] | 337 | P) prompt=0 ;; |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 338 | S) signals=0 ;; |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 339 | T) strip_bin=0 ;; |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 340 | -) |
| 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 Howard | e2d185f | 2019-08-03 12:13:46 -0600 | [diff] [blame] | 350 | force) force=1 ;; |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 351 | 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 Howard | 1444c9f | 2019-06-21 21:16:11 -0600 | [diff] [blame] | 421 | disable-prompt) prompt=0 ;; |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 422 | disable-signal-handling) signals=0 ;; |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 423 | disable-strip) strip_bin=0 ;; |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 424 | 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 Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 432 | disable-strip*) |
| 433 | usage "No arg allowed for --$arg option" ;; |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 434 | '') break ;; # "--" terminates argument processing |
Gavin Howard | a0a1df4 | 2019-04-15 17:00:39 -0600 | [diff] [blame] | 435 | * ) usage "Invalid option $LONG_OPTARG" ;; |
Gavin Howard | 8931a77 | 2019-04-09 10:24:55 -0600 | [diff] [blame] | 436 | esac |
Gavin Howard | b7fbdab | 2019-08-12 14:56:26 -0600 | [diff] [blame] | 437 | shift |
| 438 | OPTIND=1 ;; |
Gavin Howard | 4e61548 | 2019-04-15 17:18:30 -0600 | [diff] [blame] | 439 | ?) usage "Invalid option $opt" ;; |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 440 | esac |
| 441 | |
| 442 | done |
| 443 | |
| 444 | if [ "$bc_only" -eq 1 -a "$dc_only" -eq 1 ]; then |
Gavin Howard | 2f06134 | 2018-12-24 14:15:44 -0700 | [diff] [blame] | 445 | usage "Can only specify one of -b(-D) or -d(-B)" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 446 | fi |
| 447 | |
| 448 | case $karatsuba_len in |
Gavin Howard | ab6ba68 | 2019-05-10 08:42:15 -0600 | [diff] [blame] | 449 | (*[!0-9]*|'') usage "KARATSUBA_LEN is not a number" ;; |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 450 | (*) ;; |
| 451 | esac |
| 452 | |
Gavin Howard | df9b2a6 | 2019-05-10 18:39:01 -0600 | [diff] [blame] | 453 | if [ "$karatsuba_len" -lt 16 ]; then |
| 454 | usage "KARATSUBA_LEN is less than 16" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 455 | fi |
| 456 | |
Gavin Howard | ddff709 | 2019-03-30 14:58:24 -0600 | [diff] [blame] | 457 | set -e |
| 458 | |
Gavin Howard | 00e0eef | 2019-01-05 20:11:43 -0700 | [diff] [blame] | 459 | link="@printf 'No link necessary\\\\n'" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 460 | main_exec="BC" |
| 461 | executable="BC_EXEC" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 462 | |
Gavin Howard | 2fbbf25 | 2019-05-10 11:34:24 -0600 | [diff] [blame] | 463 | bc_test="@tests/all.sh bc $extra_math 1 $generate_tests 0 \$(BC_EXEC)" |
| 464 | bc_time_test="@tests/all.sh bc $extra_math 1 $generate_tests 1 \$(BC_EXEC)" |
| 465 | dc_test="@tests/all.sh dc $extra_math 1 $generate_tests 0 \$(DC_EXEC)" |
| 466 | dc_time_test="@tests/all.sh dc $extra_math 1 $generate_tests 1 \$(DC_EXEC)" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 467 | |
Gavin Howard | 36ae629 | 2019-04-01 07:30:27 -0600 | [diff] [blame] | 468 | timeconst="@tests/bc/timeconst.sh tests/bc/scripts/timeconst.bc \$(BC_EXEC)" |
Gavin Howard | a3af22f | 2018-12-13 16:53:58 -0700 | [diff] [blame] | 469 | |
| 470 | # In order to have cleanup at exit, we need to be in |
| 471 | # debug mode, so don't run valgrind without that. |
| 472 | if [ "$debug" -ne 0 ]; then |
Gavin Howard | 2fbbf25 | 2019-05-10 11:34:24 -0600 | [diff] [blame] | 473 | 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 Howard | a3af22f | 2018-12-13 16:53:58 -0700 | [diff] [blame] | 475 | else |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 476 | vg_bc_test="@printf 'Cannot run valgrind without debug flags\\\\n'" |
| 477 | vg_dc_test="@printf 'Cannot run valgrind without debug flags\\\\n'" |
Gavin Howard | a3af22f | 2018-12-13 16:53:58 -0700 | [diff] [blame] | 478 | fi |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 479 | |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 480 | karatsuba="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'" |
| 481 | karatsuba_test="@printf 'karatsuba cannot be run because one of bc or dc is not built\\\\n'" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 482 | |
Gavin Howard | 1fe4545 | 2018-12-20 10:34:05 -0700 | [diff] [blame] | 483 | bc_lib="\$(GEN_DIR)/lib.o" |
Gavin Howard | a1cd122 | 2019-01-02 14:40:46 -0700 | [diff] [blame] | 484 | bc_help="\$(GEN_DIR)/bc_help.o" |
| 485 | dc_help="\$(GEN_DIR)/dc_help.o" |
Gavin Howard | 1fe4545 | 2018-12-20 10:34:05 -0700 | [diff] [blame] | 486 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 487 | if [ "$bc_only" -eq 1 ]; then |
| 488 | |
| 489 | bc=1 |
| 490 | dc=0 |
| 491 | |
Gavin Howard | a1cd122 | 2019-01-02 14:40:46 -0700 | [diff] [blame] | 492 | dc_help="" |
Gavin Howard | 1fe4545 | 2018-12-20 10:34:05 -0700 | [diff] [blame] | 493 | |
Gavin Howard | f1a0404 | 2018-12-13 14:07:33 -0700 | [diff] [blame] | 494 | executables="bc" |
| 495 | |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 496 | dc_test="@printf 'No dc tests to run\\\\n'" |
Gavin Howard | 2fbbf25 | 2019-05-10 11:34:24 -0600 | [diff] [blame] | 497 | dc_time_test="@printf 'No dc tests to run\\\\n'" |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 498 | vg_dc_test="@printf 'No dc tests to run\\\\n'" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 499 | |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 500 | install_prereqs=" install_bc_manpage" |
Gavin Howard | 98fcceb | 2019-01-23 12:12:26 -0700 | [diff] [blame] | 501 | uninstall_prereqs=" uninstall_bc" |
| 502 | uninstall_man_prereqs=" uninstall_bc_manpage" |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 503 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 504 | elif [ "$dc_only" -eq 1 ]; then |
| 505 | |
| 506 | bc=0 |
| 507 | dc=1 |
| 508 | |
Gavin Howard | 1fe4545 | 2018-12-20 10:34:05 -0700 | [diff] [blame] | 509 | bc_lib="" |
Gavin Howard | a1cd122 | 2019-01-02 14:40:46 -0700 | [diff] [blame] | 510 | bc_help="" |
Gavin Howard | 8725070 | 2018-12-31 15:49:33 -0700 | [diff] [blame] | 511 | |
Gavin Howard | f1a0404 | 2018-12-13 14:07:33 -0700 | [diff] [blame] | 512 | executables="dc" |
| 513 | |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 514 | main_exec="DC" |
| 515 | executable="DC_EXEC" |
Gavin Howard | 4f3cf8d | 2018-12-13 11:33:19 -0700 | [diff] [blame] | 516 | |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 517 | bc_test="@printf 'No bc tests to run\\\\n'" |
Gavin Howard | 2fbbf25 | 2019-05-10 11:34:24 -0600 | [diff] [blame] | 518 | bc_time_test="@printf 'No bc tests to run\\\\n'" |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 519 | vg_bc_test="@printf 'No bc tests to run\\\\n'" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 520 | |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 521 | timeconst="@printf 'timeconst cannot be run because bc is not built\\\\n'" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 522 | |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 523 | install_prereqs=" install_dc_manpage" |
Gavin Howard | 98fcceb | 2019-01-23 12:12:26 -0700 | [diff] [blame] | 524 | uninstall_prereqs=" uninstall_dc" |
| 525 | uninstall_man_prereqs=" uninstall_dc_manpage" |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 526 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 527 | else |
| 528 | |
| 529 | bc=1 |
| 530 | dc=1 |
| 531 | |
Gavin Howard | f1a0404 | 2018-12-13 14:07:33 -0700 | [diff] [blame] | 532 | executables="bc and dc" |
| 533 | |
Gavin Howard | 36ae629 | 2019-04-01 07:30:27 -0600 | [diff] [blame] | 534 | link="\$(LINK) \$(BIN) \$(EXEC_PREFIX)\$(DC)" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 535 | |
Gavin Howard | 36ae629 | 2019-04-01 07:30:27 -0600 | [diff] [blame] | 536 | karatsuba="@\$(KARATSUBA) 0 \$(BC_EXEC)" |
Gavin Howard | 233cf1d | 2018-12-27 12:32:09 -0700 | [diff] [blame] | 537 | karatsuba_test="@\$(KARATSUBA) 100 \$(BC_EXEC)" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 538 | |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 539 | install_prereqs=" install_bc_manpage install_dc_manpage" |
Gavin Howard | 98fcceb | 2019-01-23 12:12:26 -0700 | [diff] [blame] | 540 | uninstall_prereqs=" uninstall_bc uninstall_dc" |
| 541 | uninstall_man_prereqs=" uninstall_bc_manpage uninstall_dc_manpage" |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 542 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 543 | fi |
| 544 | |
Gavin Howard | 277b514 | 2019-05-10 10:58:57 -0600 | [diff] [blame] | 545 | if [ -z "${LONG_BIT+set}" ]; then |
Gavin Howard | 51a87e9 | 2019-05-14 09:59:50 -0600 | [diff] [blame] | 546 | LONG_BIT_DEFINE="" |
Gavin Howard | bed3002 | 2019-05-18 23:56:26 -0600 | [diff] [blame] | 547 | elif [ "$LONG_BIT" -lt 32 ]; then |
| 548 | usage "LONG_BIT is less than 32" |
Gavin Howard | 51a87e9 | 2019-05-14 09:59:50 -0600 | [diff] [blame] | 549 | else |
| 550 | LONG_BIT_DEFINE="-DBC_LONG_BIT=\$(BC_LONG_BIT)" |
Gavin Howard | 277b514 | 2019-05-10 10:58:57 -0600 | [diff] [blame] | 551 | fi |
| 552 | |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 553 | if [ -z "${HOSTCFLAGS+set}" -a -z "${HOST_CFLAGS+set}" ]; then |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 554 | HOSTCFLAGS="$CFLAGS" |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 555 | elif [ -z "${HOSTCFLAGS+set}" ]; then |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 556 | HOSTCFLAGS="$HOST_CFLAGS" |
| 557 | fi |
| 558 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 559 | if [ "$debug" -eq 1 ]; then |
| 560 | |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 561 | if [ -z "$CFLAGS" -a -z "$optimization" ]; then |
Gavin Howard | 5cfc8dc | 2019-02-20 11:18:35 -0700 | [diff] [blame] | 562 | CFLAGS="-O0" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 563 | fi |
Gavin Howard | d366bb1 | 2018-12-19 14:05:13 -0700 | [diff] [blame] | 564 | |
Gavin Howard | 73c77ff | 2019-11-09 12:03:48 -0700 | [diff] [blame] | 565 | CFLAGS="-g $CFLAGS" |
Gavin Howard | 8725070 | 2018-12-31 15:49:33 -0700 | [diff] [blame] | 566 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 567 | else |
Gavin Howard | 73c77ff | 2019-11-09 12:03:48 -0700 | [diff] [blame] | 568 | CPPFLAGS="-DNDEBUG $CPPFLAGS" |
Gavin Howard | 96ac427 | 2019-11-27 22:16:26 -0700 | [diff] [blame] | 569 | if [ "$strip_bin" -ne 0 ]; then |
| 570 | LDFLAGS="-s $LDFLAGS" |
| 571 | fi |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 572 | fi |
| 573 | |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 574 | if [ -n "$optimization" ]; then |
Gavin Howard | 73c77ff | 2019-11-09 12:03:48 -0700 | [diff] [blame] | 575 | CFLAGS="-O$optimization $CFLAGS" |
Gavin Howard | 24f942f | 2018-12-20 10:08:49 -0700 | [diff] [blame] | 576 | fi |
| 577 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 578 | if [ "$coverage" -eq 1 ]; then |
| 579 | |
| 580 | if [ "$bc_only" -eq 1 -o "$dc_only" -eq 1 ]; then |
Gavin Howard | 629b5c0 | 2018-12-12 03:21:01 -0700 | [diff] [blame] | 581 | usage "Can only specify -c without -b or -d" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 582 | fi |
| 583 | |
Gavin Howard | 73c77ff | 2019-11-09 12:03:48 -0700 | [diff] [blame] | 584 | CFLAGS="-fprofile-arcs -ftest-coverage -g -O0 $CFLAGS" |
| 585 | CPPFLAGS="-DNDEBUG $CPPFLAGS" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 586 | |
Gavin Howard | f01c138 | 2018-12-27 13:22:55 -0700 | [diff] [blame] | 587 | COVERAGE="@gcov -pabcdf \$(GCDA) \$(BC_GCDA) \$(DC_GCDA)" |
Gavin Howard | 62cf3ca | 2018-12-13 13:30:29 -0700 | [diff] [blame] | 588 | COVERAGE="$COVERAGE;\$(RM) -f \$(GEN)*.gc*" |
Gavin Howard | 573259c | 2018-12-28 00:11:28 -0700 | [diff] [blame] | 589 | COVERAGE="$COVERAGE;gcovr --html-details --output index.html" |
Gavin Howard | ce513f7 | 2019-02-15 08:52:57 -0700 | [diff] [blame] | 590 | COVERAGE_PREREQS=" test" |
Gavin Howard | 62cf3ca | 2018-12-13 13:30:29 -0700 | [diff] [blame] | 591 | |
| 592 | else |
Gavin Howard | 6686f6b | 2019-01-05 20:35:26 -0700 | [diff] [blame] | 593 | COVERAGE="@printf 'Coverage not generated\\\\n'" |
Gavin Howard | 62cf3ca | 2018-12-13 13:30:29 -0700 | [diff] [blame] | 594 | COVERAGE_PREREQS="" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 595 | fi |
| 596 | |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 597 | if [ -z "${DESTDIR+set}" ]; then |
| 598 | destdir="" |
| 599 | else |
| 600 | destdir="DESTDIR = $DESTDIR" |
| 601 | fi |
| 602 | |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 603 | if [ -z "${PREFIX+set}" ]; then |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 604 | PREFIX="/usr/local" |
| 605 | fi |
| 606 | |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 607 | if [ -z "${BINDIR+set}" ]; then |
Gavin Howard | 471b6c0 | 2019-01-17 14:25:07 -0700 | [diff] [blame] | 608 | BINDIR="$PREFIX/bin" |
| 609 | fi |
| 610 | |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 611 | if [ "$install_manpages" -ne 0 -o "$nls" -ne 0 ]; then |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 612 | if [ -z "${DATAROOTDIR+set}" ]; then |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 613 | DATAROOTDIR="$PREFIX/share" |
| 614 | fi |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 615 | fi |
| 616 | |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 617 | if [ "$install_manpages" -ne 0 ]; then |
Gavin Howard | 471b6c0 | 2019-01-17 14:25:07 -0700 | [diff] [blame] | 618 | |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 619 | if [ -z "${DATADIR+set}" ]; then |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 620 | DATADIR="$DATAROOTDIR" |
| 621 | fi |
Gavin Howard | 471b6c0 | 2019-01-17 14:25:07 -0700 | [diff] [blame] | 622 | |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 623 | if [ -z "${MANDIR+set}" ]; then |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 624 | MANDIR="$DATADIR/man" |
| 625 | fi |
| 626 | |
Gavin Howard | 05ae38d | 2019-04-08 09:48:19 -0600 | [diff] [blame] | 627 | if [ -z "${MAN1DIR+set}" ]; then |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 628 | MAN1DIR="$MANDIR/man1" |
| 629 | fi |
| 630 | |
| 631 | else |
| 632 | install_prereqs="" |
Gavin Howard | 98fcceb | 2019-01-23 12:12:26 -0700 | [diff] [blame] | 633 | uninstall_man_prereqs="" |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 634 | fi |
| 635 | |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 636 | if [ -z "$CC" ]; then |
Gavin Howard | 67222d3 | 2018-12-14 12:38:10 -0700 | [diff] [blame] | 637 | CC="c99" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 638 | fi |
| 639 | |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 640 | if [ -z "$HOSTCC" -a -z "$HOST_CC" ]; then |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 641 | HOSTCC="$CC" |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 642 | elif [ -z "$HOSTCC" ]; then |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 643 | HOSTCC="$HOST_CC" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 644 | fi |
| 645 | |
Gavin Howard | 91c3801 | 2019-04-09 14:42:22 -0600 | [diff] [blame] | 646 | if [ "$nls" -ne 0 ]; then |
Gavin Howard | 54dfdc6 | 2019-03-27 11:09:10 -0600 | [diff] [blame] | 647 | |
| 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 Howard | d8dced3 | 2019-03-30 14:58:59 -0600 | [diff] [blame] | 655 | flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" |
Gavin Howard | 54dfdc6 | 2019-03-27 11:09:10 -0600 | [diff] [blame] | 656 | |
Gavin Howard | 73c77ff | 2019-11-09 12:03:48 -0700 | [diff] [blame] | 657 | "$HOSTCC" $HOSTCFLAGS $flags -c "src/vm.c" -o "$scriptdir/vm.o" > /dev/null 2>&1 |
Gavin Howard | 54dfdc6 | 2019-03-27 11:09:10 -0600 | [diff] [blame] | 658 | |
| 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 Howard | e2d185f | 2019-08-03 12:13:46 -0600 | [diff] [blame] | 667 | if [ $force -eq 0 ]; then |
| 668 | printf 'Disabling NLS...\n' |
| 669 | nls=0 |
| 670 | else |
| 671 | printf 'Forcing NLS...\n' |
| 672 | fi |
Gavin Howard | 54dfdc6 | 2019-03-27 11:09:10 -0600 | [diff] [blame] | 673 | else |
Gavin Howard | 5d0d10e | 2019-04-05 13:53:50 -0600 | [diff] [blame] | 674 | printf 'NLS works.\n\n' |
| 675 | |
Gavin Howard | f8a5d39 | 2019-04-05 14:07:57 -0600 | [diff] [blame] | 676 | printf 'Testing gencat...\n' |
Gavin Howard | ea73c8c | 2019-04-09 07:21:38 -0600 | [diff] [blame] | 677 | gencat "$scriptdir/en_US.cat" "$scriptdir/locales/en_US.msg" > /dev/null 2>&1 |
Gavin Howard | f8a5d39 | 2019-04-05 14:07:57 -0600 | [diff] [blame] | 678 | |
| 679 | err="$?" |
| 680 | |
Gavin Howard | ea73c8c | 2019-04-09 07:21:38 -0600 | [diff] [blame] | 681 | rm -rf "$scriptdir/en_US.cat" |
Gavin Howard | f8a5d39 | 2019-04-05 14:07:57 -0600 | [diff] [blame] | 682 | |
| 683 | if [ "$err" -ne 0 ]; then |
| 684 | printf 'gencat does not work.\n' |
Gavin Howard | e2d185f | 2019-08-03 12:13:46 -0600 | [diff] [blame] | 685 | 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 Howard | 5d0d10e | 2019-04-05 13:53:50 -0600 | [diff] [blame] | 691 | else |
Gavin Howard | 91c3801 | 2019-04-09 14:42:22 -0600 | [diff] [blame] | 692 | |
Gavin Howard | f8a5d39 | 2019-04-05 14:07:57 -0600 | [diff] [blame] | 693 | printf 'gencat works.\n\n' |
Gavin Howard | 91c3801 | 2019-04-09 14:42:22 -0600 | [diff] [blame] | 694 | |
Gavin Howard | 8752b26 | 2019-04-09 14:54:52 -0600 | [diff] [blame] | 695 | 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 Howard | 91c3801 | 2019-04-09 14:42:22 -0600 | [diff] [blame] | 701 | 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 Howard | 5d0d10e | 2019-04-05 13:53:50 -0600 | [diff] [blame] | 708 | fi |
| 709 | |
Gavin Howard | 54dfdc6 | 2019-03-27 11:09:10 -0600 | [diff] [blame] | 710 | fi |
| 711 | |
| 712 | set -e |
| 713 | |
Gavin Howard | 91c3801 | 2019-04-09 14:42:22 -0600 | [diff] [blame] | 714 | else |
| 715 | install_locales_prereqs="" |
| 716 | uninstall_locales_prereqs="" |
Gavin Howard | 54dfdc6 | 2019-03-27 11:09:10 -0600 | [diff] [blame] | 717 | fi |
| 718 | |
Gavin Howard | 2a669ea | 2018-12-24 12:19:20 -0700 | [diff] [blame] | 719 | if [ "$hist" -eq 1 ]; then |
| 720 | |
| 721 | set +e |
| 722 | |
Gavin Howard | 4fe954e | 2018-12-24 14:06:18 -0700 | [diff] [blame] | 723 | printf 'Testing history...\n' |
| 724 | |
Gavin Howard | 401954f | 2019-02-19 11:56:04 -0700 | [diff] [blame] | 725 | flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc -DBC_ENABLE_SIGNALS=$signals" |
Gavin Howard | efa3495 | 2019-02-21 11:44:58 -0700 | [diff] [blame] | 726 | flags="$flags -DBC_ENABLE_NLS=$nls" |
Gavin Howard | a2e5bb0 | 2019-02-23 12:34:05 -0700 | [diff] [blame] | 727 | flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/" |
Gavin Howard | d8dced3 | 2019-03-30 14:58:59 -0600 | [diff] [blame] | 728 | flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" |
Gavin Howard | 2a669ea | 2018-12-24 12:19:20 -0700 | [diff] [blame] | 729 | |
Gavin Howard | 73c77ff | 2019-11-09 12:03:48 -0700 | [diff] [blame] | 730 | "$HOSTCC" $HOSTCFLAGS $flags -c "src/history/history.c" -o "$scriptdir/history.o" > /dev/null 2>&1 |
Gavin Howard | 2a669ea | 2018-12-24 12:19:20 -0700 | [diff] [blame] | 731 | |
| 732 | err="$?" |
| 733 | |
Gavin Howard | 26c7b19 | 2018-12-25 11:25:01 -0700 | [diff] [blame] | 734 | rm -rf "$scriptdir/history.o" |
| 735 | |
Gavin Howard | 2a669ea | 2018-12-24 12:19:20 -0700 | [diff] [blame] | 736 | # 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 Howard | 959375c | 2018-12-24 14:07:02 -0700 | [diff] [blame] | 739 | printf 'History does not work.\n' |
Gavin Howard | e2d185f | 2019-08-03 12:13:46 -0600 | [diff] [blame] | 740 | if [ $force -eq 0 ]; then |
| 741 | printf 'Disabling history...\n' |
| 742 | hist=0 |
| 743 | else |
| 744 | printf 'Forcing history...\n' |
| 745 | fi |
Gavin Howard | 57ef47e | 2018-12-24 14:08:35 -0700 | [diff] [blame] | 746 | else |
| 747 | printf 'History works.\n' |
Gavin Howard | 2a669ea | 2018-12-24 12:19:20 -0700 | [diff] [blame] | 748 | fi |
| 749 | |
| 750 | set -e |
| 751 | |
| 752 | fi |
| 753 | |
Gavin Howard | a1cd122 | 2019-01-02 14:40:46 -0700 | [diff] [blame] | 754 | if [ "$extra_math" -eq 1 -a "$bc" -ne 0 ]; then |
Gavin Howard | 6fcb504 | 2018-12-26 17:44:06 -0700 | [diff] [blame] | 755 | BC_LIB2_O="\$(GEN_DIR)/lib2.o" |
| 756 | else |
| 757 | BC_LIB2_O="" |
| 758 | fi |
| 759 | |
Gavin Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 760 | GEN="strgen" |
| 761 | GEN_EXEC_TARGET="\$(HOSTCC) \$(HOSTCFLAGS) -o \$(GEN_EXEC) \$(GEN_C)" |
| 762 | CLEAN_PREREQS=" clean_gen" |
| 763 | |
| 764 | if [ -z "${GEN_HOST+set}" ]; then |
| 765 | GEN_HOST=1 |
| 766 | else |
| 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 |
| 772 | fi |
| 773 | |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 774 | # Print out the values; this is for debugging. |
| 775 | printf '\n' |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 776 | if [ "$bc" -ne 0 ]; then |
| 777 | printf 'Building bc\n' |
| 778 | else |
| 779 | printf 'Not building bc\n' |
| 780 | fi |
| 781 | if [ "$dc" -ne 0 ]; then |
| 782 | printf 'Building dc\n' |
| 783 | else |
| 784 | printf 'Not building dc\n' |
| 785 | fi |
| 786 | printf '\n' |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 787 | printf 'BC_ENABLE_SIGNALS=%s\n' "$signals" |
| 788 | printf 'BC_ENABLE_HISTORY=%s\n' "$hist" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 789 | printf 'BC_ENABLE_EXTRA_MATH=%s\n' "$extra_math" |
| 790 | printf 'BC_ENABLE_NLS=%s\n' "$nls" |
Gavin Howard | 1444c9f | 2019-06-21 21:16:11 -0600 | [diff] [blame] | 791 | printf 'BC_ENABLE_PROMPT=%s\n' "$prompt" |
Gavin Howard | 64005c4 | 2019-01-29 10:32:52 -0700 | [diff] [blame] | 792 | printf '\n' |
Gavin Howard | df9b2a6 | 2019-05-10 18:39:01 -0600 | [diff] [blame] | 793 | printf 'BC_NUM_KARATSUBA_LEN=%s\n' "$karatsuba_len" |
| 794 | printf '\n' |
Gavin Howard | 64005c4 | 2019-01-29 10:32:52 -0700 | [diff] [blame] | 795 | printf 'CC=%s\n' "$CC" |
| 796 | printf 'CFLAGS=%s\n' "$CFLAGS" |
| 797 | printf 'HOSTCC=%s\n' "$HOSTCC" |
| 798 | printf 'HOSTCFLAGS=%s\n' "$HOSTCFLAGS" |
| 799 | printf 'CPPFLAGS=%s\n' "$CPPFLAGS" |
| 800 | printf 'LDFLAGS=%s\n' "$LDFLAGS" |
| 801 | printf 'PREFIX=%s\n' "$PREFIX" |
| 802 | printf 'BINDIR=%s\n' "$BINDIR" |
| 803 | printf 'DATAROOTDIR=%s\n' "$DATAROOTDIR" |
| 804 | printf 'DATADIR=%s\n' "$DATADIR" |
| 805 | printf 'MANDIR=%s\n' "$MANDIR" |
| 806 | printf 'MAN1DIR=%s\n' "$MAN1DIR" |
Gavin Howard | bc02129 | 2019-04-09 10:04:01 -0600 | [diff] [blame] | 807 | printf 'NLSPATH=%s\n' "$NLSPATH" |
Gavin Howard | 64005c4 | 2019-01-29 10:32:52 -0700 | [diff] [blame] | 808 | printf 'EXECSUFFIX=%s\n' "$EXECSUFFIX" |
Gavin Howard | 36ae629 | 2019-04-01 07:30:27 -0600 | [diff] [blame] | 809 | printf 'EXECPREFIX=%s\n' "$EXECPREFIX" |
Gavin Howard | 64005c4 | 2019-01-29 10:32:52 -0700 | [diff] [blame] | 810 | printf 'DESTDIR=%s\n' "$DESTDIR" |
Gavin Howard | 277b514 | 2019-05-10 10:58:57 -0600 | [diff] [blame] | 811 | printf 'LONG_BIT=%s\n' "$LONG_BIT" |
Gavin Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 812 | printf 'GEN_HOST=%s\n' "$GEN_HOST" |
Gavin Howard | 64005c4 | 2019-01-29 10:32:52 -0700 | [diff] [blame] | 813 | printf 'GEN_EMU=%s\n' "$GEN_EMU" |
| 814 | |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 815 | contents=$(cat "$scriptdir/Makefile.in") |
| 816 | |
| 817 | needle="WARNING" |
Gavin Howard | b55ad00 | 2018-12-20 16:59:23 -0700 | [diff] [blame] | 818 | replacement='*** WARNING: Autogenerated from Makefile.in. DO NOT MODIFY ***' |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 819 | |
| 820 | contents=$(replace "$contents" "$needle" "$replacement") |
| 821 | |
| 822 | contents=$(gen_file_lists "$contents" "$scriptdir/src" "") |
Gavin Howard | e18c248 | 2018-12-20 11:15:28 -0700 | [diff] [blame] | 823 | contents=$(gen_file_lists "$contents" "$scriptdir/src/bc" "BC_" "$bc") |
| 824 | contents=$(gen_file_lists "$contents" "$scriptdir/src/dc" "DC_" "$dc") |
| 825 | contents=$(gen_file_lists "$contents" "$scriptdir/src/history" "HISTORY_" "$hist") |
Gavin Howard | 6a94fd7 | 2018-12-20 10:28:42 -0700 | [diff] [blame] | 826 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 827 | contents=$(replace "$contents" "BC_ENABLED" "$bc") |
| 828 | contents=$(replace "$contents" "DC_ENABLED" "$dc") |
| 829 | contents=$(replace "$contents" "LINK" "$link") |
| 830 | |
| 831 | contents=$(replace "$contents" "SIGNALS" "$signals") |
| 832 | contents=$(replace "$contents" "HISTORY" "$hist") |
Gavin Howard | 6fcb504 | 2018-12-26 17:44:06 -0700 | [diff] [blame] | 833 | contents=$(replace "$contents" "EXTRA_MATH" "$extra_math") |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 834 | contents=$(replace "$contents" "NLS" "$nls") |
Gavin Howard | 1444c9f | 2019-06-21 21:16:11 -0600 | [diff] [blame] | 835 | contents=$(replace "$contents" "PROMPT" "$prompt") |
Gavin Howard | a1cd122 | 2019-01-02 14:40:46 -0700 | [diff] [blame] | 836 | contents=$(replace "$contents" "BC_LIB_O" "$bc_lib") |
| 837 | contents=$(replace "$contents" "BC_HELP_O" "$bc_help") |
| 838 | contents=$(replace "$contents" "DC_HELP_O" "$dc_help") |
Gavin Howard | 6fcb504 | 2018-12-26 17:44:06 -0700 | [diff] [blame] | 839 | contents=$(replace "$contents" "BC_LIB2_O" "$BC_LIB2_O") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 840 | contents=$(replace "$contents" "KARATSUBA_LEN" "$karatsuba_len") |
| 841 | |
Gavin Howard | bc02129 | 2019-04-09 10:04:01 -0600 | [diff] [blame] | 842 | contents=$(replace "$contents" "NLSPATH" "$NLSPATH") |
Gavin Howard | 9a67974 | 2019-04-06 09:44:57 -0600 | [diff] [blame] | 843 | contents=$(replace "$contents" "DESTDIR" "$destdir") |
Gavin Howard | 5d05715 | 2019-01-29 10:31:40 -0700 | [diff] [blame] | 844 | contents=$(replace "$contents" "EXECSUFFIX" "$EXECSUFFIX") |
Gavin Howard | 36ae629 | 2019-04-01 07:30:27 -0600 | [diff] [blame] | 845 | contents=$(replace "$contents" "EXECPREFIX" "$EXECPREFIX") |
Gavin Howard | 471b6c0 | 2019-01-17 14:25:07 -0700 | [diff] [blame] | 846 | contents=$(replace "$contents" "BINDIR" "$BINDIR") |
| 847 | contents=$(replace "$contents" "MAN1DIR" "$MAN1DIR") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 848 | contents=$(replace "$contents" "CFLAGS" "$CFLAGS") |
Gavin Howard | 593a518 | 2019-01-17 10:22:45 -0700 | [diff] [blame] | 849 | contents=$(replace "$contents" "HOSTCFLAGS" "$HOSTCFLAGS") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 850 | contents=$(replace "$contents" "CPPFLAGS" "$CPPFLAGS") |
| 851 | contents=$(replace "$contents" "LDFLAGS" "$LDFLAGS") |
| 852 | contents=$(replace "$contents" "CC" "$CC") |
| 853 | contents=$(replace "$contents" "HOSTCC" "$HOSTCC") |
| 854 | contents=$(replace "$contents" "COVERAGE" "$COVERAGE") |
Gavin Howard | 62cf3ca | 2018-12-13 13:30:29 -0700 | [diff] [blame] | 855 | contents=$(replace "$contents" "COVERAGE_PREREQS" "$COVERAGE_PREREQS") |
Gavin Howard | 074b38a | 2019-01-17 11:15:59 -0700 | [diff] [blame] | 856 | contents=$(replace "$contents" "INSTALL_PREREQS" "$install_prereqs") |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 857 | contents=$(replace "$contents" "INSTALL_LOCALES_PREREQS" "$install_locales_prereqs") |
Gavin Howard | 98fcceb | 2019-01-23 12:12:26 -0700 | [diff] [blame] | 858 | contents=$(replace "$contents" "UNINSTALL_MAN_PREREQS" "$uninstall_man_prereqs") |
Gavin Howard | ed9b6c2 | 2019-01-23 12:02:43 -0700 | [diff] [blame] | 859 | contents=$(replace "$contents" "UNINSTALL_PREREQS" "$uninstall_prereqs") |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 860 | contents=$(replace "$contents" "UNINSTALL_LOCALES_PREREQS" "$uninstall_locales_prereqs") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 861 | |
Gavin Howard | f1a0404 | 2018-12-13 14:07:33 -0700 | [diff] [blame] | 862 | contents=$(replace "$contents" "EXECUTABLES" "$executables") |
Gavin Howard | 4f3cf8d | 2018-12-13 11:33:19 -0700 | [diff] [blame] | 863 | contents=$(replace "$contents" "MAIN_EXEC" "$main_exec") |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 864 | contents=$(replace "$contents" "EXEC" "$executable") |
Gavin Howard | 4f3cf8d | 2018-12-13 11:33:19 -0700 | [diff] [blame] | 865 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 866 | contents=$(replace "$contents" "BC_TEST" "$bc_test") |
Gavin Howard | 2fbbf25 | 2019-05-10 11:34:24 -0600 | [diff] [blame] | 867 | contents=$(replace "$contents" "BC_TIME_TEST" "$bc_time_test") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 868 | contents=$(replace "$contents" "DC_TEST" "$dc_test") |
Gavin Howard | 2fbbf25 | 2019-05-10 11:34:24 -0600 | [diff] [blame] | 869 | contents=$(replace "$contents" "DC_TIME_TEST" "$dc_time_test") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 870 | |
| 871 | contents=$(replace "$contents" "VG_BC_TEST" "$vg_bc_test") |
| 872 | contents=$(replace "$contents" "VG_DC_TEST" "$vg_dc_test") |
| 873 | |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 874 | contents=$(replace "$contents" "TIMECONST" "$timeconst") |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 875 | |
| 876 | contents=$(replace "$contents" "KARATSUBA" "$karatsuba") |
| 877 | contents=$(replace "$contents" "KARATSUBA_TEST" "$karatsuba_test") |
| 878 | |
Gavin Howard | 277b514 | 2019-05-10 10:58:57 -0600 | [diff] [blame] | 879 | contents=$(replace "$contents" "LONG_BIT" "$LONG_BIT") |
Gavin Howard | 51a87e9 | 2019-05-14 09:59:50 -0600 | [diff] [blame] | 880 | contents=$(replace "$contents" "LONG_BIT_DEFINE" "$LONG_BIT_DEFINE") |
Gavin Howard | 277b514 | 2019-05-10 10:58:57 -0600 | [diff] [blame] | 881 | |
Gavin Howard | a513224 | 2019-04-22 08:34:28 -0600 | [diff] [blame] | 882 | contents=$(replace "$contents" "GEN" "$GEN") |
| 883 | contents=$(replace "$contents" "GEN_EXEC_TARGET" "$GEN_EXEC_TARGET") |
| 884 | contents=$(replace "$contents" "CLEAN_PREREQS" "$CLEAN_PREREQS") |
Gavin Howard | 4dff545 | 2018-12-20 10:06:58 -0700 | [diff] [blame] | 885 | contents=$(replace "$contents" "GEN_EMU" "$GEN_EMU") |
| 886 | |
Gavin Howard | d15e01d | 2018-12-19 12:49:02 -0700 | [diff] [blame] | 887 | printf '%s\n' "$contents" > "$scriptdir/Makefile" |
Gavin Howard | 27fa9cd | 2018-12-12 02:52:52 -0700 | [diff] [blame] | 888 | |
| 889 | cd "$scriptdir" |
| 890 | |
| 891 | make clean > /dev/null |