linux - Makefile命令替换问题

标签 linux 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

我错过了什么?

最佳答案

您缺少需要使用 shell 的部分以便在定义变量时实际调用外部程序。

LAST_CONFIG:=$(shell cat config.tmp)

关于linux - Makefile命令替换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4678967/

相关文章:

c - STM32F4编译Makefile报错

c++ - Google 的 Native Client 和编译 SDL2

linux - Makefile:运行多个目标

c++ - 如何创建仅包含主文件和模板 header 的 makefile (C++)

linux - Unix - 对特定输出进行排序

linux - gcloud 始终使用默认凭据

c - 当进程连续写入文件时如何清空文件

c - 修改我不是其所有者的程序

linux - 无法在 .cshrc 中获取脚本源

c - makefile 不分别更新 .o 文件和 .h 文件