Index: share/mk/bsd.cpu.mk =================================================================== --- share/mk/bsd.cpu.mk +++ share/mk/bsd.cpu.mk @@ -273,9 +273,34 @@ . endif .endif -.if ${MACHINE_CPUARCH} == "mips" -CFLAGS += -G0 -.endif +# All the special-case hacks for robust external toolchain support +. if ${MACHINE_CPUARCH} == "mips" +# always add -G0 +_ABI_CFLAGS += -G0 +# Get endian right in case the default isn't correct +. if ${MACHINE_ARCH:M*el} != "" +_ABI_CFLAGS += -EL +. else +_ABI_CFLAGS += -EB +. endif +# Get ABI right in case the default is wrong +. if ${MACHINE_ARCH} == "mips" || ${MACHINE_ARCH} == "mipsel" +_ABI_CFLAGS += -mabi=32 +. elif ${MACHINE_ARCH} == "mipsn32" +_ABI_CFLAGS += -mabi=n32 +. else +_ABI_CFLAGS += -mabi=64 +. endif +# Get the default ISA correct. Kinda trick to pull off, hope this hueristic +# works out: specify it when no CPUTYPE is specified +. if !defined(CPUTYPE) || empty(CPUTYPE) +. if ${MACHINE_ARCH:Mmips64*} || ${MACHINE_ARCH} == "mipsn32" +_ABI_CFLAGS += -march=mips64 +. else +_ABI_CFLAGS += -march=mips3 +. endif +. endif +. endif ########## arm .if ${MACHINE_CPUARCH} == "arm" @@ -290,10 +315,16 @@ . if ${MACHINE_ARCH:Marmv6*} == "" MACHINE_CPU += softfp . endif +# Get endian right for external toolchains +.if ${MACHINE_ARCH} == "armeb" +_ABI_CFLAGS += -mbig-endian +.else +_ABI_CFLAGS += -mlittle-endian +.endif .if ${MACHINE_ARCH} == "armv6" # Needs to be CFLAGS not _CPUCFLAGS because it's needed for the ABI # not a nice optimization. -CFLAGS += -mfloat-abi=softfp +_ABI_CFLAGS += -mfloat-abi=softfp .endif .endif @@ -302,6 +333,8 @@ .if !defined(NO_CPU_CFLAGS) CFLAGS += ${_CPUCFLAGS} .endif +CFLAGS += ${_ABI_CFLAGS} +ACFLAGS+= ${_ABI_CFLAGS} # # Prohibit the compiler from emitting SIMD instructions. Index: sys/conf/kern.pre.mk =================================================================== --- sys/conf/kern.pre.mk +++ sys/conf/kern.pre.mk @@ -60,6 +60,7 @@ .if !defined(NO_CPU_COPTFLAGS) COPTFLAGS+= ${_CPUCFLAGS} .endif +COPTFLAGS+= ${_ABI_CFLAGS} NOSTDINC= -nostdinc INCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S