From a671aa3007c8d50efea686615d497eecf84c0cd9 Mon Sep 17 00:00:00 2001 From: Takahiro Ueda Date: Mon, 9 Aug 2021 21:12:42 +0900 Subject: [PATCH] feat: introduce MAKEFILE4LATEX_WAIT_COMMAND (#30) MAKEFILE4LATEX_WAIT_COMMAND selects the command to be used to wait some time in "make watch". Its default value is (effectively) "sleep 1". Close #30 --- Makefile | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c6fb211..b42bf4f 100644 --- a/Makefile +++ b/Makefile @@ -1277,8 +1277,9 @@ watch: $(ensure_build_dir); \ touch $(addprefix $(build_prefix),$(srctexfiles:.tex=.log)); \ $(print_watching_message); \ + $(define_wait_command); \ while :; do \ - sleep 1; \ + $$MAKEFILE4LATEX_WAIT_COMMAND; \ if $(MAKE) -q -s BUILDDIR=$(BUILDDIR) $(addprefix $(build_prefix),$(srctexfiles:.tex=.log)); then :; else \ $(call set_title,running); \ if time $(MAKE) -s BUILDDIR=$(BUILDDIR) $(addprefix $(build_prefix),$(srctexfiles:.tex=.log)); then \ @@ -1299,6 +1300,23 @@ print_watching_message = $(call colorize, \ echo "Watching for $(srctexfiles:.tex=.$(default_target)). Press Ctrl+C to quit" \ ) +# $(call define_wait_command) defines $MAKEFILE4LATEX_WAIT_COMMAND in +# the current shell as follows: +# (1) If $(MAKEFILE4LATEX_WAIT_COMMAND) is defined at the level of +# Makefile (from the configuration files or command line options), +# then use it. +# (2) If $MAKEFILE4LATEX_WAIT_COMMAND is defined at the level of +# the shell (i.e., as the environment variable), then use it. +# (3) Otherwise, provide the default command "sleep 1". +define_wait_command = \ + $(if $(MAKEFILE4LATEX_WAIT_COMMAND), \ + MAKEFILE4LATEX_WAIT_COMMAND="$(MAKEFILE4LATEX_WAIT_COMMAND)" \ + , \ + if [ -z "$$MAKEFILE4LATEX_WAIT_COMMAND" ]; then \ + MAKEFILE4LATEX_WAIT_COMMAND="sleep 1"; \ + fi \ + ) + # Upgrade files in the setup. (Be careful!) # Files to be upgraded must have a tag like #