C makefile with shell commands and variables

This is from a bash script I used to build the program:

dateString=$(date +%Y/%m/%d\ %H:%M:%S) revision=(`svn info | grep Revision | tr -d [:alpha:]':'`) echo "#define VERSION_DATE \"$dateString\"" > version.h echo "#define VERSION_REVISION \"$revision\"" >> version.h 

I changed the use of the build.sh file in the make file:

 version.h: dateString=$$(date +%Y/%m/%d\ %H:%M:%S) revision=(`svn info | grep Revision | tr -d [:alpha:]':'`) echo "#define VERSION_DATE \"$dateString\"" > version.h.tmp echo "#define VERSION_REVISION \"$revision\"" >> version.h.tmp mv version.h.tmp version.h 

But the version.h file ends as follows:

 #define VERSION_DATE "\ateString" #define VERSION_REVISION "\evision" 

It seems I cannot correctly interpret shell variables. I think this is because they are ultimately Makefile vars. If someone knows how to do this, I do not mind knowing how to do it. Many thanks.

+7
source share
1 answer

Remember that each command runs in its own shell, so dateString and revision will be canceled in the third and fourth command.

Thus, you use semicolons and backslashes in each line to make it one command. You also need to use $$ to reference shell $.

Or do not use intermediate variables, then you will not need one command. Something like that:

 version.h: echo \#define VERSION_DATE \"$$(date +%Y/%m/%d\ %H:%M:%S)\" > version.h.tmp echo \#define VERSION_REVISION \"$$(svn info | grep Revision | tr -d [:alpha:]:)\" >> version.h.tmp mv version.h.tmp version.h 
+9
source

All Articles