Glossary action icon
[kdeaccessibility.git] / kttsd / cvs2dist
blobda2c08d9d1d647dda7fd8546a3eaf98b130c77e4
1 #! /bin/bash
3 # This is cvs2dist
4 # Webpage: http://www.katzbrown.com/shiritsu/programming/cvs2dist/
5 # Newest version is always available there!
6 # Please report bugs to <jason@katzbrown.com>.
8 # Original author (of cvs2pack.sh) was Sebastian Stein <seb.stein@hpfsc.de>
9 # Heavy, heavy modifications by Jason Katz-Brown <jason@katzbrown.com>
10 # Some modifications for i18n inclusion by Dominique Devriese <devriese@kde.org>
11 # Added --no-i18n-lang and --replace-files by Michael Buesch <mbuesch@freenet.de>
12 # License: GPL (http://www.gnu.org/)
13 # Last modification: 2004/10/13
15 cmdline="$@"
17 returndir=`pwd`
18 override="README ChangeLog INSTALL AUTHORS AUTHOR COPYING COPYING.LIB TODO"
19 remove="config.cache config.log config.status Makefile configure inst-apps CVS acinclude.m4 aclocal.m4 config.h config.h.bot config.h.in configure.files libtool stamp-h stamp-h.in stamp-h1 subdirs *.moc *.la .libs .deps .cvsignore autom4te.cache {arch} .arch-ids"
20 toplevelremove="configure.in.bot"
21 # whitespace seperated list of languages to never include.
22 always_skip_languages="xx"
24 pofilenames="kttsd kttsd_commandplugin kttsd_eposplugin kttsd_festivalintplugin
25 kttsd_fliteplugin kttsd_freettsplugin kttsd_hadifixplugin kttsd_sbdplugin
26 kttsd_stringreplacerplugin kttsd_talkerchooserplugin kttsd_xmltransformerplugin
27 kttsjobmgr kttsmgr kcmkttsd khtmlkttsd ktexteditor_kttsd"
29 exit_cleanup()
31 echo -n "Cleaning up... "
32 if [ -d $temp_dir ]; then
33 test -z "$debug" && rm -Rf $temp_dir
35 echo "done."
38 trap "exit_cleanup; exit 1" SIGINT SIGTERM
40 test -e ~/.cvs2distrc && extraoptions=`cat ~/.cvs2distrc`
42 # getopt usage from the getopt bash example
43 # --log has optional argument
44 TEMP=`getopt \
45 -o v:n:r:e:a:B:dhmbgol \
46 --long log::,version:,name:,required-header:,required-header-error-message:,make-unpackaged,help,no-bz2,no-bzip2,no-gzip,only-directory,remove-hidden,admin-dir:,branch:,no-i18n,no-i18n-lang:,cvs-root:,debug,replace-files: \
47 -n cvs2dist -- $extraoptions "$@"`
49 if [ $? != 0 ]; then
50 echo "Aborted." >&2
51 exit 1
54 eval set -- "$TEMP"
56 log="/dev/null"
57 calclog=0
58 doi18n="yes"
59 noi18nlang=""
60 replace_files=""
61 cvsroot=""
62 debug=""
64 while true; do
65 case "$1" in
66 -v|--version) version=$2; shift 2 ;;
67 -n|--name) name=$2; shift 2 ;;
68 -a|--admin-dir) admindir=$2;
69 if [ `echo $admindir | sed -e 's#^/##'` = $admindir ]; then
70 admindir="`pwd`/$admindir"
72 shift 2 ;;
73 -B|--branch) branch="-r$2"; shift 2;;
74 --debug) debug="non-empty"; shift 1 ;;
75 --cvs-root) cvsroot="$2"; shift 2 ;;
76 -r|--required-header) requiredheader=$2; shift 2 ;;
77 --no-i18n) doi18n="no"; shift 1 ;;
78 --no-i18n-lang) noi18nlang="$2"; shift 2 ;;
79 -e|--required-header-error-message) requiredmsg=$2; shift 2 ;;
80 -m|--make-unpackaged) leavedir="non-empty"; shift 1 ;;
81 -h|--help) showhelp="non-empty"; shift 1 ;;
82 -b|--no-bz2|--no-bzip2) nobzip2="non-empty"; shift 1 ;;
83 -o|--only-directory)
84 nogzip="non-empty"
85 nobzip2="non-empty"
86 leavedir="non-empty"
87 shift 1 ;;
88 -g|--no-gzip) nogzip="non-empty"; shift 1 ;;
89 -d|--remove-hidden) removehidden="non-empty"; shift 1 ;;
90 -l) calclog=1; shift 1 ;;
91 --log)
92 case "$2" in
93 # no-argument case
94 "") calclog=1; shift 2 ;;
95 # something, should be a file
96 *) log=$2
97 origlog=$log
98 if [ `echo $log | sed -e 's#^/##'` = $log ]; then
99 log="`pwd`/$log"
102 shift 2 ;;
103 esac ;;
104 --replace-files) replace_files="$2"; shift 2 ;;
105 --) shift
106 break ;;
107 *) echo "Aborted."
108 exit 1 ;;
109 esac
110 done
112 count=0
113 for arg do
114 test $count = 0 && module=$arg
115 test $count = 1 && directory=$arg
117 if [ $count -ge 2 ]; then
118 modarg=$arg
119 if [ `echo $modarg | sed -e 's#^/##'` = $modarg ]; then
120 modarg="`pwd`/$modarg"
122 addfiles="$addfiles $modarg"
125 let count count++
126 done
128 # test if a module and directory name was given
129 if [ ! -z $showhelp ] || [ -z $module ] || [ -z $directory ]; then
130 echo "Usage: cvs2dist module directory [options] [addfile1] [addfile2] ..."
131 echo ""
132 echo " -n --name <name>"
133 echo " -v --version <version>"
134 echo " --cvs-root <root> the value to use as cvs root"
135 echo " variable. It is not necessary if you use --no-i18n."
136 echo " if this is not given, it is taken from the CVSROOT "
137 echo " environment variable."
138 echo " --admin-dir <dir> admin/ location (default is module/admin)"
139 echo " (symbolic links are OK.)"
140 echo " -B --branch <branch> use branch for i18n checkouts."
141 echo " --no-i18n don't try to automatically checkout the translations from cvs."
142 echo " --no-i18n-lang <languages> exclude all languages in the given comma"
143 echo " seperated list. example:"
144 echo " --no-i18n-lang uk,de,en_GB"
145 echo " --log=<logfile> If logfile unspecified, default file is used."
146 echo " (The '=' is essential and may not be ommited"
147 echo " when specifying the logfile.)"
148 echo " -l Log to default logfile."
149 echo " -m --make-unpackaged Also makes an unpacked distribution"
150 echo " in the current directory."
151 echo " -g --no-gzip Do not create gzip package."
152 echo " -b --no-bz2 Do not create bzip2 package."
153 echo " --no-bzip2 Alias for the above."
154 echo " -o --only-directory Alias for -mbg (no packages, only a directory.)"
155 echo " -r --required-header <header> Errors if header is not installed."
156 echo " -e --required-header-error-message <message>"
157 echo " Error message for above."
158 echo " -d --remove-hidden Remove hidden files/directories from packages"
159 echo " --replace-files <file-pair-list>"
160 echo " <file-pair-list> is a comma separated list of file pairs"
161 echo " which should be replaced in the final distribution package."
162 echo " Each element of a pair is separated by an @"
163 echo -n " Example: --replace-files take_this_file@and_move_it_here,"
164 echo "configure.in.bot.dist@configure.in.bot"
165 echo " The filenames are all relative to your package root."
166 echo " Please be careful! Try to avoid the usage of .. in the path. It"
167 echo " may break stuff! There can not be blank characters in the paths."
168 echo " -h --help Show this help"
169 echo ""
170 echo " Name defaults to the last part of the directory."
171 echo "By default, creates name[-version].tar.gz if gzip is installed"
172 echo "and/or name[-version].tar.bz2 if bzip2 is installed in the current"
173 echo "directory. Removes all temporary files it creates. Produces"
174 echo "tarballs that are standard distribution tarballs with a"
175 echo "configure script."
176 echo " Unless --no-i18n is given, it automatically tries to check out "
177 echo "strings and documentation translation from cvs."
178 echo " Arguments after the second are added to the toplevel directory"
179 echo "in the package. Short options can be combined, eg -dm to create"
180 echo "a directory and remove hidden files. ~/.cvs2distrc is added to"
181 echo "the beginning of command line arguments if it exists."
182 echo " '--' signifies the end of options."
183 echo ""
184 echo "Example: cvs2dist /sources/kdegames kolf/objects/picture \\"
185 echo " -n kolf-picture -v 0.9 -r \"kolf/game.h\" \\"
186 echo " --log ~/tmp/extra-file"
187 echo ""
188 echo " Creates packages of the kolf picture plugin, naming the"
189 echo " packages kolf-picture-0.9 and logging the process. For configure"
190 echo " to succeed, kolf/game.h must be installed or an error will occur."
191 echo " ~/tmp/extra-file is added to the packages."
192 echo ""
193 echo "Webpage: http://www.katzbrown.com/shiritsu/programming/cvs2dist/"
194 echo "Authors: Jason Katz-Brown <jason@katzbrown.com>,"
195 echo " Sebastian Stein <seb.stein@hpfsc.de>,"
196 echo " Dominique Devriese <devriese@kde.org>"
197 exit 1
200 # expand module
201 module=`echo $module | sed -e 's#/$##'`
202 if [ `echo $module | sed -e 's#^/##'` = $module ]; then
203 module="`pwd`/$module"
206 # test if the given module is a directory
207 test -d $module
208 if [ $? -ne 0 ]; then
209 echo "$module is not a directory."
210 echo "Aborted."
211 exit 1
214 # go to our module
215 cd $module
217 directory=`echo $directory | sed -e 's#^/##'`
219 if [ -z $name ]; then
220 name=$directory
221 # get rid of trailing slash
222 name=`echo $name | sed -e 's#/$##'`
223 # leading slash
224 name=`echo $name | sed -e 's#^/##'`
226 if [ `echo $name | sed -e 's#/##'` != $name ]; then
227 name=`echo $name | sed -e 's#^.*/##'`
231 test $calclog = 1 && log="$returndir/cvs2dist-$name.log" && origlog="cvs2dist-$name.log"
233 # test if the given name is a sub-directory
234 if [ ! -d "$directory" ]; then
235 echo "$directory is not a sub-directory of $module."
236 echo "Aborted."
237 exit 1
240 test $log != "/dev/null" && echo "Logging to $log."
242 echo "cvs2dist log on "`date` > $log
243 echo "http://katzbrown.com/shiritsu/programming/cvs2dist/" >> $log
244 echo -n "Module: $module; Directory: $directory; Name: $name; " >> $log
245 if [ -z $version ]; then
246 echo "Version unspecified." >> $log
247 else
248 echo "Version $version." >> $log
250 echo $cmdline >> $log
251 echo "--------" >> $log
253 if [ -z $version ]; then
254 filename=$name
255 else
256 filename="$name-$version"
259 if [ -z $cvsroot ]; then
260 cvsroot="$CVSROOT";
262 if [ $doi18n = "yes" ]; then
263 # a little warning...
264 echo "Will try to fetch i18n files from KDE's CVS."
265 echo "If this doesn't work, use --no-i18n."
267 if [ -z "$cvsroot" ]; then
268 echo "No cvs root specified, CVSROOT env var is empty, " >> $log
269 echo "and --no-i18n option is not given.." >> $log
270 echo "Using anonymous cvs.." >> $log
271 cvsroot=":pserver:anonymous@anoncvs.kde.org:/home/kde"
272 # append an entry to ~/.cvspass so the user will not be asked
273 # for a pwd. Thanks to coolo for the idea..
274 if ! grep "anoncvs.kde.org" ~/.cvspass >/dev/null 2>&1; then
275 echo "/1 :pserver:anonymous@anoncvs.kde.org:2401/home/kde A" >> ~/.cvspass
280 # the temporary directory
281 temp_dir="$module/cvs2dist-tmp"
282 temp_dist="$temp_dir/$filename"
284 echo "Temporary directory is $temp_dir." >> $log
286 # make a temporary directory
287 test -d $temp_dir && rm -Rf $temp_dir
289 mkdir -p $temp_dist
291 # check if we were able to create temp_dir
292 test -d $temp_dist
293 if [ $? -ne 0 ]; then
294 echo "Could not create temporary directory $temp_dist."
295 echo "$temp_dist could not be created." >> $log
296 echo "Aborted."
297 exit 1
300 test -z "$requiredmsg" && requiredmsg="Install development package needed first! $requiredheader, for one, is missing."
302 ### configure.in.in
303 if [ ! -z $requiredheader ]; then
304 naiyou="KDE_CHECK_HEADER(
305 $requiredheader,
307 [AC_MSG_ERROR(\"$requiredmsg\")]
309 echo $naiyou > $temp_dir/configure.in.in
310 echo "configure.in.in contents: " >> $log
311 echo "--------" >> $log
312 echo $naiyou >> $log
313 appaddfiles="$appaddfiles $temp_dir/configure.in.in"
316 # copy all files of the module to temp_dir/name
317 cp -RL $module/$directory $temp_dist/$name
319 echo "cp -R $module/$directory $temp_dist/$name" >> $log
321 modulename="$module"
322 # get rid of trailing slash
323 modulename=`echo $modulename | sed -e 's#/$##'`
324 # get the last part
325 modulename=`echo $modulename | sed -e 's#^.*/##'`
327 remove="$remove $modulename.lsm"
329 # we check out kde-i18n/subdirs in temp_dir/kde-i18n..
330 if [ $doi18n = "yes" ]; then
331 pushd $temp_dir
332 echo "cvs co kde-i18n/subdirs" >> $log
333 cvs -z4 -q -d "$cvsroot" co $branch -P kde-i18n/subdirs > /dev/null 2>&1
334 i18nlangs_tmp="$(cat kde-i18n/subdirs)"
335 skiplist="`echo $noi18nlang | sed -e 's/,/ /g'`"
336 skiplist="$skiplist $always_skip_languages"
337 for lang in $i18nlangs_tmp; do
338 must_skip="no"
339 for skip in $skiplist; do
340 if [ "$lang" = "$skip" ]; then
341 must_skip="yes"
343 done
344 if [ "$must_skip" = "no" ]; then
345 i18nlangs="$i18nlangs $lang"
347 done
348 echo "available languages: $i18nlangs" >> $log
349 popd
352 # if a handbook exists, we also copy it to the directory
353 if [ -d $module/doc/$name ]; then
354 mkdir -p $temp_dist/doc/$name
355 cp -Rf $module/doc/$name $temp_dist/doc
356 find $module/doc/ ! -xtype d -maxdepth 1 | xargs --replace={} cp {} $temp_dist/doc
358 if [ $doi18n = "yes" ]; then
359 pushd $temp_dir
360 for lang in $i18nlangs; do
361 test -d $temp_dist/doc/$lang && rm -Rf $temp_dist/doc/$lang
362 docdirname="kde-i18n/$lang/docs/$modulename/$name"
363 echo "cvs co $docdirname" >> $log
364 cvs -z4 -q -d "$cvsroot" co $branch -P "$docdirname" > /dev/null 2>&1
365 if [ ! -d "$docdirname" ]; then
366 echo "$lang's $name documentation does not exist." >> $log
367 continue
369 echo -n "Copying $lang's $name documentation over... "
370 cp -R $docdirname $temp_dist/doc/$lang
371 # we don't want KDE_DOCS = AUTO, cause that makes the
372 # build system assume that the name of the app is the
373 # same as the name of the dir the Makefile.am is in.
374 # Instead, we explicitly pass the name..
375 cat $temp_dist/doc/$lang/Makefile.am | sed -e "s/AUTO/$name/" > $temp_dist/doc/$lang/Makefile.am.nw
376 mv $temp_dist/doc/$lang/Makefile.am.nw $temp_dist/doc/$lang/Makefile.am
377 echo "done."
378 echo "$lang documentation included." >> $log
379 done
380 popd
384 # clean up doc directory
385 if [ -d $temp_dist/doc/$name ]; then
386 pushd $temp_dist/doc/$name
387 echo -n "make clean in $temp_dist/doc/$name/... "
388 echo >> $log
389 echo "make clean in $temp_dist/doc/$name/" >> $log
390 make clean >> $log
391 echo "--------" >> $log
392 echo "done."
393 popd
396 if [ $doi18n = "yes" ]; then
397 test -d $temp_dist/po && rm -Rf $temp_dist/po
398 mkdir $temp_dist/po
400 pushd $temp_dir/
401 for lang in $i18nlangs; do
402 dest=$temp_dist/po/$lang
403 for poname in $pofilenames; do
404 pofilename="kde-i18n/$lang/messages/$modulename/$poname.po";
405 echo "cvs co $pofilename" >> $log
406 cvs -z4 -q -d "$cvsroot" co $branch -P "$pofilename" > /dev/null 2>&1
407 if [ ! -f "$pofilename" ]; then
408 echo "$lang's $poname.po does not exist." >> $log
409 continue
412 if [ ! -d $dest ]; then
413 mkdir $dest
415 echo -n "Copying $lang's $poname.po over... "
416 echo "$lang's $poname.po file included." >> $log
417 cp $pofilename $dest
418 done
419 echo "done."
421 echo "KDE_LANG = $lang
422 SUBDIRS = \$(AUTODIRS)
423 POFILES = AUTO" > $dest/Makefile.am
425 subdirs="non_empty"
426 done
428 if [ -z "$subdirs" ]; then
429 rm -Rf $temp_dist/po
430 else
431 echo "SUBDIRS = \$(AUTODIRS)" > $temp_dist/po/Makefile.am
435 # copy the admin directory
436 if [ -z $admindir ]; then
437 cp -pRL $module/admin $temp_dist
438 echo "cp -pRL $module/admin $temp_dist" >> $log
439 else
440 cp -pRL $admindir $temp_dist
441 echo "cp -pRL $admindir $temp_dist" >> $log
444 # and all files from the base dir, except directories
445 echo "Copying over files from the module directory:" >> $log
446 find $module ! -xtype d -maxdepth 1 | xargs --verbose --replace={} cp {} $temp_dist 2>> $log
447 echo "--------" >> $log
449 # we now enter the temp_dist and delete all unwanted files
450 # and add wanted files
451 cd $temp_dist
453 # override top-level files
454 echo "Override files: " >> $log
455 for file in $override; do
456 test -e $temp_dist/$name/$file && mv $temp_dist/$name/$file . && echo "mv $temp_dist/$name/$file ." >> $log
457 done
459 test ! -z "$addfiles" && echo "Addfiles: " >> $log
460 for file in $addfiles; do
461 test -e $file && cp -R $file $temp_dist && echo "cp -R $file $temp_dist" >> $log
462 done
464 test ! -z "$appaddfiles" && echo "Application addfiles: " >> $log
465 for file in $appaddfiles; do
466 test -e $file && cp -R $file $temp_dist/$name/ && echo "cp -R $file $temp_dist/$name/" >> $log
467 done
469 echo "--------" >> $log
471 # replace all user requested files
472 if [ -n "$replace_files" ]; then
473 echo "Replace user requested files" >> $log
474 pair_list="`echo $replace_files | sed -e 's/,/ /g'`"
475 for pair in $pair_list; do
476 pair_tmp="`echo $pair | sed -e 's/@/ /g'`"
477 from="`echo $pair_tmp | awk '//{print $1}'`"
478 to="`echo $pair_tmp | awk '//{print $2}'`"
479 if [ -z "$from" ] || [ -z "$to" ]; then
480 echo "bogus pair \"$from@$to\"" >> $log
481 continue
483 echo "Replacing \"$to\" by \"$from\"" >> $log
484 from_path="$temp_dist/$name/$from"
485 to_path="$temp_dist/$name/$to"
486 if [ ! -f "$from_path" ]; then
487 echo "$from_path does not exist!" >> $log
488 echo ""
489 echo "Warning: \"$from\" does not exist!"
490 echo -n "Please enter the path in --replace-files relative "
491 echo "to the package root of your project."
492 echo "Your package root is: \"$module/$directory\""
493 echo ""
494 continue
496 rm -f "$to_path" && \
497 mv "$from_path" "$to_path"
498 if [ $? -ne 0 ]; then
499 echo -n "Moving \"$from_path\" failed! " >> $log
500 echo -n "This should not happen." >> $log
501 if [ -f "$to_path" ]; then
502 echo ""
503 else
504 echo " No \"$to\" will exist in the archive!" >> $log
507 done
508 echo "--------" >> $log
511 # version file, if it doesn't exist
512 test ! -z $version && test ! -e VERSION && echo "$name version $version" > VERSION
514 cd $temp_dist/$name
515 echo "make clean in $temp_dist/$name/:" >> $log
516 echo "" >> $log
517 echo -n "make clean in $temp_dist/$name/... "
518 make clean >> $log
519 echo "--------" >> $log
520 echo "done."
522 cd $temp_dist
524 # remove files
525 echo "Remove files: " >> $log
526 for file in $remove; do
527 find . -name $file | xargs rm -Rf
528 echo "find . -name $file | xargs rm -Rf" >> $log
529 done
531 # remove more files
532 echo "Remove toplevel files: " >> $log
533 for file in $toplevelremove; do
534 test -e $file && rm -Rf $file && echo "rm -Rf $file" >> $log
535 done
536 unset file
538 # remove hidden files
539 test ! -z $removehidden && echo "Remove hidden files: " >> $log && find $temp_dist -name ".*" -and ! -name "." | xargs --verbose rm -Rf 2>> $log
541 echo "--------" >> $log
543 cd $temp_dist
545 # create the configure script
546 # working directory is $temp_dist
547 echo "make -f Makefile.cvs in $temp_dist/:" >> $log
548 echo "" >> $log
549 echo -n "make -f Makefile.cvs in $temp_dist/... "
550 make -f Makefile.cvs >> $log 2>> $log
551 echo "rm Makefile.cvs" >> $log
552 rm -f Makefile.cvs
553 echo "rm autom4te.cache" >> $log
554 rm -Rf autom4te.cache
555 echo "--------" >> $log
556 echo "done."
558 echo "Directory will be $filename."
560 # play around with our tar file in temp_dir
561 cd $temp_dir
563 if [ ! -z $leavedir ]; then
564 test -e $returndir/$filename && rm -Rf $returndir/$filename
565 cp -R $filename $returndir
568 # make a tar of temp_dist
569 if [ -z $nogzip ] || [ -z $nobzip2 ]; then
570 echo -n "Tarring... "
571 echo "tar cf $filename.tar $filename" >> $log
572 tar cf $filename.tar $filename >> $log
573 echo "done."
576 if [ -z $nogzip ] && [ ! -z `which gzip 2> /dev/null` ]; then
577 cp $filename.tar $filename.tar.tmp
578 echo -n "running gzip... "
579 echo "gzip $filename.tar" >> $log
580 gzip $filename.tar
581 echo "done."
582 mv $filename.tar.tmp $filename.tar
583 mv $filename.tar.gz $returndir
584 echo "mv $filename.tar.gz $returndir" >> $log
586 if [ -z $nobzip2 ] && [ ! -z `which bzip2 2> /dev/null` ]; then
587 echo -n "running bzip2... "
588 echo "bzip2 $filename.tar" >> $log
589 bzip2 $filename.tar
590 echo "done."
591 mv $filename.tar.bz2 $returndir
592 echo "mv $filename.tar.bz2 $returndir" >> $log
595 test -e $filename.tar && rm -f $filename.tar
597 # cleanup all tempoaries
598 exit_cleanup
600 cd $returndir
602 test -z $leavedir && test ! -z $nobzip2 && test ! -z $nogzip && echo "Finished - no created files." && exit 1
604 # cool, everything went ok!
605 if [ -z $leavedir ]; then
606 echo "Finished. Created packages:"
607 else
608 if [ -z $nogzip ] || [ -z $nobzip2 ]; then
609 echo "Finished. Created packages/directories:"
610 else
611 echo "Finished. Created directory:"
615 echo "--------" >> $log
616 echo "Done: " >> $log
617 echo "Files are in `pwd`." >> $log
619 if [ ! -z $leavedir ] && [ -d $filename ]; then
620 ls -ld $filename
621 ls -ld $filename >> $log
623 if [ -z $nogzip ] && [ -e $filename.tar.gz ]; then
624 ls -l $filename.tar.gz
625 ls -l $filename.tar.gz >> $log
627 if [ -z $nobzip2 ] && [ -e $filename.tar.bz2 ]; then
628 ls -l $filename.tar.bz2
629 ls -l $filename.tar.bz2 >> $log
631 if [ $log != "/dev/null" ]; then
632 echo "Created log:"
633 ls -l $origlog