90 lines
2.5 KiB
Plaintext
90 lines
2.5 KiB
Plaintext
|
#!/bin/sh
|
||
|
# Front-end kludge to cause a Cygwin gcc to default to
|
||
|
# an installed version of the MinGW components.
|
||
|
|
||
|
#
|
||
|
# Find the path to the compiler
|
||
|
#
|
||
|
compiler=$1; shift
|
||
|
case "$compiler" in
|
||
|
*/*) ;;
|
||
|
*) compiler=($(type "$compiler"))
|
||
|
compiler=${compiler[2]} ;;
|
||
|
esac
|
||
|
|
||
|
#
|
||
|
# The mingw32 directory should live somewhere close by to the
|
||
|
# compiler. Search for it.
|
||
|
#
|
||
|
updir=$(dirname "$compiler")
|
||
|
dir=$(cd "$updir"/..; pwd)
|
||
|
[ "$dir" = '/' ] && dir=''
|
||
|
mingw_dir=''
|
||
|
for d in "$dir"/*-mingw32 "$dir"/usr/*-mingw32 "$dir"/*-mingw* "$dir"/usr/*-mingw*; do
|
||
|
case "$d" in
|
||
|
*\**) continue ;;
|
||
|
*) mingw_dir=$d; break;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
if [ -z "$mingw_dir" ]; then
|
||
|
echo "$0: couldn't find i686-pc-mingw32 directory" 1>&2
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
#
|
||
|
# Inspect each argument throwing away ones that seem to try to include the
|
||
|
# Cygwin environment.
|
||
|
#
|
||
|
newargs=()
|
||
|
sawcomp() { return 1; }
|
||
|
sawcfile() { return 1; }
|
||
|
sawofile() { return 1; }
|
||
|
eatnext() { return 1; }
|
||
|
pushnext() { return 1; }
|
||
|
for f do
|
||
|
if eatnext; then
|
||
|
eatnext() { return 1; }
|
||
|
continue;
|
||
|
fi
|
||
|
if pushnext; then
|
||
|
pushnext() { return 1; }
|
||
|
else
|
||
|
case "$f" in
|
||
|
*cygwin/include*|*newlib*) continue ;;
|
||
|
-c|-E) sawcomp() { return 0; } ;;
|
||
|
-isystem) eatnext() { return 0; }; continue ;;
|
||
|
-o) pushnext() { return 0; } ; /bin/true ;;
|
||
|
-*) ;;
|
||
|
*.cc|*.c) sawcfile() { return 0; } ;;
|
||
|
*.o) sawofile() { return 0; }; /bin/true ;;
|
||
|
esac
|
||
|
fi
|
||
|
newargs[${#newargs[*]}]="$f"
|
||
|
done
|
||
|
|
||
|
# Set up a new set of arguments + also search the installed mingw
|
||
|
# directory.
|
||
|
set -- -B"$mingw_dir"/lib/ "${newargs[@]}"
|
||
|
|
||
|
# Add some default options depending on whether this looks like
|
||
|
# an attempt to link, compile, or both.
|
||
|
if sawcomp || sawcfile; then
|
||
|
ccdir=$(dirname $($compiler -print-libgcc-file-name))
|
||
|
set -- -isystem "$ccdir"/include -D__MINGW32__ -D__MSVCRT__ -DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ -U__CYGWIN__ -Uunix -U__unix__ -U__unix -U __CYGWIN32__ -I"${mingw_dir}"/include "$@"
|
||
|
case "$compiler" in
|
||
|
*++*) set -- -nostdinc++ "$@" ;;
|
||
|
*) set -- -nostdinc "$@" ;;
|
||
|
esac
|
||
|
fi
|
||
|
|
||
|
if sawofile || ! sawcfile || ! sawcomp; then
|
||
|
w32api=$($compiler -print-file-name=libc.a)
|
||
|
w32api=$(cd $(dirname "$w32api")/w32api; pwd)
|
||
|
set -- "$@" -nostdlib -Wl,-nostdlib -L"$w32api" -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -lmingw32 -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt
|
||
|
{ sawofile || sawcfile; } && set -- "$mingw_dir"/lib/crt2.o "$@"
|
||
|
fi
|
||
|
|
||
|
# Execute the compiler with new mingw-specific options.
|
||
|
exec $compiler "$@"
|