Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining and using a build timestamp for GNU Make on Windows

I am trying to build some software on Windows using both GNU make 3.81 and an ancient make distributed with Wind River Tornado (make 3.76).

So far, I managed to capture the date from windows:

NOW=\"$(shell cmd /C date /T) $(shell cmd /C time /T)\"

but when I am passing it on the compiler

CFLAGS = ... -DBUILD_TIMESTAMP=$(NOW) ...

I am getting build errors because of the spaces and colons and slashes in the timestamp. If I echo the $(NOW) variable, it is properly quoted, but when I echo the $(CFLAGS) variable, the quotes disappear.

like image 704
florin Avatar asked Jan 28 '26 13:01

florin


1 Answers

You want to quote the variable for the shell (so it isn't subject to word splitting) and quote it again for C (so when it's substituted by cpp, you have a string literal). Try this:

NOW := "\"$(shell cmd /C date /T) $(shell cmd /C time /T)\""

Note also that I'm using := instead of =. Unless your old make doesn't support it, use :=, which evaluates the substitution at the point of definition, not the point of expansion. Using = will make it call those two shell commands twice every time you try to compile a file. Not so good for performance.

like image 93
Jack Kelly Avatar answered Jan 31 '26 05:01

Jack Kelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!