commit e5ad324e23d617bc975b15a18de325c2601ec34e from: Thomas Adam date: Sun Sep 11 18:22:31 2022 UTC portable: macos: look for gnu bison harder When checking for GNU Bison (and presumably other) toolchain commands on MacOS, ther's two main systems most users use. Brew, and Ports. Both of these take different approaches when building software, and although a Portsfile exists for -portable now, those users who don't use that directly, or use brew, and try and build -portable from git directly, will likely be at the mercy of ./configure being able to go off and find the appropriate tools. Therefore, ./configure *tries* to be smart about handling this, and will go and check if brew(1) is installed and try and use that to determine the likely path for where it puts its software. Indeed, for MacPorts, the story is very different, and although some users might therfore use --prefix to ./configure to determine this path, there is an overloaded assumption between --prefix meaning where the binaries are to be installed, and --prefix meaning "go and look elsewhere for other applications". At some point, a dedicated configure option might be required. Reported by grey and jamsek. commit - 9ffe20fdada0d0603909c9dee12683390d9f8570 commit + e5ad324e23d617bc975b15a18de325c2601ec34e blob - fd92eb8182fe62d6c7fffea4b7f79b53a2282f78 blob + 79c04745ef45c12ae0d38cd89a3af780c66dc674 --- configure.ac +++ configure.ac @@ -234,27 +234,82 @@ if test x"$PLATFORM" = "xdarwin"; then # onward, this changed to a different path. # # Rather than hardcode this, check for HOMEBREW_PREFIX in the - # environment if it's already set, and use it. Otherwise, chec for + # environment if it's already set, and use it. Otherwise, check for # brew(1) and use that. If that fails, default to /usr/local # # This also means that MacPorts should continue to work. - if test -z "$HOMEBREW_PREFIX"; then + # + # But with MacPorts, we should also check --prefix, and use that if it + # has been supplied. + # + # In both cases, the variable HOMEBREW_PREFIX is used for both. + HB_PREFIX="" + HB_USR_LOCAL="" + FOUND_BISON="no" + if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE"; then # HOMEBREW_PREFIX not set, check for brew(1) - if test -x command -v brew >/dev/null 2>&1; then + if command -v brew >/dev/null 2>&1; then + AC_MSG_NOTICE("HOMEBREW_PREFIX set via 'brew --prefix'") export HOMEBREW_PREFIX="$(brew --prefix)" - else + fi + + if test -z "$HOMEBREW_PREFIX" -o "$HOMEBREW_PREFIX" = "NONE" + then # Default. - export HOMEBREW_PREFIX="/usr/local" + if test -z "${prefix}" -o "${prefix}" = "NONE"; then + export HOMEBREW_PREFIX="/usr/local" + HB_USR_LOCAL="/usr/local" + AC_MSG_NOTICE("HOMEBREW_PREFIX defaulting to /usr/local") + else + export HOMEBREW_PREFIX="$(eval echo ${prefix})" + AC_MSG_NOTICE("HOMEBREW_PREFIX using --prefix") + fi fi fi + AC_MSG_NOTICE("HOMEBREW_PREFIX determined as: $HOMEBREW_PREFIX") + if ! test -x "${HOMEBREW_PREFIX}/opt/bison/bin/bison"; then - AC_MSG_ERROR("GNU Bison not found") + AC_MSG_WARN([ + "*********************************************************** + GNU Bison not found: ${HOMEBREW_PREFIX}/opt/bison/bin/bison + *********************************************************** + + Falling back to checking either /usr/local or \${prefix}" + ]) + + if test -z "$HB_USR_LOCAL"; then + FOUND_BISON="no" + AC_MSG_WARN("Trying ${HB_USR_LOCAL}/opt/bison/bin/bison") + if test -x "${HB_USR_LOCAL}/opt/bison/bin/bison"; then + export HOMEBREW_PREFIX="/usr/local" + FOUND_BISON="yes" + fi + fi + + if test -z "$HB_PREFIX"; then + FOUND_BISON="no" + AC_MSG_WARN("Trying ${HB_PREFIX}/opt/bison/bin/bison") + export HOMEBREW_PREFIX="$(eval echo ${prefix})" + + if test -x "${HB_USR_LOCAL}/opt/bison/bin/bison"; then + export HOMEBREW_PREFIX="$(eval echo ${prefix})" + FOUND_BISON="yes" + fi + fi + else + FOUND_BISON="yes" + fi + + if test "$FOUND_BISON" = "no"; then + AC_MSG_ERROR("*** Couldn't find GNU BISON ***") fi + AC_MSG_NOTICE("Found GNU Bison as: ${HOMEBREW_PREFIX}/opt/bison/bin/bison") + # Override YACC here to point to the GNU version of bison. export YACC="${HOMEBREW_PREFIX}/opt/bison/bin/bison -y" - export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFI}/opt/openssl@3/lib $LDFLAGS" + export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/ncurses/lib -L${HOMEBREW_PREFIX}/opt/openssl@3/lib $LDFLAGS" export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/ncurses/include -I${HOMEBREW_PREFIX}/opt/openssl@3/include $CPPFLAGS" export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/ncurses/lib/pkgconfig" export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${HOMEBREW_PREFIX}/opt/openssl@3/lib/pkgconfig"