Bug 5006

Summary: make performs library lookup in the build and host library directores and not in the staging area
Product: buildroot Reporter: Christoph Schulz <develop>
Component: OtherAssignee: unassigned
Status: RESOLVED WONTFIX    
Severity: normal CC: buildroot
Priority: P5    
Version: 2012.02   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:
Bug Depends on: 4922    
Bug Blocks:    
Attachments: patches make.mk to replace @LIBDIR@ and @USRLIBDIR@
replaces hard-code library paths in remake.c; removes LIBDIR path

Description Christoph Schulz 2012-04-01 06:40:45 UTC
Consider the following Makefile:

CC = gcc
prog: prog.o -lcrypt
        $(CC) -o $@ $^

This links prog.o to libcrypt.so in the staging area, but GNU make searches for the library in the following directories:

/lib
/usr/lib
$(HOST_DIR)/usr/lib

which is obviously wrong in a cross-compiling environment. (The paths are hard-coded in remake.c at the beginning of the function directory_search).

I have attached a patch that fixes this bug. It removes LIBDIR (which is defined to $(HOST_DIR)/usr/lib in the make's Makefile) from the search path and replaces the hard-coded paths by @LIBDIR@ and @USRLIBDIR@, respectively. In the buildroot's make.mk, these strings are replaced by the correct staging library paths.

However, this patch only works in combination with a host-make as requested in bug #4922, where the discussion has not reached a final consensus yet :-(

Regards,

Christoph Schulz
Comment 1 Christoph Schulz 2012-04-01 06:41:38 UTC
Created attachment 4214 [details]
patches make.mk to replace @LIBDIR@ and @USRLIBDIR@
Comment 2 Christoph Schulz 2012-04-01 06:42:23 UTC
Created attachment 4220 [details]
replaces hard-code library paths in remake.c; removes LIBDIR path
Comment 3 Arnout Vandecappelle 2012-04-16 19:32:10 UTC
The way we usually call make, this isn't needed:

$(MAKE) CC="$(TARGET_CC)" ...

Variables specified on the command line override variables in the Makefile, unless 'override' is put in front of it.  See http://www.gnu.org/savannah-checkouts/gnu/make/manual/html_node/Override-Directive.html
Comment 4 Christoph Schulz 2012-04-16 19:45:29 UTC
(In reply to comment #3)
> The way we usually call make, this isn't needed:
> 
> $(MAKE) CC="$(TARGET_CC)" ...

Sorry, but that is plain wrong. You did not fully understand the problem I described. The "-lcrypt" target is _not_ looked up in the staging area _regardless_ how you specify CC. You may not have encountered this problem so far as there are almost no Makefiles using this syntax. If some Makefile uses "-l<lib>" as dependency, the Makefile is _not cross-compilable_ unless you patch GNU make. The patches I attached solve the issue.


Regards,

Christoph Schulz
Comment 5 Arnout Vandecappelle 2012-04-17 22:03:41 UTC
My bad, I was confused by the CC=gcc line.

A Makefile that uses a -lfoo dependency for something it can't rebuild is pretty silly, I think.  As a workaround, though, you could pass VPATH="$(STAGING_DIR)/lib:$(STAGING_DIR)/usr/lib" - hopefully that Makefile doesn't use VPATH itself.

BTW it's definitely worthwhile to upstream a patch that gets the libdirs from a variable similar to .LIBPATTERNS.
Comment 6 Thomas Petazzoni 2013-05-26 15:17:31 UTC
As per the discussion in #4922, we really don't want to be building a host make, so the problem discussed in this bug should be solved upstream with the GNU make developers.