One of the compilation key parameters is the kammit git hash: REPO_REV = 0x $ (shell git rev-parse --short = 8 HEAD) And naturally, make does not know that this parameter has changed. How can make make rebuild the project in this case?
- Is this a line from the makefile and you change it from time to time? - aleksandr barakin
- Not. The string itself naturally does not change. The result is 0x $ (shell git rev-parse --short = 8 HEAD), i.e. REPO_REV, which is included in CFLAGS. And even though it is changing, make does not think that the project needs to be re-assembled - Aleksandr Safronov
- When assembling projects, we use complete cleaning, then complete assembly. This ensures the cleanliness of the assembly. Several times we encountered assembly errors, so such an extreme measure was taken. Fully project for all platforms in our case is going to 15-20 minutes for reference. This is not an answer, just an option, maybe it will suit you. - wirtwelt
- Our complete compilation takes less time ~ 2 minutes, but this is a lot. I would like a faster option. Thank! - Aleksandr Safronov
1 answer
How can make make rebuild the project in this case?
if by “rebuilding a project” you mean accomplishing some additional goals (for example,
clean,distclean, etc.), then a substitution of goals is required. it is, in principle, possible, but rather “fragile” and completely “non-universal”.from my point of view, such processing is better done at a higher level:
- if you run the make program manually, then, of course, you know that
headinside the repository has changed, and you need to specify an additional target; - if the make program launch is automated for you, then you need to check the output of the
git rev-parse HEADcommand before calling it, and if it has changed, call the program with an additional goal.
- if you run the make program manually, then, of course, you know that
If by “rebuilding a project” you mean that you just need to update a certain set of goals, you can do this:
save the previous output of the
git rev-parse HEADcommand in some temporary file, when you call the make program, compare the contents of this file with the current output of the same command, and if they do not match, overwrite the file with new content, and for the purposes you need to specify this temporary file as a prerequisite.I will illustrate with an example. Let's say you now have this primitive
makefilewith two real goals -file1andfile2:all: file1 file2 file1: touch $@ file2: touch $@add to the beginning the receiving: a) the current
headvalue in therepo_revvariable and b) stored in a temporary file with the name, for example,rev.save, in therev_savevariable:repo_rev = 0x$(shell git rev-parse --short=8 HEAD) rev_save = 0x$(shell cat rev.save 2>/dev/null)as well as updating the contents of the
rev.savefile in case the contents of therepo_revandrev_savedo not match:ifneq ($(repo_rev),$(rev_save)) $(shell echo $(repo_rev) > rev.save) endifthen after the default target (in this case,
all) add the prerequisite filerev.saveto all the targets that need to be updated after updating this file:file1 file2: rev.saveThe resulting file will look like this:
repo_rev = 0x$(shell git rev-parse --short=8 HEAD) rev_save = 0x$(shell cat rev.save 2>/dev/null) ifneq ($(repo_rev),$(rev_save)) $(shell echo $(repo_rev) > rev.save) endif all: file1 file2 file1 file2: rev.save file1: touch $@ file2: touch $@now the targets
file1andfile2(when the make program is called) will be updated even if thegit rev-parse HEADcommand returns a new value.
- Thanks for the detailed answer! It was with the file that I originally did. But now I just put the touch files after the linker. Files "small" compile quickly. The only this option does not work normally when invoking the launch of compilation with the -jN key (N threads). All dependencies start to run in parallel. And the tach file does not work! - Aleksandr Safronov
- Those. Your option does not work with a key in multiple threads. - Aleksandr Safronov
- 1. put after the linker touch files - do not catch the meaning. 2. This option does not work - the first and second options - exactly work. 3. Your option does not work with a key in several threads - the third of the options? What exactly is the inoperability? Please give a minimal self-sufficient example that “does not work” - aleksandr barakin