]> git.lyx.org Git - features.git/blob - development/Win32/packaging/build_lyxwin.sh
79dcb955992b44d7d29cf6a7222c0944a89aa81b
[features.git] / development / Win32 / packaging / build_lyxwin.sh
1 #! /bin/sh
2
3 # This script aims to do everything 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 # Notes:
11 # It uses the MSYS environment and MinGW compiler.
12
13 # It asks whether the Qt and LyX cvs trees are up to date.
14 # It asks whether the Qt library has been compiled.
15 # It checks that qt-mt3.dll, mingw10.dll and clean_dvi.py exist.
16 # It compiles the dv2dt and dt2dv utilites.
17 # It compiles and installs LyX.
18
19 # Once all this is done, you're ready to "package" LyX.
20 # See the README for details.
21
22 # The script compiles the .dll version of the Qt libraries. Linking of LyX
23 # against this will, therefore, take "some time".
24
25 # You may need to change these four variables.
26 MINGW_DIR="/j/MinGW"
27 QT_DIR="${HOME}"/Qt/3x-msys
28
29 # Everything from here on down should be OK "as is".
30 LYX_DIR="../../.."
31 PACKAGING_DIR="$LYX_DIR/development/Win32/packaging"
32 DTL_DIR="$PACKAGING_DIR/dtl"
33 CLEAN_DVI_DIR="$PACKAGING_DIR"
34
35 ASPELL_INSTALL_DIR="c:/Aspell"
36 LYX_ASPELL_DIR="/c/Aspell" # the Autotools don't like "C:/" syntax.
37 LYX_RELATIVE_BUILDDIR=build
38 LYX_INSTALL_DIR=installprefix
39
40 # These are all installed in the final LyX package
41 QT_DLL="${QT_DIR}/bin/qt-mt3.dll"
42 MINGW_DLL="${MINGW_DIR}/bin/mingwm10.dll"
43
44 DT2DV="${DTL_DIR}/dt2dv.exe"
45 DV2DT="${DTL_DIR}/dv2dt.exe"
46 CLEAN_DVI_PY="${CLEAN_DVI_DIR}/clean_dvi.py"
47
48 # Change this to 'mv -f' when you are confident that
49 # the various sed scripts are working correctly.
50 MV='mv -f'
51
52 check_dirs_exist()
53 {
54     for dir in "$QT_DIR" "$LYX_DIR" "$DTL_DIR"
55     do
56       test -d "$dir" || {
57           echo "$dir does not exist" >&2
58           exit 1
59       }
60     done
61 }
62
63
64 query_qt()
65 {
66     echo "Please ensure that the Qt and LyX cvs trees are up to date"
67     echo "and that the Qt library is compiled and ready to go."
68     echo "Press any key to continue"
69     read ans
70 }
71
72
73 check_files_exist()
74 {
75     # Check that the dlls and clean_dvi.py exist
76     for file in "${QT_DLL}" "${MINGW_DLL}" "${CLEAN_DVI_PY}"
77     do
78       test -r "${file}" || {
79           echo "$file does not exist" >&2
80           exit 1
81       }
82     done
83 }
84
85
86 build_dtl()
87 {
88     # dt2dv and dv2dt
89     (
90         cd "$DTL_DIR" || {
91             echo "Unable to cd $DTL_DIR" >&2
92             exit 1
93         }
94
95         make || {
96             echo "Failed to make $DTL_DIR" >&2
97             exit 1
98         }
99     )
100
101     for file in "${DT2DV}" "${DV2DT}"
102     do
103       test -x "$file" || {
104           echo "${file} does not exist or is not executable" >&2
105           exit 1
106       }
107     done
108 }
109
110
111 modify_version_C()
112 {
113         VERSION_C="src/version.C"
114         test -r "${VERSION_C}" || {
115             echo "Unable to find ${VERSION_C}"
116             return
117         }
118         test "${LYX_VERSION_STR}" == "" && return
119
120         sed '/char const \* lyx_version = /s/"[^"]*"/"'${LYX_VERSION_STR}'"/' \
121             ${VERSION_C} > tmp.$$
122         diff -u ${VERSION_C} tmp.$$
123         ${MV} tmp.$$ ${VERSION_C}
124 }
125
126
127 run_automake()
128 {
129     (
130         cd "${LYX_DIR}" || {
131             echo "Unable to cd ${LYX_DIR}" >&2
132             exit 1
133         }
134
135         # Check the line endings of configure.ac
136         # The configure script will be unable to create config.h if it
137         # contains Win32-style line endings.
138         sed 's/\r$//' configure.ac > configure.ac.$$
139         cmp -s configure.ac configure.ac.$$ && {
140             rm -f configure.ac.$$
141         } || {
142             mv -f configure.ac.$$ configure.ac
143             cat <<EOF >&2
144 configure.ac has Win32-style line endings. Corrected
145 Please use the Cygwin flavours of the autotools to
146 run autogen.sh
147 EOF
148             exit 1
149         }
150
151 #       ./autogen.sh || {
152 #           echo "autogen.sh failed" >&2
153 #           exit 1
154 #       }
155     )
156 }
157
158
159 build_lyx()
160 {
161     (
162         cd "${LYX_DIR}" || {
163             echo "Unable to cd ${LYX_DIR}" >&2
164             exit 1
165         }
166
167         BUILDDIR="${LYX_RELATIVE_BUILDDIR}"
168         test ! -d "${BUILDDIR}" && {
169             mkdir "${BUILDDIR}" || \
170                 Error "Unable to create build dir, ${BUILDDIR}."
171         }
172
173         CONFIGURE="../configure --without-x --with-included-gettext --with-extra-prefix='${LYX_ASPELL_DIR}' --with-frontend=qt QTDIR='$QT_DIR' --disable-maintainer-mode --disable-debug --enable-optimization --disable-pch --disable-concept-checks --disable-stdlib-debug"
174
175         echo "${CONFIGURE}"
176         cd "${BUILDDIR}"
177         echo "${PWD}"
178         eval "${CONFIGURE}" || {
179             echo "Failed to configure LyX" >&2
180             exit 1
181         }
182
183         # Modify the "lyx_version" string in build/src/version.C
184         modify_version_C
185
186         # Build LyX
187         make || {
188             echo "Failed to make $LYX_DIR" >&2
189             exit 1
190         }
191     )
192 }
193
194
195 install_lyx()
196 {
197     (
198         BUILDDIR="${LYX_RELATIVE_BUILDDIR}"
199         cd "${LYX_DIR}/${BUILDDIR}" || {
200             echo "Unable to cd ${LYX_DIR}/${BUILDDIR}" >&2
201             exit 1
202         }
203
204         rm -fr "$LYX_INSTALL_DIR" || {
205             echo "Failed to remove $LYX_INSTALL_DIR prior to installing LyX" >&2
206             exit 1
207         }
208
209         make install || {
210             echo "Failed to install" >&2
211             exit 1
212         }
213     )
214 }
215
216 LYX_VERSION_STR=""
217 test $# -ne 0 && LYX_VERSION_STR=$1
218
219 check_dirs_exist || exit 1
220 query_qt || exit 1
221 check_files_exist || exit 1
222 build_dtl || exit 1
223 run_automake || exit 1
224 build_lyx || exit 1
225 install_lyx || exit 1
226 # The end