summaryrefslogtreecommitdiff
path: root/extra/scripts/MAKEALL
blob: f467741e9d6a804ef9f95068dd3d579552c2907b (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
#
# helper script to quick build testing with cross-compilers
#

: ${MAKE:=make}

: ${BUILD_NCPUS:=$(getconf _NPROCESSORS_ONLN)}
if [ "$BUILD_NCPUS" -gt 1 ] ; then
	JOBS=-j$((BUILD_NCPUS + 1))
else
	JOBS=""
fi
MAKE="${MAKE} ${JOBS}"

: ${CROSS_COMPILE:=${CROSS_COMPILER_PREFIX}}

setconfig()
{
	local opt=$1
	shift
	case $1 in
		[yn])   ;;
		[0-9]*) ;;
		*)      set -- '"'$*'"'
	esac
	sed -i \
		-e "/${opt}=/s:=.*:=$*:" \
		.config
	echo "  ## setconfig ${opt} $*"
}

get_arches()
{
	case $1 in
		sh) echo sh4 sh2 sh3 sh1 sh;;
		*)  echo $1;;
	esac
}

find_compiler()
{
	local t a v o l
	for a in $(get_arches $1) ; do
		for v in unknown pc gentoo "" ; do
			for o in linux uclinux "" ; do
				for l in uclibc "" ; do
					t="${a}${v:+-${v}}${o:+-${o}}${l:+-${l}}"
					if ${t}-gcc --help > /dev/null 2>&1 ; then
						echo ${t}-
						return 0
					fi
				done
			done
		done
	done
}

do_make()
{
	echo "  ## ${MAKE} -s $*"
	${MAKE} -s "$@"
}

mark_arch()
{
	local r=$1 a=$2
	eval $r=\"\$$r $a\"
}

if [ -z "$*" ] ; then
	set -- $(awk \
		'$0 ~ /^config TARGET_/ { sub("TARGET_",""); print $NF }' \
		extra/Configs/Config.in | grep -v SUBARCH)
fi
pass=""
fail=""
skip=""
for a in "$@" ; do
	if [ -z "${CROSS_COMPILE}" ] ; then
		CROSS_COMPILE=$(find_compiler ${a})
	fi

	if [ -z "${CROSS_COMPILE}" ] ; then
		mark_arch skip $a
		echo " ### SKIP: ${a}: could not find compiler"
		continue
	fi

	rm -f ${a}.log ${a}.fail
	(
	set -e

	echo " ### Building target ${a} (${CROSS_COMPILE})"

	do_make distclean
	do_make ARCH=$a defconfig
	do_make oldconfig

	setconfig CROSS_COMPILER_PREFIX ${CROSS_COMPILE}

	header_path=${KERNEL_HEADERS:-$(echo '#include <linux/version.h>' | ${CROSS_COMPILE}cpp 2>/dev/null | grep -o '[^"]*linux/version.h')} || :
	if [ -z "${header_path}" ] ; then
		for p in /usr/${CROSS_COMPILE%-}/usr/include ; do
			if [ -e ${p}/linux/version.h ] ; then
				header_path=${p}
				break
			fi
		done
		if [ -z "${header_path}" ] ; then
			echo "  ## unable to locate KERNEL_HEADERS"
		fi
	fi
	setconfig KERNEL_HEADERS ${header_path%/linux/version.h}

	if do_make ; then
		echo "  ## PASS"
	else
		echo "  ## FAIL"
		touch ${a}.fail
	fi
	) 2>&1 | tee ${a}.log

	if [ -e ${a}.fail ] ; then
		rm -f ${a}.fail
		mark_arch fail $a
	else
		mark_arch pass $a
	fi
done

if [ -n "${skip}" ] ; then
	printf '\nSKIPPED: %s\n' "${skip}"
fi
if [ -n "${fail}" ] ; then
	printf '\nPASSED: %s\nFAILED: %s\n\n' "${pass}" "${fail}"
	exit 1
else
	printf '\nAll arches passed!\n\n'
	exit 0
fi