OSDN Git Service

mkostemp: fix implementation
[uclinux-h8/uClibc.git] / extra / scripts / MAKEALL
1 #!/bin/sh
2 #
3 # helper script to quick build testing with cross-compilers
4 #
5
6 : ${MAKE:=make}
7
8 : ${BUILD_NCPUS:=$(getconf _NPROCESSORS_ONLN)}
9 if [ "$BUILD_NCPUS" -gt 1 ] ; then
10         JOBS=-j$((BUILD_NCPUS + 1))
11 else
12         JOBS=""
13 fi
14 MAKE="${MAKE} ${JOBS}"
15
16 : ${CROSS_COMPILE:=${CROSS_COMPILER_PREFIX}}
17
18 setconfig()
19 {
20         local opt=$1
21         shift
22         case $1 in
23                 [yn])   ;;
24                 [0-9]*) ;;
25                 *)      set -- '"'$*'"'
26         esac
27         sed -i \
28                 -e "/${opt}=/s:=.*:=$*:" \
29                 .config
30         echo "  ## setconfig ${opt} $*"
31 }
32
33 get_arches()
34 {
35         case $1 in
36                 hppa) echo hppa hppa2.0 hppa1.1 hppa1.0;;
37                 i386) echo i386 i486 i586 i686;;
38                 sh) echo sh4 sh2 sh3 sh1 sh;;
39                 sparc) echo sparc sparc64;;
40                 *)  echo $1;;
41         esac
42 }
43
44 find_compiler()
45 {
46         local t a v o l
47         for a in $(get_arches $1) ; do
48                 for l in uclibc gnu gnueabi "" ; do
49                         for v in unknown pc gentoo "" ; do
50                                 for o in linux uclinux "" ; do
51                                         t="${a}${v:+-${v}}${o:+-${o}}${l:+-${l}}"
52                                         if ${t}-gcc --help > /dev/null 2>&1 ; then
53                                                 echo ${t}-
54                                                 return 0
55                                         fi
56                                 done
57                         done
58                 done
59         done
60 }
61
62 do_make()
63 {
64         echo "  ## ${MAKE} -s $*"
65         ${MAKE} -s "$@"
66 }
67
68 mark_arch()
69 {
70         local r=$1 a=$2
71         eval $r=\"\$$r $a\"
72 }
73
74 if [ -z "$*" ] ; then
75         set -- $(awk \
76                 '$0 ~ /^config TARGET_/ { sub("TARGET_",""); print $NF }' \
77                 extra/Configs/Config.in | grep -v SUBARCH)
78 fi
79 pass=""
80 fail=""
81 skip=""
82 for a in "$@" ; do
83         if [ -z "${CROSS_COMPILE}" ] ; then
84                 CROSS_COMPILE=$(find_compiler ${a})
85         fi
86
87         if [ -z "${CROSS_COMPILE}" ] ; then
88                 mark_arch skip $a
89                 echo " ### SKIP: ${a}: could not find compiler"
90                 continue
91         fi
92
93         rm -f ${a}.log ${a}.fail
94         (
95         set -e
96
97         echo " ### Building target ${a} (${CROSS_COMPILE})"
98
99         do_make distclean
100         do_make ARCH=$a defconfig
101         do_make oldconfig
102
103         setconfig CROSS_COMPILER_PREFIX ${CROSS_COMPILE}
104
105         header_path=${KERNEL_HEADERS:-$(echo '#include <linux/version.h>' | ${CROSS_COMPILE}cpp 2>/dev/null | grep -o '[^"]*linux/version.h')} || :
106         if [ -z "${header_path}" ] ; then
107                 for p in /usr/${CROSS_COMPILE%-}/usr/include ; do
108                         if [ -e ${p}/linux/version.h ] ; then
109                                 header_path=${p}
110                                 break
111                         fi
112                 done
113                 if [ -z "${header_path}" ] ; then
114                         echo "  ## unable to locate KERNEL_HEADERS"
115                 fi
116         fi
117         setconfig KERNEL_HEADERS ${header_path%/linux/version.h}
118
119         if do_make ; then
120                 echo "  ## PASS"
121         else
122                 echo "  ## FAIL"
123                 touch ${a}.fail
124         fi
125         ) 2>&1 | tee ${a}.log
126
127         if [ -e ${a}.fail ] ; then
128                 rm -f ${a}.fail
129                 mark_arch fail $a
130         else
131                 mark_arch pass $a
132         fi
133
134         unset CROSS_COMPILE
135 done
136
137 if [ -n "${skip}" ] ; then
138         printf '\nSKIPPED: %s\n' "${skip}"
139 fi
140 if [ -n "${fail}" ] ; then
141         printf '\nPASSED: %s\nFAILED: %s\n\n' "${pass}" "${fail}"
142         exit 1
143 else
144         printf '\nAll arches passed!\n\n'
145         exit 0
146 fi