Skip to content

Commit

Permalink
scripts/Windows/build-mingw-prereqs.sh: revise determination of ARCH …
Browse files Browse the repository at this point in the history
…and PREFIX, so they can be customized (e.g. for non-Windows prereq builds eventually) [#1491]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
  • Loading branch information
jimklimov committed Jan 20, 2025
1 parent 2568523 commit 420333f
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions scripts/Windows/build-mingw-prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,58 @@ prepareEnv() {
if [ -n "${ARCH-}" ] && [ -n "${PREFIX-}" ] ; then
[ -n "${WSDIR-}" ] || WSDIR="$DLDIR"/"$ARCH"
mkdir -p "$WSDIR" "$DLDIR"
return 0
fi

BUILD_FLAG=""
HOST_FLAG=""
export HOST_FLAG
if [ -n "${MSYS2_PATH-}" ]; then
# Assume semi-native build for same env
ARCH="$MINGW_CHOST"
PREFIX="$MINGW_PREFIX"
PATH="$PREFIX/bin:$PATH"
export ARCH PATH PREFIX

if ! (command -v sudo) ; then sudo() ( "$@" ) ; fi
else
# TODO: Select by args, envvars, directory presence...
ARCH="x86_64-w64-mingw32"
#ARCH="i686-w64-mingw32"
BUILD_FLAG=""
HOST_FLAG=""
export HOST_FLAG
if [ -n "${MSYS2_PATH-}" ]; then
# Assume semi-native build for same env
[ -n "${ARCH-}" ] || ARCH="$MINGW_CHOST"
[ -n "${PREFIX-}" ] || PREFIX="$MINGW_PREFIX"
PATH="$PREFIX/bin:$PATH"
export ARCH PATH PREFIX

if ! (command -v sudo) ; then sudo() ( "$@" ) ; fi
else
if [ -z "${ARCH-}" ] ; then
# TODO: Select by args, envvars, directory presence...
ARCH="x86_64-w64-mingw32"
#ARCH="i686-w64-mingw32"
fi

# Assumes Ubuntu/Debian with mingw prepared, per README
HOST_FLAG="--host=$ARCH"
PREFIX="/usr/$ARCH"
# Assumes Ubuntu/Debian with mingw prepared, per README
HOST_FLAG="--host=$ARCH"
[ -n "${PREFIX-}" ] || PREFIX="/usr/$ARCH"

export ARCH PREFIX
export ARCH PREFIX

if (command -v dpkg-architecture) ; then
BUILD_FLAG="--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE`"
if (command -v dpkg-architecture) ; then
BUILD_FLAG="--build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE`"
fi
fi
fi

CFLAGS="$CFLAGS -D_POSIX=1 -I${PREFIX}/include/"
CXXFLAGS="$CXXFLAGS -D_POSIX=1 -I${PREFIX}/include/"
LDFLAGS="$LDFLAGS -L${PREFIX}/lib/"
PKG_CONFIG_PATH="${PREFIX}"/lib/pkgconfig
if [ -z "${ARCH-}" ] || [ -z "${PREFIX-}" ] ; then
echo "FAILED to determine ARCH and/or PREFIX!" >&2
exit 1
fi

case "$CFLAGS" in
*"${PREFIX}/include"*) ;;
*) CFLAGS="$CFLAGS -D_POSIX=1 -I${PREFIX}/include/" ;;
esac
case "$CXXFLAGS" in
*"${PREFIX}/include"*) ;;
*) CXXFLAGS="$CXXFLAGS -D_POSIX=1 -I${PREFIX}/include/" ;;
esac
case "$LDFLAGS" in
*"${PREFIX}/lib"*) ;;
*) LDFLAGS="$LDFLAGS -L${PREFIX}/lib/" ;;
esac
case "$PKG_CONFIG_PATH" in
*"${PREFIX}/lib"*) ;;
*) PKG_CONFIG_PATH="${PREFIX}"/lib/pkgconfig ;;
esac

export CFLAGS CXXFLAGS LDFLAGS PKG_CONFIG_PATH

Expand Down

0 comments on commit 420333f

Please sign in to comment.