OSDN Git Service

* Makefile.in (CYGWIN_BINS): Add getconf.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / utils / mingw
1 #!/bin/bash
2 # Front-end kludge to cause a Cygwin gcc to default to
3 # an installed version of the MinGW components.
4
5 #
6 # Find the path to the compiler.
7 #
8 compiler=$1; shift
9 dir=$(cd $(dirname $("$compiler" -print-prog-name=ld))/../..; pwd)
10
11 #
12 # The mingw32 directory should live somewhere close by to the
13 # compiler.  Search for it.
14 #
15 [ "$dir" = '/' ] && dir=''
16 mingw_dir=''
17 for d in "$dir"/*-mingw32 "$dir"/usr/*-mingw32 "$dir"/*-mingw* "$dir"/usr/*-mingw* \
18          /*-mingw32 /usr/*-mingw32 /*-mingw* /usr/*-mingw*; do
19     case "$d" in
20         *\**)   continue ;;
21         *)      if [ -d "$d"/sys-root/mingw ]; then
22                     mingw_dir=$d/sys-root/mingw
23                 else
24                     mingw_dir=$d;
25                 fi; break;
26     esac
27 done
28
29 if [ -z "$mingw_dir" ]; then
30     echo "$0: couldn't find i686-pc-mingw32 directory" 1>&2
31     exit 1
32 fi
33
34 #
35 # Inspect each argument throwing away ones that seem to try to include the
36 # Cygwin environment.
37 #
38 newargs=()
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; }
47 for f do
48     if eatnext; then
49         eatnext() { return 1; }
50         continue;
51     fi
52     if pushnext; then
53         pushnext() { return 1; }
54     else
55         case "$f" in
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; } ;;
64             -*)         ;;
65             *.cc|*.c|*.s|*.S|*.i|*.ii)  sawcfile() { return 0; } ;;
66             *.o)                sawofile() { return 0; };;
67         esac
68     fi
69     newargs[${#newargs[*]}]="$f"
70 done
71
72 # Set up a new set of arguments + also search the installed mingw
73 # directory.
74 set -- -B"$mingw_dir"/lib/ "${newargs[@]}"
75
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
83         case "$compiler" in
84             *++*) set -- -nostdinc++ "$@" ;;
85             *) set -- -nostdinc "$@" ;;
86         esac
87     fi
88 fi
89
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 "$@"
96 fi
97
98 # Execute the compiler with new mingw-specific options.
99 exec $compiler "$@"