From 02925ff461a78ffb8790448634464279e18afe03 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 4 Nov 2014 00:40:58 +0100 Subject: [PATCH] Added support for building with OBJDIR --- Makefile | 18 +++++++++++++++--- data/Makefile | 1 + po/Makefile | 13 +++++++------ po/gettext.sh | 46 ++++++++++++++++++++++++++++++++++++---------- po/project.conf | 2 +- src/Makefile | 23 ++++++++++++----------- 6 files changed, 72 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 34c9186..501f431 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ VERSION = 0.0.0 SUBDIRS = data po src RM = rm -f LN = ln -f -TAR = tar -czvf +TAR = tar +MKDIR = mkdir -m 0755 -p all: subdirs @@ -20,7 +21,7 @@ distclean: dist: $(RM) -r -- $(PACKAGE)-$(VERSION) $(LN) -s -- . $(PACKAGE)-$(VERSION) - @$(TAR) $(PACKAGE)-$(VERSION).tar.gz -- \ + @$(TAR) -czvf $(PACKAGE)-$(VERSION).tar.gz -- \ $(PACKAGE)-$(VERSION)/data/Makefile \ $(PACKAGE)-$(VERSION)/data/deforaos-xmleditor.desktop \ $(PACKAGE)-$(VERSION)/data/project.conf \ @@ -43,10 +44,21 @@ dist: $(PACKAGE)-$(VERSION)/project.conf $(RM) -- $(PACKAGE)-$(VERSION) +distcheck: dist + $(TAR) -xzvf $(PACKAGE)-$(VERSION).tar.gz + $(MKDIR) -- $(PACKAGE)-$(VERSION)/objdir + $(MKDIR) -- $(PACKAGE)-$(VERSION)/destdir + (cd "$(PACKAGE)-$(VERSION)" && $(MAKE) OBJDIR="$$PWD/objdir/") + (cd "$(PACKAGE)-$(VERSION)" && $(MAKE) OBJDIR="$$PWD/objdir/" DESTDIR="$$PWD/destdir" install) + (cd "$(PACKAGE)-$(VERSION)" && $(MAKE) OBJDIR="$$PWD/objdir/" DESTDIR="$$PWD/destdir" uninstall) + (cd "$(PACKAGE)-$(VERSION)" && $(MAKE) OBJDIR="$$PWD/objdir/" distclean) + (cd "$(PACKAGE)-$(VERSION)" && $(MAKE) dist) + $(RM) -r -- $(PACKAGE)-$(VERSION) + install: @for i in $(SUBDIRS); do (cd "$$i" && $(MAKE) install) || exit; done uninstall: @for i in $(SUBDIRS); do (cd "$$i" && $(MAKE) uninstall) || exit; done -.PHONY: all subdirs clean distclean dist install uninstall +.PHONY: all subdirs clean distclean dist distcheck install uninstall diff --git a/data/Makefile b/data/Makefile index 35ba2b1..2d7bb0c 100644 --- a/data/Makefile +++ b/data/Makefile @@ -1,3 +1,4 @@ +OBJDIR = PREFIX = /usr/local DESTDIR = MKDIR = mkdir -m 0755 -p diff --git a/po/Makefile b/po/Makefile index 9608ac9..78a9f94 100644 --- a/po/Makefile +++ b/po/Makefile @@ -1,4 +1,5 @@ -TARGETS = XMLEditor.pot fr.mo +TARGETS = $(OBJDIR)XMLEditor.pot $(OBJDIR)fr.mo +OBJDIR = PREFIX = /usr/local DESTDIR = RM = rm -f @@ -9,11 +10,11 @@ INSTALL = install all: $(TARGETS) -XMLEditor.pot: POTFILES - ./gettext.sh -P "$(PREFIX)" -- "XMLEditor.pot" +$(OBJDIR)XMLEditor.pot: POTFILES + ./gettext.sh -P "$(PREFIX)" -- "$(OBJDIR)XMLEditor.pot" -fr.mo: XMLEditor.pot fr.po - ./gettext.sh -P "$(PREFIX)" -- "fr.mo" +$(OBJDIR)fr.mo: $(OBJDIR)XMLEditor.pot fr.po + ./gettext.sh -P "$(PREFIX)" -- "$(OBJDIR)fr.mo" clean: $(RM) -- $(XMLEditor.pot_OBJS) $(fr.mo_OBJS) @@ -24,7 +25,7 @@ distclean: clean $(RM) -- $(TARGETS) install: $(TARGETS) - ./gettext.sh -P "$(DESTDIR)$(PREFIX)" -i -- "fr.mo" + ./gettext.sh -P "$(DESTDIR)$(PREFIX)" -i -- "$(OBJDIR)fr.mo" uninstall: ./gettext.sh -P "$(DESTDIR)$(PREFIX)" -u -- "fr.mo" diff --git a/po/gettext.sh b/po/gettext.sh index 11a8805..c3ae919 100755 --- a/po/gettext.sh +++ b/po/gettext.sh @@ -70,9 +70,12 @@ _gettext_mo() { package="$1" lang="$2" + potfile="$3" + pofile="$4" + mofile="$5" - _gettext_po "$package" "$lang" || return 1 - $DEBUG $MSGFMT -c -v -o "$lang.mo" "$lang.po" || return 1 + _gettext_po "$package" "$lang" "$potfile" "$pofile" || return 1 + $DEBUG $MSGFMT -c -v -o "$mofile" "$pofile" || return 1 } @@ -81,11 +84,13 @@ _gettext_po() { package="$1" lang="$2" + potfile="$3" + pofile="$4" - if [ -f "$lang.po" ]; then - $DEBUG $MSGMERGE -U "$lang.po" "$package.pot" || return 1 + if [ -f "$pofile" ]; then + $DEBUG $MSGMERGE -U "$pofile" "$potfile" || return 1 else - $DEBUG $MSGINIT -l "$lang" -o "$lang.po" -i "$package.pot" \ + $DEBUG $MSGINIT -l "$lang" -o "$pofile" -i "$potfile" \ || return 1 fi } @@ -95,8 +100,9 @@ _gettext_po() _gettext_pot() { package="$1" + potfile="$2" - $DEBUG $XGETTEXT -d "$package" -o "$package.pot" --keyword="_" \ + $DEBUG $XGETTEXT -d "$package" -o "$potfile" --keyword="_" \ --keyword="N_" -f "$POTFILES" || return 1 } @@ -142,7 +148,8 @@ fi LOCALEDIR="$PREFIX/share/locale" while [ $# -gt 0 ]; do target="$1" - lang="${target%%.mo}" + source="${target#$OBJDIR}" + lang="${source%%.mo}" lang="${lang%%.po}" shift @@ -168,13 +175,32 @@ while [ $# -gt 0 ]; do #create case "$target" in *.mo) - _gettext_mo "$PACKAGE" "$lang" || exit 2 + #XXX may not match + if [ -n "$OBJDIR" ]; then + potfile="$OBJDIR/$PACKAGE.pot" + else + potfile="$PACKAGE.pot" + fi + mofile="$target" + pofile="${source%%.mo}.po" + _gettext_mo "$PACKAGE" "$lang" "$potfile" "$pofile" \ + "$mofile" || exit 2 ;; *.po) - _gettext_po "$PACKAGE" "$lang" || exit 2 + #XXX may not match + if [ -n "$OBJDIR" ]; then + potfile="$OBJDIR/$PACKAGE.pot" + else + potfile="$PACKAGE.pot" + fi + pofile="$target" + _gettext_po "$PACKAGE" "$lang" "$potfile" "$pofile" \ + || exit 2 ;; *.pot) - _gettext_pot "${target%%.pot}" || exit 2 + package="${source%%.pot}" + potfile="$target" + _gettext_pot "$package" "$potfile" || exit 2 ;; *) exit 2 diff --git a/po/project.conf b/po/project.conf index aa41379..43a374c 100644 --- a/po/project.conf +++ b/po/project.conf @@ -10,4 +10,4 @@ depends=POTFILES type=script script=./gettext.sh install= -depends=XMLEditor.pot,fr.po +depends=$(OBJDIR)XMLEditor.pot,fr.po diff --git a/src/Makefile b/src/Makefile index 6a98ffb..20730dc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,5 @@ -TARGETS = xmleditor +TARGETS = $(OBJDIR)xmleditor +OBJDIR = PREFIX = /usr/local DESTDIR = BINDIR = $(PREFIX)/bin @@ -18,21 +19,21 @@ INSTALL = install all: $(TARGETS) -xmleditor_OBJS = callbacks.o xmleditor.o main.o +xmleditor_OBJS = $(OBJDIR)callbacks.o $(OBJDIR)xmleditor.o $(OBJDIR)main.o xmleditor_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) xmleditor_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -xmleditor: $(xmleditor_OBJS) - $(CC) -o xmleditor $(xmleditor_OBJS) $(xmleditor_LDFLAGS) +$(OBJDIR)xmleditor: $(xmleditor_OBJS) + $(CC) -o $(OBJDIR)xmleditor $(xmleditor_OBJS) $(xmleditor_LDFLAGS) -callbacks.o: callbacks.c callbacks.h xmleditor.h - $(CC) $(xmleditor_CFLAGS) -c callbacks.c +$(OBJDIR)callbacks.o: callbacks.c callbacks.h xmleditor.h + $(CC) $(xmleditor_CFLAGS) -o $(OBJDIR)callbacks.o -c callbacks.c -xmleditor.o: xmleditor.c callbacks.h xmleditor.h ../config.h - $(CC) $(xmleditor_CFLAGS) -c xmleditor.c +$(OBJDIR)xmleditor.o: xmleditor.c callbacks.h xmleditor.h ../config.h + $(CC) $(xmleditor_CFLAGS) -o $(OBJDIR)xmleditor.o -c xmleditor.c -main.o: main.c xmleditor.h ../config.h - $(CC) $(xmleditor_CFLAGS) -c main.c +$(OBJDIR)main.o: main.c xmleditor.h ../config.h + $(CC) $(xmleditor_CFLAGS) -o $(OBJDIR)main.o -c main.c clean: $(RM) -- $(xmleditor_OBJS) @@ -42,7 +43,7 @@ distclean: clean install: $(TARGETS) $(MKDIR) $(DESTDIR)$(BINDIR) - $(INSTALL) -m 0755 xmleditor $(DESTDIR)$(BINDIR)/xmleditor + $(INSTALL) -m 0755 $(OBJDIR)xmleditor $(DESTDIR)$(BINDIR)/xmleditor uninstall: $(RM) -- $(DESTDIR)$(BINDIR)/xmleditor