Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / scripts / mono-test-install
1 #!/usr/bin/env bash
2 #
3 # Does various checks for people that we can use to diagnose
4 # an end user installation
5 #
6 temp_cs=temp$$.cs
7 temp_exe=temp$$.exe
8 if test -f $temp_cs; then
9     echo Error: need a temporary file name, and $temp_cs already exists
10     echo Run this program from a different directory, or delete the file and try again.
11     exit 1
12 fi
13
14 set `echo $PATH | sed 's/:/ /g'`
15
16 while test x$1 != x; do
17     if test -x $1/mono; then
18         if test x$monocmd = x; then
19            monocmd=$1/mono
20         else
21            other_monos="$1/mono $other_monos"
22         fi
23     fi
24     shift
25 done
26
27 echo Active Mono: $monocmd
28
29 if test "x$other_monos" != x; then
30         echo "Other Mono executables: $other_monos"
31 fi
32
33
34 #
35 # Check that the pkg-config mono points to this mono
36 #
37 if pkg-config --modversion mono >& /dev/null; then 
38         pkg_config_mono=`(cd \`pkg-config --variable prefix mono\`/bin; pwd)`/mono
39         if test $pkg_config_mono != $monocmd; then
40             echo "Error: pkg-config Mono installation points to a different install"
41             echo "       than the Mono found:"
42             echo "       Mono on PATH: $monocmd"
43             echo "       Mono from pkg-config: $pkg_config_mono"
44         fi
45 else 
46         echo "Warning: pkg-config could not find mono installed on this system"
47 fi
48
49 ##########################################################################################
50 #
51 # Tests below this point require the dotnet install
52 #
53 #
54
55 #
56 # Check that -pkg:dotnet is available
57 #
58 if pkg-config --modversion dotnet >& /dev/null; then
59        echo ""
60 else
61        echo "No dotnet pkgconfig found, Windows.Forms, System.Drawing and others will not work"
62        exit 1
63 fi
64
65 case `uname` in
66     Darwin) 
67         macos=true
68         libgdiplus=libgdiplus.dylib
69         LD_PATH=DYLD_LIBRARY_PATH
70         ;;
71     *) 
72         macos=false;
73         libgdiplus=libgdiplus.so
74         LD_PATH=LD_LIBRARY_PATH
75         ;;
76 esac
77
78 search_libgdiplus_on_path()
79 {
80     libgdiplus_found=false
81         if $macos; then
82             set `echo $DYLD_LIBRARY_PATH | sed 's/:/ /g'`
83         else
84             set `echo $LD_LIBRARY_PATH | sed 's/:/ /g'`
85         fi
86         while test x$1 != x; do
87             if test -e $1/$libgdiplus; then
88                    echo "    The $libgdiplus is found on $libdir/$libgdiplus"
89                    libgdiplus_found=true
90                    libgdiplus_path=$1/$libgdiplus
91                    break
92             fi
93             shift
94         done
95 }
96
97 #
98 # Check GDI+ installation
99 #
100 cat > $temp_cs <<EOF
101 using System;
102 using System.Drawing;
103
104 class X { 
105     static void Main ()
106     {
107             Bitmap b = new Bitmap (100, 100);
108     }
109 }
110 EOF
111 if mcs -pkg:dotnet $temp_cs >& /dev/null; then
112     if mono $temp_exe >& /dev/null; then
113         echo Your have a working System.Drawing setup
114     else
115         echo Your system has a broken System.Drawing setup
116         if mono $temp_exe 2>&1 | grep 'System.DllNotFoundException: gdiplus.dll' > /dev/null; then
117            echo "    your gdiplus.dll can not be loaded"
118
119            libdir=`dirname $monocmd`/../lib
120            if test -f $libdir/$libgdiplus; then
121                echo "    The $libgdiplus is found on $libdir/$libgdiplus"
122                if test -e $libdir/$libgdiplus; then
123                    libgdiplus_path=$libdir/$libgdiplus
124                    libgdiplus_found=true
125                else
126                    echo "    but it seems to be a broken link"
127                fi
128            else
129                search_libgdiplus_on_path
130            fi
131            if $libgdiplus_found; then
132                echo ssss 
133                if which ldd >/dev/null; then
134                    LANG=C dirs=`ldd $libgdiplus_path | grep 'not found'`
135                    if echo $dirs | grep 'not found' >& /dev/null; then
136                        echo "    libgdiplus is missing the following dependencies to run:"
137                        echo $dirs | sed 's/^/        /'
138                    fi
139                fi 
140            else
141                echo "    No libgdiplus was found on your $LD_PATH"
142            fi
143         fi
144     fi
145 else
146     echo Failed to compile sample System.Drawing program, your installation is broken
147     exit 1
148 fi
149
150 cat > $temp_cs <<EOF
151 using System;
152 using System.Reflection;
153 using System.IO;
154
155 class Program {
156
157     public static void Main()
158     {
159         object watcher = new FileSystemWatcher()
160             .GetType ()
161             .GetField ("watcher", BindingFlags.NonPublic | BindingFlags.Static)
162             .GetValue (null);
163         
164         Console.WriteLine ("Your file system watcher is: {0}",
165                    watcher != null
166                    ? watcher.GetType ().FullName
167                    : "unknown");
168     }
169 }
170 EOF
171
172 if mcs $temp_cs >& /dev/null; then
173     mono $temp_exe
174 else
175     echo Failed to compile sample test program, your installation is broken
176     exit 1
177 fi