Issue with replacing Makefile command

rebar does not automatically rebuild files when a different configuration file is provided. So, I tried to do this at the Makefile level:

REBAR=./rebar REBAR_DEBUG=$(REBAR) -C rebar.debug.config REBAR_COMPILE=$(REBAR) get-deps compile LAST_CONFIG:=$(cat config.tmp) PLT=dialyzer/sqlite3.plt all: config_normal compile compile: $(REBAR_COMPILE) test: $(REBAR_COMPILE) eunit clean: -rm -rf deps ebin priv doc/* .eunit c_src/*.o docs: $(REBAR_COMPILE) doc static: config_debug $(REBAR_DEBUG) get-deps compile ifeq ($(wildcard $(PLT)),) dialyzer --build_plt --apps kernel stdlib erts --output_plt $(PLT) else dialyzer --plt $(PLT) -r ebin endif cross_compile: config_cross $(REBAR_COMPILE) -C rebar.cross_compile.config valgrind: clean $(REBAR_DEBUG) get-deps compile valgrind --tool=memcheck --leak-check=yes --num-callers=20 ./test.sh ifeq ($(LAST_CONFIG),normal) config_normal: echo "$(LAST_CONFIG) == normal" else config_normal: clean echo "$(LAST_CONFIG) != normal" rm -f config.tmp echo "normal" > config.tmp endif ifeq ($(LAST_CONFIG),debug) config_debug: ; else config_debug: clean rm -f config.tmp echo "debug" > config.tmp endif ifeq ($(LAST_CONFIG),cross) config_cross: ; else config_cross: clean rm -f config.tmp echo "cross" > config.tmp endif .PHONY: all compile test clean docs static valgrind config_normal config_debug config_cross 

We hope that the intention will be obvious: when I use a target that needs a specific configuration file, check if the same file was used last time; run clean and write down the configuration we are currently using.

But this does not work, and the files are constantly recompiled:

 aromanov@alexey-desktop :~/workspace/gmcontroller/lib/sqlite3$ make rm -rf deps ebin priv doc/* .eunit c_src/*.o echo " != normal" != normal rm -f config.tmp echo "normal" > config.tmp ./rebar get-deps compile ==> sqlite3 (get-deps) ==> sqlite3 (compile) Compiled src/sqlite3_lib.erl Compiled src/sqlite3.erl Compiling c_src/sqlite3_drv.c 

Despite the fact that config.tmp contains "normal":

 aromanov@alexey-desktop :~/workspace/gmcontroller/lib/sqlite3$ LAST_CONFIG=$(cat config.tmp); echo $LAST_CONFIG normal 

What am I missing?

+4
source share
2 answers

You are missing the part where you need to use the shell to actually call external programs when defining a variable.

 LAST_CONFIG:=$(shell cat config.tmp) 
+10
source

You can also use the shell assignment operator.

 LAST_CONFIG != cat config.tmp 

& sect; How to Make Reads Makefile

Example

+1
source

Source: https://habr.com/ru/post/1335386/


All Articles