我的makefile目標:更新時傳遞的變量改變
ifndef VEC_LEN
VEC_LEN = 1
endif
my_target: a.c
gcc a.c -DVEC_LEN=$(VEC_LEN)
有沒有辦法告訴做出my_target應更新時VEC_LEN 改變?
更新:
我的腳本現在這個樣子(和他們的工作): 的Makefile
SHELL := /bin/bash
# Define the answer if not defined yet
ANSWERTOLIFETHEUNIVERSEANDEVERYTHING ?= 42
# Update the header file if the answer has changed
# := always executes the shell command, = does not! Quote from http://www.gnu.org/software/make/manual/make.html:
# immediate = deferred
# immediate := immediate
DUMMY := $(shell ./updateAnswer.sh $(ANSWERTOLIFETHEUNIVERSEANDEVERYTHING) >logMakefile.txt)
answer : answer.h
echo "Updated!"
touch answer
updateAnswer.sh
#!/bin/bash
# Check if the definition of the answer has changed in the header file
# If yes, re-write it. If not, do not touch it to avoid an updated timestamp.
if grep -q "ANSWER ${1}" answer.h
then
echo "ANSWER unchanged, is still ${1}."
else
echo "#define ANSWER ${1}" >answer.h
echo 'Answer has changed:'
cat answer.h
fi
輸出示例:
[email protected]:~$ make
echo "Updated!"
Updated!
touch answer
[email protected]:~$ make
make: `answer' is up to date.
[email protected]:~$ make ANSWERTOLIFETHEUNIVERSEANDEVERYTHING=3
echo "Updated!"
Updated!
touch answer
[email protected]:~$ make ANSWERTOLIFETHEUNIVERSEANDEVERYTHING=3
make: `answer' is up to date.
更改時間?在建立其他目標?自從上次運行Make?你能給個例子嗎? – Beta
@Beta我有一個bash腳本,多次構建我的目標進行基準測試,通常使用不同的VEC_LEN。所以如果我打電話「make; make」,那麼my_target只能被構建一次。對於「make; make VEC_LEN = 10」,應該使用VEC_LEN = 1和VEC_LEN = 10來構建。 –
Duplicate:http://stackoverflow.com/questions/3236145/force-gnu-make-to-rebuild-objects-affected-by-compiler-definition – slowdog