Reputation: 1350
I'm using a makefile to check some configuration files before checking into version control. I am having difficulty with one of the rules, which needs to essentially just run
/usr/local/bin/check-program config/file1.conf
/usr/local/bin/check-program config/file2.conf
[...]
The check-program does not accept multiple arguments, so each config file needs to be checked individually. All the configuration files are in one subdirectory and all end in .config.
As there is no source/dependency relationship I haven't been able to find the correct makefile syntax to get this to run. As a work-around, a for-loop will do the check for me, but this will neither exit on failure nor skip a file that has already been checked.
Here is a cut-down version of what I have so far:
SHELL := /bin/sh
WD := $(shell pwd)
HOST := $(shell hostname -s)
BPCFG := $(wildcard config/*.conf)
all : check-bp
check-bp : $(BPCFG)
for file in $(BPCFG); do \
/usr/local/bin/check-program $$file; \
echo ""; \
done
Upvotes: 1
Views: 83
Reputation: 34873
You can do this with sentinel files. For each .conf
file, have the check step create a .conf.checked
file if it succeeds.
SHELL := /bin/sh
WD := $(shell pwd)
HOST := $(shell hostname -s)
BPCFG := $(wildcard config/*.conf)
all : $(BCFG:%=%.checked)
%.conf.checked: %.conf
/usr/local/bin/check-program $< && touch $@
As for the for loop not exiting on failure—that’s just the way shell works. Try
for ((i = 0; i < 10; i++)); do if (( $i < 9 )); then false; else true; fi; done
The command will fail 9 times out of ten, but all that counts is the the exit status of the last run through the loop.
To fix this, change the SHELL
line to SHELL = /bin/sh -e
to make the shell’s default behaviour be to abort scripts when a command fails. Since that will make shell commands abort even when you don’t mind that some things return non-zero exit statues, you may have to add || true
to the end of commands like grep Warning error.log
.
Upvotes: 2