ALL_CFLAGS := $(CFLAGS)
ALL_CPPFLAGS := $(SDL_CPPFLAGS) $(PNG_CPPFLAGS) -Ishare \
- -DVERSION=\"$(VERSION)\" $(CPPFLAGS)
+ -DVERSION=\"$(VERSION)\"
+
+ifdef DISABLE_NLS
+ ALL_CPPFLAGS += -DDISABLE_NLS=1
+endif
+
+ALL_CPPFLAGS += $(CPPFLAGS)
#------------------------------------------------------------------------------
PNG_LIBS := $(shell libpng-config --libs)
ifdef MINGW
+ifndef DISABLE_NLS
+ INTL_LIBS := -lintl
+endif
+endif
+
+ifdef MINGW
OGL_LIBS := -lopengl32 -lm
- BASE_LIBS := -lSDL -lSDL_image -lintl
- ALL_LIBS := $(SDL_LIBS) -lSDL_image -lintl \
+ BASE_LIBS := -lSDL -lSDL_image $(INTL_LIBS)
+ ALL_LIBS := $(SDL_LIBS) -lSDL_image $(INTL_LIBS) \
$(PNG_LIBS) -lSDL_ttf -lSDL_mixer $(OGL_LIBS)
else
OGL_LIBS := -lGL -lm
#------------------------------------------------------------------------------
-LOCALEDIR := locale
-LOCALEDOM := neverball
-POTFILE := po/neverball.pot
-MESSAGEPART := /LC_MESSAGES/$(LOCALEDOM).mo
-POS := $(shell echo po/*.po)
-LINGUAS := $(POS:po/%.po=%)
-MESSAGES := $(LINGUAS:%=$(LOCALEDIR)/%$(MESSAGEPART))
-
-#-------------------------------------------------------------------------------
-
MAPC_OBJS := \
share/vec3.o \
share/base_image.o \
%.sol : %.map $(MAPC_TARG)
$(WINE) ./$(MAPC_TARG) $< data
-$(LOCALEDIR)/%$(MESSAGEPART) : po/%.po
- mkdir -p `dirname $@`
- msgfmt -c -v -o $@ $<
-
#------------------------------------------------------------------------------
all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales
sols : $(SOLS)
-locales : $(MESSAGES)
+locales :
+ifndef DISABLE_NLS
+ $(MAKE) -C po
+endif
clean-src :
$(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
clean : clean-src
$(RM) $(SOLS)
- rm -rf $(LOCALEDIR)
+ $(MAKE) -C po clean
test : all
./neverball
#------------------------------------------------------------------------------
-po/%.po : $(POTFILE)
- msgmerge -U $@ $<
- touch $@
-
-po-update-extract :
- sh scripts/extractpo.sh $(POTFILE) $(LOCALEDOM)
-
-po-update-merge : $(POS)
-
-po-update : po-update-extract po-update-merge
-
-#------------------------------------------------------------------------------
-
-.PHONY : all sols locales clean-src clean test \
- po-update-extract po-update-merge po-update \
-
+.PHONY : all sols locales clean-src clean test
-include $(BALL_DEPS) $(PUTT_DEPS) $(MAPC_DEPS)
--- /dev/null
+#-------------------------------------------------------------------------------
+
+# Basic LINGUAS environment variable support
+
+ALL_LINGUAS := $(basename $(wildcard *.po))
+
+ifneq ($(LINGUAS),)
+ LINGUAS := $(filter $(ALL_LINGUAS), $(LINGUAS))
+else
+ LINGUAS := $(ALL_LINGUAS)
+endif
+
+#-------------------------------------------------------------------------------
+
+ROOT := ..
+
+DOMAIN := neverball
+LOCALEDIR := $(ROOT)/locale
+POFILES := $(LINGUAS:%=%.po)
+MOFILES := $(LINGUAS:%=$(LOCALEDIR)/%/LC_MESSAGES/$(DOMAIN).mo)
+SOURCES := \
+ $(wildcard $(ROOT)/ball/*.[ch]) \
+ $(wildcard $(ROOT)/share/*.[ch]) \
+ $(wildcard $(ROOT)/putt/*.[ch])
+
+#------------------------------------------------------------------------------
+
+COPYRIGHT := Robert Kooima
+BUGADDR := robert.kooima@gmail.com
+
+XGETTEXT := xgettext
+XGETTEXT_FLAGS := \
+ --add-comments=TRANSLATORS --from-code=UTF-8 \
+ --keyword=_ --keyword=N_ --keyword=sgettext \
+ --default-domain="$(DOMAIN)" \
+ --copyright-holder="$(COPYRIGHT)" \
+ --msgid-bugs-address="$(BUGADDR)"
+
+#------------------------------------------------------------------------------
+
+all: $(MOFILES)
+
+clean:
+ rm -rf $(LOCALEDIR)
+
+#------------------------------------------------------------------------------
+
+# Here it gets somewhat convoluted. Basic idea is: we want the
+# update-po target which is widely supported in autotools-based
+# internationalised packages. update-po unconditionally updates the POT
+# file, and thus forces PO and MO files to be updated as well. The
+# logic is loosely based on Makefile.in.in distributed with GNU gettext.
+
+update-po: $(DOMAIN).pot-update $(POFILES) $(MOFILES)
+
+$(LOCALEDIR)/%/LC_MESSAGES/$(DOMAIN).mo: %.po
+ mkdir -p $$(dirname $@)
+ msgfmt -c --statistics -o $@ $<
+
+%.po: $(DOMAIN).pot
+ msgmerge -U $@ $<
+ touch $@
+
+$(DOMAIN).pot:
+ $(MAKE) $(DOMAIN).pot-update
+
+$(DOMAIN).pot-update:
+ $(XGETTEXT) $(XGETTEXT_FLAGS) -o $(DOMAIN).pot \
+ --directory="$(ROOT)" $(SOURCES:$(ROOT)/%=%)
+
+ # Force encoding to UTF-8
+ sed "1,/^$$/ s/CHARSET/UTF-8/" < $(DOMAIN).pot > $(DOMAIN).pot.utf8
+ mv -f $(DOMAIN).pot.utf8 $(DOMAIN).pot
+
+ sh $(ROOT)/scripts/extractpo.sh $(ROOT) >> $(DOMAIN).pot
+ msguniq -o $(DOMAIN).pot $(DOMAIN).pot
+
+#------------------------------------------------------------------------------
+
#!/bin/sh
-# This program creates the neverball.pot file from source code and level files.
-
+# This script extracts translatable messages from maps and sets.
# Copyright (C) 2006 Jean Privat
-# Part of the Neverball Project http://icculus.org/neverball/
+#
+# Part of the Neverball project
+# http://icculus.org/neverball/
#
# NEVERBALL is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
-set -B
-
-POTFILE="$1"
-DOMAIN="$2"
-COPYRIGHT="Robert Kooima"
-BUGADDR="robert.kooima@gmail.com"
-
-DATA=data
-SETS="$DATA"/sets.txt
-COURSES="$DATA"/courses.txt
+test -n "$1" || exit 1
-export LC_ALL=C
+LC_ALL=C
+export LC_ALL
-# First, extract from source
-echo "# Sources"
-> "$POTFILE"
-xgettext --add-comments=TRANSLATORS --from-code=UTF-8 --keyword=_ --keyword=N_ --keyword=sgettext -d "$DOMAIN" --copyright-holder="$COPYRIGHT" --msgid-bugs-address="$BUGADDR" -F -o "$POTFILE" {ball,putt,share}/*.[ch]
+cd "$1"
-# Force encoding to UTF-8
-sed "1,/^$/ s/charset=CHARSET/charset=UTF-8/" < "$POTFILE" > "$POTFILE".utf8
-mv "$POTFILE".utf8 "$POTFILE"
+DATA="data"
+SETS="$DATA/sets.txt"
+COURSES="$DATA/courses.txt"
-# Second, extract from neverball sets and neverputt courses
-echo "# Sets and courses"
for i in $(cat "$SETS"); do
- i="$DATA"/"$i"
-
- # Only translate the two first lines
- head -2 $i | while read -r d; do
- echo
- echo "#: $i"
- # Convert \ to \\
- echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
- echo "msgstr \"\""
- done >> $POTFILE
+ i="$DATA/$i"
+
+ # Only translate the two first lines
+ head -n 2 $i | while read -r d; do
+ echo
+ echo "#: $i"
+ echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
+ echo "msgstr \"\""
+ done
done
# the "echo | cat x -" forces the end of the last line
echo | cat "$COURSES" - | while read -r d; do
- # Heuristic: description is non empty line without .txt inside
- if test -n "$d" && echo "$d" | grep -v ".txt" &> /dev/null; then
- echo
- echo "#: $COURSES"
- # Convert \ to \\
- echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
- echo "msgstr \"\""
- fi
-done >> $POTFILE
-
-# Third, extracts from levels
-echo -n "# Levels: "
-find "$DATA" -name "*.map" | sort | tee .map_list | wc -l
-for i in $(cat .map_list); do
- # Check encoding?
- # file --mime $i
- echo -n '.'
- # Only translatable string is "message"
- grep -E "^\"message\"" "$i" | while read -r a b; do
- echo
- echo "#: $i"
- echo "msgid $(echo "$b" | sed 's/\\/\\\\/g')"
- echo "msgstr \"\""
- done >> $POTFILE
+ # Heuristic: description is non empty line without .txt inside
+ if test -n "$d" && echo "$d" | grep -v ".txt" &> /dev/null; then
+ echo
+ echo "#: $COURSES"
+ echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
+ echo "msgstr \"\""
+ fi
done
-echo " ok"
-rm .map_list
-# Remove duplicates, to keep msgmerge from complaining
-echo "# Removing duplicates."
-msguniq -o "$POTFILE" -t UTF-8 "$POTFILE"
+for i in $(find $DATA -name "*.map" | sort); do
+ # Only translatable string is "message"
+ grep -E "^\"message\"" "$i" | while read -r a b; do
+ echo
+ echo "#: $i"
+ echo "msgid $(echo "$b" | sed 's/\\/\\\\/g')"
+ echo "msgstr \"\""
+ done
+done
void lang_init(const char *domain, const char *default_dir)
{
+#ifndef DISABLE_NLS
char *dir = getenv("NEVERBALL_LOCALE");
setlocale(LC_ALL, "");
bindtextdomain(domain, dir ? dir : default_dir);
bind_textdomain_codeset(domain, "UTF-8");
textdomain(domain);
+#endif
}
const char *sgettext(const char *msgid)
{
+#ifndef DISABLE_NLS
const char *msgval = gettext(msgid);
+#else
+ const char *msgval = msgid;
+#endif
if (msgval == msgid)
{
#ifndef LANG_H
#define LANG_H
-#ifndef POSIX
+#ifndef DISABLE_NLS
#include <libintl.h>
#define _(String) gettext(String)
#else