build: Prepare for kernel variants.
[mes.git] / build-aux / build-scaffold.sh
1 #! /bin/sh
2
3 # GNU Mes --- Maxwell Equations of Software
4 # Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 #
6 # This file is part of GNU Mes.
7 #
8 # GNU Mes is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # GNU Mes is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Mes.  If not, see <http://www.gnu.org/licenses/>.
20
21 set -e
22 set -u
23
24 V=${V-1}
25
26 if [ "$V" = 2 ]; then
27     set -x
28 fi
29
30 . ./config.sh
31 . ${srcdest}build-aux/trace.sh
32
33 if $courageous; then
34     set +e
35     set_min_e () {
36         echo "Applying courage"
37     }
38     set_min_e
39 else
40     set_min_e () {
41         set -e
42     }
43 fi
44
45 case "$mes_cpu" in
46     arm)
47         stage0_arch=40
48         stage0_cpu=armv7l
49         ;;
50     x86_64)
51         stage0_arch=2
52         stage0_cpu=amd64
53         ;;
54     x86)
55         stage0_arch=1
56         stage0_cpu=x86
57         ;;
58     *)
59         stage0_arch=1
60         stage0_cpu=$mes_cpu
61         ;;
62 esac
63
64 trace "CCLD       ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/exit-42.S" $CC\
65       -nostdlib\
66       -g\
67       ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/exit-42.S\
68       -o exit-42
69
70 trace "TEST       exit-42"
71 { set +e; ./exit-42; r=$?; set_min_e; }
72 [ $r != 42 ] && echo "  => $r"
73 [ $r = 42 ]
74
75 if $numbered_arch; then
76     stage0_cpu_flag="--Architecture $stage0_arch";
77 else
78     stage0_cpu_flag="--architecture $stage0_cpu";
79 fi
80
81 trace "HEX2       ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-0exit-42.hex2" $HEX2\
82       --LittleEndian\
83       $stage0_cpu_flag\
84       --BaseAddress 0x1000000\
85       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-0header.hex2\
86       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-0exit-42.hex2\
87       --exec_enable\
88       -o 0exit-42
89
90 trace "TEST       0exit-42"
91 { set +e; ./0exit-42; r=$?; set_min_e; }
92 [ $r != 42 ] && echo "  => $r"
93 [ $r = 42 ]
94
95 trace "HEX2       ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2" $HEX2\
96       --LittleEndian\
97       $stage0_cpu_flag\
98       --BaseAddress 0x1000000\
99       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-header.hex2\
100       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-body-exit-42.hex2\
101       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-footer-single-main.hex2\
102       --exec_enable\
103       -o body-exit-42
104
105 trace "TEST       body-exit-42"
106 { set +e; ./body-exit-42; r=$?; set_min_e; }
107 [ $r != 42 ] && echo "  => $r"
108 [ $r = 42 ]
109
110 ### FIXME: c&p from exit-42
111 trace "CCLD       ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/hello-mes.S" $CC\
112       -nostdlib\
113       -g\
114       ${srcdest}lib/$mes_kernel/$mes_cpu-mes-$compiler/hello-mes.S\
115       -o hello-mes
116
117 trace "TEST       hello-mes"
118 { set +e; ./hello-mes; r=$?; set_min_e; }
119 [ $r != 0 ] && echo "  => $r"
120 [ $r = 0 ]
121
122 trace "HEX2       ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-0hello-mes.hex2" $HEX2\
123       --LittleEndian\
124       $stage0_cpu_flag\
125       --BaseAddress 0x1000000\
126       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-0header.hex2\
127       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-0hello-mes.hex2\
128       --exec_enable\
129       -o 0hello-mes
130
131 trace "TEST       0hello-mes"
132 { set +e; ./0hello-mes; r=$?; set_min_e; }
133 [ $r != 0 ] && echo "  => $r"
134 [ $r = 0 ]
135
136 trace "HEX2       ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-body-hello-mes.hex2" $HEX2\
137       --LittleEndian\
138       $stage0_cpu_flag\
139       --BaseAddress 0x1000000\
140       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-header.hex2\
141       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-body-hello-mes.hex2\
142       -f ${srcdest}lib/$mes_kernel/$mes_cpu-mes/elf$mes_bits-footer-single-main.hex2\
143       --exec_enable\
144       -o body-hello-mes
145
146 trace "TEST       body-hello-mes"
147 { set +e; ./body-hello-mes; r=$?; set_min_e; }
148 [ $r != 0 ] && echo "  => $r"
149 [ $r = 0 ]