1252884aeSStefan Eßer# Build 2252884aeSStefan Eßer 3252884aeSStefan EßerThis `bc` attempts to be as portable as possible. It can be built on any 4252884aeSStefan EßerPOSIX-compliant system. 5252884aeSStefan Eßer 6252884aeSStefan EßerTo accomplish that, a POSIX-compatible, custom `configure.sh` script is used to 7252884aeSStefan Eßerselect build options, compiler, and compiler flags and generate a `Makefile`. 8252884aeSStefan Eßer 9252884aeSStefan EßerThe general form of configuring, building, and installing this `bc` is as 10252884aeSStefan Eßerfollows: 11252884aeSStefan Eßer 12252884aeSStefan Eßer``` 13252884aeSStefan Eßer[ENVIRONMENT_VARIABLE=<value>...] ./configure.sh [build_options...] 14252884aeSStefan Eßermake 15252884aeSStefan Eßermake install 16252884aeSStefan Eßer``` 17252884aeSStefan Eßer 18252884aeSStefan EßerTo get all of the options, including any useful environment variables, use 19252884aeSStefan Eßereither one of the following commands: 20252884aeSStefan Eßer 21252884aeSStefan Eßer``` 22252884aeSStefan Eßer./configure.sh -h 23252884aeSStefan Eßer./configure.sh --help 24252884aeSStefan Eßer``` 25252884aeSStefan Eßer 26252884aeSStefan Eßer***WARNING***: even though `configure.sh` supports both option types, short and 27252884aeSStefan Eßerlong, it does not support handling both at the same time. Use only one type. 28252884aeSStefan Eßer 29252884aeSStefan EßerTo learn the available `make` targets run the following command after running 30252884aeSStefan Eßerthe `configure.sh` script: 31252884aeSStefan Eßer 32252884aeSStefan Eßer``` 33252884aeSStefan Eßermake help 34252884aeSStefan Eßer``` 35252884aeSStefan Eßer 36252884aeSStefan EßerSee [Build Environment Variables][4] for a more detailed description of all 37252884aeSStefan Eßeraccepted environment variables and [Build Options][5] for more detail about all 38252884aeSStefan Eßeraccepted build options. 39252884aeSStefan Eßer 407e5c51e5SStefan Eßer## Windows 417e5c51e5SStefan Eßer 4244d4804dSStefan EßerFor releases, Windows builds of `bc`, `dc`, and `bcl` are available for download 43*4fca8e0fSStefan Eßerfrom <https://git.gavinhoward.com/gavin/bc> and GitHub. 447e5c51e5SStefan Eßer 4544d4804dSStefan EßerHowever, if you wish to build it yourself, this `bc` can be built using Visual 4644d4804dSStefan EßerStudio or MSBuild. 4744d4804dSStefan Eßer 4844d4804dSStefan EßerUnfortunately, only one build configuration (besides Debug or Release) is 4978bc019dSStefan Eßersupported: extra math and history enabled, NLS (locale support) disabled, with 5044d4804dSStefan Eßerboth calculators built. The default [settings][11] are `BC_BANNER=1`, 5144d4804dSStefan Eßer`{BC,DC}_SIGINT_RESET=0`, `{BC,DC}_TTY_MODE=1`, `{BC,DC}_PROMPT=1`. 527e5c51e5SStefan Eßer 537e5c51e5SStefan EßerThe library can also be built on Windows. 547e5c51e5SStefan Eßer 557e5c51e5SStefan Eßer### Visual Studio 567e5c51e5SStefan Eßer 577e5c51e5SStefan EßerIn Visual Studio, open up the solution file (`bc.sln` for `bc`, or `bcl.sln` for 587e5c51e5SStefan Eßerthe library), select the desired configuration, and build. 597e5c51e5SStefan Eßer 607e5c51e5SStefan Eßer### MSBuild 617e5c51e5SStefan Eßer 627e5c51e5SStefan EßerTo build with MSBuild, first, *be sure that you are using the MSBuild that comes 637e5c51e5SStefan Eßerwith Visual Studio*. 647e5c51e5SStefan Eßer 657e5c51e5SStefan EßerTo build `bc`, run the following from the root directory: 667e5c51e5SStefan Eßer 677e5c51e5SStefan Eßer``` 68a30efc5cSStefan Eßermsbuild -property:Configuration=<config> vs/bc.sln 697e5c51e5SStefan Eßer``` 707e5c51e5SStefan Eßer 717e5c51e5SStefan Eßerwhere `<config>` is either one of `Debug` or `Release`. 727e5c51e5SStefan Eßer 737e5c51e5SStefan EßerTo build the library, run the following from the root directory: 747e5c51e5SStefan Eßer 757e5c51e5SStefan Eßer``` 76a30efc5cSStefan Eßermsbuild -property:Configuration=<config> vs/bcl.sln 777e5c51e5SStefan Eßer``` 787e5c51e5SStefan Eßer 79a30efc5cSStefan Eßerwhere `<config>` is either one of `Debug`, `ReleaseMD`, or `ReleaseMT`. 807e5c51e5SStefan Eßer 817e5c51e5SStefan Eßer## POSIX-Compatible Systems 827e5c51e5SStefan Eßer 837e5c51e5SStefan EßerBuilding `bc`, `dc`, and `bcl` (the library) is more complex than on Windows 847e5c51e5SStefan Eßerbecause many build options are supported. 857e5c51e5SStefan Eßer 8610041e99SStefan Eßer### Out-of-Source Builds 8710041e99SStefan Eßer 8810041e99SStefan EßerOut-of-source builds are done by calling `configure.sh` from the directory where 8910041e99SStefan Eßerthe build will happen. The `Makefile` is generated into that directory, and the 9010041e99SStefan Eßerbuild can happen normally from there. 9110041e99SStefan Eßer 9210041e99SStefan EßerFor example, if the source is in `bc`, the build should happen in `build`, then 9310041e99SStefan Eßercall `configure.sh` and `make` like so: 9410041e99SStefan Eßer 9510041e99SStefan Eßer``` 9610041e99SStefan Eßer../bc/configure.sh 9710041e99SStefan Eßermake 9810041e99SStefan Eßer``` 9910041e99SStefan Eßer 10010041e99SStefan Eßer***WARNING***: The path to `configure.sh` from the build directory must not have 10110041e99SStefan Eßerspaces because `make` does not support target names with spaces. 10210041e99SStefan Eßer 1037e5c51e5SStefan Eßer### Cross Compiling 104252884aeSStefan Eßer 105252884aeSStefan EßerTo cross-compile this `bc`, an appropriate compiler must be present and assigned 106252884aeSStefan Eßerto the environment variable `HOSTCC` or `HOST_CC` (the two are equivalent, 107252884aeSStefan Eßerthough `HOSTCC` is prioritized). This is in order to bootstrap core file(s), if 108252884aeSStefan Eßerthe architectures are not compatible (i.e., unlike i686 on x86_64). Thus, the 109252884aeSStefan Eßerapproach is: 110252884aeSStefan Eßer 111252884aeSStefan Eßer``` 112252884aeSStefan EßerHOSTCC="/path/to/native/compiler" ./configure.sh 113252884aeSStefan Eßermake 114252884aeSStefan Eßermake install 115252884aeSStefan Eßer``` 116252884aeSStefan Eßer 117252884aeSStefan Eßer`HOST_CC` will work in exactly the same way. 118252884aeSStefan Eßer 119252884aeSStefan Eßer`HOSTCFLAGS` and `HOST_CFLAGS` can be used to set compiler flags for `HOSTCC`. 120252884aeSStefan Eßer(The two are equivalent, as `HOSTCC` and `HOST_CC` are.) `HOSTCFLAGS` is 121252884aeSStefan Eßerprioritized over `HOST_CFLAGS`. If neither are present, `HOSTCC` (or `HOST_CC`) 122252884aeSStefan Eßeruses `CFLAGS` (see [Build Environment Variables][4] for more details). 123252884aeSStefan Eßer 124252884aeSStefan EßerIt is expected that `CC` produces code for the target system and `HOSTCC` 125252884aeSStefan Eßerproduces code for the host system. See [Build Environment Variables][4] for more 126252884aeSStefan Eßerdetails. 127252884aeSStefan Eßer 128252884aeSStefan EßerIf an emulator is necessary to run the bootstrap binaries, it can be set with 129252884aeSStefan Eßerthe environment variable `GEN_EMU`. 130252884aeSStefan Eßer 1317e5c51e5SStefan Eßer### Build Environment Variables 132252884aeSStefan Eßer 133252884aeSStefan EßerThis `bc` supports `CC`, `HOSTCC`, `HOST_CC`, `CFLAGS`, `HOSTCFLAGS`, 134252884aeSStefan Eßer`HOST_CFLAGS`, `CPPFLAGS`, `LDFLAGS`, `LDLIBS`, `PREFIX`, `DESTDIR`, `BINDIR`, 135d101cdd6SStefan Eßer`DATAROOTDIR`, `DATADIR`, `MANDIR`, `MAN1DIR`, `MAN3DIR`, `EXECSUFFIX`, 136252884aeSStefan Eßer`EXECPREFIX`, `LONG_BIT`, `GEN_HOST`, and `GEN_EMU` environment variables in 137252884aeSStefan Eßer`configure.sh`. Any values of those variables given to `configure.sh` will be 138252884aeSStefan Eßerput into the generated Makefile. 139252884aeSStefan Eßer 140252884aeSStefan EßerMore detail on what those environment variables do can be found in the following 141252884aeSStefan Eßersections. 142252884aeSStefan Eßer 1437e5c51e5SStefan Eßer#### `CC` 144252884aeSStefan Eßer 145252884aeSStefan EßerC compiler for the target system. `CC` must be compatible with POSIX `c99` 146252884aeSStefan Eßerbehavior and options. However, **I encourage users to use any C99 or C11 147252884aeSStefan Eßercompatible compiler they wish.** 148252884aeSStefan Eßer 149252884aeSStefan EßerIf there is a space in the basename of the compiler, the items after the first 150252884aeSStefan Eßerspace are assumed to be compiler flags, and in that case, the flags are 151252884aeSStefan Eßerautomatically moved into CFLAGS. 152252884aeSStefan Eßer 153252884aeSStefan EßerDefaults to `c99`. 154252884aeSStefan Eßer 15544d4804dSStefan Eßer#### `HOSTCC` or `HOST_CC` 156252884aeSStefan Eßer 157252884aeSStefan EßerC compiler for the host system, used only in [cross compiling][6]. Must be 158252884aeSStefan Eßercompatible with POSIX `c99` behavior and options. 159252884aeSStefan Eßer 160252884aeSStefan EßerIf there is a space in the basename of the compiler, the items after the first 161252884aeSStefan Eßerspace are assumed to be compiler flags, and in that case, the flags are 162252884aeSStefan Eßerautomatically moved into HOSTCFLAGS. 163252884aeSStefan Eßer 164252884aeSStefan EßerDefaults to `$CC`. 165252884aeSStefan Eßer 1667e5c51e5SStefan Eßer#### `CFLAGS` 167252884aeSStefan Eßer 168252884aeSStefan EßerCommand-line flags that will be passed verbatim to `CC`. 169252884aeSStefan Eßer 170252884aeSStefan EßerDefaults to empty. 171252884aeSStefan Eßer 1727e5c51e5SStefan Eßer#### `HOSTCFLAGS` or `HOST_CFLAGS` 173252884aeSStefan Eßer 174252884aeSStefan EßerCommand-line flags that will be passed verbatim to `HOSTCC` or `HOST_CC`. 175252884aeSStefan Eßer 176252884aeSStefan EßerDefaults to `$CFLAGS`. 177252884aeSStefan Eßer 1787e5c51e5SStefan Eßer#### `CPPFLAGS` 179252884aeSStefan Eßer 180252884aeSStefan EßerCommand-line flags for the C preprocessor. These are also passed verbatim to 181252884aeSStefan Eßerboth compilers (`CC` and `HOSTCC`); they are supported just for legacy reasons. 182252884aeSStefan Eßer 183252884aeSStefan EßerDefaults to empty. 184252884aeSStefan Eßer 1857e5c51e5SStefan Eßer#### `LDFLAGS` 186252884aeSStefan Eßer 187252884aeSStefan EßerCommand-line flags for the linker. These are also passed verbatim to both 188252884aeSStefan Eßercompilers (`CC` and `HOSTCC`); they are supported just for legacy reasons. 189252884aeSStefan Eßer 190252884aeSStefan EßerDefaults to empty. 191252884aeSStefan Eßer 1927e5c51e5SStefan Eßer#### `LDLIBS` 193252884aeSStefan Eßer 194252884aeSStefan EßerLibraries to link to. These are also passed verbatim to both compilers (`CC` and 195252884aeSStefan Eßer`HOSTCC`); they are supported just for legacy reasons and for cross compiling 196252884aeSStefan Eßerwith different C standard libraries (like [musl][3]). 197252884aeSStefan Eßer 198252884aeSStefan EßerDefaults to empty. 199252884aeSStefan Eßer 2007e5c51e5SStefan Eßer#### `PREFIX` 201252884aeSStefan Eßer 202252884aeSStefan EßerThe prefix to install to. 203252884aeSStefan Eßer 204252884aeSStefan EßerCan be overridden by passing the `--prefix` option to `configure.sh`. 205252884aeSStefan Eßer 206252884aeSStefan EßerDefaults to `/usr/local`. 207252884aeSStefan Eßer 208d101cdd6SStefan Eßer***WARNING***: Locales ignore the prefix because they *must* be installed at a 209d101cdd6SStefan Eßerfixed location to work at all. If you do not want that to happen, you must 210d101cdd6SStefan Eßerdisable locales (NLS) completely. 211d101cdd6SStefan Eßer 2127e5c51e5SStefan Eßer#### `DESTDIR` 213252884aeSStefan Eßer 214252884aeSStefan EßerPath to prepend onto `PREFIX`. This is mostly for distro and package 215252884aeSStefan Eßermaintainers. 216252884aeSStefan Eßer 217252884aeSStefan EßerThis can be passed either to `configure.sh` or `make install`. If it is passed 218252884aeSStefan Eßerto both, the one given to `configure.sh` takes precedence. 219252884aeSStefan Eßer 220252884aeSStefan EßerDefaults to empty. 221252884aeSStefan Eßer 2227e5c51e5SStefan Eßer#### `BINDIR` 223252884aeSStefan Eßer 224252884aeSStefan EßerThe directory to install binaries in. 225252884aeSStefan Eßer 226252884aeSStefan EßerCan be overridden by passing the `--bindir` option to `configure.sh`. 227252884aeSStefan Eßer 228252884aeSStefan EßerDefaults to `$PREFIX/bin`. 229252884aeSStefan Eßer 2307e5c51e5SStefan Eßer#### `INCLUDEDIR` 2319a995fe1SStefan Eßer 2329a995fe1SStefan EßerThe directory to install header files in. 2339a995fe1SStefan Eßer 2349a995fe1SStefan EßerCan be overridden by passing the `--includedir` option to `configure.sh`. 2359a995fe1SStefan Eßer 2369a995fe1SStefan EßerDefaults to `$PREFIX/include`. 2379a995fe1SStefan Eßer 2387e5c51e5SStefan Eßer#### `LIBDIR` 2399a995fe1SStefan Eßer 2409a995fe1SStefan EßerThe directory to install libraries in. 2419a995fe1SStefan Eßer 2429a995fe1SStefan EßerCan be overridden by passing the `--libdir` option to `configure.sh`. 2439a995fe1SStefan Eßer 2449a995fe1SStefan EßerDefaults to `$PREFIX/lib`. 2459a995fe1SStefan Eßer 2467e5c51e5SStefan Eßer#### `DATAROOTDIR` 247252884aeSStefan Eßer 248252884aeSStefan EßerThe root directory to install data files in. 249252884aeSStefan Eßer 250252884aeSStefan EßerCan be overridden by passing the `--datarootdir` option to `configure.sh`. 251252884aeSStefan Eßer 252252884aeSStefan EßerDefaults to `$PREFIX/share`. 253252884aeSStefan Eßer 2547e5c51e5SStefan Eßer#### `DATADIR` 255252884aeSStefan Eßer 256252884aeSStefan EßerThe directory to install data files in. 257252884aeSStefan Eßer 258252884aeSStefan EßerCan be overridden by passing the `--datadir` option to `configure.sh`. 259252884aeSStefan Eßer 260252884aeSStefan EßerDefaults to `$DATAROOTDIR`. 261252884aeSStefan Eßer 2627e5c51e5SStefan Eßer#### `MANDIR` 263252884aeSStefan Eßer 264252884aeSStefan EßerThe directory to install manpages in. 265252884aeSStefan Eßer 266252884aeSStefan EßerCan be overridden by passing the `--mandir` option to `configure.sh`. 267252884aeSStefan Eßer 268252884aeSStefan EßerDefaults to `$DATADIR/man` 269252884aeSStefan Eßer 2707e5c51e5SStefan Eßer#### `MAN1DIR` 271252884aeSStefan Eßer 272252884aeSStefan EßerThe directory to install Section 1 manpages in. Because both `bc` and `dc` are 273252884aeSStefan EßerSection 1 commands, this is the only relevant section directory. 274252884aeSStefan Eßer 275252884aeSStefan EßerCan be overridden by passing the `--man1dir` option to `configure.sh`. 276252884aeSStefan Eßer 277252884aeSStefan EßerDefaults to `$MANDIR/man1`. 278252884aeSStefan Eßer 279d101cdd6SStefan Eßer#### `MAN3DIR` 280252884aeSStefan Eßer 281d101cdd6SStefan EßerThe directory to install Section 3 manpages in. 282252884aeSStefan Eßer 283d101cdd6SStefan EßerCan be overridden by passing the `--man3dir` option to `configure.sh`. 284252884aeSStefan Eßer 285d101cdd6SStefan EßerDefaults to `$MANDIR/man3`. 286252884aeSStefan Eßer 2877e5c51e5SStefan Eßer#### `EXECSUFFIX` 288252884aeSStefan Eßer 289252884aeSStefan EßerThe suffix to append onto the executable names *when installing*. This is for 290252884aeSStefan Eßerpackagers and distro maintainers who want this `bc` as an option, but do not 291252884aeSStefan Eßerwant to replace the default `bc`. 292252884aeSStefan Eßer 293252884aeSStefan EßerDefaults to empty. 294252884aeSStefan Eßer 2957e5c51e5SStefan Eßer#### `EXECPREFIX` 296252884aeSStefan Eßer 297252884aeSStefan EßerThe prefix to append onto the executable names *when building and installing*. 298252884aeSStefan EßerThis is for packagers and distro maintainers who want this `bc` as an option, 299252884aeSStefan Eßerbut do not want to replace the default `bc`. 300252884aeSStefan Eßer 301252884aeSStefan EßerDefaults to empty. 302252884aeSStefan Eßer 3037e5c51e5SStefan Eßer#### `LONG_BIT` 304252884aeSStefan Eßer 305252884aeSStefan EßerThe number of bits in a C `long` type. This is mostly for the embedded space. 306252884aeSStefan Eßer 307252884aeSStefan EßerThis `bc` uses `long`s internally for overflow checking. In C99, a `long` is 308252884aeSStefan Eßerrequired to be 32 bits. For this reason, on 8-bit and 16-bit microcontrollers, 309252884aeSStefan Eßerthe generated code to do math with `long` types may be inefficient. 310252884aeSStefan Eßer 311252884aeSStefan EßerFor most normal desktop systems, setting this is unnecessary, except that 32-bit 312252884aeSStefan Eßerplatforms with 64-bit longs may want to set it to `32`. 313252884aeSStefan Eßer 314252884aeSStefan EßerDefaults to the default value of `LONG_BIT` for the target platform. For 315252884aeSStefan Eßercompliance with the `bc` spec, the minimum allowed value is `32`. 316252884aeSStefan Eßer 317252884aeSStefan EßerIt is an error if the specified value is greater than the default value of 318252884aeSStefan Eßer`LONG_BIT` for the target platform. 319252884aeSStefan Eßer 3207e5c51e5SStefan Eßer#### `GEN_HOST` 321252884aeSStefan Eßer 322252884aeSStefan EßerWhether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to produce the C 323252884aeSStefan Eßerfiles that contain the help texts as well as the math libraries. By default, 324252884aeSStefan Eßer`gen/strgen.c` is used, compiled by `$HOSTCC` and run on the host machine. Using 325252884aeSStefan Eßer`gen/strgen.sh` removes the need to compile and run an executable on the host 326252884aeSStefan Eßermachine since `gen/strgen.sh` is a POSIX shell script. However, `gen/lib2.bc` is 327252884aeSStefan Eßerperilously close to 4095 characters, the max supported length of a string 328252884aeSStefan Eßerliteral in C99 (and it could be added to in the future), and `gen/strgen.sh` 329252884aeSStefan Eßergenerates a string literal instead of an array, as `gen/strgen.c` does. For most 330252884aeSStefan Eßerproduction-ready compilers, this limit probably is not enforced, but it could 331252884aeSStefan Eßerbe. Both options are still available for this reason. 332252884aeSStefan Eßer 333252884aeSStefan EßerIf you are sure your compiler does not have the limit and do not want to compile 334252884aeSStefan Eßerand run a binary on the host machine, set this variable to "0". Any other value, 335252884aeSStefan Eßeror a non-existent value, will cause the build system to compile and run 336252884aeSStefan Eßer`gen/strgen.c`. 337252884aeSStefan Eßer 338252884aeSStefan EßerDefault is "". 339252884aeSStefan Eßer 3407e5c51e5SStefan Eßer#### `GEN_EMU` 341252884aeSStefan Eßer 342252884aeSStefan EßerThe emulator to run bootstrap binaries under. This is only if the binaries 343252884aeSStefan Eßerproduced by `HOSTCC` (or `HOST_CC`) need to be run under an emulator to work. 344252884aeSStefan Eßer 345252884aeSStefan EßerDefaults to empty. 346252884aeSStefan Eßer 3477e5c51e5SStefan Eßer### Build Options 348252884aeSStefan Eßer 349252884aeSStefan EßerThis `bc` comes with several build options, all of which are enabled by default. 350252884aeSStefan Eßer 351252884aeSStefan EßerAll options can be used with each other, with a few exceptions that will be 352252884aeSStefan Eßernoted below. 353252884aeSStefan Eßer 354252884aeSStefan Eßer**NOTE**: All long options with mandatory argumenst accept either one of the 355252884aeSStefan Eßerfollowing forms: 356252884aeSStefan Eßer 357252884aeSStefan Eßer``` 358252884aeSStefan Eßer--option arg 359252884aeSStefan Eßer--option=arg 360252884aeSStefan Eßer``` 361252884aeSStefan Eßer 362d101cdd6SStefan Eßer#### Predefined Builds 363d101cdd6SStefan Eßer 364d101cdd6SStefan EßerTo quickly get a release build of a `bc` and `dc` that is (by default) 365d101cdd6SStefan Eßercompatible with the BSD `bc` and `dc`, use the `-p` or `--predefined-build-type` 366d101cdd6SStefan Eßeroptions: 367d101cdd6SStefan Eßer 368d101cdd6SStefan Eßer``` 369d101cdd6SStefan Eßer./configure.sh -pBSD 370d101cdd6SStefan Eßer./configure.sh --predefined-build-type=BSD 371d101cdd6SStefan Eßer``` 372d101cdd6SStefan Eßer 373d101cdd6SStefan EßerBoth commands are equivalent. 374d101cdd6SStefan Eßer 375d101cdd6SStefan EßerTo quickly get a release build of a `bc` and `dc` that is (by default) 376d101cdd6SStefan Eßercompatible with the GNU `bc` and `dc`, use the `-p` or `--predefined-build-type` 377d101cdd6SStefan Eßeroptions: 378d101cdd6SStefan Eßer 379d101cdd6SStefan Eßer``` 380d101cdd6SStefan Eßer./configure.sh -pGNU 381d101cdd6SStefan Eßer./configure.sh --predefined-build-type=GNU 382d101cdd6SStefan Eßer``` 383d101cdd6SStefan Eßer 384d101cdd6SStefan EßerBoth commands are equivalent. 385d101cdd6SStefan Eßer 3867e5c51e5SStefan Eßer#### Library 38750696a6eSStefan Eßer 38850696a6eSStefan EßerTo build the math library, use the following commands for the configure step: 38950696a6eSStefan Eßer 39050696a6eSStefan Eßer``` 39150696a6eSStefan Eßer./configure.sh -a 39250696a6eSStefan Eßer./configure.sh --library 39350696a6eSStefan Eßer``` 39450696a6eSStefan Eßer 39550696a6eSStefan EßerBoth commands are equivalent. 39650696a6eSStefan Eßer 39744d4804dSStefan EßerWhen the library is built, history and locales are disabled, and the 39850696a6eSStefan Eßerfunctionality for `bc` and `dc` are both enabled, though the executables are 39950696a6eSStefan Eßer*not* built. This is because the library's options clash with the executables. 40050696a6eSStefan Eßer 40150696a6eSStefan EßerTo build an optimized version of the library, users can pass optimization 40250696a6eSStefan Eßeroptions to `configure.sh` or include them in `CFLAGS`. 40350696a6eSStefan Eßer 40450696a6eSStefan EßerThe library API can be found in `manuals/bcl.3.md` or `man bcl` once the library 40550696a6eSStefan Eßeris installed. 40650696a6eSStefan Eßer 40750696a6eSStefan EßerThe library is built as `bin/libbcl.a`. 40850696a6eSStefan Eßer 4097e5c51e5SStefan Eßer#### `bc` Only 410252884aeSStefan Eßer 411252884aeSStefan EßerTo build `bc` only (no `dc`), use any one of the following commands for the 412252884aeSStefan Eßerconfigure step: 413252884aeSStefan Eßer 414252884aeSStefan Eßer``` 415252884aeSStefan Eßer./configure.sh -b 416252884aeSStefan Eßer./configure.sh --bc-only 417252884aeSStefan Eßer./configure.sh -D 418252884aeSStefan Eßer./configure.sh --disable-dc 419252884aeSStefan Eßer``` 420252884aeSStefan Eßer 421252884aeSStefan EßerThose commands are all equivalent. 422252884aeSStefan Eßer 423252884aeSStefan Eßer***Warning***: It is an error to use those options if `bc` has also been 424252884aeSStefan Eßerdisabled (see below). 425252884aeSStefan Eßer 4267e5c51e5SStefan Eßer#### `dc` Only 427252884aeSStefan Eßer 428252884aeSStefan EßerTo build `dc` only (no `bc`), use either one of the following commands for the 429252884aeSStefan Eßerconfigure step: 430252884aeSStefan Eßer 431252884aeSStefan Eßer``` 432252884aeSStefan Eßer./configure.sh -d 433252884aeSStefan Eßer./configure.sh --dc-only 434252884aeSStefan Eßer./configure.sh -B 435252884aeSStefan Eßer./configure.sh --disable-bc 436252884aeSStefan Eßer``` 437252884aeSStefan Eßer 438252884aeSStefan EßerThose commands are all equivalent. 439252884aeSStefan Eßer 440252884aeSStefan Eßer***Warning***: It is an error to use those options if `dc` has also been 441252884aeSStefan Eßerdisabled (see above). 442252884aeSStefan Eßer 4437e5c51e5SStefan Eßer#### History 444252884aeSStefan Eßer 44544d4804dSStefan EßerTo disable hisory, pass either the `-H` flag or the `--disable-history` option 44644d4804dSStefan Eßerto `configure.sh`, as follows: 447252884aeSStefan Eßer 448252884aeSStefan Eßer``` 449252884aeSStefan Eßer./configure.sh -H 450252884aeSStefan Eßer./configure.sh --disable-history 451252884aeSStefan Eßer``` 452252884aeSStefan Eßer 453252884aeSStefan EßerBoth commands are equivalent. 454252884aeSStefan Eßer 455252884aeSStefan Eßer***WARNING***: Of all of the code in the `bc`, this is the only code that is not 456252884aeSStefan Eßercompletely portable. If the `bc` does not work on your platform, your first step 457252884aeSStefan Eßershould be to retry with history disabled. 458252884aeSStefan Eßer 45944d4804dSStefan EßerThis option affects the [build type][7]. 46044d4804dSStefan Eßer 46178bc019dSStefan Eßer##### Editline 46278bc019dSStefan Eßer 46378bc019dSStefan EßerHistory support can be provided by editline, in order to implement `vi`-like 46478bc019dSStefan Eßerkeybindings and other features. 46578bc019dSStefan Eßer 466d101cdd6SStefan EßerTo enable editline support, pass either the `-e` flag or the `--enable-editline` 46778bc019dSStefan Eßeroption to `configure.sh`, as follows: 46878bc019dSStefan Eßer 46978bc019dSStefan Eßer``` 47078bc019dSStefan Eßer./configure.sh -e 47178bc019dSStefan Eßer./configure.sh --enable-editline 47278bc019dSStefan Eßer``` 47378bc019dSStefan Eßer 47478bc019dSStefan EßerBoth commands are equivalent. 47578bc019dSStefan Eßer 47678bc019dSStefan EßerThis is ignored if history is disabled. 47778bc019dSStefan Eßer 478d101cdd6SStefan EßerThis option is only used if it is after any other `-e`/`--enable-editline` 479d101cdd6SStefan Eßeroptions, any `-r`/`--enable-readline` options, and any 480d101cdd6SStefan Eßer`-i`/`--enable-internal-history` options. 481d101cdd6SStefan Eßer 48278bc019dSStefan Eßer##### Readline 48378bc019dSStefan Eßer 48478bc019dSStefan EßerHistory support can be provided by readline, in order to implement `vi`-like 48578bc019dSStefan Eßerkeybindings and other features. 48678bc019dSStefan Eßer 487d101cdd6SStefan EßerTo enable readline support, pass either the `-r` flag or the `--enable-readline` 48878bc019dSStefan Eßeroption to `configure.sh`, as follows: 48978bc019dSStefan Eßer 49078bc019dSStefan Eßer``` 49178bc019dSStefan Eßer./configure.sh -r 49278bc019dSStefan Eßer./configure.sh --enable-readline 49378bc019dSStefan Eßer``` 49478bc019dSStefan Eßer 49578bc019dSStefan EßerBoth commands are equivalent. 49678bc019dSStefan Eßer 49778bc019dSStefan EßerThis is ignored if history is disabled. 49878bc019dSStefan Eßer 499d101cdd6SStefan EßerThis option is only used if it is after any other `-r`/`--enable-readline` 500d101cdd6SStefan Eßeroptions, any `-e`/`--enable-editline` options, and any 501d101cdd6SStefan Eßer`-i`/`--enable-internal-history` options. 502d101cdd6SStefan Eßer 503d101cdd6SStefan Eßer##### Internal History 504d101cdd6SStefan Eßer 505d101cdd6SStefan EßerHistory support is also available as an internal implementation with no 506d101cdd6SStefan Eßerdependencies. This is the default if editline and readline are not selected. 507d101cdd6SStefan Eßer 508d101cdd6SStefan EßerHowever, if `-p` option is used, then this option can be useful for selecting 509d101cdd6SStefan Eßerthe internal history regardless of what the predefined build has. 510d101cdd6SStefan Eßer 511d101cdd6SStefan EßerTo enable the internal history, pass either the `-i` flag or the 512d101cdd6SStefan Eßer`--enable-internal-history` option to `configure.sh` as follows: 513d101cdd6SStefan Eßer 514d101cdd6SStefan Eßer``` 515d101cdd6SStefan Eßer./configure.sh -i 516d101cdd6SStefan Eßer./configure.sh --enable-internal-history 517d101cdd6SStefan Eßer``` 518d101cdd6SStefan Eßer 519d101cdd6SStefan EßerThis option is only used if it is after any other 520d101cdd6SStefan Eßer`-i`/`--enable-internal-history` options, any `-e`/`--enable-editline` options, 521d101cdd6SStefan Eßerand any `-r`/`--enable-readline` options. 522d101cdd6SStefan Eßer 5237e5c51e5SStefan Eßer#### NLS (Locale Support) 524252884aeSStefan Eßer 525252884aeSStefan EßerTo disable locale support (use only English), pass either the `-N` flag or the 526252884aeSStefan Eßer`--disable-nls` option to `configure.sh`, as follows: 527252884aeSStefan Eßer 528252884aeSStefan Eßer``` 529252884aeSStefan Eßer./configure.sh -N 530252884aeSStefan Eßer./configure.sh --disable-nls 531252884aeSStefan Eßer``` 532252884aeSStefan Eßer 533252884aeSStefan EßerBoth commands are equivalent. 534252884aeSStefan Eßer 535252884aeSStefan EßerNLS (locale support) is automatically disabled when building for Windows or on 536252884aeSStefan Eßeranother platform that does not support the POSIX locale API or utilities. 537252884aeSStefan Eßer 53844d4804dSStefan EßerThis option affects the [build type][7]. 539252884aeSStefan Eßer 540d101cdd6SStefan Eßer***WARNING***: Locales ignore the prefix because they *must* be installed at a 541d101cdd6SStefan Eßerfixed location to work at all. If you do not want that to happen, you must 542d101cdd6SStefan Eßerdisable locales (NLS) completely. 543d101cdd6SStefan Eßer 5447e5c51e5SStefan Eßer#### Extra Math 545252884aeSStefan Eßer 546252884aeSStefan EßerThis `bc` has 7 extra operators: 547252884aeSStefan Eßer 548252884aeSStefan Eßer* `$` (truncation to integer) 549252884aeSStefan Eßer* `@` (set precision) 550252884aeSStefan Eßer* `@=` (set precision and assign) 551252884aeSStefan Eßer* `<<` (shift number left, shifts radix right) 552252884aeSStefan Eßer* `<<=` (shift number left and assign) 553252884aeSStefan Eßer* `>>` (shift number right, shifts radix left) 554252884aeSStefan Eßer* `>>=` (shift number right and assign) 555252884aeSStefan Eßer 556252884aeSStefan EßerThere is no assignment version of `$` because it is a unary operator. 557252884aeSStefan Eßer 558252884aeSStefan EßerThe assignment versions of the above operators are not available in `dc`, but 559252884aeSStefan Eßerthe others are, as the operators `$`, `@`, `H`, and `h`, respectively. 560252884aeSStefan Eßer 561252884aeSStefan EßerIn addition, this `bc` has the option of outputting in scientific notation or 562252884aeSStefan Eßerengineering notation. It can also take input in scientific or engineering 563252884aeSStefan Eßernotation. On top of that, it has a pseudo-random number generator. (See the 5643aa99676SStefan Eßerfull manual for more details.) 565252884aeSStefan Eßer 566252884aeSStefan EßerExtra operators, scientific notation, engineering notation, and the 567252884aeSStefan Eßerpseudo-random number generator can be disabled by passing either the `-E` flag 568252884aeSStefan Eßeror the `--disable-extra-math` option to `configure.sh`, as follows: 569252884aeSStefan Eßer 570252884aeSStefan Eßer``` 571252884aeSStefan Eßer./configure.sh -E 572252884aeSStefan Eßer./configure.sh --disable-extra-math 573252884aeSStefan Eßer``` 574252884aeSStefan Eßer 575252884aeSStefan EßerBoth commands are equivalent. 576252884aeSStefan Eßer 577252884aeSStefan EßerThis `bc` also has a larger library that is only enabled if extra operators and 578252884aeSStefan Eßerthe pseudo-random number generator are. More information about the functions can 5793aa99676SStefan Eßerbe found in the Extended Library section of the full manual. 580252884aeSStefan Eßer 58144d4804dSStefan EßerThis option affects the [build type][7]. 582252884aeSStefan Eßer 5837e5c51e5SStefan Eßer#### Karatsuba Length 584252884aeSStefan Eßer 585252884aeSStefan EßerThe Karatsuba length is the point at which `bc` and `dc` switch from Karatsuba 586252884aeSStefan Eßermultiplication to brute force, `O(n^2)` multiplication. It can be set by passing 587252884aeSStefan Eßerthe `-k` flag or the `--karatsuba-len` option to `configure.sh` as follows: 588252884aeSStefan Eßer 589252884aeSStefan Eßer``` 59044d4804dSStefan Eßer./configure.sh -k32 59144d4804dSStefan Eßer./configure.sh --karatsuba-len 32 592252884aeSStefan Eßer``` 593252884aeSStefan Eßer 594252884aeSStefan EßerBoth commands are equivalent. 595252884aeSStefan Eßer 59644d4804dSStefan EßerDefault is `32`. 597252884aeSStefan Eßer 598252884aeSStefan Eßer***WARNING***: The Karatsuba Length must be a **integer** greater than or equal 599252884aeSStefan Eßerto `16` (to prevent stack overflow). If it is not, `configure.sh` will give an 600252884aeSStefan Eßererror. 601252884aeSStefan Eßer 60244d4804dSStefan Eßer#### Settings 60344d4804dSStefan Eßer 60444d4804dSStefan EßerThis `bc` and `dc` have a few settings to override default behavior. 60544d4804dSStefan Eßer 60644d4804dSStefan EßerThe defaults for these settings can be set by package maintainers, and the 60744d4804dSStefan Eßersettings themselves can be overriden by users. 60844d4804dSStefan Eßer 60944d4804dSStefan EßerTo set a default to **on**, use the `-s` or `--set-default-on` option to 61044d4804dSStefan Eßer`configure.sh`, with the name of the setting, as follows: 61144d4804dSStefan Eßer 61244d4804dSStefan Eßer``` 61344d4804dSStefan Eßer./configure.sh -s bc.banner 61444d4804dSStefan Eßer./configure.sh --set-default-on=bc.banner 61544d4804dSStefan Eßer``` 61644d4804dSStefan Eßer 61744d4804dSStefan EßerBoth commands are equivalent. 61844d4804dSStefan Eßer 61944d4804dSStefan EßerTo set a default to **off**, use the `-S` or `--set-default-off` option to 62044d4804dSStefan Eßer`configure.sh`, with the name of the setting, as follows: 62144d4804dSStefan Eßer 62244d4804dSStefan Eßer``` 62344d4804dSStefan Eßer./configure.sh -S bc.banner 62444d4804dSStefan Eßer./configure.sh --set-default-off=bc.banner 62544d4804dSStefan Eßer``` 62644d4804dSStefan Eßer 62744d4804dSStefan EßerBoth commands are equivalent. 62844d4804dSStefan Eßer 62944d4804dSStefan EßerUsers can override the default settings set by packagers with environment 63044d4804dSStefan Eßervariables. If the environment variable has an integer, then the setting is 63144d4804dSStefan Eßerturned **on** for a non-zero integer, and **off** for zero. 63244d4804dSStefan Eßer 63344d4804dSStefan EßerThe table of the available settings, along with their defaults and the 63444d4804dSStefan Eßerenvironment variables to override them, is below: 63544d4804dSStefan Eßer 63644d4804dSStefan Eßer``` 63744d4804dSStefan Eßer| Setting | Description | Default | Env Variable | 63844d4804dSStefan Eßer| =============== | ==================== | ============ | ==================== | 63944d4804dSStefan Eßer| bc.banner | Whether to display | 0 | BC_BANNER | 64044d4804dSStefan Eßer| | the bc version | | | 64144d4804dSStefan Eßer| | banner when in | | | 64244d4804dSStefan Eßer| | interactive mode. | | | 64344d4804dSStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 64444d4804dSStefan Eßer| bc.sigint_reset | Whether SIGINT will | 1 | BC_SIGINT_RESET | 64544d4804dSStefan Eßer| | reset bc, instead of | | | 64644d4804dSStefan Eßer| | exiting, when in | | | 64744d4804dSStefan Eßer| | interactive mode. | | | 64844d4804dSStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 64944d4804dSStefan Eßer| dc.sigint_reset | Whether SIGINT will | 1 | DC_SIGINT_RESET | 65044d4804dSStefan Eßer| | reset dc, instead of | | | 65144d4804dSStefan Eßer| | exiting, when in | | | 65244d4804dSStefan Eßer| | interactive mode. | | | 65344d4804dSStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 65444d4804dSStefan Eßer| bc.tty_mode | Whether TTY mode for | 1 | BC_TTY_MODE | 65544d4804dSStefan Eßer| | bc should be on when | | | 65644d4804dSStefan Eßer| | available. | | | 65744d4804dSStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 65844d4804dSStefan Eßer| dc.tty_mode | Whether TTY mode for | 0 | BC_TTY_MODE | 65944d4804dSStefan Eßer| | dc should be on when | | | 66044d4804dSStefan Eßer| | available. | | | 66144d4804dSStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 66244d4804dSStefan Eßer| bc.prompt | Whether the prompt | $BC_TTY_MODE | BC_PROMPT | 66344d4804dSStefan Eßer| | for bc should be on | | | 66444d4804dSStefan Eßer| | in tty mode. | | | 66544d4804dSStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 66644d4804dSStefan Eßer| dc.prompt | Whether the prompt | $DC_TTY_MODE | DC_PROMPT | 66744d4804dSStefan Eßer| | for dc should be on | | | 66844d4804dSStefan Eßer| | in tty mode. | | | 66944d4804dSStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 670d101cdd6SStefan Eßer| bc.expr_exit | Whether to exit bc | 1 | BC_EXPR_EXIT | 671d101cdd6SStefan Eßer| | if an expression or | | | 672d101cdd6SStefan Eßer| | expression file is | | | 673d101cdd6SStefan Eßer| | given with the -e or | | | 674d101cdd6SStefan Eßer| | -f options. | | | 675d101cdd6SStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 676d101cdd6SStefan Eßer| dc.expr_exit | Whether to exit dc | 1 | DC_EXPR_EXIT | 677d101cdd6SStefan Eßer| | if an expression or | | | 678d101cdd6SStefan Eßer| | expression file is | | | 679d101cdd6SStefan Eßer| | given with the -e or | | | 680d101cdd6SStefan Eßer| | -f options. | | | 681d101cdd6SStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 682d101cdd6SStefan Eßer| bc.digit_clamp | Whether to have bc | 0 | BC_DIGIT_CLAMP | 683d101cdd6SStefan Eßer| | clamp digits that | | | 684d101cdd6SStefan Eßer| | are greater than or | | | 685d101cdd6SStefan Eßer| | equal to the current | | | 686d101cdd6SStefan Eßer| | ibase when parsing | | | 687d101cdd6SStefan Eßer| | numbers. | | | 688d101cdd6SStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 689d101cdd6SStefan Eßer| dc.digit_clamp | Whether to have dc | 0 | DC_DIGIT_CLAMP | 690d101cdd6SStefan Eßer| | clamp digits that | | | 691d101cdd6SStefan Eßer| | are greater than or | | | 692d101cdd6SStefan Eßer| | equal to the current | | | 693d101cdd6SStefan Eßer| | ibase when parsing | | | 694d101cdd6SStefan Eßer| | numbers. | | | 695d101cdd6SStefan Eßer| --------------- | -------------------- | ------------ | -------------------- | 69644d4804dSStefan Eßer``` 69744d4804dSStefan Eßer 69844d4804dSStefan EßerThese settings are not meant to be changed on a whim. They are meant to ensure 69944d4804dSStefan Eßerthat this bc and dc will conform to the expectations of the user on each 70044d4804dSStefan Eßerplatform. 70144d4804dSStefan Eßer 7027e5c51e5SStefan Eßer#### Install Options 703252884aeSStefan Eßer 704252884aeSStefan EßerThe relevant `autotools`-style install options are supported in `configure.sh`: 705252884aeSStefan Eßer 706252884aeSStefan Eßer* `--prefix` 707252884aeSStefan Eßer* `--bindir` 708252884aeSStefan Eßer* `--datarootdir` 709252884aeSStefan Eßer* `--datadir` 710252884aeSStefan Eßer* `--mandir` 711252884aeSStefan Eßer* `--man1dir` 712d101cdd6SStefan Eßer* `--man3dir` 713252884aeSStefan Eßer 714252884aeSStefan EßerAn example is: 715252884aeSStefan Eßer 716252884aeSStefan Eßer``` 717d101cdd6SStefan Eßer./configure.sh --prefix=/usr 718252884aeSStefan Eßermake 719252884aeSStefan Eßermake install 720252884aeSStefan Eßer``` 721252884aeSStefan Eßer 722252884aeSStefan EßerThey correspond to the environment variables `$PREFIX`, `$BINDIR`, 723d101cdd6SStefan Eßer`$DATAROOTDIR`, `$DATADIR`, `$MANDIR`, `$MAN1DIR`, `$MAN3DIR`, and respectively. 724d101cdd6SStefan Eßer 725d101cdd6SStefan Eßer***WARNING***: Locales ignore the prefix because they *must* be installed at a 726d101cdd6SStefan Eßerfixed location to work at all. If you do not want that to happen, you must 727d101cdd6SStefan Eßerdisable locales (NLS) completely. 728252884aeSStefan Eßer 729252884aeSStefan Eßer***WARNING***: If the option is given, the value of the corresponding 730252884aeSStefan Eßerenvironment variable is overridden. 731252884aeSStefan Eßer 732252884aeSStefan Eßer***WARNING***: If any long command-line options are used, the long form of all 733252884aeSStefan Eßerother command-line options must be used. Mixing long and short options is not 734252884aeSStefan Eßersupported. 735252884aeSStefan Eßer 73644d4804dSStefan Eßer##### Manpages 73744d4804dSStefan Eßer 73844d4804dSStefan EßerTo disable installing manpages, pass either the `-M` flag or the 73944d4804dSStefan Eßer`--disable-man-pages` option to `configure.sh` as follows: 74044d4804dSStefan Eßer 74144d4804dSStefan Eßer``` 74244d4804dSStefan Eßer./configure.sh -M 74344d4804dSStefan Eßer./configure.sh --disable-man-pages 74444d4804dSStefan Eßer``` 74544d4804dSStefan Eßer 74644d4804dSStefan EßerBoth commands are equivalent. 74744d4804dSStefan Eßer 74844d4804dSStefan Eßer##### Locales 74944d4804dSStefan Eßer 75044d4804dSStefan EßerBy default, `bc` and `dc` do not install all locales, but only the enabled 75144d4804dSStefan Eßerlocales. If `DESTDIR` exists and is not empty, then they will install all of 75244d4804dSStefan Eßerthe locales that exist on the system. The `-l` flag or `--install-all-locales` 75344d4804dSStefan Eßeroption skips all of that and just installs all of the locales that `bc` and `dc` 75444d4804dSStefan Eßerhave, regardless. To enable that behavior, you can pass the `-l` flag or the 75544d4804dSStefan Eßer`--install-all-locales` option to `configure.sh`, as follows: 75644d4804dSStefan Eßer 75744d4804dSStefan Eßer``` 75844d4804dSStefan Eßer./configure.sh -l 75944d4804dSStefan Eßer./configure.sh --install-all-locales 76044d4804dSStefan Eßer``` 76144d4804dSStefan Eßer 76244d4804dSStefan EßerBoth commands are equivalent. 76344d4804dSStefan Eßer 764d101cdd6SStefan Eßer***WARNING***: Locales ignore the prefix because they *must* be installed at a 765d101cdd6SStefan Eßerfixed location to work at all. If you do not want that to happen, you must 766d101cdd6SStefan Eßerdisable locales (NLS) completely. 767d101cdd6SStefan Eßer 7687e5c51e5SStefan Eßer### Optimization 769252884aeSStefan Eßer 770252884aeSStefan EßerThe `configure.sh` script will accept an optimization level to pass to the 771252884aeSStefan Eßercompiler. Because `bc` is orders of magnitude faster with optimization, I 772252884aeSStefan Eßer***highly*** recommend package and distro maintainers pass the highest 773252884aeSStefan Eßeroptimization level available in `CC` to `configure.sh` with the `-O` flag or 774252884aeSStefan Eßer`--opt` option, as follows: 775252884aeSStefan Eßer 776252884aeSStefan Eßer``` 777252884aeSStefan Eßer./configure.sh -O3 778252884aeSStefan Eßer./configure.sh --opt 3 779252884aeSStefan Eßer``` 780252884aeSStefan Eßer 781252884aeSStefan EßerBoth commands are equivalent. 782252884aeSStefan Eßer 783252884aeSStefan EßerThe build and install can then be run as normal: 784252884aeSStefan Eßer 785252884aeSStefan Eßer``` 786252884aeSStefan Eßermake 787252884aeSStefan Eßermake install 788252884aeSStefan Eßer``` 789252884aeSStefan Eßer 790252884aeSStefan EßerAs usual, `configure.sh` will also accept additional `CFLAGS` on the command 791252884aeSStefan Eßerline, so for SSE4 architectures, the following can add a bit more speed: 792252884aeSStefan Eßer 793252884aeSStefan Eßer``` 794252884aeSStefan EßerCFLAGS="-march=native -msse4" ./configure.sh -O3 795252884aeSStefan Eßermake 796252884aeSStefan Eßermake install 797252884aeSStefan Eßer``` 798252884aeSStefan Eßer 799252884aeSStefan EßerBuilding with link-time optimization (`-flto` in clang) can further increase the 800252884aeSStefan Eßerperformance. I ***highly*** recommend doing so. 801252884aeSStefan Eßer 80244d4804dSStefan EßerI do ***NOT*** recommend building with `-march=native`; doing so reduces this 803252884aeSStefan Eßer`bc`'s performance. 804252884aeSStefan Eßer 805252884aeSStefan EßerManual stripping is not necessary; non-debug builds are automatically stripped 806252884aeSStefan Eßerin the link stage. 807252884aeSStefan Eßer 8087e5c51e5SStefan Eßer### Debug Builds 809252884aeSStefan Eßer 810252884aeSStefan EßerDebug builds (which also disable optimization if no optimization level is given 811252884aeSStefan Eßerand if no extra `CFLAGS` are given) can be enabled with either the `-g` flag or 812252884aeSStefan Eßerthe `--debug` option, as follows: 813252884aeSStefan Eßer 814252884aeSStefan Eßer``` 815252884aeSStefan Eßer./configure.sh -g 816252884aeSStefan Eßer./configure.sh --debug 817252884aeSStefan Eßer``` 818252884aeSStefan Eßer 819252884aeSStefan EßerBoth commands are equivalent. 820252884aeSStefan Eßer 821252884aeSStefan EßerThe build and install can then be run as normal: 822252884aeSStefan Eßer 823252884aeSStefan Eßer``` 824252884aeSStefan Eßermake 825252884aeSStefan Eßermake install 826252884aeSStefan Eßer``` 827252884aeSStefan Eßer 8287e5c51e5SStefan Eßer### Stripping Binaries 829252884aeSStefan Eßer 830252884aeSStefan EßerBy default, when `bc` and `dc` are not built in debug mode, the binaries are 831252884aeSStefan Eßerstripped. Stripping can be disabled with either the `-T` or the 832252884aeSStefan Eßer`--disable-strip` option, as follows: 833252884aeSStefan Eßer 834252884aeSStefan Eßer``` 835252884aeSStefan Eßer./configure.sh -T 836252884aeSStefan Eßer./configure.sh --disable-strip 837252884aeSStefan Eßer``` 838252884aeSStefan Eßer 839252884aeSStefan EßerBoth commands are equivalent. 840252884aeSStefan Eßer 841252884aeSStefan EßerThe build and install can then be run as normal: 842252884aeSStefan Eßer 843252884aeSStefan Eßer``` 844252884aeSStefan Eßermake 845252884aeSStefan Eßermake install 846252884aeSStefan Eßer``` 847252884aeSStefan Eßer 84844d4804dSStefan Eßer### Build Type 84944d4804dSStefan Eßer 85044d4804dSStefan Eßer`bc` and `dc` have 8 build types, affected by the [History][8], [NLS (Locale 85144d4804dSStefan EßerSupport)][9], and [Extra Math][10] build options. 85244d4804dSStefan Eßer 85344d4804dSStefan EßerThe build types are as follows: 85444d4804dSStefan Eßer 85544d4804dSStefan Eßer* `A`: Nothing disabled. 85644d4804dSStefan Eßer* `E`: Extra math disabled. 85744d4804dSStefan Eßer* `H`: History disabled. 85844d4804dSStefan Eßer* `N`: NLS disabled. 85944d4804dSStefan Eßer* `EH`: Extra math and History disabled. 86044d4804dSStefan Eßer* `EN`: Extra math and NLS disabled. 86144d4804dSStefan Eßer* `HN`: History and NLS disabled. 86244d4804dSStefan Eßer* `EHN`: Extra math, History, and NLS all disabled. 86344d4804dSStefan Eßer 86444d4804dSStefan EßerThese build types correspond to the generated manuals in `manuals/bc` and 86544d4804dSStefan Eßer`manuals/dc`. 86644d4804dSStefan Eßer 8677e5c51e5SStefan Eßer### Binary Size 868252884aeSStefan Eßer 869252884aeSStefan EßerWhen built with both calculators, all available features, and `-Os` using 870252884aeSStefan Eßer`clang` and `musl`, the executable is 140.4 kb (140,386 bytes) on `x86_64`. That 871252884aeSStefan Eßerisn't much for what is contained in the binary, but if necessary, it can be 872252884aeSStefan Eßerreduced. 873252884aeSStefan Eßer 874252884aeSStefan EßerThe single largest user of space is the `bc` calculator. If just `dc` is needed, 875252884aeSStefan Eßerthe size can be reduced to 107.6 kb (107,584 bytes). 876252884aeSStefan Eßer 877252884aeSStefan EßerThe next largest user of space is history support. If that is not needed, size 878252884aeSStefan Eßercan be reduced (for a build with both calculators) to 119.9 kb (119,866 bytes). 879252884aeSStefan Eßer 880252884aeSStefan EßerThere are several reasons that history is a bigger user of space than `dc` 881252884aeSStefan Eßeritself: 882252884aeSStefan Eßer 883252884aeSStefan Eßer* `dc`'s lexer and parser are *tiny* compared to `bc`'s because `dc` code is 884252884aeSStefan Eßer almost already in the form that it is executed in, while `bc` has to not only 885252884aeSStefan Eßer adjust the form to be executable, it has to parse functions, loops, `if` 886252884aeSStefan Eßer statements, and other extra features. 887252884aeSStefan Eßer* `dc` does not have much extra code in the interpreter. 888252884aeSStefan Eßer* History has a lot of const data for supporting `UTF-8` terminals. 889252884aeSStefan Eßer* History pulls in a bunch of more code from the `libc`. 890252884aeSStefan Eßer 891252884aeSStefan EßerThe next biggest user is extra math support. Without it, the size is reduced to 892252884aeSStefan Eßer124.0 kb (123,986 bytes) with history and 107.6 kb (107,560 bytes) without 893252884aeSStefan Eßerhistory. 894252884aeSStefan Eßer 895252884aeSStefan EßerThe reasons why extra math support is bigger than `dc`, besides the fact that 896252884aeSStefan Eßer`dc` is small already, are: 897252884aeSStefan Eßer 898252884aeSStefan Eßer* Extra math supports adds an extra math library that takes several kilobytes of 899252884aeSStefan Eßer constant data space. 900252884aeSStefan Eßer* Extra math support includes support for a pseudo-random number generator, 901252884aeSStefan Eßer including the code to convert a series of pseudo-random numbers into a number 902252884aeSStefan Eßer of arbitrary size. 903252884aeSStefan Eßer* Extra math support adds several operators. 904252884aeSStefan Eßer 905252884aeSStefan EßerThe next biggest user is `dc`, so if just `bc` is needed, the size can be 906252884aeSStefan Eßerreduced to 128.1 kb (128,096 bytes) with history and extra math support, 107.6 907252884aeSStefan Eßerkb (107,576 bytes) without history and with extra math support, and 95.3 kb 908252884aeSStefan Eßer(95,272 bytes) without history and without extra math support. 909252884aeSStefan Eßer 910252884aeSStefan Eßer*Note*: all of these binary sizes were compiled using `musl` `1.2.0` as the 911252884aeSStefan Eßer`libc`, making a fully static executable, with `clang` `9.0.1` (well, 912252884aeSStefan Eßer`musl-clang` using `clang` `9.0.1`) as the compiler and using `-Os` 913252884aeSStefan Eßeroptimizations. These builds were done on an `x86_64` machine running Gentoo 914252884aeSStefan EßerLinux. 915252884aeSStefan Eßer 9167e5c51e5SStefan Eßer### Testing 917252884aeSStefan Eßer 918252884aeSStefan EßerThe default test suite can be run with the following command: 919252884aeSStefan Eßer 920252884aeSStefan Eßer``` 921252884aeSStefan Eßermake test 922252884aeSStefan Eßer``` 923252884aeSStefan Eßer 924252884aeSStefan EßerTo test `bc` only, run the following command: 925252884aeSStefan Eßer 926252884aeSStefan Eßer``` 927252884aeSStefan Eßermake test_bc 928252884aeSStefan Eßer``` 929252884aeSStefan Eßer 930252884aeSStefan EßerTo test `dc` only, run the following command: 931252884aeSStefan Eßer 932252884aeSStefan Eßer``` 933252884aeSStefan Eßermake test_dc 934252884aeSStefan Eßer``` 935252884aeSStefan Eßer 936252884aeSStefan EßerThis `bc`, if built, assumes a working, GNU-compatible `bc`, installed on the 937252884aeSStefan Eßersystem and in the `PATH`, to generate some tests, unless the `-G` flag or 938252884aeSStefan Eßer`--disable-generated-tests` option is given to `configure.sh`, as follows: 939252884aeSStefan Eßer 940252884aeSStefan Eßer``` 941252884aeSStefan Eßer./configure.sh -G 942252884aeSStefan Eßer./configure.sh --disable-generated-tests 943252884aeSStefan Eßer``` 944252884aeSStefan Eßer 945252884aeSStefan EßerAfter running `configure.sh`, build and run tests as follows: 946252884aeSStefan Eßer 947252884aeSStefan Eßer``` 948252884aeSStefan Eßermake 949252884aeSStefan Eßermake test 950252884aeSStefan Eßer``` 951252884aeSStefan Eßer 952252884aeSStefan EßerThis `dc` also assumes a working, GNU-compatible `dc`, installed on the system 953252884aeSStefan Eßerand in the `PATH`, to generate some tests, unless one of the above options is 954252884aeSStefan Eßergiven to `configure.sh`. 955252884aeSStefan Eßer 956252884aeSStefan EßerTo generate test coverage, pass the `-c` flag or the `--coverage` option to 957252884aeSStefan Eßer`configure.sh` as follows: 958252884aeSStefan Eßer 959252884aeSStefan Eßer``` 960252884aeSStefan Eßer./configure.sh -c 961252884aeSStefan Eßer./configure.sh --coverage 962252884aeSStefan Eßer``` 963252884aeSStefan Eßer 964252884aeSStefan EßerBoth commands are equivalent. 965252884aeSStefan Eßer 966252884aeSStefan Eßer***WARNING***: Both `bc` and `dc` must be built for test coverage. Otherwise, 967252884aeSStefan Eßer`configure.sh` will give an error. 968252884aeSStefan Eßer 969d101cdd6SStefan Eßer#### Problematic Tests 970d101cdd6SStefan Eßer 971d101cdd6SStefan EßerSome tests are problematic, in that they can cause `SIGKILL` on FreeBSD or 972d101cdd6SStefan Eßer`SIGSEGV` on Linux from being killed by the "OOM Killer" part of the kernel. On 973d101cdd6SStefan EßerLinux, these tests are usually fine, but on FreeBSD, they are usually a problem. 974d101cdd6SStefan Eßer 975d101cdd6SStefan EßerTo disable problematic tests, pass the `-P` flag or the 976d101cdd6SStefan Eßer`--disable-problematic-tests` option to `configure.sh` as follows: 977d101cdd6SStefan Eßer 978d101cdd6SStefan Eßer``` 979d101cdd6SStefan Eßer./configure.sh -P 980d101cdd6SStefan Eßer./configure.sh --disable-problematic-tests 981d101cdd6SStefan Eßer``` 982d101cdd6SStefan Eßer 983d101cdd6SStefan EßerBoth commands are equivalent. 984d101cdd6SStefan Eßer 985252884aeSStefan Eßer[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html 986252884aeSStefan Eßer[2]: https://www.gnu.org/software/bc/ 987252884aeSStefan Eßer[3]: https://www.musl-libc.org/ 988252884aeSStefan Eßer[4]: #build-environment-variables 989252884aeSStefan Eßer[5]: #build-options 990252884aeSStefan Eßer[6]: #cross-compiling 99144d4804dSStefan Eßer[7]: #build-type 99244d4804dSStefan Eßer[8]: #history 99344d4804dSStefan Eßer[9]: #nls-locale-support 99444d4804dSStefan Eßer[10]: #extra-math 99544d4804dSStefan Eßer[11]: #settings 996