Мой make-файл:
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
Пример вывода:
simon@x220:~$ make
echo "Updated!"
Updated!
touch answer
simon@x220:~$ make
make: `answer' is up to date.
simon@x220:~$ make ANSWERTOLIFETHEUNIVERSEANDEVERYTHING=3
echo "Updated!"
Updated!
touch answer
simon@x220:~$ make ANSWERTOLIFETHEUNIVERSEANDEVERYTHING=3
make: `answer' is up to date.