-
-
Save TheAngryByrd/651c687f937da35afdb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Copyright (c) 2011-2012, Mihail Szabolcs | |
# | |
# Released into the public domain. For more information see http://unlicense.org/ . | |
# | |
# Bootstraps an environment that makes it possible to cross-compile libraries like SDL, | |
# or pretty much anything else in an easy and unobstrusive manner. | |
# | |
# Requirements: | |
# * MingW Cross Compiler | |
# * Wine (for testing only) | |
# * Linux | |
# | |
# Example: | |
# create file: main.c | |
# | |
# #include <windows.h> | |
# | |
# int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |
# { | |
# MessageBox(NULL, "Hello World!", "Hello :)", MB_OK | MB_ICONINFORMATION); | |
# return 0; | |
# } | |
# | |
# boot into a shell: ./mingw bash | |
# compile the file: $CC main.c -o hello.exe | |
# test the resulting executable: wine hello.exe | |
# | |
# One can also run ./mingw ./configure directly without booting into a shell | |
# in order to configure third party libraries like SDL in an easy fashion. | |
# | |
if [ -z "$1" ]; then | |
echo "usage: mingw command [arguments]" | |
exit | |
fi | |
MINGW_GCC_VARIANTS=(i586-mingw32msvc-gcc i386-mingw32msvc-gcc i686-pc-mingw32-gcc) | |
for gcc in ${MINGW_GCC_VARIANTS[@]}; do | |
MINGW_GCC=$(which $gcc 2>/dev/null) | |
if [ -n "$MINGW_GCC" ]; then | |
echo -e "\e[92mFound: $MINGW_GCC\e[00m" | |
break | |
fi | |
done | |
if [ -z "$MINGW_GCC" ]; then | |
echo -e "\e[91mCannot find mingw32-gcc or any of it's variants, aborting ...\e[00m" | |
exit | |
fi | |
export MINGW_PREFIX_PATH=${MINGW_GCC/-gcc/} | |
export MINGW_PREFIX=$(basename $MINGW_PREFIX_PATH) | |
export CC="$MINGW_PREFIX_PATH-gcc" | |
export CXX="$MINGW_PREFIX_PATH-g++" | |
export LD="$MINGW_PREFIX_PATH-ld" | |
export AR="$MINGW_PREFIX_PATH-ar" | |
export AS="$MINGW_PREFIX_PATH-as" | |
export NM="$MINGW_PREFIX_PATH-nm" | |
export STRIP="$MINGW_PREFIX_PATH-strip" | |
export RANLIB="$MINGW_PREFIX_PATH-ranlib" | |
export DLLTOOL="$MINGW_PREFIX_PATH-dlltool" | |
export OBJDUMP="$MINGW_PREFIX_PATH-objdump" | |
export RESCOMP="$MINGW_PREFIX_PATH-windres" | |
export WINDRES="$MINGW_PREFIX_PATH-windres" | |
if [ "$1" == "bash" -a -f .localrc ]; then | |
$@ --rcfile .localrc | |
elif [ "$1" == "./configure" ]; then | |
$@ --host=$MINGW_PREFIX | |
else | |
$@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment