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