2008-10-12 05:06:12 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Front-end kludge to cause a Cygwin gcc to default to
|
|
|
|
# an installed version of the MinGW components.
|
|
|
|
|
|
|
|
#
|
2008-10-12 05:08:33 +02:00
|
|
|
# Find the path to the compiler.
|
2008-10-12 05:06:12 +02:00
|
|
|
#
|
|
|
|
compiler=$1; shift
|
2008-10-12 05:20:37 +02:00
|
|
|
dir=$(cd $(dirname $("$compiler" -print-prog-name=ld))/../..; pwd)
|
2008-10-12 05:06:12 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# The mingw32 directory should live somewhere close by to the
|
|
|
|
# compiler. Search for it.
|
|
|
|
#
|
|
|
|
[ "$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; }
|
2008-10-13 01:54:03 +02:00
|
|
|
sawshared() { return 1; }
|
|
|
|
sawnostdinc() { return 1; }
|
|
|
|
sawnostdlib() { return 1; }
|
2008-10-12 05:06:12 +02:00
|
|
|
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
|
2008-10-13 01:54:03 +02:00
|
|
|
*cygwin/include*|*newlib|-mno-cygwin) continue ;;
|
2008-10-12 05:06:12 +02:00
|
|
|
-c|-E) sawcomp() { return 0; } ;;
|
2008-10-13 02:56:09 +02:00
|
|
|
-xc*) sawcfile() { return 0; } ;;
|
2008-10-12 05:06:12 +02:00
|
|
|
-isystem) eatnext() { return 0; }; continue ;;
|
2008-10-13 01:54:03 +02:00
|
|
|
-o) pushnext() { return 0; } ;;
|
|
|
|
-nostdinc*) sawnostdinc() { return 0; } ;;
|
|
|
|
-nostdlib) sawnostdlib() { return 0; } ;;
|
|
|
|
-shared|-Wl,-shared) sawshared() { return 0; } ;;
|
2008-10-12 05:06:12 +02:00
|
|
|
-*) ;;
|
2008-10-13 02:56:09 +02:00
|
|
|
*.cc|*.c|*.s|*.S|*.i|*.ii) sawcfile() { return 0; } ;;
|
2008-10-13 01:54:03 +02:00
|
|
|
*.o) sawofile() { return 0; };;
|
2008-10-12 05:06:12 +02:00
|
|
|
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))
|
2008-10-13 01:54:03 +02:00
|
|
|
sawnostdinc || set -- -isystem "$ccdir"/include -I"${mingw_dir}"/include "$@"
|
|
|
|
set -- -D__MINGW32__ -D__MSVCRT__ -DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ -U__CYGWIN__ -Uunix -U__unix__ -U__unix -U __CYGWIN32__ "$@"
|
|
|
|
if ! sawnostdinc; then
|
|
|
|
case "$compiler" in
|
|
|
|
*++*) set -- -nostdinc++ "$@" ;;
|
|
|
|
*) set -- -nostdinc "$@" ;;
|
|
|
|
esac
|
|
|
|
fi
|
2008-10-12 05:06:12 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if sawofile || ! sawcfile || ! sawcomp; then
|
|
|
|
w32api=$($compiler -print-file-name=libc.a)
|
|
|
|
w32api=$(cd $(dirname "$w32api")/w32api; pwd)
|
2008-10-13 01:54:03 +02:00
|
|
|
set -- -Wl,-nostdlib -L"${w32api}" "$@"
|
|
|
|
! sawnostdlib && set -- -nostdlib "$@" -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -lmingw32 -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt
|
|
|
|
! sawnostdlib && ! sawshared && { sawofile || sawcfile; } && set -- "$mingw_dir"/lib/crt2.o "$@"
|
2008-10-12 05:06:12 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Execute the compiler with new mingw-specific options.
|
|
|
|
exec $compiler "$@"
|