Devos
Devos

Reputation: 142

C++ makefiles - Header files dependencies with external libraries

I want to add dependency target to my Makefile, I knew it could be done through makedepend or g++ -MM option, and I am open for using any of them but I prefer -MM option as it allowed me to exclude standard libraries (I do not know if makedepend can do it or not).

The problem is that I use some external libraries headers in my application and I want these headers to be excluded from the dependencies generated so how can I exclude certain directories from these generated dependencies. [Edit-start] I already tried using grep -v but the problem is that if the excluded line is the last wrapped line in a certain target, the next target would be joined to that target due to the escape '\' character at the end of the line before it leading to a corrupted dependency rule. In addition to that the time it takes to go through the library headers parsing them [Edit-end].

Another problem is that How can I edit the suffixes of the generated object-files targets, I am using a Makefile that compiles the source files provided through a variable by using through a target like that:

%.o: %.cpp
    g++ $< -o$*.o ...

Upvotes: 1

Views: 1496

Answers (2)

Devos
Devos

Reputation: 142

The first problem (external libraries) could be solved by first using grep -v and then passing the output to sed 'N;s/\\\n\(.*\.o\)/\n\1/;P;D' which removes unneeded escape characters '\' to solve the problem of joined targets due to the exclusion introduced by grep -v. But the time overhead of going through the external libraries headers parsing them still as it is.

And the second problem (generated targets suffixes edit) could be solved by sed also using sed 's/.o:/$(MY_SUFFIX):/' where $(MY_SUFFIX) is the suffix to replace .o in the generated target rules.

Upvotes: 1

Jarod42
Jarod42

Reputation: 218323

#pragma GCC system_header is a gcc pragma to identify system header.

You may use proxy header with this pragma which include library header

//Proxy_header.h
#ifndef PROXY_HEADER_H
#define PROXY_HEADER_H

#pragma GCC system_header

#include "external_library.h"

#endif

but post-processing dependencies seems cleaner.


-MF file seems to be the gcc option you want to edit the suffix of dependency files.

Upvotes: 0

Related Questions