Include generated makefile without warning

For my project, I automatically generate makefiles and including them, for example:

all: @echo 'SUCCESS is $(SUCCESS)' clean: rm depend.mk depend.mk: @echo 'Creating $@ ' @echo 'SUCCESS := 1' > $@ .PHONY: all clean include depend.mk 

This works, but the include line generates a warning message:

 $ make Makefile:13: depend.mk: No such file or directory Creating depend.mk SUCCESS is 1 

I would like to disable this first warning line, which says that depend.mk does not exist. I know that this does not exist, because I have a rule written to create it, so a warning is not needed (unless, of course, there is no rule for it). I DO NOT want make to ignore the error when the included file does not exist and there is no rule for it, so the include prefix with - to ignore the error will not work for me. I would like something similar to the bash convention for the stderr pipeline to / dev / null, for example some_cmd 2>/dev/null , but for inclusion in make.

The sample above is a very simplified example of this case. In my actual project, there are a lot of automatically generated makefiles (using the automatic clang dependency generation), which means that a new run of make will lead to the flow of my screen with these warning messages.

Is this possible, or will I just have to deal with annoying warning messages?

+7
makefile gnu-make
source share
2 answers

I ran into and (re-re-re-re-re) solved this problem several times myself. Actually, the problem is that thinking surrounds when dependency files are generated and used.

This link contains a detailed description of the "permission": http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

This is mainly due to the fact that dependency files are really only needed for recovery, and not for the initial creation of your library / executable file. As a result, you don’t need to have a rule for generating dependency files in front (which is actually less efficient), instead you should generate them during the stage of the object file as intermediate files marked with precious ones (therefore they are created and tracked as third-party effects, which should never be cleaned automatically). Subsequent builds will have access to the files, which is exactly what you were trying to achieve as a whole. Then you can make it β€œincluded” in dependency files, with the prudence that the assembly step of the object object will fail if a failure to generate the dependency file leads to an immediate error, as you already mentioned, is preferable to an obscure and indirect one much later.

I actually made a couple of fairly large build systems that implement this method, and it works very well, including those that used non-GNU toolchains. It seems identical to the external user, but internally it works more efficiently and does not hide potentially important errors.

+2
source share

I tried many (many!) Things to see if I can prevent or redirect the error message. Bad luck.

But when I tried -include (enable with leading dash), it did not give an error, and make with clean , all , depend.mk and 'default' everything worked correctly and as expected.

Is there a special reason why you did not want to use the -include option? It seems that you need to do exactly what you are looking for and does not change the way the Makefile works, it just does not show an error during the first pass through the Makefile.

+1
source share

All Articles