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

70 lines
1.7 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
2013-06-29 11:47:01 -07:00
mkdir -p ~/opt/mingw
_mw_enabled=0
2013-09-15 18:09:46 -07:00
_mw_host=x86_64-w64-mingw32
_mw_bin=~/src/mxe/usr/bin
_mw_misc=~/src/mxe/usr/$_mw_host
2013-06-29 11:47:01 -07:00
_mw_prefix=~/opt/mingw
typeset -Ag _mw_ # cryptic math expression errors if not global!
2013-06-29 11:47:01 -07:00
_mw_export() {
[ -z "$1" ] && return 1
[ -n "${ZSH_VERSION:-}" ] && _mw_[$1]="${(P)1}" || _mw_[$1]="${!1}"
2013-06-29 11:47:01 -07:00
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
2013-06-29 11:47:01 -07:00
export "$e=${_mw_[$e]}"
done
}
mingw-enable() {
[ $_mw_enabled -eq 1 ] && return 1
_mw_enabled=1
set -- CC gcc CXX g++ CPP cpp AR ar RANLIB ranlib RC windres WINDRES windres
2013-09-15 18:09:46 -07:00
while _mw_export "$1" "$_mw_bin/$_mw_host-$2"; do
2013-06-29 11:47:01 -07:00
shift 2
done
2013-09-15 18:09:46 -07:00
_mw_export PATH "$PATH:$_mw_bin"
_mw_export PREFIX "$_mw_prefix"
2013-06-29 11:47:01 -07:00
_mw_export CFLAGS "-O2 -I $_mw_misc/include -I $_mw_prefix/include"
2013-11-06 01:28:52 -08:00
_mw_export LDFLAGS "-s -L $_mw_misc/lib -L $_mw_prefix/lib"
2013-06-29 11:47:01 -07:00
_mw_export CPPFLAGS ''
_mw_export CXXFLAGS "$CFLAGS"
2013-10-20 06:22:26 -07:00
# 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)"
}
2013-06-29 11:47:01 -07:00
}
2013-09-15 18:09:46 -07:00
mw() {
2013-10-20 06:22:26 -07:00
if [ "$#" -eq 1 ]; then
if [ "$1" -eq 1 ]; then
mingw-enable
else
mingw-disable
2013-09-15 18:09:46 -07:00
fi
2013-10-20 06:22:26 -07:00
else
if [ $_mw_enabled -eq 0 ]; then
2013-09-15 18:09:46 -07:00
echo "mingw enabled"
mingw-enable
2013-10-20 06:22:26 -07:00
else
2013-09-15 18:09:46 -07:00
echo "mingw disabled"
mingw-disable
2013-10-20 06:22:26 -07:00
fi
fi
2013-09-15 18:09:46 -07:00
}
mw $1