8e6ebb2c49752e9cc55a0c7cbf6585502c533d01
[karo-tx-redboot.git] / build.sh
1 #!/bin/sh
2 options="cnqrR"
3 release=false
4 tools_dir=${HOME}/projects/RedBoot/ecos/tools/bin/
5 src_dir=$PWD/packages
6 quiet=false
7 clean=false
8 rebuild=false
9 doit=true
10 make_opts=
11
12 error() {
13     if [ -n "${target}" ];then
14         echo "${target} build aborted"
15     fi
16 }
17
18 if [ `uname -s` = Linux ];then
19     PATH=/usr/local/arm/cross-gcc-1.2.0/i686-pc-linux-gnu/bin:$PATH
20 #    PATH=/usr/local/arm/cross-gcc-3.4.3-2.6.17/i686-pc-linux-gnu/bin:$PATH
21 #    PATH=/usr/local/arm/cross-gcc/i686-pc-linux-gnu/bin:$PATH
22     PATH=$tools_dir:$PATH
23 else
24     PATH=$PWD/host/tools/configtool:$PWD/build/tools/src/tools/configtool/standalone/common/:$PATH
25 fi
26
27 ECOSCONFIG=$tools_dir/ecosconfig
28
29 while getopts "$options" opt;do
30     case $opt in
31         c)
32             clean=true
33             ;;
34         n)
35             doit=false
36             make_opts="${make_opts} -n"
37             ;;
38         q)
39             quiet=true
40             ;;
41         r)
42             rebuild=true
43             ;;
44         R)
45             release=true
46             ;;
47         '?')
48             exit 1
49             ;;
50         *)
51             echo "Unsupported option '$opt'"
52             exit 1
53     esac
54 done
55 shift $(($OPTIND - 1))
56
57 cmd_prefix=${CROSS_COMPILE-arm-linux-}
58
59 if [ $# -gt 0 ];then
60     targets="$@"
61 else
62     targets=$(cd config; ls *.ecc)
63 fi
64
65 set -e
66 conf_dir="$PWD/config"
67 [ -d build ] || mkdir -p build
68 cd build
69 wd=$PWD
70 trap error 0
71 for target in ${targets};do
72     target="${target%.ecc}"
73     if [ ! -d "${target}" ];then
74         echo "Creating build dir ${target}"
75         mkdir -p "${target}"
76     fi
77
78     cd "${target}"
79     echo "Building ${target}"
80
81     build_dir="$PWD/${target}_build"
82     inst_dir="$PWD/${target}_install"
83
84     $quiet || echo "Checking configuration ${target}"
85     echo ecosconfig --srcdir="$src_dir" --config="${conf_dir}/${target}.ecc" check
86     $doit && ${ECOSCONFIG} --srcdir="$src_dir" --config="${conf_dir}/${target}.ecc" check
87
88     if $rebuild;then
89         echo "Removing build dir ${build_dir} and ${inst_dir}"
90         $doit && rm -rf "${build_dir}" "${inst_dir}"
91     fi
92     if [ ! -d "${build_dir}" ];then
93         $quiet || echo "Creating build tree for ${target}"
94         echo mkdir "${build_dir}"
95         $doit && mkdir "${build_dir}"
96     fi
97     echo ecosconfig --srcdir="$src_dir" --prefix="${inst_dir}" --config="${conf_dir}/${target}.ecc" tree
98     if $doit;then
99         cd "${build_dir}"
100         ${ECOSCONFIG} --srcdir="$src_dir" --prefix="${inst_dir}" --config="${conf_dir}/${target}.ecc" tree
101         rm -f ${target} ../../current && ln -svf ${target} ../../current
102         rm -f ../install && ln -svf ${target}_install ../install
103         rm -f ../build && ln -svf ${target}_build ../build
104     fi
105
106     if $clean;then
107         $quiet || echo "Cleaning up build tree for ${target}"
108         make ${make_opts} COMMAND_PREFIX=${cmd_prefix} clean
109     fi
110
111     $quiet || echo "Compiling ${target}"
112     [ -d "${build_dir}" ] && make -C "${build_dir}" COMMAND_PREFIX=${cmd_prefix} ${make_opts}
113
114     cd $wd
115     if $doit && [ -s "${inst_dir}/bin/redboot.elf" ];then
116         ${cmd_prefix}objdump -d "${inst_dir}/bin/redboot.elf" | grep '<Now_in_SDRAM>:' | grep -v 'a1f00[89a-f]'
117     fi
118     echo "${target} build finished"
119 done
120
121 trap - 0