DEADSOFTWARE

sync with mainstream CPfront (14c6ba1->1b426ec)
[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 export CPCFLAGS="$CPCFLAGS"
26 export CPLFLAGS="$CPLFLAGS"
28 ###^^^^^^^^^^^###
29 ### Functions ###
30 ###___________###
32 usage() {
33 echo "Usage: make-all.sh [options] cpu target os"
34 echo "Options:"
35 echo " -c path Path to compiler binary"
36 echo " -l path Path to linker binary"
37 echo " -b Bootstrap compiler (result in bootstrap/<cpu>-cpfront-<os>/)"
38 echo " -g num Set max verify stages (0..2)"
39 # echo " -e Cross compile (result in stage-cross)"
40 # echo " -u cpu Host cpu"
41 # echo " -t target Host compiler"
42 # echo " -s os Host operaion system"
43 echo "Processors:"
44 echo " 486 Intel 486+"
45 echo " arm ARM 32-bit"
46 echo "Targets:"
47 echo " native Native"
48 echo " cpfront Generic C"
49 echo "Operation systems:"
50 echo " linux GNU/Linux"
51 echo " cygwin Cygwin"
52 echo "Environment variables:"
53 echo " CC C compiler binary"
54 echo " CFLAGS C compiler options"
55 echo " CPCFLAGS CPC compiler options"
56 echo " CPLFLAGS CPL linker options"
57 exit 2
58 }
60 error() {
61 echo "$_exec:" "$@"
62 exit 1
63 }
65 make_stage() {
66 local _dir="$1"
67 local _this_cpu="$2"
68 local _this_target="$3"
69 local _this_system="$4"
70 shift 4
71 "$_this/make.sh" -o "$_dir" -c "$_compiler" -l "$_linker" "$@" "$_this_cpu" "$_this_target" "$_this_system"
72 local _ext=
73 if [ "$_host_system" = "cygwin" ]; then
74 _ext=".exe"
75 fi
76 if [ "$_target" = "cpfront" ]; then
77 _compiler="$_dir/cpfront${_ext}"
78 _linker=
79 else
80 if [ "$_cpu" = "486" ]; then
81 _compiler="$_dir/cpc486${_ext}"
82 _linker="$_dir/cpl486${_ext}"
83 else
84 error "unsupported cpu $_cpu"
85 fi
86 fi
87 }
89 make_verify_stage() {
90 local _N="$1"
91 shift
92 if $_cross; then
93 make_stage "$_this/stage$_N" "$@" "$_host_cpu" "$_host_target" "$_host_system"
94 else
95 make_stage "$_this/stage$_N" "$@" "$_cpu" "$_target" "$_system"
96 fi
97 }
99 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
100 ### Parse arguments and options ###
101 ###_____________________________###
103 while getopts c:l:u:t:s:g:beh _name
104 do
105 case "$_name" in
106 c) _compiler="$OPTARG" ;;
107 l) _linker="$OPTARG" ;;
108 u) _host_cpu="$OPTARG" ;;
109 t) _host_target="$OPTARG" ;;
110 s) _host_system="$OPTARG" ;;
111 g) _stages="$OPTARG" ;;
112 b) _bootstrap=true ;;
113 e) _cross=true ;;
114 h|?) usage ;;
115 esac
116 done
118 if [ "$_stages" -lt "0" -o "$_stages" -gt "2" ]; then
119 usage
120 fi
122 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
123 usage
124 fi
126 shift $(($OPTIND - 1))
127 _cpu="$1"
128 _target="$2"
129 _system="$3"
131 if [ -z "$_host_cpu" ]; then
132 _host_cpu="$_cpu"
133 fi
135 if [ -z "$_host_target" ]; then
136 _host_target="$_target"
137 fi
139 if [ -z "$_host_system" ]; then
140 _host_system="$_system"
141 fi
143 ###^^^^^^^^^^^^^^^^^^^^###
144 ### Bootstrap compiler ###
145 ###____________________###
147 if $_bootstrap; then
148 echo "==> Bootstrap"
149 _compiler=
150 _linker=
151 if $_cross; then
152 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_host_cpu" "cpfront" "$_host_system" -b
153 else
154 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_cpu" "cpfront" "$_system" -b
155 fi
156 else
157 echo "==> Stage 0"
158 make_verify_stage 0
159 fi
161 ###^^^^^^^^^^^^^^^^^^###
162 ### Recompile itself ###
163 ###__________________###
165 for _N in $(seq 1 "$_stages")
166 do
167 echo "==> Stage $_N"
168 make_verify_stage "$_N"
169 done
170 _N=
172 ###^^^^^^^^^^^^^^^###
173 ### Cross compile ###
174 ###_______________###
176 if $_cross; then
177 echo "==> Cross compile"
178 make_stage "$_this/stage-cross/$_cpu-$_target-$_system" "$_cpu" "$_target" "$_system"
179 fi
181 echo "==> Done"