]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/build_lyxwin.sh
Sync 13x and 14x
[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/
246 $//' config/configure.ac > configure.ac.$$
247         cmp -s config/configure.ac configure.ac.$$ && {
248             rm -f configure.ac.$$
249         } || {
250             mv -f configure.ac.$$ config/configure.ac
251             echo 'configure.ac has Win32-style line endings. Corrected' >&2
252         }
253
254         ./autogen.sh || {
255             echo "autogen.sh failed" >&2
256             exit 1
257         }
258
259         BUILDDIR="${LYX_RELATIVE_BUILDDIR}"
260         test ! -d "${BUILDDIR}" && {
261             mkdir "${BUILDDIR}" || \
262                 Error "Unable to create build dir, ${BUILDDIR}."
263         }
264
265         CONFIGURE="../configure --without-x --with-included-gettext --with-extra-prefix='${LYX_ASPELL_DIR}' --with-frontend=qt QTDIR='$QT_DIR'"
266
267         echo "${CONFIGURE}"
268         cd "${BUILDDIR}"
269         echo "${PWD}"
270         eval "${CONFIGURE}" || {
271             echo "Failed to configure LyX" >&2
272             exit 1
273         }
274
275         # Modify the "lyx_version" string in build/src/version.C
276         modify_version_C
277
278         # Build LyX
279         make || {
280             echo "Failed to make $LYX_DIR" >&2
281             exit 1
282         }
283     )
284 }
285
286
287 install_lyx()
288 {
289     (
290         BUILDDIR="${LYX_RELATIVE_BUILDDIR}"
291         cd "${LYX_DIR}/${BUILDDIR}" || {
292             echo "Unable to cd ${LYX_DIR}/${BUILDDIR}" >&2
293             exit 1
294         }
295
296         rm -fr "$LYX_INSTALL_DIR" || {
297             echo "Failed to remove $LYX_INSTALL_DIR prior to installing LyX" >&2
298             exit 1
299         }
300
301         make install || {
302             echo "Failed to install" >&2
303             exit 1
304         }
305     )
306 }
307
308 LYX_VERSION_STR=""
309 test $# -ne 0 && LYX_VERSION_STR=$1
310
311 check_dirs_exist || exit 1
312 query_qt || exit 1
313 check_files_exist || exit 1
314 build_dtl || exit 1
315 build_aspell || exit 1
316 build_aspell_dicts || exit 1
317 build_lyx || exit 1
318 install_lyx || exit 1
319 # The end