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 1

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 head inside 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 HEAD command before calling it, and if it has changed, call the program with an additional goal.
  • 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 HEAD command 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 makefile with two real goals - file1 and file2 :

     all: file1 file2 file1: touch $@ file2: touch $@ 

    add to the beginning the receiving: a) the current head value in the repo_rev variable and b) stored in a temporary file with the name, for example, rev.save , in the rev_save variable:

     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.save file in case the contents of the repo_rev and rev_save do not match:

     ifneq ($(repo_rev),$(rev_save)) $(shell echo $(repo_rev) > rev.save) endif 

    then after the default target (in this case, all ) add the prerequisite file rev.save to all the targets that need to be updated after updating this file:

     file1 file2: rev.save 

    The 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 file1 and file2 (when the make program is called) will be updated even if the git rev-parse HEAD command 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