1

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 ...
asked Sep 8, 2013 at 13:55
2
  • You don't explain precisely enough what are the exact external libraries involved and how they are given inside your Makefile. Do you use pkg-config for them? Can't you filter them out from generated dependencies using grep -v ? Please give much more code from your Makefile... Commented Sep 8, 2013 at 14:00
  • @BasileStarynkevitch libraries like wxWidgets, given inside Makefile by wx-config; other libraries I include their headers using -I option. I already tried to use 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 '\' character at 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. Commented Sep 8, 2013 at 16:15

2 Answers 2

1

The first problem (external libraries) could be solved by first using grep -v and then passing the output to sed 'N;s/\\\n\(.*\.o\)/\n1円/;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.

answered Sep 9, 2013 at 8:18
Sign up to request clarification or add additional context in comments.

Comments

0

#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.

answered Sep 8, 2013 at 14:59

4 Comments

well, this is a nice trick but unfortunately this means that I would add header_proxies for external headers that are used and edit all the files that them to let them adopt this technique. I agree with you, post-processing seems cleaner so I hoped there is some 'exclude' option or sth like that.
As I know, the -MF specifies the file to output the dependencies rules to. what I am targeting is editing the suffix of the target itself, for example instead of generating foo.o: foo.cpp foo.h, I need to make it foo$(MY_SUFFIX): foo.cpp foo.h
Post-processing: grep -v to exclude may help. sed s/.o:/$(MY_SUFFIX)/g to replace extension... (not sure that my sed syntax is correct, but you have the idea).
I already tried to use 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 '\' character at 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. According to replacing the extension: Yes I got it, I think replacing the extension through sed would do the job.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.