Linking rule advice

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Linking rule advice

Darin Johnson
I've got over 100 libraries to link in a final build, and the command lines
are extremely long.  I'd like to use the "-lthing" syntax with a "-L" flag
to shorten things.  What I've got now is something like:

    mytarget: $(OBJS) $(LIBRARIES)
    ...
    # in a "rules.mk" file
    $(outdir)/%.elf:
            $(LINK.o) $^ $(LDLIBS) -o $@

But the $^ expands into full paths.  If I put the libraries into LDLIBS and
not as a dependency, then make doesn't know to relink if a library is
modified.  Other solutions I've seen look like:

    $(LINK.o) $(OBJS) $(LDLIBS) ...

But that doesn't work to well in a pattern rule.  What do others do for this
sort of thing?  Is it not worth bothering to keep the command lines small
(I already have quiet vs. verbose flag)?

Darin Johnson


_______________________________________________
Help-make mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Linking rule advice

Paul Smith-20
%% Darin Johnson <[hidden email]> writes:

  dj> I've got over 100 libraries to link in a final build, and the
  dj> command lines are extremely long.  I'd like to use the "-lthing"
  dj> syntax with a "-L" flag to shorten things.  What I've got now is
  dj> something like:

  dj>     mytarget: $(OBJS) $(LIBRARIES)
  dj>     ...
  dj>     # in a "rules.mk" file
  dj>     $(outdir)/%.elf:
  dj>             $(LINK.o) $^ $(LDLIBS) -o $@

  dj> But the $^ expands into full paths.

You have two choices:

 1) Use the "-lfoo" syntax on the prerequisites list, and make sure that
    the directory containing the libraries is listed via VPATH or vpath.

    See the GNU make manual for how make handles these special
    prerequisites.

 2) Use functions to manipulate the contents of $^ when you run the
    shell.  Because it's a requirement that the libraries keep their
    same order, this is very tricky to do.  I expect you'll need to use
    eval to do it.  I suggest using option #1 :-)

--
-------------------------------------------------------------------------------
 Paul D. Smith <[hidden email]>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist


_______________________________________________
Help-make mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Linking rule advice

Darin Johnson
In reply to this post by Darin Johnson
>  dj> But the $^ expands into full paths.

> You have two choices:
>
> 1) Use the "-lfoo" syntax on the prerequisites list, and make sure that
>    the directory containing the libraries is listed via VPATH or vpath.

This doesn't do anything, and I have tried this approach.  The -"-lfoo"
will expand out into the full path name and be included in the command
line.  Ie, I've got this test makefile:
   VPATH=zzz
   test: a.o b.o -lfoo -lbar ; @echo $^

And it prints out "a.o b.o zzz/libfoo.a zzz/libbar.a".

Darin Johnson



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