]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/build_lyxwin.sh
Check if we are on column 0 for special case
[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 HOME="/home/Angus"
40
41 # You may need to change these three variables.
42 QT_DIR="${HOME}"/qt3
43 ASPELL_DIR="${HOME}"/aspell-0.50.5
44 # A space-separated string of directories
45 # ASPELL_DICT_DIRS="${HOME}/aspell-en-0.50-2 ${HOME}/aspell-de-0.50-2 "
46 ASPELL_DICT_DIRS="${HOME}/aspell-en-0.50-2"
47 LYX_DIR="${HOME}"/lyx/13x
48
49 # Everything from here on down should be OK "as is".
50 PACKAGING_DIR="$LYX_DIR/development/Win32/packaging"
51 DTL_DIR="$PACKAGING_DIR/dtl"
52 CLEAN_DVI_DIR="$PACKAGING_DIR"
53
54 ASPELL_INSTALL_DIR="c:/Aspell"
55 LYX_ASPELL_DIR="/c/Aspell" # the Autotools don't like "C:/" syntax.
56 LYX_RELATIVE_BUILDDIR=build
57 LYX_INSTALL_DIR=installprefix
58
59 # These are all installed in the final LyX package
60 QT_DLL="${QT_DIR}/bin/qt-mt3.dll"
61 LIBICONV_DLL="/j/MinGW/bin/libiconv-2.dll"
62 MINGW_DLL="/j/MinGW/bin/mingwm10.dll"
63
64 DT2DV="$DTL_DIR/dt2dv.exe"
65 DV2DT="$DTL_DIR/dv2dt.exe"
66 CLEAN_DVI_PY="$CLEAN_DVI_DIR/clean_dvi.py"
67
68 # Change this to 'mv -f' when you are confident that
69 # the various sed scripts are working correctly.
70 MV='mv -f'
71
72 check_dirs_exist()
73 {
74     for dir in "$QT_DIR" "$ASPELL_DIR" "$LYX_DIR" "$DTL_DIR"
75     do
76       test -d "$dir" || {
77           echo "$dir does not exist" >&2
78           exit 1
79       }
80     done
81 }
82
83
84 query_qt()
85 {
86     echo "Please ensure that the Qt and LyX cvs trees are up to date"
87     echo "and that the Qt library is compiled and ready to go."
88     echo "Press any key to continue"
89     read ans
90 }
91
92
93 check_files_exist()
94 {
95     # Check that the dlls and clean_dvi.py exist
96     for file in "${QT_DLL}" "${LIBICONV_DLL}" "${MINGW_DLL}" "${CLEAN_DVI_PY}"
97     do
98       test -r "${file}" || {
99           echo "$file does not exist" >&2
100           exit 1
101       }
102     done
103 }
104
105
106 build_dtl()
107 {
108     # dt2dv and dv2dt
109     (
110         cd "$DTL_DIR" || {
111             echo "Unable to cd $DTL_DIR" >&2
112             exit 1
113         }
114
115         make || {
116             echo "Failed to make $DTL_DIR" >&2
117             exit 1
118         }
119     )
120
121     for file in "${DT2DV}" "${DV2DT}"
122     do
123       test -x "$file" || {
124           echo "${file} does not exist or is not executable" >&2
125           exit 1
126       }
127     done
128 }
129
130
131 build_aspell()
132 {
133     # Aspell
134     (
135         cd "$ASPELL_DIR" || {
136             echo "Unable to cd $ASPELL_DIR" >&2
137             exit 1
138         }
139
140         ./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 || {
141             echo "Failed to configure $ASPELL_DIR" >&2
142             exit 1
143         }
144
145         # We have to clean up two of the generated Makefiles.
146         TMP=tmp.$$
147         MAKEFILE=examples/Makefile
148         sed '
149 # Replace "CC = gcc" with "CC = g++"
150 s/^ *\(CC *= *\)gcc *$/\1g++/
151 # Remove trailing "/" from the -I directory.
152 s@^ *\(INCLUDES *= *-I\${top_srcdir}/interfaces/cc\)/ *$@\1@
153 ' "${MAKEFILE}" > "${TMP}"
154         cmp -s "${MAKEFILE}" "${TMP}" && {
155             echo "${MAKEFILE} is unchanged" 2>&1
156         } || {
157             diff -u "${MAKEFILE}" "${TMP}"
158             ${MV} "${TMP}" "${MAKEFILE}"
159         }
160         rm -f "${TMP}"
161
162         MAKEFILE=prog/Makefile
163         sed '
164 # Remove trailing "/" from the -I directories.
165 /^ *INCLUDES *= *-I\${top_srcdir}\/common/{
166 :loop
167 $!{
168 N
169 /\n *$/!bloop
170 }
171 s@/ *\(\\ *\n\)@ \1@g
172 }' "${MAKEFILE}" > "${TMP}"
173         cmp -s "${MAKEFILE}" "${TMP}" && {
174             echo "${MAKEFILE} is unchanged" 2>&1
175         } || {
176             diff -u "${MAKEFILE}" "${TMP}"
177             ${MV} "${TMP}" "${MAKEFILE}"
178         }
179         rm -f "${TMP}"
180
181         make || {
182             echo "Failed to make $ASPELL_DIR" >&2
183             exit 1
184         }
185
186         rm -fr "$ASPELL_INSTALL_DIR" || {
187             echo "Failed to remove $ASPELL_INSTALL_DIR prior to installing Aspell" >&2
188             exit 1
189         }
190
191         make install || {
192             echo "Failed to install $ASPELL_DIR" >&2
193             exit 1
194         }
195     )
196 }
197
198
199 build_aspell_dicts()
200 {
201     (
202         PATH="${LYX_ASPELL_DIR}:$PATH"
203         export PATH
204
205         for dir in $ASPELL_DICT_DIRS
206         do
207           (
208                 cd $dir
209                 ./configure
210                 make
211                 make install
212           )
213         done
214     )
215
216 }
217
218 modify_version_C()
219 {
220         VERSION_C="src/version.C"
221         test -r "${VERSION_C}" || {
222             echo "Unable to find ${VERSION_C}"
223             return
224         }
225         test "${LYX_VERSION_STR}" == "" && return
226
227         sed '/char const \* lyx_version = /s/"[^"]*"/"'${LYX_VERSION_STR}'"/' \
228             ${VERSION_C} > tmp.$$
229         diff -u ${VERSION_C} tmp.$$
230         ${MV} tmp.$$ ${VERSION_C}
231 }
232
233
234 build_lyx()
235 {
236     (
237         cd "${LYX_DIR}" || {
238             echo "Unable to cd ${LYX_DIR}" >&2
239             exit 1
240         }
241
242         # Check the line endings of configure.ac
243         # The configure script will be unable to create config.h if it
244         # contains Win32-style line endings.
245         sed 's/
246 $//' ${LYX_DIR}/configure.ac > configure.ac.$$
247         cmp -s ${LYX_DIR}/configure.ac configure.ac.$$ && {
248             rm -f configure.ac.$$
249         } || {
250             mv -f configure.ac.$$ ${LYX_DIR}/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 $LYX_DIR" >&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