Makefile命令替换问题
当给定不同的配置文件时,rebar 不会自动重建文件。因此,我尝试在 Makefile 级别上执行此操作:
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
希望意图很明显:当我使用需要特定配置文件的目标时,检查上次是否使用了相同的文件;运行clean
并记录我们现在使用的配置。
但它不起作用,并且文件不断重新编译:
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
尽管 config.tmp 包含“正常”:
aromanov@alexey-desktop:~/workspace/gmcontroller/lib/sqlite3$ LAST_CONFIG=$(cat config.tmp); echo $LAST_CONFIG
normal
我缺少什么?
rebar doesn't automatically rebuild files when given a different configuration file. So, I've tried to do it on 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
The intention is hopefully obvious: when I use a target which needs a certain config file, check if the same file was used last time; run clean
and record the configuration we are using now.
But it doesn't work, and the files get recompiled constantly:
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 config.tmp containing "normal":
aromanov@alexey-desktop:~/workspace/gmcontroller/lib/sqlite3$ LAST_CONFIG=$(cat config.tmp); echo $LAST_CONFIG
normal
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您缺少需要使用 的部分
shell
以便在定义变量时实际调用外部程序。You're missing the part where you need to use
shell
in order to actually call external programs when defining a variable.您还可以使用 shell 赋值运算符
§ make 如何读取一个 Makefile
示例
You can also use the shell assignment operator
§ How make Reads a Makefile
Example