DEADSOFTWARE

Added workaround that fixes field renaming for CPfront
[cpc.git] / make-all.sh
1 #! /bin/sh
3 set -e
5 ###^^^^^^^^^^^^^^^^^^###
6 ### Global variables ###
7 ###__________________###
9 _this="$(dirname "$(readlink -f "$0")")"
10 _exec="make-all.sh"
11 _compiler=
12 _linker=
14 _cross=false
15 _bootstrap=false
16 _stages=2
18 _cpu=
19 _target=
20 _system=
21 _host_cpu=
22 _host_target=
23 _host_system=
25 ###^^^^^^^^^^^###
26 ### Functions ###
27 ###___________###
29 usage() {
30 echo "Usage: make-all.sh [options] cpu target os"
31 echo "Options:"
32 echo " -c path Path to compiler binary"
33 echo " -l path Path to linker binary"
34 echo " -b Bootstrap compiler (result in bootstrap/<cpu>-cpfront-<os>/)"
35 echo " -g num Set max verify stages (0..2)"
36 # echo " -e Cross compile (result in stage-cross)"
37 # echo " -u cpu Host cpu"
38 # echo " -t target Host compiler"
39 # echo " -s os Host operaion system"
40 echo "Processors:"
41 echo " 486 Intel 486+"
42 echo "Targets:"
43 echo " native Native"
44 echo " cpfront Generic C"
45 echo "Operation systems:"
46 echo " linux GNU/Linux"
47 exit 2
48 }
50 error() {
51 echo "$_exec:" "$@"
52 exit 1
53 }
55 make_stage() {
56 local _dir="$1"
57 local _this_cpu="$2"
58 local _this_target="$3"
59 local _this_system="$4"
60 shift 4
61 "$_this/make.sh" -o "$_dir" -c "$_compiler" -l "$_linker" "$@" "$_this_cpu" "$_this_target" "$_this_system"
62 if [ "$_target" = "cpfront" ]; then
63 _compiler="$_dir/cpfront"
64 _linker=
65 else
66 if [ "$_cpu" = "486" ]; then
67 _compiler="$_dir/cpc486"
68 _linker="$_dir/cpl486"
69 else
70 error "unsupported cpu $_cpu"
71 fi
72 fi
73 }
75 make_verify_stage() {
76 local _N="$1"
77 shift
78 if $_cross; then
79 make_stage "$_this/stage$_N" "$@" "$_host_cpu" "$_host_target" "$_host_system"
80 else
81 make_stage "$_this/stage$_N" "$@" "$_cpu" "$_target" "$_system"
82 fi
83 }
85 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
86 ### Parse arguments and options ###
87 ###_____________________________###
89 while getopts c:l:u:t:s:g:beh _name
90 do
91 case "$_name" in
92 c) _compiler="$OPTARG" ;;
93 l) _linker="$OPTARG" ;;
94 u) _host_cpu="$OPTARG" ;;
95 t) _host_target="$OPTARG" ;;
96 s) _host_system="$OPTARG" ;;
97 g) _stages="$OPTARG" ;;
98 b) _bootstrap=true ;;
99 e) _cross=true ;;
100 h|?) usage ;;
101 esac
102 done
104 if [ "$_stages" -lt "0" -o "$_stages" -gt "2" ]; then
105 usage
106 fi
108 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
109 usage
110 fi
112 shift $(($OPTIND - 1))
113 _cpu="$1"
114 _target="$2"
115 _system="$3"
117 if [ -z "$_host_cpu" ]; then
118 _host_cpu="$_cpu"
119 fi
121 if [ -z "$_host_target" ]; then
122 _host_target="$_target"
123 fi
125 if [ -z "$_host_system" ]; then
126 _host_system="$_system"
127 fi
129 ###^^^^^^^^^^^^^^^^^^^^###
130 ### Bootstrap compiler ###
131 ###____________________###
133 if $_bootstrap; then
134 echo "==> Bootstrap"
135 _compiler=
136 _linker=
137 if $_cross; then
138 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_host_cpu" "cpfront" "$_host_system" -b
139 else
140 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_cpu" "cpfront" "$_system" -b
141 fi
142 else
143 echo "==> Stage 0"
144 make_verify_stage 0
145 fi
147 ###^^^^^^^^^^^^^^^^^^###
148 ### Recompile itself ###
149 ###__________________###
151 for _N in $(seq 1 "$_stages")
152 do
153 echo "==> Stage $_N"
154 make_verify_stage "$_N"
155 done
156 _N=
158 ###^^^^^^^^^^^^^^^###
159 ### Cross compile ###
160 ###_______________###
162 if $_cross; then
163 echo "==> Cross compile"
164 make_stage "$_this/stage-cross/$_cpu-$_target-$_system" "$_cpu" "$_target" "$_system"
165 fi
167 echo "==> Done"