2008-10-12 11:06:12 +08:00
|
|
|
#!/bin/sh
|
|
|
|
# Front-end kludge to cause a Cygwin gcc to default to
|
|
|
|
# an installed version of the MinGW components.
|
|
|
|
|
|
|
|
#
|
2008-10-12 11:08:33 +08:00
|
|
|
# Find the path to the compiler.
|
2008-10-12 11:06:12 +08:00
|
|
|
#
|
|
|
|
compiler=$1; shift
|
2008-10-12 11:20:37 +08:00
|
|
|
dir=$(cd $(dirname $("$compiler" -print-prog-name=ld))/../..; pwd)
|
2008-10-12 11:06:12 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# The mingw32 directory should live somewhere close by to the
|
|
|
|
# compiler. Search for it.
|
|
|
|
#
|
|
|
|
[ "$dir" = '/' ] && dir=''
|
|
|
|
mingw_dir=''
|
2009-08-10 09:55:14 +08:00
|
|
|
for d in "$dir"/*-mingw32 "$dir"/usr/*-mingw32 "$dir"/*-mingw* "$dir"/usr/*-mingw* \
|
|
|
|
/*-mingw32 /usr/*-mingw32 /*-mingw* /usr/*-mingw*; do
|
2008-10-12 11:06:12 +08:00
|
|
|
case "$d" in
|
|
|
|
*\**) continue ;;
|
2010-08-11 11:01:55 +08:00
|
|
|
*) if [ -d "$d"/sys-root/mingw ]; then
|
|
|
|
mingw_dir=$d/sys-root/mingw
|
|
|
|
else
|
|
|
|
mingw_dir=$d;
|
|
|
|
fi; break;
|
2008-10-12 11:06:12 +08:00
|
|
|
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 07:54:03 +08:00
|
|
|
sawshared() { return 1; }
|
|
|
|
sawnostdinc() { return 1; }
|
|
|
|
sawnostdlib() { return 1; }
|
2008-10-12 11:06:12 +08: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 07:54:03 +08:00
|
|
|
*cygwin/include*|*newlib|-mno-cygwin) continue ;;
|
2008-10-12 11:06:12 +08:00
|
|
|
-c|-E) sawcomp() { return 0; } ;;
|
2008-10-13 08:56:09 +08:00
|
|
|
-xc*) sawcfile() { return 0; } ;;
|
2008-10-12 11:06:12 +08:00
|
|
|
-isystem) eatnext() { return 0; }; continue ;;
|
2008-10-13 07:54:03 +08:00
|
|
|
-o) pushnext() { return 0; } ;;
|
|
|
|
-nostdinc*) sawnostdinc() { return 0; } ;;
|
|
|
|
-nostdlib) sawnostdlib() { return 0; } ;;
|
|
|
|
-shared|-Wl,-shared) sawshared() { return 0; } ;;
|
2008-10-12 11:06:12 +08:00
|
|
|
-*) ;;
|
2008-10-13 08:56:09 +08:00
|
|
|
*.cc|*.c|*.s|*.S|*.i|*.ii) sawcfile() { return 0; } ;;
|
2008-10-13 07:54:03 +08:00
|
|
|
*.o) sawofile() { return 0; };;
|
2008-10-12 11:06:12 +08: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 07:54:03 +08: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 11:06:12 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if sawofile || ! sawcfile || ! sawcomp; then
|
|
|
|
w32api=$($compiler -print-file-name=libc.a)
|
|
|
|
w32api=$(cd $(dirname "$w32api")/w32api; pwd)
|
2008-10-13 07:54:03 +08: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 11:06:12 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Execute the compiler with new mingw-specific options.
|
|
|
|
exec $compiler "$@"
|