On Fri, Oct 19, 2007 at 01:38:38AM -0500, Rob Landley wrote: > On Thursday 18 October 2007 4:14:20 pm Sam Ravnborg wrote: > > > Anyway, here's a try to make it autodetect m68k-linux-gnu-gcc and > > > m68k-linux-gcc. Perhaps it can be generalized in kbuild, to allow > > > arch/*/Makefile to set a list of possible cross-compiler prefixes? > > > > Here is my first try. > > We only touch CROSS_COMPILE is empty and building for another arch. > > > > I can obviously move crossgcc part of this to core kbuild. > > Any better name? find-crossgcc
> > > > Sam > > > > > > diff --git a/arch/m68k/Makefile b/arch/m68k/Makefile > > index 4a1bd44..6465bbe 100644 > > --- a/arch/m68k/Makefile > > +++ b/arch/m68k/Makefile > > @@ -13,17 +13,26 @@ > > # Copyright (C) 1994 by Hamish Macdonald > > # > > > > -# test for cross compiling > > -COMPILE_ARCH = $(shell uname -m) > > +# usage: > > +# CROSS_COMPILE := $(call crossgcc, foo bar /usr/bin/) > > +# CROSS_COMPILE will be assinged the first prefix that point > > +# to a gcc in the path > > +crossgcc = $(word 1, $(foreach c,$(1), \ > > + $(shell set -e; \ > > + if (which $(strip $(c))$(CC)) > /dev/null 2>&1 ; then \ > > + echo $(c); \ > > + fi))) > > Searching for common cross compiler prefixes. Cool. > > What do you do if you want to use gcc as your host compiler, but m68k-pcc or > arm-tcc as your target compiler? (I have no idea, CROSS_COMPILE=m68k- CC=pcc > HOSTCC=gcc perhaps? Where does CC get set right now, anyway... Ah, top > level Makefile: > CC = $(CROSS_COMPILE)gcc > > That... should work. Odd and roundabout, but ok... I see no other way to do it - and it seems obvious since you guessed right. > > > +ifneq ($(SUBARCH),$(ARCH)) > > + ifeq ($(CROSS_COMPILE),) > > + CROSS_COMPILE := $(call crossgcc, m68k-linux-gnu-) > > + endif > > +endif > > Other query: > > If CROSS_COMPILE isn't set, and we iterate through all the standard prefixes > but don't find a compiler, what's the right "fall off the end" behavior? If > it falls back to using the host gcc, presumably the build will break if you > feed your host gcc target flags it doesn't understand, but there are > platforms where that sometimes doesn't seem to happen until the very end > (building x86_64 on x86 for example)... Should the build just die with > a "You are cross compiling, set CROSS_COMPILE". No - that would be a bug. One may set up PATH sp gcc point to the cross-compile gcc. fallback to native (host) gcc is expected and fine. > > I suppose there's the weird corner case where your hostcc is tcc and your > targetcc is gcc... I do not see why thats a problem - you just need to set both CC and HOSTCC. Sam - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/