Makefile: expand dependencies

Posted by Danyel on Stack Overflow See other posts from Stack Overflow or by Danyel
Published on 2013-06-25T16:18:53Z Indexed on 2013/06/25 16:21 UTC
Read the original article Hit count: 129

Filed under:
|
|

First off, the title is very generic because there are just tons of ways of how to possibly solve this. However, I'm looking for a clean and neat way.

Situation:
I have two equal object files foo.o and foo-pi.o, the latter of which is position-independent (compiled with -fPIC). Both depend on foo.h and bar.h.

Problem:
How do I, without code duplication, declare dependency of all foo*.o to bar.h?

Solutions so far:
$(shell bash -c 'echo -ne foo{-pi,}.o'}: bar.h
$(addsuffix .o, $(addprefix fo, o-pi o)): bar.h

The first solution is not portable on systems that don't support bash, the second is a dirty solution since I could not figure out how to use empty strings in addprefix.

© Stack Overflow or respective owner

Related posts about c

    Related posts about design-patterns