DEADSOFTWARE

flush called only for exclusive-mode files
[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 _verify=true
18 _cpu=
19 _target=
20 _system=
21 _host_cpu=
22 _host_system=
24 ###^^^^^^^^^^^###
25 ### Functions ###
26 ###___________###
28 usage() {
29 echo "Usage: make-all.sh [options] cpu target os"
30 echo "Options:"
31 echo " -c path Path to compiler binary"
32 echo " -l path Path to linker binary"
33 echo " -b Bootstrap compiler (result in bootstrap/<cpu>-cpfront-<os>/)"
34 echo " -v Do not recompile itself (result in stage2/)"
35 # echo " -e Cross compile (result in stage-cross)"
36 # echo " -u cpu Host cpu"
37 # echo " -s os Host operaion system"
38 echo "Processors:"
39 echo " 486 Intel 486+"
40 echo "Targets:"
41 echo " native Native"
42 echo " cpfront Generic C"
43 echo "Operation systems:"
44 echo " linux GNU/Linux"
45 exit 2
46 }
48 error() {
49 echo "$_exec:" "$@"
50 exit 1
51 }
53 make_stage() {
54 local _dir="$1"
55 local _this_cpu="$2"
56 local _this_target="$3"
57 local _this_system="$4"
58 shift 4
59 "$_this/make.sh" -o "$_dir" -c "$_compiler" -l "$_linker" "$@" "$_this_cpu" "$_this_target" "$_this_system"
60 if [ "$_target" = "cpfront" ]; then
61 _compiler="$_dir/cpfront"
62 _linker=
63 else
64 if [ "$_cpu" = "486" ]; then
65 _compiler="$_dir/cpc486"
66 _linker="$_dir/cpl486"
67 else
68 error "unsupported cpu $_cpu"
69 fi
70 fi
71 }
73 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
74 ### Parse arguments and options ###
75 ###_____________________________###
77 while getopts c:l:u:s:bveh _name
78 do
79 case "$_name" in
80 c) _compiler="$OPTARG" ;;
81 l) _linker="$OPTARG" ;;
82 u) _host_cpu="$OPTARG" ;;
83 s) _host_system="$OPTARG" ;;
84 b) _bootstrap=true ;;
85 v) _verify=false ;;
86 e) _cross=true ;;
87 h|?) usage ;;
88 esac
89 done
91 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
92 usage
93 fi
95 shift $(($OPTIND - 1))
96 _cpu="$1"
97 _target="$2"
98 _system="$3"
100 if [ -z "$_host_cpu" ]; then
101 _host_cpu="$_cpu"
102 fi
104 if [ -z "$_host_system" ]; then
105 _host_system="$_system"
106 fi
108 ###^^^^^^^^^^^^^^^^^^^^^^^^^###
109 ### Link bootstrap compiler ###
110 ###_________________________###
112 if $_bootstrap; then
113 echo "==> Bootstrap from C"
114 _compiler=
115 _linker=
116 if $_cross; then
117 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_host_cpu" "cpfront" "$_host_system" -b
118 else
119 make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_cpu" "cpfront" "$_system" -b
120 fi
121 fi
123 ###^^^^^^^^^^^^^^^^###
124 ### Compile stages ###
125 ###________________###
127 if $_verify; then
128 if $_cross; then
129 echo "==> Stage 0"
130 make_stage "$_this/stage0" "$_host_cpu" "native" "$_host_system"
131 echo "==> Stage 1"
132 make_stage "$_this/stage1" "$_host_cpu" "native" "$_host_system"
133 echo "==> Stage 2"
134 make_stage "$_this/stage2" "$_host_cpu" "native" "$_host_system"
135 else
136 echo "==> Stage 0"
137 make_stage "$_this/stage0" "$_cpu" "$_target" "$_system"
138 echo "==> Stage 1"
139 make_stage "$_this/stage1" "$_cpu" "$_target" "$_system"
140 echo "==> Stage 2"
141 make_stage "$_this/stage2" "$_cpu" "$_target" "$_system"
142 fi
143 fi
145 ###^^^^^^^^^^^^^^^###
146 ### Cross compile ###
147 ###_______________###
149 if $_cross; then
150 echo "==> Build for target machine"
151 make_stage "$_this/stage-cross/$_cpu-$_target-$_system" "$_cpu" "$_target" "$_system"
152 fi
154 echo "==> Done"