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: [email protected] [mailto:[email protected]] 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
<[email protected]> 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/
        

_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to