1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
NAME = txt2regex
VERSION = 0.9
BASHVERSIONS = 3.0 3.1 3.2 4.0 4.1 4.2 4.3 4.4 5.0
REGEXTESTERIMAGE = aureliojargas/regex-tester:2020-05-09
SCRIPT = $(NAME).sh
PODIR = po
POTFILE = $(PODIR)/$(NAME).pot
DESTDIR =
BINDIR = $(DESTDIR)/usr/bin
LOCALEDIR = $(DESTDIR)/usr/share/locale
MANDIR = $(DESTDIR)/usr/share/man/man1
.PHONY: check check-po clean doc fmt install install-bin \
install-mo lint mo po pot test test-bash test-regex \
test-regex-build test-regex-shell
#-----------------------------------------------------------------------
# Dev
check: lint test
fmt:
shfmt -w -i 4 -ci -sr $(SCRIPT) tests/regex-tester.sh
lint:
shellcheck $(SCRIPT) tests/regex-tester.sh
shfmt -d -i 4 -ci -sr $(SCRIPT) tests/regex-tester.sh
test:
clitest README.md tests/*.md
# Run the tests in multiple Bash versions, using the official Docker
# image https://hub.docker.com/_/bash (each image is ~10MB)
test-bash:
@for v in $(BASHVERSIONS); do \
printf '\nTesting in Bash version %s\n' $$v; \
docker run --rm -v $$PWD:/code -w /code bash:$$v \
clitest tests/*.md; \
done
# Run regex tests for the supported programs, inside a Docker container
test-regex:
# Explicit pull to make sure all the log messages from the pulling
# process appear here, and not when executing the next "docker run",
# whose output goes directly to the .txt file.
docker image inspect $(REGEXTESTERIMAGE) >/dev/null 2>&1 || \
docker pull $(REGEXTESTERIMAGE)
# Test all programs except "vi"
docker run --rm -v "$$PWD":/code -w /code $(REGEXTESTERIMAGE) \
tests/regex-tester.sh --skip vi > tests/regex-tester.txt 2>&1
# vi: no stderr redirect to avoid "inappropriate ioctl for device"
# vi: docker run -t adds a trailing \r to every line :/
docker run --rm -v "$$PWD":/code -w /code -t $(REGEXTESTERIMAGE) \
tests/regex-tester.sh vi | tr -d '\r' >> tests/regex-tester.txt
test-regex-shell:
docker run --rm -v "$$PWD":/code -w /code -it $(REGEXTESTERIMAGE)
test-regex-build:
docker build -t $(REGEXTESTERIMAGE) tests/
clean:
rm -f $(NAME)
rm -f messages.mo $(PODIR)/{messages,*.mo,*.tmp,*~}
rm -rf $(PODIR)/??/ $(PODIR)/??_??/
rm -f tmp.lex.*.{l,run,yy.c}
doc:
txt2tags -t man man/txt2regex.t2t
txt2tags -t html man/txt2regex.t2t
#-----------------------------------------------------------------------
# Translation files
#
# Learn more: http://pology.nedohodnik.net/doc/user/en_US/ch-poformat.html
# Example potfile: http://git.savannah.gnu.org/cgit/gawk.git/tree/po/gawk.pot
pot:
@date=`date '+%Y-%m-%d %H:%M %Z'`; \
( \
printf '%s\n' '#, fuzzy'; \
printf '%s\n' 'msgid ""'; \
printf '%s\n' 'msgstr ""'; \
printf '"%s"\n' 'Project-Id-Version: $(NAME) $(VERSION)\n'; \
printf '"%s"\n' "POT-Creation-Date: $$date\n"; \
printf '"%s"\n' 'PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n'; \
printf '"%s"\n' 'Last-Translator: FULL NAME <EMAIL@ADDRESS>\n'; \
printf '"%s"\n' 'MIME-Version: 1.0\n'; \
printf '"%s"\n' 'Content-Type: text/plain; charset=UTF-8\n'; \
printf '"%s"\n' 'Content-Transfer-Encoding: 8bit\n'; \
bash --dump-po-strings $(SCRIPT); \
) | msguniq --no-wrap --sort-by-file -o $(POTFILE); \
printf '%s was generated\n' $(POTFILE)
po: pot
@for pofile in $(PODIR)/*.po; do \
printf 'Merging %s...' $$pofile; \
msgmerge --update --sort-by-file --no-wrap --previous \
$$pofile $(POTFILE); \
done; \
printf 'Remember to grep for the fuzzy messages in all .po files\n'
mo:
@for pofile in $(PODIR)/*.po; do \
printf 'Compiling %s... ' $$pofile; \
msgfmt -o $${pofile%.po}.mo $$pofile && \
echo ok; \
done
check-po:
@for pofile in $(PODIR)/*.po; do \
printf 'Checking %s...' $$pofile; \
msgfmt --verbose $$pofile || exit 1; \
done
#-----------------------------------------------------------------------
# Release
install: install-mo install-bin
install-mo: mo
test -d $(LOCALEDIR) || mkdir -p $(LOCALEDIR); \
for mofile in $(PODIR)/*.mo; do \
moinstalldir=$(LOCALEDIR)/`basename $$mofile .mo`/LC_MESSAGES; \
test -d $$moinstalldir || mkdir -p $$moinstalldir; \
install -m644 $$mofile $$moinstalldir/$(NAME).mo; \
done
install-bin:
test -d $(BINDIR) || mkdir -p $(BINDIR); \
sed -e '/^TEXTDOMAINDIR=/s,=.*,=/usr/share/locale,' \
$(SCRIPT) > $(BINDIR)/$(NAME) && \
chmod +x $(BINDIR)/$(NAME) && \
printf '\nProgram "%s" installed. Just run %s\n' \
$(NAME) $(BINDIR)/$(NAME)
|