1#! /bin/sh
2#
3# cvs.sh
4#
5# This file contains support code from Makefile.common
6# It defines a shell function for each known target
7# and then does a case to call the correct function.
8
9call_and_fix_autoconf()
10{
11  $AUTOCONF || exit 1
12  if test -r configure.in.in ; then
13    perl -pi -e "print \"if test \\\"x\\\$with_fast_perl\\\" = \\\"xyes\\\"; then\
14    \\n  perl -i.bak \\\$ac_aux_dir/conf.change.pl \\\$CONFIG_STATUS\
15    \\\\\\n    || mv \\\$CONFIG_STATUS.bak \\\$CONFIG_STATUS\
16    \\n  rm -f \\\$CONFIG_STATUS.bak\\nfi\
17    \\n\" if /^\\s*chmod\\s+.*\\+x\\s+.*CONFIG_STATUS/;" configure
18  fi
19}
20
21strip_makefile()
22{
23  if test -f $makefile_wo; then :; else
24    perl -e '$in=0; while ( <> ) { $in = 1 if ($_=~ m/^if /); print $_ unless ($in); $in = 0 if ($_ =~ m/^endif/); }' < Makefile.am.in > $makefile_wo
25  fi
26}
27
28check_autotool_versions()
29{
30AUTOCONF_VERSION=`$AUTOCONF --version | head -n 1`
31case $AUTOCONF_VERSION in
32  Autoconf*2.[5-9]* | autoconf*2.[5-9]* ) : ;;
33  "" )
34    echo "*** AUTOCONF NOT FOUND!."
35    echo "*** KDE requires autoconf 2.52, 2.53 or 2.54"
36    exit 1
37    ;;
38  * )
39    echo "*** YOU'RE USING $AUTOCONF_VERSION."
40    echo "*** KDE requires autoconf 2.52, 2.53 or 2.54"
41    exit 1
42    ;;
43esac
44 
45AUTOHEADER_VERSION=`$AUTOHEADER --version | head -n 1`
46case $AUTOHEADER_VERSION in
47  Autoconf*2.[5-9]* | autoheader*2.[5-9]* ) : ;;
48  "" )
49    echo "*** AUTOHEADER NOT FOUND!."
50    echo "*** KDE requires autoheader 2.52 or 2.53 (part of autoconf)"
51    exit 1
52    ;;
53  * )
54    echo "*** YOU'RE USING $AUTOHEADER_VERSION."
55    echo "*** KDE requires autoheader 2.52 or 2.53 (part of autoconf)"
56    exit 1
57    ;;
58esac
59
60AUTOMAKE_STRING=`$AUTOMAKE --version | head -n 1`
61case $AUTOMAKE_STRING in
62  automake*1.5d* )
63    echo "*** YOU'RE USING $AUTOMAKE_STRING."
64    echo "*** KDE requires automake 1.6"
65    exit 1
66    ;;
67  automake*1.[6-9] | automake*1.[6-9].* | automake*1.1[0-9] | automake*1.1[0-9].* ) : ;;
68  "" )
69    echo "*** AUTOMAKE NOT FOUND!."
70    echo "*** KDE requires automake 1.6"
71    exit 1
72    ;;
73  unsermake* ) :
74    echo "*** YOU'RE USING UNSERMAKE."
75    echo "*** GOOD LUCK!! :)"
76    ;;
77  * )
78    echo "*** YOU'RE USING $AUTOMAKE_STRING."
79    echo "*** KDE requires automake 1.6"
80    exit 1
81    ;;
82esac
83}
84
85cvs()
86{
87check_autotool_versions
88 
89### Produce acinclude.m4
90if grep '\$(top_srcdir)/acinclude.m4:' $makefile_am >/dev/null; then
91  echo "*** Creating acinclude.m4"
92  rm -f acinclude.m4 configure.files
93  
94  strip_makefile
95  $MAKE -f $makefile_wo top_srcdir=. ./acinclude.m4
96fi
97
98### Make new subdirs and configure.in.
99### The make calls could be optimized away here,
100### with a little thought.
101if test -r configure.in.in; then
102  rm -f subdirs configure.in
103  echo "*** Creating list of subdirectories"
104  subdirs
105  echo "*** Creating configure.in"
106  configure_files
107  strip_makefile
108  $MAKE -f $makefile_wo top_srcdir=. ./configure.in || exit 1
109fi
110
111echo "*** Creating aclocal.m4"
112$ACLOCAL || exit 1
113echo "*** Creating configure"
114call_and_fix_autoconf
115
116if egrep "^AM_CONFIG_HEADER" configure.in >/dev/null 2>&1; then
117  echo "*** Creating config.h template"
118  $AUTOHEADER || exit 1
119fi
120
121echo "*** Creating Makefile templates"
122$AUTOMAKE || exit 1
123if test -z "$UNSERMAKE"; then
124  echo "*** Postprocessing Makefile templates"
125  perl -w admin/am_edit || exit 1
126fi
127
128if egrep "^cvs-local:" $makefile_am >/dev/null; then \
129  strip_makefile
130  $MAKE -f $makefile_wo cvs-local top_srcdir=. || exit 1
131fi
132
133echo "*** Creating date/time stamp"
134touch stamp-h.in
135
136echo "*** Finished"
137echo "    Don't forget to run ./configure"
138echo "    If you haven't done so in a while, run ./configure --help"
139}
140
141dist()
142{
143check_autotool_versions
144
145###
146### First build all of the files necessary to do just "make"
147###
148if grep '\$(top_srcdir)/acinclude.m4:' $makefile_am >/dev/null; then
149  strip_makefile
150  $MAKE -f $makefile_wo top_srcdir=. ./acinclude.m4
151fi
152if test -r configure.in.in; then
153  subdirs
154  configure_files
155  strip_makefile
156  $MAKE -f $makefile_wo top_srcdir=. ./configure.in
157fi
158$ACLOCAL
159$AUTOHEADER
160$AUTOMAKE --foreign --include-deps
161perl -w admin/am_edit
162call_and_fix_autoconf
163touch stamp-h.in
164if grep "^cvs-local:" $makefile_am >/dev/null; then
165  strip_makefile
166  $MAKE -f $makefile_wo cvs-local top_srcdir=.
167fi
168
169###
170### Then make messages
171###
172if test -d po; then
173 LIST=`find ./po -name "*.po"`
174 for i in $LIST; do
175  file2=`echo $i | sed -e "s#\.po#\.gmo#"`
176  msgfmt -o $file2 $i || touch $file2
177 done
178fi
179if grep "^cvs-dist-local:" $makefile_am >/dev/null; then
180  strip_makefile
181  $MAKE -f $makefile_wo cvs-dist-local top_srcdir=.
182fi
183}
184
185subdir_dist()
186{
187$ACLOCAL
188$AUTOHEADER
189$AUTOMAKE --foreign --include-deps
190perl -w ../admin/am_edit
191call_and_fix_autoconf
192touch stamp-h.in
193}
194
195configure_in()
196{
197rm -f configure.in configure.in.new
198kde_use_qt_param=
199test -f configure.files || { echo "need configure.files for configure.in"; exit 1; }
200cat `egrep -v "configure.in.bot" < configure.files` > configure.in.new
201echo "KDE_CREATE_SUBDIRSLIST" >> configure.in.new
202if test -f Makefile.am.in; then
203  subdirs=`cat subdirs`
204  for dir in $subdirs; do
205    dir=`echo $dir | sed -e "s,[-+.],_,g"`
206    echo "AM_CONDITIONAL($dir""_SUBDIR_included, test \"x\$$dir""_SUBDIR_included\" = xyes)" >> configure.in.new
207  done
208fi
209# echo "AC_OUTPUT( \\" >> configure.in.new
210mfs=`find . -type d -print | fgrep -v "/." | \
211     sed -e "s#\./##" -e "/^debian/d" | sort`
212for i in $mfs; do
213  topleveldir=`echo $i| sed -e "s#/.*##"`
214  if test -f $topleveldir/configure.in; then
215	continue
216  fi
217  if test -f $i/Makefile.am; then :; else
218	continue
219  fi
220  if test -s inst-apps; then
221    if grep "\"^$topleveldir\"" inst-apps > /dev/null 2>&1; then
222	continue
223    fi
224  fi
225  if test "$i" = "."; then
226     echo "AC_CONFIG_FILES([ Makefile ])" >> configure.in.new
227  else
228     echo "AC_CONFIG_FILES([ $i/Makefile ])" >> configure.in.new
229  fi
230  if test -n "$UNSERMAKE"; then
231      if test "$i" = "."; then
232        echo "AC_CONFIG_FILES([ Makefile.rules ])" >> configure.in.new
233      else
234        echo "AC_CONFIG_FILES([ $i/Makefile.rules ])" >> configure.in.new
235      fi
236  fi
237done
238
239files=`cat configure.files`
240list=`egrep '^dnl AC_OUTPUT\(.*\)' $files | sed -e "s#^.*dnl AC_OUTPUT(\(.*\))#\1#"`
241for file in $list; do 
242    echo "AC_CONFIG_FILES([ $file ])" >>  configure.in.new
243done
244
245if test -n "$UNSERMAKE"; then
246  echo "AC_CONFIG_FILES([ MakeVars ])" >> configure.in.new
247fi
248echo "AC_OUTPUT" >> configure.in.new
249modulename=
250if test -f configure.in.in; then
251   if head -n 2 configure.in.in | egrep "^#MIN_CONFIG\(.*\)$" > /dev/null; then
252      kde_use_qt_param=`cat configure.in.in | sed -n -e "s/#MIN_CONFIG(\(.*\))/\1/p"`
253   fi
254   if head -n 2 configure.in.in | egrep "^#MIN_CONFIG" > /dev/null; then
255      line=`grep "^AM_INIT_AUTOMAKE(" configure.in.in`
256      if test -n "$line"; then
257	  modulename=`echo $line | sed -e "s#AM_INIT_AUTOMAKE(\([^,]*\),.*#\1#"`
258	  VERSION=`echo $line | sed -e "s#AM_INIT_AUTOMAKE([^,]*, *\([^)]*\)).*#\1#"`
259      fi
260      sed -e "s#AM_INIT_AUTOMAKE([^@].*#dnl PACKAGE set before#" \
261          configure.in.new > configure.in && mv configure.in configure.in.new
262   fi
263fi
264if test -z "$VERSION" || test "$VERSION" = "@VERSION@"; then
265     VERSION="\"3.1.3\""
266fi
267if test -z "$modulename" || test "$modulename" = "@MODULENAME@"; then
268   modulename=`pwd`; 
269   modulename=`basename $modulename`
270   esc_VERSION=`echo $VERSION | sed -e "s#[^.0-9a-zA-Z]##g"`
271   modulename=`echo $modulename | sed -e "s#-$esc_VERSION##"`   
272
273fi
274if test -n "$kde_use_qt_param"; then
275      sed -e "s#^dnl KDE_USE_QT#KDE_USE_QT($kde_use_qt_param)#" \
276      	configure.in.new > configure.in && mv configure.in configure.in.new
277fi
278sed -e "s#@MODULENAME@#$modulename#" configure.in.new |
279	sed -e "s#@VERSION@#$VERSION#" > configure.in
280botfiles=`cat configure.files | egrep "configure.in.bot"`
281test -n "$botfiles" && cat $botfiles >> configure.in
282cat $admindir/configure.in.bot.end >> configure.in
283rm -f configure.in.new
284}
285
286configure_files()
287{
288admindir=NO
289for i in . .. ../.. ../../..; do
290  if test -x $i/admin; then admindir=$i/admin; break; fi
291done
292rm -f configure.files
293touch configure.files
294if test -f configure.in.in && head -n 2 configure.in.in | grep "^#MIN_CONFIG" > /dev/null; then
295	echo $admindir/configure.in.min >> configure.files
296fi
297test -f configure.in.in && echo configure.in.in >> configure.files
298list=`find . -name "configure.in.in" -o -name "configure.in.bot" | \
299               sed -e "s,/configure,/aaaconfigure," | sort | sed -e "s,/aaaconfigure,/configure,"`
300for i in $list; do if test -f $i && test `dirname $i` != "." ; then
301  echo $i >> configure.files
302fi; done
303test -f configure.in.mid && echo configure.in.mid >> configure.files
304test -f configure.in.bot && echo configure.in.bot >> configure.files
305}
306
307subdirs()
308{
309dirs=
310compilefirst=`sed -ne 's#^COMPILE_FIRST[ ]*=[ ]*##p' $makefile_am | head -n 1`
311compilelast=`sed -ne 's#^COMPILE_LAST[ ]*=[ ]*##p' $makefile_am | head -n 1`
312for i in `ls -1`; do
313    if test -f $i/Makefile.am; then
314       case " $compilefirst $compilelast " in
315         *" $i "*) ;;
316         *) dirs="$dirs $i"
317       esac
318    fi
319done
320
321: > ./_SUBDIRS
322
323for d in $compilefirst; do
324   echo $d >> ./_SUBDIRS
325done
326
327(for d in $dirs; do 
328   list=`sed -ne "s#^COMPILE_BEFORE_$d""[ ]*=[ ]*##p" $makefile_am | head -n 1`
329   for s in $list; do
330      echo $s $d
331   done
332   list=`sed -ne "s#^COMPILE_AFTER_$d""[ ]*=[ ]*##p" $makefile_am | head -n 1`
333   for s in $list; do
334      echo $d $s
335   done
336   echo $d $d
337done ) | tsort >> ./_SUBDIRS
338
339for d in $compilelast; do
340   echo $d >> ./_SUBDIRS
341done
342
343if test -f Makefile.am.in; then
344  cp Makefile.am.in Makefile.am
345  if test -n "$UNSERMAKE"; then
346    topsubdirs=
347    for i in $compilefirst $dirs $compilelast; do
348       vari=`echo $i | sed -e "s,[-+],_,g"`
349       echo "if $vari""_SUBDIR_included" >> Makefile.am
350       echo "$vari""_SUBDIR=$i" >> Makefile.am
351       echo "endif" >> Makefile.am
352       topsubdirs="$topsubdirs \$($vari""_SUBDIR)"
353    done
354    echo "SUBDIRS=$topsubdirs" >> Makefile.am
355  else
356    echo "SUBDIRS="'$(TOPSUBDIRS)' >> Makefile.am
357  fi
358fi
359if test -r subdirs && diff subdirs _SUBDIRS > /dev/null; then
360  rm -f _SUBDIRS
361fi
362test -r _SUBDIRS && mv _SUBDIRS subdirs || true
363}
364
365cvs_clean()
366{
367if test -d CVS; then :; else
368  echo "You don't have a toplevel CVS directory."
369  echo "You most certainly didn't use cvs to get these sources."
370  echo "But this function depends on cvs's information."
371  exit 1
372fi
373perl $admindir/cvs-clean.pl
374}
375
376package_merge()
377{
378catalogs=$POFILES
379for cat in $catalogs; do
380  msgmerge -o $cat.new $cat $PACKAGE.pot
381  if test -s $cat.new; then
382    grep -v "\"POT-Creation" $cat.new > $cat.new.2
383    grep -v "\"POT-Creation" $cat >> $cat.new.1
384    if diff $cat.new.1 $cat.new.2; then
385	rm $cat.new
386    else
387	mv $cat.new $cat
388    fi
389    rm -f $cat.new.1 $cat.new.2
390  fi
391done
392}
393
394package_messages()
395{
396rm -rf po.backup
397mkdir po.backup
398
399for i in `ls -1 po/*.pot 2>/dev/null | sed -e "s#po/##"`; do
400  egrep -v '^#([^:]|$)' po/$i | egrep '^.*[^ ]+.*$' | grep -v "\"POT-Creation" > po.backup/$i
401  cp po/$i po.backup/backup_$i
402  touch -r po/$i po.backup/backup_$i
403  rm po/$i
404done
405
406podir=${podir:-$PWD/po}
407files=`find . -name Makefile.am | xargs egrep -l '^messages:' `
408dirs=`for i in $files; do echo \`dirname $i\`; done`
409tmpname="$PWD/messages.log"
410if test -z "$EXTRACTRC"; then EXTRACTRC=extractrc ; fi
411if test -z "$PREPARETIPS"; then PREPARETIPS=preparetips ; fi
412export EXTRACTRC PREPARETIPS
413
414for subdir in $dirs; do
415  test -z "$VERBOSE" || echo "Making messages in $subdir"
416  (cd $subdir
417   if test -n "`grep -e '^messages:.*rc.cpp' Makefile.am`"; then
418	$EXTRACTRC *.rc *.ui > rc.cpp
419   else
420	candidates=`ls -1 *.rc *.ui 2>/dev/null`
421	if test -n "$candidates"; then
422	    echo "$subdir has *.rc or *.ui files, but not correct messages line"
423	fi
424   fi
425   if test -n "`grep -r KAboutData *.c* *.C* 2>/dev/null`"; then
426	echo -e 'i18n("_: NAME OF TRANSLATORS\\n"\n"Your names")\ni18n("_: EMAIL OF TRANSLATORS\\n"\n"Your emails")' > _translatorinfo.cpp
427   else echo " " > _translatorinfo.cpp
428   fi
429   perl -e '$mes=0; while (<STDIN>) { next if (/^(if|else|endif)\s/); if (/^messages:/) { $mes=1; print $_; next; } if ($mes) { if (/$\\(XGETTEXT\)/ && / -o/) { s/ -o \$\(podir\)/ _translatorinfo.cpp -o \$\(podir\)/ } print $_; } else { print $_; } }' < Makefile.am | egrep -v '^include ' > _transMakefile
430
431   $MAKE -s -f _transMakefile podir=$podir EXTRACTRC="$EXTRACTRC" PREPARETIPS="$PREPARETIPS" \
432	XGETTEXT="${XGETTEXT:-xgettext} -C -ki18n -ktr2i18n -kI18N_NOOP -ktranslate -kaliasLocale -x ${includedir:-$KDEDIR/include}/kde.pot" \
433	messages 
434   ) 2>&1 | grep -v '^make\[1\]' > $tmpname
435   test -s $tmpname && { echo $subdir ; cat "$tmpname"; }
436   test -f $subdir/rc.cpp && rm -f $subdir/rc.cpp
437   rm -f $subdir/_translatorinfo.cpp
438   rm -f $subdir/_transMakefile
439done
440rm -f $tmpname
441for i in `ls -1 po.backup/*.pot 2>/dev/null | sed -e "s#po.backup/##" | egrep -v '^backup_'`; do
442  test -f po/$i || echo "disappeared: $i"
443done
444for i in `ls -1 po/*.pot 2>/dev/null | sed -e "s#po/##"`; do
445   msgmerge -q -o po/$i po/$i po/$i
446   egrep -v '^#([^:]|$)' po/$i | egrep '^.*[^ ]+.*$' | grep -v "\"POT-Creation" > temp.pot
447  if test -f po.backup/$i && test -n "`diff temp.pot po.backup/$i`"; then
448	echo "will update $i"
449	msgmerge -q po.backup/backup_$i po/$i > temp.pot
450	mv temp.pot po/$i
451  else
452    if test -f po.backup/backup_$i; then
453      test -z "$VERBOSE" || echo "I'm restoring $i"
454      mv po.backup/backup_$i po/$i
455      rm po.backup/$i
456    else
457      echo "will add $i"
458    fi
459  fi
460done
461rm -f temp.pot
462rm -rf po.backup
463}
464
465admindir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'`
466test "x$admindir" = "x$0" && admindir=.
467
468test "x$MAKE" = x && MAKE=make
469makefile_am=Makefile.am
470makefile_wo=Makefile.am
471if test -f Makefile.am.in; then
472  makefile_am=Makefile.am.in
473  makefile_wo=Makefile.am.in.wo
474fi
475
476# Sucking AUTOCONF detection code - commented out
477#. $admindir/detect-autoconf.sh
478AUTOCONF="autoconf"
479AUTOHEADER="autoheader"
480AUTOM4TE="autom4te"
481AUTOMAKE="automake"
482ACLOCAL="aclocal -I m4"
483
484###
485### Main
486###
487
488arg=`echo $1 | tr '\-.' __`
489case $arg in
490  cvs | dist | subdir_dist | configure_in | configure_files | subdirs | \
491  cvs_clean | package_merge | package_messages ) $arg ;;
492  * ) echo "Usage: cvs.sh <target>"
493      echo "Target can be one of:"
494      echo "    cvs cvs-clean dist"
495      echo "    configure.in configure.files"
496      echo "    package-merge package-messages"
497      echo ""
498      echo "Usage: anything but $1"
499      exit 1 ;;
500esac
501
502if test -f Makefile.am.in.wo; then
503  rm Makefile.am.in.wo
504fi
505
506exit 0
507