Update the panic msg from #1257 to be an ordinary error, not a panic
[ghc-hetmet.git] / distrib / prep-bin-dist-mingw
1 #!/bin/sh
2 #
3 # Modify a GHC binary distribution for the purposes of creating a
4 # mingw/win32 install tree.  The resulting tree is ready for packaging
5 # up in whatever form is convenient (MSI installer / tar bundle/ ..)
6 #
7 # To use:
8 #
9 #   - make sure you set BIN_DIST=1 in your mk/build.mk before you built GHC.
10 #   $ cd <top of GHC build tree>
11 #   $ make binary-dist
12 #
13 # This script is called at the appropriate point during 'make binary-dist'.
14 # The result is a tarball at the top of your GHC build tree, named something
15 # like ghc-6.6.1-i386-unknown-mingw32.tar.bz2.
16
17 # User tweakables 
18 #    Note: you normally don't need to set any of these, the script
19 #    will try to figure them out for itself.  If the heuristics don't
20 #    work for whatever reason, you can override them using environment
21 #    variables, e.g.
22 #      mingw_top=<whatever> make binary-dist
23 #
24 #    - mingw_top   -- location of mingw distribution tree (usually c:/mingw)
25 #    - perl_dir    -- location of non-cygwin perl.exe
26 #    - gcc_lib     -- c:/mingw/lib/gcc/mingw32/3.4.2, or equivalent
27 #    - gcc_libexec -- c:/mingw/libexec/gcc/mingw32/3.4.2, or equivalent
28 #
29
30 #Directory where a (cygwin-free) perl binary resides.
31 if [ "${perl_dir}" == "" ]; then
32     for i in c:/ghc/*; do
33        if [ -e $i/perl.exe ]; then
34            perl_dir=$i
35            echo "Found perl.exe in $i"
36            break
37        fi
38     done
39     if [ "${perl_dir}" == "" ]; then
40         echo "Can't find perl.exe; please set \$perl_dir"
41         exit 1
42     fi
43 fi
44
45 if [ "${mingw_top}" == "" ]; then
46     if [ -d c:/mingw ]; then
47         mingw_top=c:/mingw
48         echo "Found mingw in $mingw_top"
49     else
50         echo "Can't find mingw; please set \$mingw_top"
51         exit 1
52     fi
53 fi
54
55 # The gcc-lib directory of the mingw tree you want to
56 # include with the binary dist.
57 if [ "x${gcc_lib}" == "x" ]; then
58     if [ -d "${mingw_top}/lib/gcc-lib/mingw32" ]; then
59         mingw_gcc_lib=${mingw_top}/lib/gcc-lib/mingw32
60     else
61         mingw_gcc_lib=${mingw_top}/lib/gcc/mingw32
62     fi
63     for i in `ls -r ${mingw_gcc_lib}`; do
64         if [ -d "${mingw_gcc_lib}/$i" ]; then
65             gcc_lib=${mingw_gcc_lib}/$i
66             echo "Found gcc lib in $gcc_lib"
67             break
68         fi
69     done
70     if [ "${gcc_lib}" == "" ]; then
71         echo "Can't find gcc lib files; please set \$gcc_lib"
72         exit 1
73     fi
74 fi
75     
76 # The gcc-lib directory of the mingw tree you want to
77 # include with the binary dist.
78 if [ "x${gcc_libexec}" == "x" ]; then
79     if [ -d "${mingw_top}/libexec/gcc-lib/mingw32" ]; then
80         mingw_gcc_libexec=${mingw_top}/libexec/gcc-lib/mingw32
81     else
82         mingw_gcc_libexec=${mingw_top}/libexec/gcc/mingw32
83     fi
84     for i in `ls -r ${mingw_gcc_libexec}`; do
85         if [ -d "${mingw_gcc_libexec}/$i" ]; then
86             gcc_libexec=${mingw_gcc_libexec}/$i
87             echo "Found gcc libexec in $gcc_libexec"
88             break
89         fi
90     done
91     if [ "${gcc_libexec}" == "" ]; then
92         echo "Can't find gcc libexec files; please set \$gcc_libexec"
93         exit 1
94     fi
95 fi
96     
97 #
98 # The mingw include, lib, and bin directories; all derived
99 # from ${mingw_top}.
100 #
101 if [ "x${mingw_include}" == "x" ]; then
102   export mingw_include=$mingw_top/include
103 fi
104 if [ "x${mingw_lib}" == "x" ]; then
105   export mingw_lib=$mingw_top/lib
106 fi
107 if [ "x${mingw_bin}" == "x" ]; then
108   export mingw_bin=$mingw_top/bin
109 fi
110
111 # Check that we're in an OK place before starting to re-org
112 # the directory tree..
113 if ! [ -d bin/i386-unknown-mingw32 ] ; then
114   echo "Doesn't look as if I'm in the toplevel directory of a mingw tree"
115   echo "Usage: cd ghc-<version> ; ../distrib/prep-bin-dist-mingw"
116   exit 1;
117 fi;
118
119 echo "Removing configure script files...not needed"
120 rm -f config.guess config.sub configure configure.ac mkdirhier
121 rm -f Makefile-bin.in Makefile.in aclocal.m4 install-sh
122 rm -rf autom4te.cache
123
124 echo "rejig bin/"
125 mv bin/i386-unknown-mingw32/* bin/
126 rmdir bin/i386-unknown-mingw32
127 strip bin/ghc.exe
128
129 echo "rejig lib/"
130 mv lib/i386-unknown-mingw32/include/* include/ 
131 rmdir lib/i386-unknown-mingw32/include
132 mv lib/i386-unknown-mingw32/* .
133 rmdir lib/i386-unknown-mingw32
134 rmdir lib
135 mv ghc-asm.prl ghc-asm
136 mv ghc-split.prl ghc-split
137
138 echo "create gcc-lib/"
139 #
140 # A bunch of stuff gets lumped into gcc-lib:
141 #
142 #  - the gcc-lib/ + gcc-lib/include of the gcc you
143 #    intend to ship (normally located as 
144 #     lib/gcc-lib/mingw/<gcc version>/ in your mingw tree.)
145 #  - the contents of mingw/lib/ 
146 #  - ld.exe, as.exe, dlltool.exe, dllwrap.exe from mingw/bin
147 #    to gcc-lib/
148 #  - ar.exe from mingw/bin to bin/
149 #
150 mkdir gcc-lib
151 mkdir gcc-lib/include
152 cp $gcc_lib/* gcc-lib/
153 cp $gcc_libexec/* gcc-lib/
154 cp $gcc_lib/include/* gcc-lib/include/
155 cp $mingw_lib/* gcc-lib/
156 cp $mingw_bin/as.exe gcc-lib/
157 cp $mingw_bin/ld.exe gcc-lib/
158 cp $mingw_bin/ar.exe bin/
159 # Note: later versions of dlltool.exe depend on a bfd helper DLL.
160 cp $mingw_bin/dllwrap.exe gcc-lib/
161 cp $mingw_bin/dlltool.exe gcc-lib/
162 # Remove worthy, but unused tools
163 rm gcc-lib/f771.exe || echo "good - f771.exe not found"
164 rm gcc-lib/gnat1.exe || echo "good - gnat1.exe not found"
165 rm gcc-lib/jc1.exe || echo "good - jc1.exe not found"
166 rm gcc-lib/libgcj* || echo "good - libgcj libs not found"
167 rm gcc-lib/jvgenmain.exe || echo "good - jvgenmain.exe not found"
168
169 echo "extra header files inside of include/"
170 #
171 # contains mingw/include
172 mkdir include/mingw
173 cp -Rf $mingw_include/* include/mingw
174 #
175 # g++-3/ subdir causes problems with installer tool (+ being a 
176 # troublesome character); leave out for now.
177 #rm -rf include/mingw/g++-3/ || echo "g++-3/ not there"
178 #rm -rf include/mingw/c++/ || echo "c++/ not there"
179 rm -rf include/mingw/ddk/ || echo "ddk/ not there"
180 rm -rf include/mingw/gnu/ || echo "gnu/ not there"
181 rm -rf include/mingw/javax/ || echo "javax/ not there"
182 rm -rf include/mingw/java/ || echo "java/ not there"
183 rm -rf include/mingw/gcj/ || echo "gcj/ not there"
184
185 echo "add gcc"
186 cp ${mingw_bin}/gcc.exe .
187 #cp ${mingw_bin}/gcc-2.exe gcc.exe
188
189 echo "copy in perl too"
190 cp ${perl_dir}/perl.exe .
191 cp ${perl_dir}/perl56.dll .
192
193 # For reasons unknown, duplicate copies of misc package files in share/
194 # (leave them be for now.)
195
196 echo "formatting documentation"
197 cp README README.txt
198 mv share doc
199
200 # Leave out pdf users_guide documentation for now; problematic to build with the versions
201 # of 'xsltproc' and 'fop' I've been able to lay my hands on.
202 #cp ../ghc/docs/users_guide/users_guide.pdf doc/ || 
203 #  (make -C ../ghc/docs/users_guide/ pdf ; cp ../ghc/docs/users_guide/users_guide.pdf doc/) || 
204 #  echo "No User Guide PDF doc found"
205 #cp ../hslibs/doc/hslibs.pdf doc/ || 
206 #  (make -C ../hslibs/doc/ pdf ; cp ../hslibs/doc/hslibs.pdf doc/) ||
207 #  echo "No HSLIBS PDF doc found"