2 # Front-end kludge to cause a Cygwin gcc to default to
3 # an installed version of the MinGW components.
6 # Find the path to the compiler.
9 dir=$(cd $(dirname $("$compiler" -print-prog-name=ld))/../..; pwd)
12 # The mingw32 directory should live somewhere close by to the
13 # compiler. Search for it.
15 [ "$dir" = '/' ] && dir=''
17 for d in "$dir"/*-mingw32 "$dir"/usr/*-mingw32 "$dir"/*-mingw* "$dir"/usr/*-mingw* \
18 /*-mingw32 /usr/*-mingw32 /*-mingw* /usr/*-mingw*; do
21 *) if [ -d "$d"/sys-root/mingw ]; then
22 mingw_dir=$d/sys-root/mingw
29 if [ -z "$mingw_dir" ]; then
30 echo "$0: couldn't find i686-pc-mingw32 directory" 1>&2
35 # Inspect each argument throwing away ones that seem to try to include the
39 sawcomp() { return 1; }
40 sawcfile() { return 1; }
41 sawofile() { return 1; }
42 sawshared() { return 1; }
43 sawnostdinc() { return 1; }
44 sawnostdlib() { return 1; }
45 eatnext() { return 1; }
46 pushnext() { return 1; }
49 eatnext() { return 1; }
53 pushnext() { return 1; }
56 *cygwin/include*|*newlib|-mno-cygwin) continue ;;
57 -c|-E) sawcomp() { return 0; } ;;
58 -xc*) sawcfile() { return 0; } ;;
59 -isystem) eatnext() { return 0; }; continue ;;
60 -o) pushnext() { return 0; } ;;
61 -nostdinc*) sawnostdinc() { return 0; } ;;
62 -nostdlib) sawnostdlib() { return 0; } ;;
63 -shared|-Wl,-shared) sawshared() { return 0; } ;;
65 *.cc|*.c|*.s|*.S|*.i|*.ii) sawcfile() { return 0; } ;;
66 *.o) sawofile() { return 0; };;
69 newargs[${#newargs[*]}]="$f"
72 # Set up a new set of arguments + also search the installed mingw
74 set -- -B"$mingw_dir"/lib/ "${newargs[@]}"
76 # Add some default options depending on whether this looks like
77 # an attempt to link, compile, or both.
78 if sawcomp || sawcfile; then
79 ccdir=$(dirname $($compiler -print-libgcc-file-name))
80 sawnostdinc || set -- -isystem "$ccdir"/include -I"${mingw_dir}"/include "$@"
81 set -- -D__MINGW32__ -D__MSVCRT__ -DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ -U__CYGWIN__ -Uunix -U__unix__ -U__unix -U __CYGWIN32__ "$@"
82 if ! sawnostdinc; then
84 *++*) set -- -nostdinc++ "$@" ;;
85 *) set -- -nostdinc "$@" ;;
90 if sawofile || ! sawcfile || ! sawcomp; then
91 w32api=$($compiler -print-file-name=libc.a)
92 w32api=$(cd $(dirname "$w32api")/w32api; pwd)
93 set -- -Wl,-nostdlib -L"${w32api}" "$@"
94 ! sawnostdlib && set -- -nostdlib "$@" -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -lmingw32 -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt
95 ! sawnostdlib && ! sawshared && { sawofile || sawcfile; } && set -- "$mingw_dir"/lib/crt2.o "$@"
98 # Execute the compiler with new mingw-specific options.