App-Greple-xlate

 view release on metacpan or  search on metacpan

share/XLATE.mk  view on Meta::CPAN

#
# ENVIRONMENTS
#
# XLATE_DEBUG:  Enable debug output
# XLATE_MAXLEN: Set maximum length for API call
# XLATE_USEAPI: Use API
# XLATE_UPDATE: Force update cache
# XLATE_ANONYMIZE:      Anonymization dictionary file
# XLATE_MARK:           Inline anonymization marks (1 or custom regex)
# XLATE_TEMPLATE:       Protect template expressions (1 or custom regex)
# XLATE_FRONTMATTER:    Exclude/anonymize YAML front matter
# XLATE_SEED:           Seed cache from another cache file
# XLATE_CONTEXT_WINDOW: Context blocks for re-translation
#
# XOPT single-quotes XLATE_ANONYMIZE/XLATE_MARK/XLATE_TEMPLATE/XLATE_SEED/
# XLATE_CONTEXT_WINDOW (and FILE.ANONYMIZE) so a value such as a custom
# --mark/--template regex containing parentheses survives /bin/sh
# unharmed.  This leaves residual limits:
#   - values must not contain a single quote (') -- there is no escaping
#     for it inside the single-quoted recipe argument;
#   - a literal $ in a value must be written as $$ at the make layer,
#     or make will try to expand it as its own variable reference;
#   - REMOVE_QUOTE (below) strips embedded double quotes from these
#     variables before XOPT ever sees them, so double quotes in a value
#     do not need separate handling here.
#

#
# PARAMETER FILES
#   If the source file is acompanied with parameter files with
#   following extension, they are used to override default parameters.
#
# .LANG:   Languages translated to
# .FORMAT: Format of output files
# .ANONYMIZE: Anonymization dictionary for the file
#

XLATE_FORMAT ?= xtxt cm
XLATE_ENGINE ?= gpt5

ifeq ($(strip $(XLATE_FILES)),)
override XLATE_FILES := \
	$(filter-out README.%.md,\
	$(wildcard *.docx *.pptx *.txt *.md *.pm *.pod))
else
override XLATE_FILES := $(subst |||, ,$(XLATE_FILES))
endif

comma:=,
override XLATE_LANG := $(subst $(comma), ,$(XLATE_LANG))

# GNU Make treat strings containing double quotes differently on versions
define REMOVE_QUOTE
  override $1 := $$(subst ",,$$($1))
endef
$(foreach name,XLATE_LANG XLATE_FORMAT XLATE_FILES \
	XLATE_ANONYMIZE XLATE_MARK XLATE_TEMPLATE \
	XLATE_FRONTMATTER XLATE_SEED XLATE_CONTEXT_WINDOW,\
	$(eval $(call REMOVE_QUOTE,$(name))))

define FOREACH
$(foreach file,$(XLATE_FILES),
$(foreach lang,$(or $(shell cat $(file).LANG 2> /dev/null),$(XLATE_LANG)),
$(foreach form,$(or $(shell cat $(file).FORMAT 2> /dev/null),$(XLATE_FORMAT)),
$(foreach ecnt,$(words $(or $(shell cat $(file).ENGINE 2> /dev/null),$(XLATE_ENGINE))),
$(foreach engn,$(or $(shell cat $(file).ENGINE 2> /dev/null),$(XLATE_ENGINE)),
$(call $1,$(lang),$(form),$(file),$(engn),$(if $(ELIMINATE_LANG_PART),$(ecnt),99))
)))))
endef

define ADD_TARGET
ifeq ($5,1)
  TARGET += $$(addsuffix .$1.$2,$$(basename $3))
else
  TARGET += $$(addsuffix .$4-$1.$2,$$(basename $3))
endif
endef
$(eval $(call FOREACH,ADD_TARGET))

ALL := $(TARGET)

ALL: $(ALL)



( run in 0.432 second using v1.01-cache-2.11-cpan-9169edd2b0e )