DEADSOFTWARE

added arm support via 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 "Environment variables:"
49 echo " CC C compiler binary"
50 echo " CFLAGS C compiler options"
51 exit 2
52 }
54 error() {
55 echo "$_exec:" "$@"
56 exit 1
57 }
59 make_stage() {
60 local _dir="$1"
61 local _this_cpu="$2"
62 local _this_target="$3"
63 local _this_system="$4"
64 shift 4
65 "$_this/make.sh" -o "$_dir" -c "$_compiler" -l "$_linker" "$@" "$_this_cpu" "$_this_target" "$_this_system"
66 if [ "$_target" = "cpfront" ]; then
67 _compiler="$_dir/cpfront"
68 _linker=
69 else
70 if [ "$_cpu" = "486" ]; then
71 _compiler="$_dir/cpc486"
72 _linker="$_dir/cpl486"
73 else
74 error "unsupported cpu $_cpu"
75 fi
76 fi
77 }
79 make_verify_stage() {
80 local _N="$1"
81 shift
82 if $_cross; then
83 make_stage "$_this/stage$_N" "$@" "$_host_cpu" "$_host_target" "$_host_system"
84 else
85 make_stage "$_this/stage$_N" "$@" "$_cpu" "$_target" "$_system"
86 fi
87 }
89 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
90 ### Parse arguments and options ###
91 ###_____________________________###
93 while getopts c:l:u:t:s:g:beh _name
94 do
95 case "$_name" in
96 c) _compiler="$OPTARG" ;;
97 l) _linker="$OPTARG" ;;
98 u) _host_cpu="$OPTARG" ;;
99 t) _host_target="$OPTARG" ;;
100 s) _host_system="$OPTARG" ;;
101 g) _stages="$OPTARG" ;;
102 b) _bootstrap=true ;;
103 e) _cross=true ;;
104 h|?) usage ;;
105 esac
106 done
108 if [ "$_stages" -lt "0" -o "$_stages" -gt "2" ]; then
109 usage
110 fi
112 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
113 usage
114 fi
116 shift $(($OPTIND - 1))
117 _cpu="$1"
118 _target="$2"
119 _system="$3"
121 if [ -z "$_host_cpu" ]; then
122 _host_cpu="$_cpu"
123 fi
125 if [ -z "$_host_target" ]; then
126 _host_target="$_target"
127 fi
129 if [ -z "$_host_system" ]; then
130 _host_system="$_system"
131 fi
133 ###^^^^^^^^^^^^^^^^^^^^###
134 ### Bootstrap compiler ###
135 ###____________________###
137 if $_bootstrap; then
138 echo "==> Bootstrap"
139 _compiler=
140 _linker=
141 if $_cross; then
142 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_host_cpu" "cpfront" "$_host_system" -b
143 else
144 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_cpu" "cpfront" "$_system" -b
145 fi
146 else
147 echo "==> Stage 0"
148 make_verify_stage 0
149 fi
151 ###^^^^^^^^^^^^^^^^^^###
152 ### Recompile itself ###
153 ###__________________###
155 for _N in $(seq 1 "$_stages")
156 do
157 echo "==> Stage $_N"
158 make_verify_stage "$_N"
159 done
160 _N=
162 ###^^^^^^^^^^^^^^^###
163 ### Cross compile ###
164 ###_______________###
166 if $_cross; then
167 echo "==> Cross compile"
168 make_stage "$_this/stage-cross/$_cpu-$_target-$_system" "$_cpu" "$_target" "$_system"
169 fi
171 echo "==> Done"