]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/build_lyxwin.sh
Fix up a missing '\r' due to ws differences between cvs and svn
[lyx.git] / development / Win32 / packaging / build_lyxwin.sh
1 #! /bin/sh
2
3 # This script aims to do averything necessary to automate the building
4 # of a LyX/Win package.
5
6 # Invocation:
7 # sh build_lyxwin.sh "1.3.6-pre23"
8 # The string will be shown in the "About LyX" dialog.
9
10 # This script is written as a bunch of subroutines. You'll probably
11 # only need to build a couple of the packages (dtl, aspell) once.
12 # Thereafter, the invocation of these subroutines can be commented out.
13 # (See the end of the script.)
14
15 # Notes:
16 # It uses the MinGW/MinSYS environment and compiler.
17
18 # It asks whether the Qt and LyX cvs trees are up to date.
19 # It asks whether the Qt library has been compiled.
20 # It checks that qt-mt3.dll, libiconv-2.dll,
21 #   mingw10.dll and clean_dvi.py exist.
22 # It compiles the dv2dt and dt2dv utilites.
23 # It compiles and installs the Aspell library.
24 # It compiles and installs LyX.
25 # It copies the dv2dt and dt2dv utilites, the .dlls and
26 #   clean_dvi.py to the lyx package.
27 # It modifies the Resources/lyx/configure script to
28 #   ensure that the generated .dvi file is usable.
29
30 # Once all this is done, you're ready to "package" LyX.
31 # See the README for details.
32
33 # The script compiles the .dll version of the Qt libraries. Linking of lyx
34 # against this will, therefore, take "some time".
35
36 # It compiles the static version of the Aspell libraries because no
37 # .dll version exists.
38
39 # You may need to change these four variables.
40 MINGW_DIR="/j/MinGW"
41 QT_DIR="${HOME}"/qt3
42 ASPELL_DIR="${HOME}"/aspell-0.50.5
43 # A space-separated string of directories
44 # ASPELL_DICT_DIRS="${HOME}/aspell-en-0.50-2 ${HOME}/aspell-de-0.50-2 "
45 ASPELL_DICT_DIRS="${HOME}/aspell-en-0.50-2"
46
47 # Everything from here on down should be OK "as is".
48 LYX_DIR="../../.."
49 PACKAGING_DIR="$LYX_DIR/development/Win32/packaging"
50 DTL_DIR="$PACKAGING_DIR/dtl"
51 CLEAN_DVI_DIR="$PACKAGING_DIR"
52
53 ASPELL_INSTALL_DIR="c:/Aspell"
54 LYX_ASPELL_DIR="/c/Aspell" # the Autotools don't like "C:/" syntax.
55 LYX_RELATIVE_BUILDDIR=build
56 LYX_INSTALL_DIR=installprefix
57
58 # These are all installed in the final LyX package
59 QT_DLL="${QT_DIR}/bin/qt-mt3.dll"
60 LIBICONV_DLL="${MINGW_DIR}/bin/libiconv-2.dll"
61 MINGW_DLL="${MINGW_DIR}/bin/mingwm10.dll"
62
63 DT2DV="${DTL_DIR}/dt2dv.exe"
64 DV2DT="${DTL_DIR}/dv2dt.exe"
65 CLEAN_DVI_PY="${CLEAN_DVI_DIR}/clean_dvi.py"
66
67 # Change this to 'mv -f' when you are confident that
68 # the various sed scripts are working correctly.
69 MV='mv -f'
70
71 check_dirs_exist()
72 {
73     for dir in "$QT_DIR" "$ASPELL_DIR" "$LYX_DIR" "$DTL_DIR"
74     do
75       test -d "$dir" || {
76           echo "$dir does not exist" >&2
77           exit 1
78       }
79     done
80 }
81
82
83 query_qt()
84 {
85     echo "Please ensure that the Qt and LyX cvs trees are up to date"
86     echo "and that the Qt library is compiled and ready to go."
87     echo "Press any key to continue"
88     read ans
89 }
90
91
92 check_files_exist()
93 {
94     # Check that the dlls and clean_dvi.py exist
95     for file in "${QT_DLL}" "${LIBICONV_DLL}" "${MINGW_DLL}" "${CLEAN_DVI_PY}"
96     do
97       test -r "${file}" || {
98           echo "$file does not exist" >&2
99           exit 1
100       }
101     done
102 }
103
104
105 build_dtl()
106 {
107     # dt2dv and dv2dt
108     (
109         cd "$DTL_DIR" || {
110             echo "Unable to cd $DTL_DIR" >&2
111             exit 1
112         }
113
114         make || {
115             echo "Failed to make $DTL_DIR" >&2
116             exit 1
117         }
118     )
119
120     for file in "${DT2DV}" "${DV2DT}"
121     do
122       test -x "$file" || {
123           echo "${file} does not exist or is not executable" >&2
124           exit 1
125       }
126     done
127 }
128
129
130 build_aspell()
131 {
132     # Aspell
133     (
134         cd "$ASPELL_DIR" || {
135             echo "Unable to cd $ASPELL_DIR" >&2
136             exit 1
137         }
138
139         ./configure --enable-static --disable-shared --prefix="${ASPELL_INSTALL_DIR}" --sysconfdir="${ASPELL_INSTALL_DIR}" --enable-docdir="${ASPELL_INSTALL_DIR}/doc" --datadir="${ASPELL_INSTALL_DIR}/data" --enable-pkgdatadir="${ASPELL_INSTALL_DIR}/data" --enable-dict-dir="${ASPELL_INSTALL_DIR}/dict" --enable-win32-relocatable || {
140             echo "Failed to configure $ASPELL_DIR" >&2
141             exit 1
142         }
143
144         # We have to clean up two of the generated Makefiles.
145         TMP=tmp.$$
146         MAKEFILE=examples/Makefile
147         sed '
148 # Replace "CC = gcc" with "CC = g++"
149 s/^ *\(CC *= *\)gcc *$/\1g++/
150 # Remove trailing "/" from the -I directory.
151 s@^ *\(INCLUDES *= *-I\${top_srcdir}/interfaces/cc\)/ *$@\1@
152 ' "${MAKEFILE}" > "${TMP}"
153         cmp -s "${MAKEFILE}" "${TMP}" && {
154             echo "${MAKEFILE} is unchanged" 2>&1
155         } || {
156             diff -u "${MAKEFILE}" "${TMP}"
157             ${MV} "${TMP}" "${MAKEFILE}"
158         }
159         rm -f "${TMP}"
160
161         MAKEFILE=prog/Makefile
162         sed '
163 # Remove trailing "/" from the -I directories.
164 /^ *INCLUDES *= *-I\${top_srcdir}\/common/{
165 :loop
166 $!{
167 N
168 /\n *$/!bloop
169 }
170 s@/ *\(\\ *\n\)@ \1@g
171 }' "${MAKEFILE}" > "${TMP}"
172         cmp -s "${MAKEFILE}" "${TMP}" && {
173             echo "${MAKEFILE} is unchanged" 2>&1
174         } || {
175             diff -u "${MAKEFILE}" "${TMP}"
176             ${MV} "${TMP}" "${MAKEFILE}"
177         }
178         rm -f "${TMP}"
179
180         make || {
181             echo "Failed to make $ASPELL_DIR" >&2
182             exit 1
183         }
184
185         rm -fr "$ASPELL_INSTALL_DIR" || {
186             echo "Failed to remove $ASPELL_INSTALL_DIR prior to installing Aspell" >&2
187             exit 1
188         }
189
190         make install || {
191             echo "Failed to install $ASPELL_DIR" >&2
192             exit 1
193         }
194     )
195 }
196
197
198 build_aspell_dicts()
199 {
200     (
201         PATH="${LYX_ASPELL_DIR}:$PATH"
202         export PATH
203
204         for dir in $ASPELL_DICT_DIRS
205         do
206           (
207                 cd $dir
208                 ./configure
209                 make
210                 make install
211           )
212         done
213     )
214
215 }
216
217 modify_version_C()
218 {
219         VERSION_C="src/version.C"
220         test -r "${VERSION_C}" || {
221             echo "Unable to find ${VERSION_C}"
222             return
223         }
224         test "${LYX_VERSION_STR}" == "" && return
225
226         sed '/char const \* lyx_version = /s/"[^"]*"/"'${LYX_VERSION_STR}'"/' \
227             ${VERSION_C} > tmp.$$
228         diff -u ${VERSION_C} tmp.$$
229         ${MV} tmp.$$ ${VERSION_C}
230 }
231
232
233 build_lyx()
234 {
235     (
236         cd "${LYX_DIR}" || {
237             echo "Unable to cd ${LYX_DIR}" >&2
238             exit 1
239         }
240
241         # Check the line endings of configure.ac
242         # The configure script will be unable to create config.h if it
243         # contains Win32-style line endings.
244         rm -f configure.ac
245         sed 's/\r$//' config/configure.ac > configure.ac.$$
246         cmp -s config/configure.ac configure.ac.$$ && {
247             rm -f configure.ac.$$
248         } || {
249             mv -f configure.ac.$$ config/configure.ac
250             echo 'configure.ac has Win32-style line endings. Corrected' >&2
251         }
252
253         ./autogen.sh || {
254             echo "autogen.sh failed" >&2
255             exit 1
256         }
257
258         BUILDDIR="${LYX_RELATIVE_BUILDDIR}"
259         test ! -d "${BUILDDIR}" && {
260             mkdir "${BUILDDIR}" || \
261                 Error "Unable to create build dir, ${BUILDDIR}."
262         }
263
264         CONFIGURE="../configure --without-x --with-included-gettext --with-extra-prefix='${LYX_ASPELL_DIR}' --with-frontend=qt QTDIR='$QT_DIR'"
265
266         echo "${CONFIGURE}"
267         cd "${BUILDDIR}"
268         echo "${PWD}"
269         eval "${CONFIGURE}" || {
270             echo "Failed to configure LyX" >&2
271             exit 1
272         }
273
274         # Modify the "lyx_version" string in build/src/version.C
275         modify_version_C
276
277         # Build LyX
278         make || {
279             echo "Failed to make $LYX_DIR" >&2
280             exit 1
281         }
282     )
283 }
284
285
286 install_lyx()
287 {
288     (
289         BUILDDIR="${LYX_RELATIVE_BUILDDIR}"
290         cd "${LYX_DIR}/${BUILDDIR}" || {
291             echo "Unable to cd ${LYX_DIR}/${BUILDDIR}" >&2
292             exit 1
293         }
294
295         rm -fr "$LYX_INSTALL_DIR" || {
296             echo "Failed to remove $LYX_INSTALL_DIR prior to installing LyX" >&2
297             exit 1
298         }
299
300         make install || {
301             echo "Failed to install" >&2
302             exit 1
303         }
304     )
305 }
306
307 LYX_VERSION_STR=""
308 test $# -ne 0 && LYX_VERSION_STR=$1
309
310 check_dirs_exist || exit 1
311 query_qt || exit 1
312 check_files_exist || exit 1
313 build_dtl || exit 1
314 build_aspell || exit 1
315 build_aspell_dicts || exit 1
316 build_lyx || exit 1
317 install_lyx || exit 1
318 # The end