2011-01-13 49 views
4

rebar在給出不同的配置文件時不會自動重建文件。所以,我一直試圖做的Makefile文件級別: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並記錄我們現在使用的配置。

但它不工作,並且這些文件得到不斷的重新編譯:

[email protected]:~/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含有 「正常」:

[email protected]:~/workspace/gmcontroller/lib/sqlite3$ LAST_CONFIG=$(cat config.tmp); echo $LAST_CONFIG 
normal 

我缺少什麼?

+0

請問這部分實際上是正常工作 「IFEQ($(LAST_CONFIG),正常)」 ? – vartec

+0

可能不是,但這就是爲什麼我添加'echo「$(LAST_CONFIG)!= normal」',並且它似乎表明$(LAST_CONFIG)是空的。 –

回答

10

您錯過了需要使用shell的部分,以便在定義變量時實際調用外部程序。

LAST_CONFIG:=$(shell cat config.tmp)