### this file is sourced not run
PKGVER=6.2.4
PKGBUILD=1
PKGARCH=x86_64

TARBALL=bc-$PKGVER.tar.xz
MD5SUM=5245ff400df17b66be7621c7a6498953
BUNDLE=fatdog-base-11.3.tar
SRC_URL=http://distro.ibiblio.org/fatdog/source/900/$BUNDLE

#SLACKREQ='libreadline' # 
SLACKDESC="bc: bc $PKGVER (command-line calculator)  
bc:  
bc: bc is an arbitrary precision numeric processing language. Syntax is 
bc: similar to C, but differs in many substantial areas. It supports 
bc: interactive execution of statements. bc is a utility included in the POSIX 
bc: P1003.2/D11 draft standard.  
bc: 
bc: This is Gavin Howard's bc, not GNU bc.
bc: https://git.yzena.com/gavin/
bc: 
bc: It is supposedly fully-compatible with GNU bc.
"


### override download for LFS sources bundle
# $1-src-dir $2-tarball 
pkg_download() {
	echo downloading $BUNDLE for $TARBALL
	wget -P $1 $SRC_URL
	tar -xf $1/$BUNDLE --strip-components=1 -C $1 
	rm $1/$BUNDLE
}

### default pkg_prepare
### default pkg_package
### build
pkg_build() {
	cd /tmp/bc* &&

# These are build instructions for GNU bc, version 1.07.1
<< "EOF" 
	# CLFS 2017.07 / LFS 8.1 patch - use sed instead of ed
	cat > bc/fix-libmath_h << "EOF" &&
#! /bin/bash
sed -e '1   s/^/{"/' \
	-e     's/$/",/' \
	-e '2,$ s/^/"/'  \
	-e   '$ d'       \
	-i libmath.h

sed -e '$ s/$/0}/' \
	-i libmath.h
EOF

	CONFFLAGS="$CONFFLAGS \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--with-readline"
	pkg_build_autoconf && 
EOF

	# LFS 11.3 using Gavin Howard's bc.
	./configure --prefix=/usr -G -r && # LFS has -O3 in it
	make && make install &&

	pkg_build_slackdesc
}

<< "EOF"
usage:
    configure -h
    configure --help
    configure [-a|-bD|-dB|-c] [-CeEfgGHilmMNPrtTvz] [-O OPT_LEVEL] [-k KARATSUBA_LEN]\
       [-s SETTING] [-S SETTING] [-p TYPE]
    configure \
       [--library|--bc-only --disable-dc|--dc-only --disable-bc|--coverage]  \
       [--force --debug --disable-extra-math --disable-generated-tests]      \
       [--disable-history --disable-man-pages --disable-nls --disable-strip] \
       [--enable-editline] [--enable-readline] [--enable-internal-history]   \
       [--disable-problematic-tests] [--install-all-locales]                 \
       [--opt=OPT_LEVEL] [--karatsuba-len=KARATSUBA_LEN]                     \
       [--set-default-on=SETTING] [--set-default-off=SETTING]                \
       [--predefined-build-type=TYPE]                                        \
       [--prefix=PREFIX] [--bindir=BINDIR] [--datarootdir=DATAROOTDIR]       \
       [--datadir=DATADIR] [--mandir=MANDIR] [--man1dir=MAN1DIR]             \
       [--man3dir=MAN3DIR]

    -a, --library
        Build the libbcl instead of the programs. This is meant to be used with
        Other software like programming languages that want to make use of the
        parsing and math capabilities. This option will install headers using
        `make install`.
    -b, --bc-only
        Build bc only. It is an error if "-d", "--dc-only", "-B", or
        "--disable-bc" are specified too.
    -B, --disable-bc
        Disable bc. It is an error if "-b", "--bc-only", "-D", or "--disable-dc"
        are specified too.
    -c, --coverage
        Generate test coverage code. Requires gcov and gcovr.
        It is an error if either "-b" ("-D") or "-d" ("-B") is specified.
        Requires a compiler that use gcc-compatible coverage options
    -C, --disable-clean
        Disable the clean that configure.sh does before configure.
    -d, --dc-only
        Build dc only. It is an error if "-b", "--bc-only", "-D", or
        "--disable-dc" are specified too.
    -D, --disable-dc
        Disable dc. It is an error if "-d", "--dc-only", "-B", or "--disable-bc"
        are specified too.
    -e, --enable-editline
        Enable the use of libedit/editline. This is meant for those users that
        want vi-like or Emacs-like behavior in history. This option is ignored
        if history is disabled. If the -r or -i options are given with this
        option, the last occurrence of all of the three is used.
    -E, --disable-extra-math
        Disable extra math. This includes: "$" operator (truncate to integer),
        "@" operator (set number of decimal places), and r(x, p) (rounding
        function). Additionally, this option disables the extra printing
        functions in the math library.
    -f, --force
        Force use of all enabled options, even if they do not work. This
        option is to allow the maintainer a way to test that certain options
        are not failing invisibly. (Development only.)
    -g, --debug
        Build in debug mode. Adds the "-g" flag, and if there are no
        other CFLAGS, and "-O" was not given, this also adds the "-O0"
        flag. If this flag is *not* given, "-DNDEBUG" is added to CPPFLAGS
        and a strip flag is added to the link stage.
    -G, --disable-generated-tests
        Disable generating tests. This is for platforms that do not have a
        GNU bc-compatible bc to generate tests.
    -h, --help
        Print this help message and exit.
    -H, --disable-history
        Disable history.
    -i, --enable-internal-history
        Enable the internal history implementation and do not depend on either
        editline or readline. This option is ignored if history is disabled.
        If this option is given along with -e and -r, the last occurrence of
        all of the three is used.
    -k KARATSUBA_LEN, --karatsuba-len KARATSUBA_LEN
        Set the karatsuba length to KARATSUBA_LEN (default is 64).
        It is an error if KARATSUBA_LEN is not a number or is less than 16.
    -l, --install-all-locales
        Installs all locales, regardless of how many are on the system. This
        option is useful for package maintainers who want to make sure that
        a package contains all of the locales that end users might need.
    -m, --enable-memcheck
        Enable memcheck mode, to ensure no memory leaks. For development only.
    -M, --disable-man-pages
        Disable installing manpages.
    -N, --disable-nls
        Disable POSIX locale (NLS) support.
        ***WARNING***: Locales ignore the prefix because they *must* be
        installed at a fixed location to work at all. If you do not want that
        to happen, you must disable locales (NLS) completely.
    -O OPT_LEVEL, --opt OPT_LEVEL
        Set the optimization level. This can also be included in the CFLAGS,
        but it is provided, so maintainers can build optimized debug builds.
        This is passed through to the compiler, so it must be supported.
    -p TYPE, --predefined-build-type=TYPE
        Sets a given predefined build type with specific defaults. This is for
        easy setting of predefined builds. For example, to get a build that
        acts like the GNU bc by default, TYPE should be "GNU" (without the
        quotes) This option *must* come before any others that might change the
        build options. Currently supported values for TYPE include: "BSD" (for
        matching the BSD bc and BSD dc), "GNU" (for matching the GNU bc and
        dc), "GDH" (for the preferred build of the author, Gavin D. Howard),
        and "DBG" (for the preferred debug build of the author). This will
        also automatically enable a release build (except for "DBG").
    -P, --disable-problematic-tests
        Disables problematic tests. These tests usually include tests that
        can cause a SIGKILL because of too much memory usage.
    -r, --enable-readline
        Enable the use of libreadline/readline. This is meant for those users
        that want vi-like or Emacs-like behavior in history. This option is
        ignored if history is disabled. If this option is given along with -e
        and -r, the last occurrence of all of the three is used.
    -s SETTING, --set-default-on SETTING
        Set the default named by SETTING to on. See below for possible values
        for SETTING. For multiple instances of the -s or -S for the the same
        setting, the last one is used.
    -S SETTING, --set-default-off SETTING
        Set the default named by SETTING to off. See below for possible values
        for SETTING. For multiple instances of the -s or -S for the the same
        setting, the last one is used.
    -t, --enable-test-timing
        Enable the timing of tests. This is for development only.
    -T, --disable-strip
        Disable stripping symbols from the compiled binary or binaries.
        Stripping symbols only happens when debug mode is off.
    -v, --enable-valgrind
        Enable a build appropriate for valgrind. For development only.
    -z, --enable-fuzz-mode
        Enable fuzzing mode. THIS IS FOR DEVELOPMENT ONLY.
    --prefix PREFIX
        The prefix to install to. Overrides "$PREFIX" if it exists.
        If PREFIX is "/usr", install path will be "/usr/bin".
        Default is "/usr/local".
        ***WARNING***: Locales ignore the prefix because they *must* be
        installed at a fixed location to work at all. If you do not want that to
        happen, you must disable locales (NLS) completely.
    --bindir BINDIR
        The directory to install binaries in. Overrides "$BINDIR" if it exists.
        Default is "$PREFIX/bin".
    --includedir INCLUDEDIR
        The directory to install headers in. Overrides "$INCLUDEDIR" if it
        exists. Default is "$PREFIX/include".
    --libdir LIBDIR
        The directory to install libraries in. Overrides "$LIBDIR" if it exists.
        Default is "$PREFIX/lib".
    --datarootdir DATAROOTDIR
        The root location for data files. Overrides "$DATAROOTDIR" if it exists.
        Default is "$PREFIX/share".
    --datadir DATADIR
        The location for data files. Overrides "$DATADIR" if it exists.
        Default is "$DATAROOTDIR".
    --mandir MANDIR
        The location to install manpages to. Overrides "$MANDIR" if it exists.
        Default is "$DATADIR/man".
    --man1dir MAN1DIR
        The location to install Section 1 manpages to. Overrides "$MAN1DIR" if
        it exists. Default is "$MANDIR/man1".
    --man3dir MAN3DIR
        The location to install Section 3 manpages to. Overrides "$MAN3DIR" if
        it exists. Default is "$MANDIR/man3".

In addition, the following environment variables are used:

    CC           C compiler. Must be compatible with POSIX c99. If there is a
                 space in the basename of the compiler, the items after the
                 first space are assumed to be compiler flags, and in that case,
                 the flags are automatically moved into CFLAGS. Default is
                 "c99".
    HOSTCC       Host C compiler. Must be compatible with POSIX c99. If there is
                 a space in the basename of the compiler, the items after the
                 first space are assumed to be compiler flags, and in the case,
                 the flags are automatically moved into HOSTCFLAGS. Default is
                 "$CC".
    HOST_CC      Same as HOSTCC. If HOSTCC also exists, it is used.
    CFLAGS       C compiler flags.
    HOSTCFLAGS   CFLAGS for HOSTCC. Default is "$CFLAGS".
    HOST_CFLAGS  Same as HOST_CFLAGS. If HOST_CFLAGS also exists, it is used.
    CPPFLAGS     C preprocessor flags. Default is "".
    LDFLAGS      Linker flags. Default is "".
    PREFIX       The prefix to install to. Default is "/usr/local".
                 If PREFIX is "/usr", install path will be "/usr/bin".
                 ***WARNING***: Locales ignore the prefix because they *must* be
                 installed at a fixed location to work at all. If you do not
                 want that to happen, you must disable locales (NLS) completely.
    BINDIR       The directory to install binaries in. Default is "$PREFIX/bin".
    INCLUDEDIR   The directory to install header files in. Default is
                 "$PREFIX/include".
    LIBDIR       The directory to install libraries in. Default is
                 "$PREFIX/lib".
    DATAROOTDIR  The root location for data files. Default is "$PREFIX/share".
    DATADIR      The location for data files. Default is "$DATAROOTDIR".
    MANDIR       The location to install manpages to. Default is "$DATADIR/man".
    MAN1DIR      The location to install Section 1 manpages to. Default is
                 "$MANDIR/man1".
    MAN3DIR      The location to install Section 3 manpages to. Default is
                 "$MANDIR/man3".
    NLSPATH      The location to install locale catalogs to. Must be an absolute
                 path (or contain one). This is treated the same as the POSIX
                 definition of $NLSPATH (see POSIX environment variables for
                 more information). Default is "/usr/share/locale/%L/%N".
    PC_PATH      The location to install pkg-config files to. Must be an
                 path or contain one. Default is the first path given by the
                 output of `pkg-config --variable=pc_path pkg-config`.
    EXECSUFFIX   The suffix to append to the executable names, used to not
                 interfere with other installed bc executables. Default is "".
    EXECPREFIX   The prefix to append to the executable names, used to not
                 interfere with other installed bc executables. Default is "".
    DESTDIR      For package creation. Default is "". If it is empty when
                 `configure` is run, it can also be passed to `make install`
                 later as an environment variable. If both are specified,
                 the one given to `configure` takes precedence.
    LONG_BIT     The number of bits in a C `long` type. This is mostly for the
                 embedded space since this `bc` uses `long`s internally for
                 overflow checking. In C99, a `long` is required to be 32 bits.
                 For most normal desktop systems, setting this is unnecessary,
                 except that 32-bit platforms with 64-bit longs may want to set
                 it to `32`. Default is the default of `LONG_BIT` for the target
                 platform. Minimum allowed is `32`. It is a build time error if
                 the specified value of `LONG_BIT` is greater than the default
                 value of `LONG_BIT` for the target platform.
    GEN_HOST     Whether to use `gen/strgen.c`, instead of `gen/strgen.sh`, to
                 produce the C files that contain the help texts as well as the
                 math libraries. By default, `gen/strgen.c` is used, compiled by
                 "$HOSTCC" and run on the host machine. Using `gen/strgen.sh`
                 removes the need to compile and run an executable on the host
                 machine since `gen/strgen.sh` is a POSIX shell script. However,
                 `gen/lib2.bc` is over 4095 characters, the max supported length
                 of a string literal in C99, and `gen/strgen.sh` generates a
                 string literal instead of an array, as `gen/strgen.c` does. For
                 most production-ready compilers, this limit probably is not
                 enforced, but it could be. Both options are still available for
                 this reason. If you are sure your compiler does not have the
                 limit and do not want to compile and run a binary on the host
                 machine, set this variable to "0". Any other value, or a
                 non-existent value, will cause the build system to compile and
                 run `gen/strgen.c`. Default is "".
    GEN_EMU      Emulator to run string generator code under (leave empty if not
                 necessary). This is not necessary when using `gen/strgen.sh`.
                 Default is "".

WARNING: even though `configure.sh` supports both option types, short and
long, it does not support handling both at the same time. Use only one type.

Settings
========

bc and dc have some settings that, while they cannot be removed by build time
options, can have their defaults changed at build time by packagers. Users are
also able to change each setting with environment variables.

The following is a table of settings, along with their default values and the
environment variables users can use to change them. (For the defaults, non-zero
means on, and zero means off.)

| Setting         | Description          | Default      | Env Variable         |
| =============== | ==================== | ============ | ==================== |
| bc.banner       | Whether to display   |            0 | BC_BANNER            |
|                 | the bc version       |              |                      |
|                 | banner when in       |              |                      |
|                 | interactive mode.    |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| bc.sigint_reset | Whether SIGINT will  |            1 | BC_SIGINT_RESET      |
|                 | reset bc, instead of |              |                      |
|                 | exiting, when in     |              |                      |
|                 | interactive mode.    |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| dc.sigint_reset | Whether SIGINT will  |            1 | DC_SIGINT_RESET      |
|                 | reset dc, instead of |              |                      |
|                 | exiting, when in     |              |                      |
|                 | interactive mode.    |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| bc.tty_mode     | Whether TTY mode for |            1 | BC_TTY_MODE          |
|                 | bc should be on when |              |                      |
|                 | available.           |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| dc.tty_mode     | Whether TTY mode for |            0 | BC_TTY_MODE          |
|                 | dc should be on when |              |                      |
|                 | available.           |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| bc.prompt       | Whether the prompt   | $BC_TTY_MODE | BC_PROMPT            |
|                 | for bc should be on  |              |                      |
|                 | in tty mode.         |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| dc.prompt       | Whether the prompt   | $DC_TTY_MODE | DC_PROMPT            |
|                 | for dc should be on  |              |                      |
|                 | in tty mode.         |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| bc.expr_exit    | Whether to exit bc   |            1 | BC_EXPR_EXIT         |
|                 | if an expression or  |              |                      |
|                 | expression file is   |              |                      |
|                 | given with the -e or |              |                      |
|                 | -f options.          |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| dc.expr_exit    | Whether to exit dc   |            1 | DC_EXPR_EXIT         |
|                 | if an expression or  |              |                      |
|                 | expression file is   |              |                      |
|                 | given with the -e or |              |                      |
|                 | -f options.          |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| bc.digit_clamp  | Whether to have bc   |            0 | BC_DIGIT_CLAMP       |
|                 | clamp digits that    |              |                      |
|                 | are greater than or  |              |                      |
|                 | equal to the current |              |                      |
|                 | ibase when parsing   |              |                      |
|                 | numbers.             |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |
| dc.digit_clamp  | Whether to have dc   |            0 | DC_DIGIT_CLAMP       |
|                 | clamp digits that    |              |                      |
|                 | are greater than or  |              |                      |
|                 | equal to the current |              |                      |
|                 | ibase when parsing   |              |                      |
|                 | numbers.             |              |                      |
| --------------- | -------------------- | ------------ | -------------------- |

These settings are not meant to be changed on a whim. They are meant to ensure
that this bc and dc will conform to the expectations of the user on each
platform.
EOF
