]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - build.sh
TX51 pre-release
[karo-tx-redboot.git] / build.sh
1 #!/bin/bash
2 options="cnqrR"
3 release=false
4 tools_dir="$PWD/tools/bin"
5 ecosconfig="$tools_dir/tools/configtool/standalone/common/ecosconfig"
6 src_dir="$PWD/packages"
7 quiet=false
8 clean=false
9 rebuild=false
10 doit=true
11 make_opts=
12
13 cmd_prefix=${CROSS_COMPILE-arm-926ejs-linux-gnu-}
14
15 error() {
16     if [ -n "${target}" ];then
17         echo "${target} build aborted"
18     fi
19 }
20
21 build_host_tools() {
22     echo "Building host tools in $tools_dir"
23     # Debian packages tcl-dev and tk-dev are required for this build
24     local wd="$PWD"
25     local tcldirs="/usr/lib/tcl /usr/local/lib/tcl"
26     local config_opts=""
27     for d in $tcldirs;do
28         if [ -d "$d" ];then
29             config_opts="$config_opts --with-tcl=${d%lib/tcl}"
30             break
31         fi
32     done
33     if [ -z "$config_opts" ];then
34         for d in /usr/lib/tcl*;do
35             [ -d "$d" ] || continue
36             config_opts="$config_opts --with-tcl-version=${d##*tcl}"
37         done
38     fi
39     if [ -z "$config_opts" ];then
40         echo "No Tcl installation found"
41         exit 1
42     fi
43
44     export TCL_INC_DIR="$(. /usr/lib/tclConfig.sh; echo $TCL_INCLUDE_SPEC | sed 's/^-I//')"
45     mkdir -p "$tools_dir"
46     cd "$tools_dir"
47     sh ../src/configure $config_opts
48     make
49     cd "$wd"
50 }
51
52 if [ `uname -s` = Linux ];then
53     PATH="/usr/local/arm/cross-gcc-4.2.0/i686-pc-linux-gnu/bin:$PATH"
54 fi
55
56 while getopts "$options" opt;do
57     case $opt in
58         c)
59             clean=true
60             ;;
61         n)
62             doit=false
63             make_opts="${make_opts} -n"
64             ;;
65         q)
66             quiet=true
67             ;;
68         r)
69             rebuild=true
70             ;;
71         R)
72             release=true
73             ;;
74         '?')
75             exit 1
76             ;;
77         *)
78             echo "Unsupported option '$opt'"
79             exit 1
80     esac
81 done
82 shift $(($OPTIND - 1))
83
84 if [ $# -gt 0 ];then
85     targets="$@"
86 else
87     targets=$(cd config;ls *.ecc)
88 fi
89
90 set -e
91 trap error 0
92 conf_dir="$PWD/config"
93 [ -d build ] || mkdir -p build
94 cd build
95 wd=$PWD
96 if [ ! -x "${ecosconfig}" ];then
97     build_host_tools
98 fi
99 for target in ${targets};do
100     target="${target%.ecc}"
101     if [ ! -d "${target}" ];then
102         echo "Creating build dir ${target}"
103         mkdir -p "${target}"
104     fi
105
106     cd "${target}"
107     echo "Building ${target}"
108
109     build_dir="$PWD/${target}_build"
110     inst_dir="$PWD/${target}_install"
111
112     $quiet || echo "Checking configuration ${target}"
113     cp -p "${conf_dir}/${target}.ecc" "${conf_dir}/${target}.ecc.bak"
114     echo ecosconfig --srcdir="$src_dir" --config="${conf_dir}/${target}.ecc" check
115     if $doit;then
116         stty -isig # prevent CTRL-C from trashing the config file
117         set +e
118         "${ecosconfig}" --srcdir="$src_dir" --config="${conf_dir}/${target}.ecc" check
119         if [ $? != 0 ];then
120             mv "${conf_dir}/${target}.ecc.bak" "${conf_dir}/${target}.ecc"
121             exit 1
122         fi
123         set -e
124         stty isig
125     fi
126
127     if $rebuild;then
128         echo "Removing build dir ${build_dir} and ${inst_dir}"
129         $doit && rm -rf "${build_dir}" "${inst_dir}"
130     fi
131     if [ ! -d "${build_dir}" ];then
132         $quiet || echo "Creating build tree for ${target}"
133         echo mkdir "${build_dir}"
134         $doit && mkdir "${build_dir}"
135     fi
136     $doit && cd "${build_dir}"
137     echo ecosconfig --srcdir="$src_dir" --prefix="${inst_dir}" \
138         --config="${conf_dir}/${target}.ecc" tree
139     if $doit;then
140         stty -isig
141         "${ecosconfig}" --srcdir="$src_dir" --prefix="${inst_dir}" \
142             --config="${conf_dir}/${target}.ecc" tree
143         stty isig
144         rm -f "${target}" ../../current && ln -svf "${target}" ../../current
145         rm -f ../install && ln -svf "${target}_install" ../install
146         rm -f ../build && ln -svf "${target}_build" ../build
147     fi
148
149     if $clean;then
150         $quiet || echo "Cleaning up build tree for ${target}"
151         #make ${make_opts} COMMAND_PREFIX=${cmd_prefix} clean
152         make ${make_opts} clean
153     fi
154
155     $quiet || echo "Compiling ${target}"
156     [ -d "${build_dir}" ]
157     #make -C "${build_dir}" COMMAND_PREFIX=${cmd_prefix} ${make_opts}
158     make -C "${build_dir}" ${make_opts}
159
160     cd $wd
161     if $doit && [ -s "${inst_dir}/bin/redboot.elf" ];then
162         bootstrap_addr="$(${cmd_prefix}nm "${inst_dir}/bin/redboot.elf" \
163             | sed '/Now_in_SDRAM/!d;s/ .*$//')"
164         if [ -n "$bootstrap_addr" ] && ! echo "$bootstrap_addr" | grep -i '^[0-9a-f]\{4\}0[0-7]';then
165             echo "ERROR: Bootstrap does not fit into first NAND page!"
166             echo $bootstrap_addr
167             exit 1
168         fi
169     fi
170     echo "${target} build finished"
171
172 done
173 trap - 0