DEADSOFTWARE

fix loop when use SYSTEM.ADDRESS with 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 " arm ARM 32-bit"
43 echo "Targets:"
44 echo " native Native"
45 echo " cpfront Generic C"
46 echo "Operation systems:"
47 echo " linux GNU/Linux"
48 echo " cygwin Cygwin"
49 echo "Environment variables:"
50 echo " CC C compiler binary"
51 echo " CFLAGS C compiler options"
52 exit 2
53 }
55 error() {
56 echo "$_exec:" "$@"
57 exit 1
58 }
60 make_stage() {
61 local _dir="$1"
62 local _this_cpu="$2"
63 local _this_target="$3"
64 local _this_system="$4"
65 shift 4
66 "$_this/make.sh" -o "$_dir" -c "$_compiler" -l "$_linker" "$@" "$_this_cpu" "$_this_target" "$_this_system"
67 local _ext=
68 if [ "$_host_system" = "cygwin" ]; then
69 _ext=".exe"
70 fi
71 if [ "$_target" = "cpfront" ]; then
72 _compiler="$_dir/cpfront${_ext}"
73 _linker=
74 else
75 if [ "$_cpu" = "486" ]; then
76 _compiler="$_dir/cpc486${_ext}"
77 _linker="$_dir/cpl486${_ext}"
78 else
79 error "unsupported cpu $_cpu"
80 fi
81 fi
82 }
84 make_verify_stage() {
85 local _N="$1"
86 shift
87 if $_cross; then
88 make_stage "$_this/stage$_N" "$@" "$_host_cpu" "$_host_target" "$_host_system"
89 else
90 make_stage "$_this/stage$_N" "$@" "$_cpu" "$_target" "$_system"
91 fi
92 }
94 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
95 ### Parse arguments and options ###
96 ###_____________________________###
98 while getopts c:l:u:t:s:g:beh _name
99 do
100 case "$_name" in
101 c) _compiler="$OPTARG" ;;
102 l) _linker="$OPTARG" ;;
103 u) _host_cpu="$OPTARG" ;;
104 t) _host_target="$OPTARG" ;;
105 s) _host_system="$OPTARG" ;;
106 g) _stages="$OPTARG" ;;
107 b) _bootstrap=true ;;
108 e) _cross=true ;;
109 h|?) usage ;;
110 esac
111 done
113 if [ "$_stages" -lt "0" -o "$_stages" -gt "2" ]; then
114 usage
115 fi
117 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
118 usage
119 fi
121 shift $(($OPTIND - 1))
122 _cpu="$1"
123 _target="$2"
124 _system="$3"
126 if [ -z "$_host_cpu" ]; then
127 _host_cpu="$_cpu"
128 fi
130 if [ -z "$_host_target" ]; then
131 _host_target="$_target"
132 fi
134 if [ -z "$_host_system" ]; then
135 _host_system="$_system"
136 fi
138 ###^^^^^^^^^^^^^^^^^^^^###
139 ### Bootstrap compiler ###
140 ###____________________###
142 if $_bootstrap; then
143 echo "==> Bootstrap"
144 _compiler=
145 _linker=
146 if $_cross; then
147 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_host_cpu" "cpfront" "$_host_system" -b
148 else
149 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_cpu" "cpfront" "$_system" -b
150 fi
151 else
152 echo "==> Stage 0"
153 make_verify_stage 0
154 fi
156 ###^^^^^^^^^^^^^^^^^^###
157 ### Recompile itself ###
158 ###__________________###
160 for _N in $(seq 1 "$_stages")
161 do
162 echo "==> Stage $_N"
163 make_verify_stage "$_N"
164 done
165 _N=
167 ###^^^^^^^^^^^^^^^###
168 ### Cross compile ###
169 ###_______________###
171 if $_cross; then
172 echo "==> Cross compile"
173 make_stage "$_this/stage-cross/$_cpu-$_target-$_system" "$_cpu" "$_target" "$_system"
174 fi
176 echo "==> Done"