]> git.lyx.org Git - features.git/blob - development/tools/lyx-build
Update build script again
[features.git] / development / tools / lyx-build
1 #!/bin/bash
2 # This script builds a maintainance LyX distribution according to 
3 # the procedure outlined at:
4 #   http://wiki.lyx.org/Devel/ReleaseProcedure
5 # It also includes several other tests, to make sure the package
6 # works as it should.
7
8 #DEBUG=echo;
9
10 #########################################################
11 # A few variables need to be set, here at the top. 
12 # The script should not need any other customization.
13 #
14 # Where we will do our work
15 BASE="/cvs/lyx/lyx-release";
16 # Where our git repository lives
17 SRCDIR="/cvs/lyx/lyx-stable";    # stable
18 DEVDIR="/cvs/lyx/lyx-devel";     # devel
19
20 BRANCH=$(git status | head -n1 | sed -e 's/On branch //');
21 if [ $BRANCH == "master" ]; then
22         SRCDIR="$DEVDIR";
23 fi
24
25 # editor 
26 if [ -z "$EDITOR" ]; then EDITOR=vi; fi
27
28
29 #########################################################
30 # Option variables
31
32 # Options to make, when we compile
33 MAKEOPTS="-j8";
34 # Compile?
35 COMPILE="YES";
36 # Make patch file?
37 PATCH="YES";
38
39 function usage() {
40 echo "lyx-build [-C] [-m MAKEARGS[ [-P]";
41 echo " -C: Do not test compilation";
42 echo " -m MAKEARGS: Arguments for make";
43 echo " -P: Do not build patch files";
44 }
45
46 while getopts ":Cm:Ph" opt; do
47   case $opt in
48     C )   COMPILE="";; # don't test compilation
49     m )   MAKEOPTS="$OPTARG";;
50     P )   PATCH="";; # don't build patch files
51     h )   usage; exit 0;;
52     \? )  echo "Unknown option $opt"; usage; exit 1;;
53   esac
54 done
55 shift $(($OPTIND - 1));
56
57 # Determine LyX version
58 cd $SRCDIR/
59 VERSION=$(head configure.ac | grep AC_INIT | \
60         perl -e 'while (<>) {m/AC_INIT\(\[LyX\],\[([^,]+)\]/; print $1;}');
61
62 # Development release?
63 DEVEL_RELEASE="";
64
65 # If the version in configure.ac is e.g. "2.3.4dev", then we are building
66 # a development release.
67 PKG_VERSION=${VERSION%dev};
68 if [ "$VERSION" != "$PKG_VERSION" ]; then
69         CURHASH=$(git rev-parse HEAD);
70         # Eight chars should be enough
71         CURHASH=${CURHASH:0:8};
72         # New version is e.g. 2.3.4dev-12649348
73         PKG_VERSION="$VERSION-$CURHASH";
74         PATCH="";
75 fi
76
77 echo "This is version $PKG_VERSION.";
78 echo -n "Ready to build source packages...";
79 read
80
81 echo "Exporting clean tree...";
82 $DEBUG rm -Rf "$BASE/lyx-export/";
83 $DEBUG git checkout-index -a -f --prefix="$BASE/lyx-export/";
84 $DEBUG cd "$BASE/lyx-export/";
85 $DEBUG ./autogen.sh
86 $DEBUG rm -Rf "$BASE/lyx-build/";
87 $DEBUG mkdir "$BASE/lyx-build/";
88 $DEBUG cd "$BASE/lyx-build/";
89
90 echo "Building distribution...";
91 $DEBUG "$BASE/lyx-export/configure" --enable-build-type=rel --enable-qt5
92 if ! $DEBUG make dist; then
93   echo "Couldn't make distribution!";
94   exit 1;
95 fi
96
97 echo "Packages created:";
98
99 # This will happen with development releases
100 if [ ! -f "lyx-$PKG_VERSION.tar.gz" ]; then
101         $DEBUG mv "lyx-$VERSION.tar.gz" "lyx-$PKG_VERSION.tar.gz" || exit 1;
102         $DEBUG mv "lyx-$VERSION.tar.xz" "lyx-$PKG_VERSION.tar.xz" || exit 1;
103 fi
104
105 $DEBUG ln lyx-$PKG_VERSION.tar.{gz,xz} $BASE/ || exit 1;
106
107 echo -n "Ready to build signatures...";
108 read
109
110 $DEBUG gpg -b lyx-$PKG_VERSION.tar.gz
111 $DEBUG gpg -b lyx-$PKG_VERSION.tar.xz
112
113 echo "Signatures created:"
114 $DEBUG ln lyx-$VERSION.tar.*.sig $BASE;
115
116 if [ -n "$COMPILE" ]; then
117         echo -n "Ready to test compilation...";
118         read
119
120         $DEBUG rm -Rf "$BASE/lyx-test/";
121         $DEBUG mkdir "$BASE/lyx-test/";
122         $DEBUG cd "$BASE/lyx-test/";
123         $DEBUG tar -zxvf "$BASE/lyx-build/lyx-$VERSION.tar.gz";
124         if ! $DEBUG cd lyx-$PKG_VERSION; then
125                 echo "Unable to enter build directory!";
126                 exit 1;
127         fi
128
129         $DEBUG ./configure --enable-build-type=rel --enable-qt5
130
131         if $DEBUG make $MAKEOPTS; then
132                 echo "Compilation complete.";
133                 echo -n "Ready to run LyX...";
134                 read;
135                 $DEBUG src/lyx -userdir /tmp/lyx-test;
136         else
137                 echo "Compilation errors!!";
138                 exit 1;
139         fi
140 fi
141
142 if [ -z "$PATCH" ]; then 
143         echo "Skipping patch files.";
144         exit 0; 
145 fi
146
147 LASTNUM=$(echo $PKG_VERSION | sed -e 's/.*\.//');
148 LAST=$((LASTNUM - 1));
149 FIRST=$(echo $PKG_VERSION | sed -e 's/[0-9]*$//');
150 ORIGINAL=${FIRST}0;
151 LAST=$FIRST$LAST;
152
153 if [ ! -d "$BASE/lyx-patch/" ]; then
154         $DEBUG mkdir "$BASE/lyx-patch/" || exit 1;
155 fi
156
157 if [ ! -d "$BASE/lyx-patch/lyx-$LAST" ]; then 
158     echo "Can't find directory for last version $LAST.";
159     echo "See if you can fix this in $BASE/lyx-patch/.";
160     echo "Try that, if you like, and then we'll continue.";
161     echo "We'll try to download from the LyX site if that does not work.";
162     read;
163
164     if [ -z "$DEBUG" ]; then
165         if [ ! -d $BASE/lyx-patch/lyx-$LAST ]; then 
166             echo "Will try to download from LyX site....";
167             pushd "$BASE/lyx-patch/";
168             wget ftp://ftp.lyx.org/pub/lyx/stable/${FIRST}x/lyx-$LAST.tar.gz;
169             wget ftp://ftp.lyx.org/pub/lyx/stable/${FIRST}x/lyx-$LAST.tar.gz.sig
170             gpg -q --verify lyx-$LAST.tar.gz.sig
171             if ! [ $? == 0 ]; then
172                 echo "Signature wrong!"
173                 exit 1;
174             fi
175             rm lyx-$LAST.tar.gz.sig
176             tar -zxvf lyx-$LAST.tar.gz;
177             if [ ! -f lyx-$LAST.tar.gz ]; then
178                 echo "Still unable to find directory for last version $LAST.";
179                 exit 1;
180             fi
181             $DEBUG popd;
182         fi
183     fi
184 fi
185
186 echo -n "Ready to make patch against $LAST...";
187 read
188
189 $DEBUG cd "$BASE/lyx-patch/";
190 if [ -z "$DEBUG" ]; then
191     tar -zxvf "$BASE/lyx-build/lyx-$VERSION.tar.gz" >/dev/null;
192     diff -urN -x .svn -x version.cpp lyx-$LAST lyx-$PKG_VERSION > patch;
193     echo -n "Please check the patch...";
194     read;
195     $EDITOR patch;
196 else
197     $DEBUG tar -zxvf "$BASE/lyx-build/lyx-$VERSION.tar.gz";
198     $DEBUG diff -urN -x .svn -x version.cpp lyx-$LAST lyx-$PKG_VERSION;
199 fi
200
201
202 NUMFIX="th";
203 if [ "$LASTNUM" = "1" ]; then
204   NUMFIX="st";
205 elif [ "$LASTNUM" = "2" ]; then
206   NUMFIX="nd";
207 fi
208 NUM="$LASTNUM$NUMFIX";
209 if [ -z "$DEBUG" ]; then
210     cat "$BASE/lyx-export/development/tools/patch-preamble" | \
211     sed -e "s/VERSION/$PKG_VERSION/; s/ORIGINAL/$ORIGINAL/; s/LAST/$LAST/; s/NUM/$NUM/;" >patch-preamble;
212     echo -n "Please verify the patch preamble...";
213     read
214     $EDITOR patch-preamble;
215     PATCH="patch-$VERSION";
216     cat patch-preamble "$BASE/lyx-export/ANNOUNCE" patch >$PATCH;
217     gzip -c $PATCH > $PATCH.gz
218     if [ -f $PATCH.gz.sig ]; then
219         rm $PATCH.gz.sig;
220     fi
221     gpg -b $PATCH.gz
222     xz -zc $PATCH > $PATCH.xz
223     if [ -f $PATCH.xz.sig ]; then
224         rm $PATCH.xz.sig;
225     fi
226     $DEBUG gpg -b $PATCH.xz
227
228     echo -n "Patch and signatures created...";
229     ln $PATCH.gz $PATCH.gz.sig $PATCH.xz $PATCH.xz.sig $BASE;
230 fi