2006-06-20 [mones] 2.3.1cvs4
[claws.git] / tools / make.themes.project
1 #!/bin/bash
2 #
3 # Generate the source directory for sylpheed-claws-themes package
4 # from the theme tarballs in http://sylpheed-claws.net/themes.php
5 #
6 # Copyright (c) 2006 Ricardo Mones <ricardo@mones.org>
7 #                    Paul Mangan <claws@thewildbeast.co.uk>
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23
24 function printHelp()
25 {
26   echo "Syntax: ";
27   echo "  $0 version {--clean[-all]|--download|--autotoolize|--all}"
28 }
29
30 test x$1 = x && echo "Error: version number not given" && printHelp && exit 1;
31
32 VERS=$1
33 shift;
34 SITE=http://sylpheed-claws.net
35 NAME=sylpheed-claws-themes
36 NOTES=RELEASE_NOTES
37 DDIR=$NAME-$VERS
38 PAGE=themes.php
39 LIST=themes.list
40 WLOG=themes.wget.log
41
42 function getListFromPage()
43 {
44   test -f ${PAGE} && rm -f ${PAGE};
45   wget -q -a ${WLOG} ${SITE}/${PAGE}
46   test ! -f ${PAGE} && echo "Error: couldn't get ${PAGE}." && exit 1;
47
48   grep 'download.php?file=' ${PAGE} \
49        | cut -f2 -d\" \
50        > ${LIST}
51 }
52
53 function makeRoomForThemes()
54 {
55   test -d ${DDIR} \
56     && rm -rf ${DDIR} \
57     && echo "Removing previous destination";
58   mkdir ${DDIR};
59 }
60
61 function downloadThemes()
62 {
63   for theme in `cat ${LIST} `;
64   do tarf=`echo $theme | cut -f2 -d/ `;
65      echo -n "Downloading... ";
66      wget -q -a ${WLOG} -P ${DDIR} ${SITE}/$theme
67      test ! -f ${DDIR}/$tarf && echo "Error: couldn't get $tarf" && exit 1;
68      pushd ${DDIR} > /dev/null
69      tarops="";
70      test ${tarf} = ${tarf/.tar.bz2/} && tarops="xzf" || tarops="xjf";
71      echo -n "unpacking... " \
72           && tar $tarops $tarf \
73           && echo -n "deleting tarball... " \
74           && rm -f $tarf \
75           && echo "Ok ($tarf)";
76      popd > /dev/null
77   done;
78 }
79
80 function removeWhitespaces()
81 {
82   cd ${DDIR};
83   for dir in *;
84   do test -d "$dir" \
85        && test ! "${dir}" = "${dir/ /_}" \
86        && mv "${dir}" "${dir// /_}"; 
87   done;
88   cd "..";
89 }
90
91 function createProject()
92 {
93   touch ${DDIR}/${NAME} ${DDIR}/${NOTES}
94   find ${DDIR} -type f -exec chmod -x '{}' +
95 }
96
97 function createThemeMakefileAm()
98 {
99   echo "Making $1";
100   MA="/tmp/tmp.makefile.am";
101   cd "$1"
102   dir="$1";
103   echo 'themedir = $(prefix)/share/sylpheed-claws/themes/'${dir} > $MA
104   echo "" >> $MA
105   echo -n 'dist_theme_DATA =' >> $MA 
106   test -f .sylpheed_themeinfo \
107     && echo " .sylpheed_themeinfo \\" >> $MA;
108   count=`ls *.xpm | wc -l `;
109   i=1;
110   for px in `ls -1 *.xpm `; 
111   do if [ $i -lt $count ]; 
112      then echo " $px \\" >> $MA; 
113      else echo " $px" >> $MA; 
114      fi; 
115      i=$((1 + $i)); 
116   done;
117   echo "" >> $MA;
118   count=`ls * | grep -v '\.xpm$' | wc -l `;
119   if [ $count -gt 0 ];
120   then echo -n 'EXTRA_DIST =' >> $MA;
121        i=1;
122        for npx in `ls -1 * | grep -v '\.xpm$' `;
123        do if [ $i -lt $count ];
124           then echo " $npx \\" >> $MA;
125           else echo " $npx" >> $MA;
126           fi;
127           i=$((1 + $i));
128        done;
129        echo "" >> $MA;
130   fi;
131   mv $MA Makefile.am
132   cd ".."
133 }
134
135 function createAutogenSh()
136 {
137   cat<<EOA > ${DDIR}/autogen.sh
138 #!/bin/sh
139
140 aclocal \
141   && automake --add-missing --foreign --copy \
142   && autoconf \
143   && ./configure --enable-maintainer-mode $@
144 EOA
145   chmod +x ${DDIR}/autogen.sh
146   echo "Created autogen.sh"
147 }
148
149 function createMakefileAm()
150 {
151   cd ${DDIR}
152   MA=Makefile.am
153   echo "EXTRA_DIST = INSTALL "${NOTES} ${NAME} > $MA
154   echo "" >> $MA
155   echo -n "SUBDIRS =" >> $MA
156   for dir in *;
157   do test -d "$dir" && echo -n " ${dir}" >> $MA;
158   done;
159   echo "" >> $MA
160   echo "" >> $MA
161   echo "BZIP2_ENV =" >> $MA
162   echo "" >> $MA
163   echo "release: distdir" >> $MA
164   echo "        -chmod -R a+r \$(distdir)" >> $MA
165   echo "        GZIP=\$(GZIP_ENV) \$(AMTAR)\$(TAR) chozf \$(distdir).tar.gz \$(distdir)" >> $MA
166   echo "        BZIP2=\$(BZIP2_ENV) \$(AMTAR)\$(TAR) --bzip2 -chof \$(distdir).tar.bz2 \$(distdir)" >> $MA
167   echo "        -rm -rf \$(distdir)" >> $MA
168   echo "" >> $MA
169   cd ".."
170   echo "Created Makefile.am"
171 }
172
173 function createConfigureAc()
174 {
175   cd ${DDIR}
176   CA=configure.ac
177   echo 'AC_PREREQ(2.59d)' > $CA
178   echo 'AC_INIT('${NAME}')' >> $CA
179   echo 'AM_INIT_AUTOMAKE('${NAME}', '${VERS}')' >> $CA
180   cat >> $CA <<EOC
181
182 AM_MAINTAINER_MODE
183
184 dnl Checks for programs.
185 AC_PROG_INSTALL
186
187 AC_OUTPUT([
188 Makefile
189 EOC
190   # the list of Makefiles
191   for dir in *;
192   do test -d "$dir" \
193        && echo "${dir}/Makefile" >> $CA \
194        && createThemeMakefileAm "$dir";
195   done;
196   echo "])" >> $CA
197   cd "..";
198   echo "Created $CA";
199 }
200
201 function cleanMine()
202 {
203   find ${DDIR} -name Makefile.am -delete
204   rm -f \
205      ${DDIR}/autogen.sh \
206      ${DDIR}/configure.ac \
207      ${DDIR}/${NAME}
208 }
209
210 function cleanGenerated()
211 {
212   find ${DDIR} -name Makefile.in -delete
213   find ${DDIR} -name Makefile -delete
214   rm -rf ${DDIR}/autom4te.cache
215   rm -f \
216      ${DDIR}/aclocal.m4 \
217      ${DDIR}/install-sh \
218      ${DDIR}/missing \
219      ${DDIR}/config.status \
220      ${DDIR}/configure \
221      ${DDIR}/config.log
222 }
223
224 case "$1" in
225   --clean)
226       cleanMine;      
227       echo "Cleaned.";
228     ;;
229   --clean-all)
230       cleanMine;
231       cleanGenerated;
232       echo "Cleaned all.";
233     ;;
234   --download)
235       getListFromPage;
236       makeRoomForThemes;
237       downloadThemes;
238       echo "Downloaded.";
239     ;;
240   --autotoolize)
241       removeWhitespaces;
242       createProject;
243       createAutogenSh;
244       createMakefileAm;
245       createConfigureAc;
246       echo "Autotoolized.";
247     ;;
248   --all)
249     $0 $VERS --download
250     $0 $VERS --autotoolize
251     echo "Done.";
252     ;;
253   *)
254       printHelp;
255     ;;
256 esac
257