Skip to content

Commit

Permalink
Fallack if gettext is not available. Shebang translation
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed Jun 1, 2020
1 parent 6075362 commit a4a361d
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 305 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.asc
*.gz
*.tar
*.xz
*.zip
sbin/zram-init
i18n/*.mo
i18n/*.po~
i18n/*.pot
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- French translation

Martin Väth <martin at mvath.de>:
- Fallback if gettext is not available
- Makefile: Separate into make | make install, shebang conversion
- Makefile: make most installs optional
- German translation

*zram-init-9.1:
Expand Down
177 changes: 112 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
BUGADDR = Martin V\"ath <martin@mvath.de>

EXENAME ?= zram-init
BINVER ?= 9.1

PREFIX ?= /usr/local
DESTDIR ?=
PREFIX ?= /usr/local
SYSCONFDIR ?= $(PREFIX)/etc
DESTDIR ?=

BINDIR ?= $(DESTDIR)$(PREFIX)/sbin
MODPROBEDIR ?= $(DESTDIR)$(PREFIX)/etc/modprobe.d
MODPROBEDIR ?= $(DESTDIR)$(SYSCONFDIR)/modprobe.d
MANDIR ?= $(DESTDIR)$(PREFIX)/share/man/man8
MODIR ?= $(DESTDIR)$(PREFIX)/share/locale
COMP_ZSHDIR ?= $(DESTDIR)$(PREFIX)/share/zsh/site-functions
SYSTEMDDIR ?= $(DESTDIR)$(PREFIX)/lib/systemd/system
CONFDIR ?= $(DESTDIR)$(PREFIX)/etc/conf.d
INITDIR ?= $(DESTDIR)$(PREFIX)/etc/init.d
CONFDIR ?= $(DESTDIR)$(SYSCONFDIR)/conf.d
INITDIR ?= $(DESTDIR)$(SYSCONFDIR)/init.d

PO ?= i18n/fr.po
PO ?= i18n/de.po i18n/fr.po

GETTEXT ?= TRUE
MODIFY_SHEBANG ?= TRUE
MODPROBED ?= TRUE
MANPAGE ?= TRUE
ZSH_COMPLETION ?= TRUE
SYSTEMD ?= TRUE
OPENRC ?= TRUE

INSTALL_EXE ?= install -D --mode=755
INSTALL_DATA ?= install -D --mode=644
Expand All @@ -26,92 +32,133 @@ MSGFMT ?= msgfmt --check --statistics --verbose
FXGETTEXT ?= --no-wrap
MSGMERGE ?= msgmerge $(FXGETTEXT) --update --backup=existing --verbose
XGETTEXT ?= xgettext $(FXGETTEXT) --from-code=UTF-8 --add-comments="TRANSLATION:" \
--keyword="Echo" --flag="Echo:1:no-sh-format" --keyword="xEcho" \
--keyword="xWarning" --keyword="Fatal" --flag="Fatal:1:no-sh-format" \
--keyword="xFatal" --language=Shell --copyright-holder="$(BUGADDR)" \
--package-name="$(EXENAME)" --package-version=$(BINVER) \
--msgid-bugs-address="$(BUGADDR)"
--keyword="Echo" --flag="Echo:1:no-sh-format" --keyword="xEcho" \
--keyword="xWarning" --keyword="Fatal" --flag="Fatal:1:no-sh-format" \
--keyword="xFatal" --language=Shell --add-location=never \
--copyright-holder="$(BUGADDR)" \
--package-name="$(EXENAME)" --msgid-bugs-address="$(BUGADDR)"

.PHONY: all
all: $(PO:.po=.mo)
ifeq ($(GETTEXT), TRUE)
all: $(PO:.po=.mo) sbin/$(EXENAME)
else
all: sbin/$(EXENAME)
endif

.PHONY: po
po: $(PO)

i18n/$(EXENAME).pot: sbin/$(EXENAME).in
@echo "Creating the Portable Object Template file: $@"
$(XGETTEXT) $< -o $@
@echo 'Creating the Portable Object Template file: $@…'
$(XGETTEXT) '$<' -o '$@'

i18n/%.po: $(EXENAME).pot
@echo "Merging the Portable Object Template file into $@"
$(MSGMERGE) $@ $<
i18n/%.po: i18n/$(EXENAME).pot
@echo 'Merging the Portable Object Template file into $@…'
$(MSGMERGE) '$@' '$<'

i18n/%.mo: i18n/%.po
@echo "Compiling the Portable Object file: $<…"
$(MSGFMT) $< -o $@
@echo 'Compiling the Portable Object file: $<…'
$(MSGFMT) '$<' -o '$@'

sbin/$(EXENAME): sbin/$(EXENAME).in
@echo 'Setting TEXTDOMAINDIR and TEXTDOMAIN variables'
sed -e "s'@MODIR@'$(MODIR)'g" -e "s'@EXENAME@'$(EXENAME)'g" \
-- '$<' >'$@'
chmod 755 -- '$@' || echo 'warn: chmod 755 $@ failed'
ifeq ($(MODIFY_SHEBANG), TRUE)
@echo 'Modifying shebang…'
sed -e "1s'"'^\#\!.*$$'"'$${SHEBANG:-#!`command -v sh 2>/dev/null`}'" \
-i -- '$@'
endif

.PHONY: install
install: all
@echo "Installing the executable…"
$(INSTALL_EXE) "sbin/$(EXENAME).in" "$(BINDIR)/$(EXENAME)"
@echo "Setting TEXTDOMAINDIR and TEXTDOMAIN variables"
sed -e "s:@MODIR@:$(MODIR):g" -e "s/@EXENAME@/$(EXENAME)/g" \
-i "$(BINDIR)/$(EXENAME)"
@echo "Installing the modprobe.d file…"
$(INSTALL_DATA) modprobe.d/zram.conf "$(MODPROBEDIR)/zram.conf"
@echo "Installing the man page…"
$(INSTALL_DATA) "man/$(EXENAME).8" "$(MANDIR)/$(EXENAME).8"
@echo "Installing the Machine Object files…"
@echo 'Installing the executable…'
$(INSTALL_EXE) 'sbin/$(EXENAME)' '$(BINDIR)/$(EXENAME)'
ifeq ($(MODPROBED), TRUE)
@echo 'Installing the modprobe.d file…'
$(INSTALL_DATA) modprobe.d/zram.conf '$(MODPROBEDIR)/zram.conf'
endif
ifeq ($(MANPAGE), TRUE)
@echo 'Installing the man page…'
$(INSTALL_DATA) 'man/$(EXENAME).8' '$(MANDIR)/$(EXENAME).8'
endif
ifeq ($(GETTEXT), TRUE)
@echo 'Installing the Machine Object files…'
for i in $(notdir $(basename $(PO))); do \
$(INSTALL_DATA) "i18n/$$i.mo" "$(MODIR)/$$i/LC_MESSAGES/$(EXENAME).mo"; \
done
@echo "Installing the completion files…"
$(INSTALL_DATA) "zsh/_$(EXENAME)" "$(COMP_ZSHDIR)/_$(EXENAME)"

endif
ifeq ($(ZSH_COMPLETION), TRUE)
@echo 'Installing the completion files…'
$(INSTALL_DATA) 'zsh/_$(EXENAME)' '$(COMP_ZSHDIR)/_$(EXENAME)'
endif
ifeq ($(SYSTEMD), TRUE)
@echo "Installing the systemd service files…"
$(INSTALL_DATA) systemd/system/zram_btrfs.service "$(SYSTEMDDIR)/zram_btrfs.service"
$(INSTALL_DATA) systemd/system/zram_swap.service "$(SYSTEMDDIR)/zram_swap.service"
$(INSTALL_DATA) systemd/system/zram_tmp.service "$(SYSTEMDDIR)/zram_tmp.service"
$(INSTALL_DATA) systemd/system/zram_var_tmp.service "$(SYSTEMDDIR)/zram_var_tmp.service"
else
@echo "Installing the OpenRC files…"
$(INSTALL_DATA) "openrc/conf.d/$(EXENAME)" "$(CONFDIR)/$(EXENAME)"
$(INSTALL_EXE) "openrc/init.d/$(EXENAME)" "$(INITDIR)/$(EXENAME)"
@echo 'Installing the systemd service files…'
$(INSTALL_DATA) systemd/system/zram_btrfs.service '$(SYSTEMDDIR)/zram_btrfs.service'
$(INSTALL_DATA) systemd/system/zram_swap.service '$(SYSTEMDDIR)/zram_swap.service'
$(INSTALL_DATA) systemd/system/zram_tmp.service '$(SYSTEMDDIR)/zram_tmp.service'
$(INSTALL_DATA) systemd/system/zram_var_tmp.service '$(SYSTEMDDIR)/zram_var_tmp.service'
endif
ifeq ($(OPENRC), TRUE)
@echo 'Installing the OpenRC files…'
$(INSTALL_DATA) 'openrc/conf.d/$(EXENAME)' '$(CONFDIR)/$(EXENAME)'
$(INSTALL_EXE) 'openrc/init.d/$(EXENAME)' '$(INITDIR)/$(EXENAME)'
endif

.PHONY: uninstall
uninstall:
@echo "Uninstalling the executable…"
$(RM) "$(BINDIR)/$(EXENAME)"
@echo "Uninstalling the modprobe.d file…"
$(RM) "$(MODPROBEDIR)/zram.conf"
@echo "Uninstalling the man page…"
$(RM) "$(MANDIR)/$(EXENAME).8"
@echo "Uninstalling the Machine Object files…"
@echo 'Uninstalling the executable…'
$(RM) '$(BINDIR)/$(EXENAME)'
ifeq ($(MODPROBED), TRUE)
@echo 'Uninstalling the modprobe.d file…'
$(RM) '$(MODPROBEDIR)/zram.conf'
endif
ifeq ($(MANPAGE), TRUE)
@echo 'Uninstalling the man page…'
$(RM) '$(MANDIR)/$(EXENAME).8'
endif
ifeq ($(GETTEXT), TRUE)
@echo 'Uninstalling the Machine Object files…'
for i in $(notdir $(basename $(PO))); do \
$(RM) "$(MODIR)/$$i/LC_MESSAGES/$(EXENAME).mo"; \
$(RM) '$(MODIR)/$$i/LC_MESSAGES/$(EXENAME).mo'; \
done
@echo "Uninstalling the completion files…"
$(RM) "$(COMP_ZSHDIR)/_$(EXENAME)"

endif
ifeq ($(ZSH_COMPLETION), TRUE)
@echo 'Uninstalling the completion files…'
$(RM) '$(COMP_ZSHDIR)/_$(EXENAME)'
endif
ifeq ($(SYSTEMD), TRUE)
@echo "Uninstalling the systemd service files…"
$(RM) "$(SYSTEMDDIR)/zram_btrfs.service"
$(RM) "$(SYSTEMDDIR)/zram_swap.service"
$(RM) "$(SYSTEMDDIR)/zram_tmp.service"
$(RM) "$(SYSTEMDDIR)/zram_var_tmp.service"
else
@echo "Uninstalling the OpenRC files…"
$(RM) "$(CONFDIR)/$(EXENAME)"
$(RM) "$(INITDIR)/$(EXENAME)"
@echo 'Uninstalling the systemd service files…'
$(RM) '$(SYSTEMDDIR)/zram_btrfs.service'
$(RM) '$(SYSTEMDDIR)/zram_swap.service'
$(RM) '$(SYSTEMDDIR)/zram_tmp.service'
$(RM) '$(SYSTEMDDIR)/zram_var_tmp.service'
endif
ifeq ($(OPENRC), TRUE)
@echo 'Uninstalling the OpenRC files…'
$(RM) '$(CONFDIR)/$(EXENAME)'
$(RM) '$(INITDIR)/$(EXENAME)'
endif

.PHONY: clean
clean:
@echo "Deleting all Machine Object files…"
@echo 'Deleting the executable…'
$(RM) sbin/$(EXENAME)
@echo 'Deleting all Machine Object files…'
$(RM) i18n/*.mo
@echo "Deleting all Portable Object backups…"
@echo 'Deleting all Portable Object backups…'
$(RM) i18n/*.po~

.PHONY: mrproper
mrproper: clean
@echo "Deleting the Portable Object Template file…"
@echo 'Deleting the Portable Object Template file…'
$(RM) i18n/$(EXENAME).pot
@echo 'Deleting archives and similar stuff…'
$(RM) *.asc *.gz *.tar *.xz *.zip *.tar.*

.PHONY: distclean
distclean: mrproper

.PHONY: maintainer-clean
maintainer-clean: mrproper
Loading

0 comments on commit a4a361d

Please sign in to comment.