1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-14 17:39:03 -08:00
rc/sh/mw

106 lines
2.6 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
2014-02-24 14:15:53 -08:00
_mw_host32=i686-w64-mingw32.static
_mw_host64=x86_64-w64-mingw32.static
if [[ "$(uname -m)" == armv7l ]]; then
_mw_hostarm=./
else
_mw_hostarm=armv7l-unknown-linux-gnueabihf
fi
_mw_host=$_mw_host64
2013-06-29 11:47:01 -07:00
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"
}
mw-disable() {
2013-06-29 11:47:01 -07:00
[ $_mw_enabled -eq 0 ] && return 1
_mw_enabled=0
local e=
2014-02-24 14:15:53 -08:00
for e in PATH PREFIX CC CPP CXX LD CFLAGS CPPFLAGS CXXFLAGS LDFLAGS \
AR RANLIB RC WINDRES OBJCOPY SDL_CFLAGS SDL_LDLIBS; do
2013-11-11 15:11:22 -08:00
local v="${_mw_[$e]}"
[ -n "$v" ] && export "$e=$v" || unset "$e"
2013-06-29 11:47:01 -07:00
done
echo "mw disabled"
2013-06-29 11:47:01 -07:00
}
mw-enable() {
[ $_mw_enabled -eq 1 ] && mw-disable || true
2013-06-29 11:47:01 -07:00
_mw_enabled=1
_mw_host=${1:-$_mw_host}
_mw_usr=${2:-/usr}
local _mw_misc=$_mw_usr/$_mw_host
local _mw_bin=$_mw_usr/bin
2013-11-15 13:48:43 -08:00
local _mw_prefix=~/opt/$_mw_host
mkdir -p "$_mw_prefix"
2014-02-24 14:15:53 -08:00
local tmp="$_mw_bin/$_mw_host"
[ -d "$tmp" ] || tmp+='-'
set -- CC gcc CXX g++ CPP cpp LD ld AR ar \
RANLIB ranlib RC windres WINDRES windres OBJCOPY objcopy
while _mw_export "$1" "$tmp$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"
_mw_export CFLAGS "-O2 -I $_mw_misc/include -I $_mw_prefix/include"
2013-11-10 12:17:42 -08:00
_mw_export LDFLAGS "-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)"
}
echo "mw enabled ($_mw_host)"
return 0
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" == 32 ]]; then
2015-05-20 20:34:03 -07:00
mw-enable $_mw_host32 ~/src/mxe/usr
export CFLAGS="-mwin32 $CFLAGS"
export CXXFLAGS="$CFLAGS"
elif [[ "$1" == 64 ]]; then
2015-05-20 20:34:03 -07:00
mw-enable $_mw_host64 ~/src/mxe/usr
export CFLAGS="-mwin32 $CFLAGS"
export CXXFLAGS="$CFLAGS"
elif [[ "$1" == arm ]]; then
mw-enable $_mw_hostarm /usr
export CFLAGS="-mfloat-abi=hard -mcpu=cortex-a9 $CFLAGS"
export CXXFLAGS="$CFLAGS"
elif [[ "$1" == 0 ]]; then
mw-disable
else
echo "usage: mw [0/32/64/arm]"
return 1
2013-09-15 18:09:46 -07:00
fi
2013-10-20 06:22:26 -07:00
else
if [ $_mw_enabled -eq 0 ]; then
mw-enable
2013-10-20 06:22:26 -07:00
else
mw-disable
2013-10-20 06:22:26 -07:00
fi
fi
2013-09-15 18:09:46 -07:00
}
mw $1