Deleted obsolete file
[karo-tx-redboot.git] / build.sh
1 #!/bin/bash
2 options="cnqrRp:"
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 pattern="*"
13
14 error() {
15     rc=$?
16     if [ -n "${target}" ];then
17         echo "${target} build aborted"
18     fi
19     return $rc
20 }
21
22 build_host_tools() {
23     echo "Building host tools in $tools_dir"
24     # Debian packages tcl-dev and tk-dev are required for this build
25     local wd="$PWD"
26     local tcldirs="/usr/lib/tcl /usr/local/lib/tcl"
27     local config_opts=""
28     for d in $tcldirs;do
29         if [ -d "$d" ];then
30             config_opts="$config_opts --with-tcl=${d%lib/tcl}"
31             break
32         fi
33     done
34     if [ -z "$config_opts" ];then
35         for d in /usr/lib/tcl*;do
36             [ -d "$d" ] || continue
37             config_opts="$config_opts --with-tcl-version=${d##*tcl}"
38         done
39     fi
40     if [ -z "$config_opts" ];then
41         echo "No Tcl installation found"
42         exit 1
43     fi
44
45     export TCL_INC_DIR="$(. /usr/lib/tclConfig.sh; echo $TCL_INCLUDE_SPEC | sed 's/^-I//')"
46     mkdir -p "$tools_dir"
47     cd "$tools_dir"
48     sh ../src/configure $config_opts
49     make
50     cd "$wd"
51 }
52
53 while getopts "$options" opt;do
54     case $opt in
55         c)
56             clean=true
57             ;;
58         n)
59             doit=false
60             make_opts="${make_opts} -n"
61             ;;
62         p)
63             pattern="$OPTARG"
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 $pattern.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} clean
152     fi
153
154     $quiet || echo "Compiling ${target}"
155     [ -d "${build_dir}" ]
156     make -C "${build_dir}" ${make_opts}
157
158     cd $wd
159     if $doit && [ -s "${inst_dir}/bin/redboot.elf" ];then
160         bootstrap_addr="$(${cmd_prefix}nm "${inst_dir}/bin/redboot.elf" \
161             | sed '/Now_in_SDRAM/!d;s/ .*$//')"
162         if [ -n "$bootstrap_addr" ] && ! echo "$bootstrap_addr" | grep -i '^[0-9a-f]\{4\}0[0-7]';then
163             echo "ERROR: Bootstrap does not fit into first NAND page!"
164             echo $bootstrap_addr
165             exit 1
166         fi
167     fi
168     echo "${target} build finished"
169
170 done
171 trap - 0