New way to run configuration scripts

This commit is contained in:
Pierre Pronchery 2010-12-31 16:09:48 +00:00
parent 2aebd89d7c
commit e6a51fd129
2 changed files with 71 additions and 46 deletions

View File

@ -10,10 +10,10 @@ INSTALL = install
all: $(TARGETS) all: $(TARGETS)
Todo.pot: POTFILES Todo.pot: POTFILES
./gettext.sh "Todo.pot" ./gettext.sh -P "$(PREFIX)" -- "Todo.pot"
fr.mo: Todo.pot fr.po fr.mo: Todo.pot fr.po
./gettext.sh "fr.mo" ./gettext.sh -P "$(PREFIX)" -- "fr.mo"
clean: clean:
$(RM) -- $(Todo.pot_OBJS) $(fr.mo_OBJS) $(RM) -- $(Todo.pot_OBJS) $(fr.mo_OBJS)
@ -22,9 +22,9 @@ distclean: clean
$(RM) -- $(TARGETS) $(RM) -- $(TARGETS)
install: all install: all
./gettext.sh -p "$(DESTDIR)$(PREFIX)" install "fr.mo" ./gettext.sh -P "$(DESTDIR)$(PREFIX)" -i -- "fr.mo"
uninstall: uninstall:
./gettext.sh -p "$(DESTDIR)$(PREFIX)" uninstall "fr.mo" ./gettext.sh -P "$(DESTDIR)$(PREFIX)" -u -- "fr.mo"
.PHONY: all clean distclean install uninstall .PHONY: all clean distclean install uninstall

View File

@ -18,16 +18,6 @@ XGETTEXT="xgettext --force-po"
#functions #functions
#usage
_usage()
{
echo "Usage: ./gettext.sh <target>" 1>&2
echo " ./gettext.sh -p <prefix> install <target>" 1>&2
echo " ./gettext.sh -p <prefix> uninstall <target>" 1>&2
return 1
}
#debug #debug
_debug() _debug()
{ {
@ -36,6 +26,14 @@ _debug()
} }
#usage
_usage()
{
echo "Usage: gettext.sh [-i|-u][-P prefix] <target>" 1>&2
return 1
}
#gettext_mo #gettext_mo
_gettext_mo() _gettext_mo()
{ {
@ -63,38 +61,65 @@ _gettext_pot()
#main #main
if [ $# -eq 4 -a "$1" = "-p" ]; then args=`getopt iuP: $*`
PREFIX="$2" if [ $? -ne 0 ]; then
LOCALEDIR="$PREFIX/share/locale"
lang="${4%%.mo}"
if [ "$3" = "install" ]; then
$DEBUG $MKDIR "$LOCALEDIR/$lang/LC_MESSAGES" || exit 2
$DEBUG $INSTALL "$4" \
"$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \
|| exit 2
exit 0
elif [ "$3" = "uninstall" ]; then
$DEBUG $RM "$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \
|| exit 2
exit 0
else
echo "gettext.sh: $3: Unknown operation" 1>&2
fi
fi
if [ $# -ne 1 ]; then
_usage _usage
exit $? exit $?
fi fi
case "$1" in set -- $args
*.mo) install=0
_gettext_mo "$PACKAGE" "${1%%.mo}" || exit 2 uninstall=0
;; while [ $# -gt 0 ]; do
*.pot) case "$1" in
_gettext_pot "${1%%.pot}" || exit 2 -i)
;; install=1
*) ;;
exit 2 -u)
;; uninstall=1
esac ;;
exit 0 -P)
PREFIX="$2"
shift
;;
--)
shift
break
;;
esac
shift
done
LOCALEDIR="$PREFIX/share/locale"
while [ $# -gt 0 ]; do
target="$1"
lang="${target%%.mo}"
shift
#uninstall
if [ "$uninstall" -eq 1 ]; then
$DEBUG $RM "$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \
|| exit 2
continue
fi
#create
case "$target" in
*.mo)
_gettext_mo "$PACKAGE" "$lang" || exit 2
;;
*.pot)
_gettext_pot "${target%%.pot}" || exit 2
;;
*)
exit 2
;;
esac
#install
if [ "$install" -eq 1 ]; then
$DEBUG $MKDIR "$LOCALEDIR/$lang/LC_MESSAGES" || exit 2
$DEBUG $INSTALL "$target" \
"$LOCALEDIR/$lang/LC_MESSAGES/$PACKAGE.mo" \
|| exit 2
fi
done