# dvdisaster: Create the locale Makefile.
# This is called from the toplevel ./configure script.

cat > Makefile <<EOF
# This makefile template was automatically generated by
# the create-makefile script. Do not hand-edit!

EOF

for i in ../*.c; do
  cfiles="$cfiles $i"
  nopath=`echo $i | sed -e 's/..\///'`
  cfiles2="$cfiles2 $nopath"
done

for i in ??.po; do
  prefix=`echo $i | sed -e 's/.po//'`
  if ! test -e $prefix; then mkdir $prefix; fi
  if ! test -e $prefix/LC_MESSAGES; then mkdir $prefix/LC_MESSAGES; fi
  localefiles="$localefiles $prefix/LC_MESSAGES/dvdisaster.mo"
  prefixes="$prefixes $prefix"
done

cat >> Makefile <<EOF
LOCALEFILES = $localefiles
CFILES      = $cfiles
CFILES_NP   = $cfiles2

locale: \$(LOCALEFILES)

# Create the locale files. 

EOF

for i in $prefixes; do
cat >> Makefile <<EOF
$i.po: \$(CFILES)
	@echo "Updating $i.po"
	@cd ..; xgettext --no-wrap -cTRANSLATORS: -o locale/messages.pot -k_ -k_utf \$(CFILES_NP)
	@msgmerge -q -U --no-wrap --no-fuzzy-matching $i.po messages.pot
	@rm -f messages.pot

$i/LC_MESSAGES/dvdisaster.mo: $i.po
	@echo "Updating $i.mo"
	@msgfmt -c -o $i/LC_MESSAGES/dvdisaster.mo $i.po


EOF
done