CONQUEST-release
CONQUEST-release copied to clipboard
Find safer way to get date and git info during build
Currently the makefile extracts the current date and time and the git branch and hash via a mixture of sed and shell commands. I found this fails, e.g. when I have a / in the git branch name. There might be a safer way to get this information.
https://github.com/OrderN/CONQUEST-release/blob/3a6e1f697e0bd3fd1101715e56bf3c7b7a7fde63/src/Makefile#L61
I think this should be doable without sed by passing the date, time and the git information through preprocessor variables and then having some #ifdef blocks in the code that grab the value. This would have the advantage of
- Not having to deal with special characters in
sed - Not relying on writing source files from the Makefile
- Being able to default to something meaningful if something fails.
- Improving the readability
https://stackoverflow.com/questions/1704907/how-can-i-get-my-c-code-to-automatically-print-out-its-git-version-hash/
Yes, but also see the linked answer on how to sort out dependencies and updates:
https://stackoverflow.com/questions/3236145/force-gnu-make-to-rebuild-objects-affected-by-compiler-definition
How about this? It creates a source file but from within Make (which I think is more reliable than sed!)
deps.obj.inc: $(SRCS_NODS) system.make
touch $(COMMENT)
$(ECHOSTR) "module datestamp" > datestamp.f90
$(ECHOSTR) " implicit none" >> datestamp.f90
$(ECHOSTR) ' character(len=*), parameter :: datestr="'`date "+%Y/%m/%d at %H:%M %z"`'"' >> datestamp.f90
$(ECHOSTR) ' character(len=*), parameter :: commentver="'`git describe --abbrev=4 --dirty --always --tags`'"' >> datestamp.f90
$(ECHOSTR) "end module datestamp" >> datestamp.f90
./makedeps makedeps.txt $^
sed /"^mpi.o"/D makedeps.txt > deps.obj.inc
The alternative would be to create a file datestamp.fpp or something which had DATE and VERSION within it, and to run that through a preprocessor to create datestamp.f90.
This has been resolved as far as I can tell.