1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 05:59:04 -08:00
rc/sh/mw

80 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
mkdir -p ~/opt/mingw
_mw_enabled=0
_mw_host32=i686-w64-mingw32
_mw_host64=x86_64-w64-mingw32
_mw_host=$_mw_host64
typeset -Ag _mw_ # cryptic math expression errors if not global!
_mw_export() {
[ -z "$1" ] && return 1
[ -n "${ZSH_VERSION:-}" ] && _mw_[$1]="${(P)1}" || _mw_[$1]="${!1}"
export "$1=$2"
}
mingw-disable() {
[ $_mw_enabled -eq 0 ] && return 1
_mw_enabled=0
local e=
for e in PATH PREFIX CC CPP CXX CFLAGS CPPFLAGS CXXFLAGS LDFLAGS AR RANLIB RC WINDRES SDL_CFLAGS SDL_LDLIBS; do
export "$e=${_mw_[$e]}"
done
echo "mingw disabled"
}
mingw-enable() {
[ $_mw_enabled -eq 1 ] && mingw-disable || true
_mw_enabled=1
_mw_host=${1:-$_mw_host}
local _mw_misc=~/src/mxe/usr/$_mw_host
local _mw_bin=~/src/mxe/usr/bin
local _mw_prefix=~/opt/mingw
set -- CC gcc CXX g++ CPP cpp AR ar RANLIB ranlib RC windres WINDRES windres
while _mw_export "$1" "$_mw_bin/$_mw_host-$2"; do
shift 2
done
_mw_export PATH "$PATH:$_mw_bin"
_mw_export PREFIX "$_mw_prefix"
_mw_export CFLAGS "-mwin32 -O2 -I $_mw_misc/include -I $_mw_prefix/include"
_mw_export LDFLAGS "-L $_mw_misc/lib -L $_mw_prefix/lib"
_mw_export CPPFLAGS ''
_mw_export CXXFLAGS "$CFLAGS"
# TODO: hackish
local sdl2c=$_mw_host-sdl2-config
which $sdl2c >/dev/null && {
_mw_export SDL_CFLAGS "$($_mw_host-sdl2-config --cflags)"
_mw_export SDL_LDLIBS "$($_mw_host-sdl2-config --libs)"
}
echo "mingw enabled ($_mw_host)"
return 0
}
mw() {
if [ "$#" -eq 1 ]; then
if [ "$1" -eq 32 ]; then
mingw-enable $_mw_host32
elif [ "$1" -eq 64 ]; then
mingw-enable $_mw_host64
elif [ "$1" -eq 0 ]; then
mingw-disable
else
echo "usage: mw [0/32/64]"
return 1
fi
else
if [ $_mw_enabled -eq 0 ]; then
mingw-enable
else
mingw-disable
fi
fi
}
mw $1