J Freebird J Freebird - 6 months ago 12
Bash Question

Understanding Some Makefile Syntax

I saw a Makefile that looks like:

TESTTMP = ./test-tmp

# VANILLA REDIS CONF
define VANILLA_CONF
daemonize yes
port 6379
dir .
pidfile redis_vanilla.pid
logfile redis_vanilla.log
save ""
appendonly no
endef

export VANILLA_CONF

.ONESHELL: # what's it used for?
start: cleanup
mkdir -p $(TESTTMP)
cd $(TESTTMP)
echo "$$VANILLA_CONF" | redis-server - # what does this look like when expanded, equivalent to what command?

cleanup:
rm -rf $(TESTTMP)

stop:
kill `cat $(TESTTMP)/redis_vanilla.pid` || true # what's "|| true"
make cleanup


Basically I need to modify it for my own use, but there're some lines that I don't quite understand. I've made the comments in the code. Any help would be appreciated. Thanks.

Answer

If you want to see the output of echo $$VANILLA_CONF, then simply remove the | redis-server -, and the output will be displayed on your screen.

The || shell connector means ‘or’: if (and only if) the command before the || fails, then the command after it is executed. In this case, the command after the || is true, which always succeeds. That is, this line in the stop rule will succeed even if the kill fails (there are other ways to express this in Makefile syntax, but I think this is clearer).

Comments