summaryrefslogtreecommitdiffstats
path: root/util/xcompile/xcompile
blob: 318f7bfdcdc554b4a58ee3b71fc305f44f62ada0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
#
# This file is part of the coreboot project.
#
# Copyright (C) 2007 coresystems GmbH
# (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

ARCH=`uname -m | sed -e s/i.86/x86/ -e s/sun4u/sparc64/ \
			-e s/arm.*/arm/ -e s/sa110/arm/ \
			-e s/s390x/s390/ -e s/parisc64/parisc/ \
			-e s/ppc.*/powerpc/ -e s/mips.*/mips/`

OS=`uname -s`

testcc()
{
	TMP=".$$$$.tmp"
	$1 $2 -S -xc /dev/null -o $TMP > /dev/null 2>&1
	ret=$?
	rm -rf $TMP
	return $ret 
}

searchgnu()
{
	# $1 short name
	# result: GNU version of that tool on stdout
	#         or no output if no GNU version was found
	for i in "$1" "g$1" "gnu$1"; do
	        if test -x "`which $i 2>/dev/null`"; then
			if test `$i --version 2>/dev/null |grep -c GNU` -gt 0; then
				echo $i
				return
			fi
	        fi
	done
	echo "ERROR: Missing toolchain: $1" >&2
	exit 1
}

case  "$ARCH" in
"x86_64")
	echo "CC_x86 := gcc -m32"
	CC="gcc -m32"

	searchgnu ar >/dev/null && echo "AR_x86 := $(searchgnu ar)"
	searchgnu as >/dev/null && echo "AS_x86 := $(searchgnu as) --32"
	searchgnu ld >/dev/null && echo "LD_x86 := $(searchgnu ld) -b elf32-i386 -melf_i386"
	searchgnu nm >/dev/null && echo "NM_x86 := $(searchgnu nm)"
	searchgnu objcopy >/dev/null && echo "OBJCOPY_x86 := $(searchgnu objcopy)"
	searchgnu objdump >/dev/null && echo "OBJDUMP_x86 := $(searchgnu objdump)"
	searchgnu readelf >/dev/null && echo "READELF_x86 := $(searchgnu readelf)"
	;;
"x86")
	if [ "$OS" != "Darwin" ]; then
		echo "CC_x86 := gcc"
		CC="gcc"

		searchgnu ar >/dev/null && echo "AR_x86 := $(searchgnu ar)"
		searchgnu as >/dev/null && echo "AS_x86 := $(searchgnu as)"
		searchgnu ld >/dev/null && echo "LD_x86 := $(searchgnu ld)"
		searchgnu nm >/dev/null && echo "NM_x86 := $(searchgnu nm)"
		searchgnu objcopy >/dev/null && echo "OBJCOPY_x86 := $(searchgnu objcopy)"
		searchgnu objdump >/dev/null && echo "OBJDUMP_x86 := $(searchgnu objdump)"
		searchgnu readelf >/dev/null && echo "READELF_x86 := $(searchgnu readelf)"
	else
		CC=`find /opt/local/bin/ -name "i386-elf-gcc-*"`
		if [ "$CC" == "" ]; then
			echo "ERROR: Please install i386-elf-gcc from MacPorts" >&2
			exit 1
		fi
		echo "CC_x86 := $CC"
		echo "AR_x86 := i386-elf-ar"
		echo "AS_x86 := i386-elf-as --divide"
		echo "LD_x86 := i386-elf-ld"
		echo "NM_x86 := i386-elf-nm"
		echo "OBJCOPY_x86 := i386-elf-objcopy"
		echo "OBJDUMP_x86 := i386-elf-objdump"
		echo "READELF_x86 := i386-elf-readelf"
		echo "INTLCFLAGS  := -I/opt/local/include"
		echo "INTLLIBS    := -L/opt/local/lib -lintl"
	fi
	;;
*)
	# FIXME: This should be detected.
	CC="i386-linux-gcc"
	echo "CC_x86 := i386-linux-gcc"
	echo "AR_x86 := i386-linux-ar"
	echo "AS_x86 := i386-linux-as"
	echo "LD_x86 := i386-linux-ld"
	echo "NM_x86 := i386-linux-nm"
	echo "OBJCOPY_x86 := i386-linux-objcopy"
	echo "OBJDUMP_x86 := i386-linux-objdump"
	echo "READELF_x86 := i386-elf-readelf"
	;;
esac

# This is where we test for various flags and other things

CFLAGS=""
testcc "$CC" "-fno-stack-protector" && CFLAGS="$CFLAGS-fno-stack-protector " 

echo "CFLAGS_x86 := $CFLAGS"

# TODO: The same as above for PowerPC, and other architectures
#       as soon as they are supported by coreboot v3.