help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Automatic dependencies for linked libraries


From: Steve Deiters
Subject: RE: Automatic dependencies for linked libraries
Date: Thu, 25 Mar 2010 15:58:34 -0500

This seems to do what I need.  It just loops through and adds any static libraries it can find based on the LDFLAGS.  I'm not sure how slow this might get if you have a large set of LDFLAGS.
 
# Add static library dependencies to target based on LDFLAGS
#
# Usage: $(call addlibdeps,TARGET,LDFLAGS)
#  TARGET - NAME of the variable for the target(s)
#  LDFLAGS - NAME of the variable for the linker flags
#
# e.g.
#
# TARGET:=foo
# LDFLAGS:=-lbar -L/home/foo/lib
# $(call addlibdeps,TARGET,LDFLAGS)
#
# Note that the NAME of the variable is used not the expansion
# to allow these to expand to multiple targets/flags
define addlibdeps
$(foreach d, $(patsubst -L%,%,$(filter -L%,$($(2)))),\
 $(foreach l, $(patsubst -l%,%,$(filter -l%,$($(2)))),\
  $(if $(shell if [ -e $(d)/lib$(l).a ]; then echo "X"; fi),\
   $(eval $($(1)): $(d)/lib$(l).a)\
  )\
 )\
)
endef
 

From: address@hidden [mailto:address@hidden On Behalf Of Stephan Beal
Sent: Thursday, March 25, 2010 10:29 AM
To: Steve Deiters; make-help mailing list
Subject: Re: Automatic dependencies for linked libraries

On Thu, Mar 25, 2010 at 3:50 PM, Steve Deiters <address@hidden> wrote:
Is there a method to have gcc or ld automatically generate a list of
dependencies for statically linked libraries?

Neither could be used generate such dependencies because such deps cannot be calculated until after the code is linked (i.e., all external symbols have been resolved). Any change of the client code could change which libs it needs. We cannot know which external symbols it needs until it is compiled, and do not know where they come from until it is linked. Chicken vs. egg.

My fallback plan is to parse through the LDFLAGS for the library names
and paths and add the dependencies programmatically by calling eval, but
I would like to avoid this if possible.

If you do get this working generically, i would like to see the code if you don't mind posting it :).

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]