OrderN / CONQUEST-release

Full public release of large scale and linear scaling DFT code CONQUEST
http://www.order-n.org/
MIT License
96 stars 25 forks source link

Find safer way to get date and git info during build #190

Open tkoskela opened 12 months ago

tkoskela commented 12 months ago

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

tkoskela commented 12 months ago

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 1) Not having to deal with special characters in sed 2) Not relying on writing source files from the Makefile 3) Being able to default to something meaningful if something fails. 4) Improving the readability

tkoskela commented 11 months ago

https://stackoverflow.com/questions/1704907/how-can-i-get-my-c-code-to-automatically-print-out-its-git-version-hash/

davidbowler commented 11 months ago

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

davidbowler commented 11 months ago

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
davidbowler commented 11 months ago

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.