DEADSOFTWARE

Added workaround that fixes field renaming for CPfront
[cpc.git] / make.sh
1 #! /bin/sh
3 set -e
5 ###^^^^^^^^^^^^^^^^^^###
6 ### Global variables ###
7 ###__________________###
9 _exec="make.sh"
10 _this="$(dirname "$(readlink -f "$0")")"
11 _cpu=
12 _target=
13 _system=
14 _compiler=
15 _linker=
16 _docompile=true
17 _dolink=true
18 _out="$_this/bin"
20 _useposix=false
22 ###^^^^^^^^^^^###
23 ### Functions ###
24 ###___________###
26 usage() {
27 echo "Usage: make.sh [options] cpu target os"
28 echo "Options:"
29 echo " -c path Path to compiler binary"
30 echo " -l path Path to linker binary"
31 echo " -o path Path to output binaries"
32 echo " -b Do not compile"
33 echo " -x Do not link"
34 echo "Processors:"
35 echo " 486 Intel 486+"
36 echo "Targets:"
37 echo " native Native"
38 echo " cpfront Generic C"
39 echo "Operation systems:"
40 echo " linux GNU/Linux"
41 exit 2
42 }
44 error() {
45 echo "$_exec:" "$@"
46 exit 1
47 }
49 copy_source() {
50 for _src
51 do
52 if test -d "$_this/src/$_src"; then
53 find "$_this/src/$_src" -mindepth 1 -maxdepth 1 -exec cp -rt "$_out" -- {} +
54 fi
55 done
56 }
58 native_compile() {
59 "$_compiler" -legacy "$@"
60 }
62 native_link() {
63 if $_dolink; then
64 "$_linker" -os "$_system" -kernel Kernel -main Kernel -legacycodedir . -o "$@"
65 fi
66 }
68 cpfront_import_list() {
69 echo
70 while [ "$1" != "" ]
71 do
72 echo -n " $1"
73 shift
74 if ! [ -z "$1" ]; then
75 echo ","
76 fi
77 done
78 }
80 cpfront_main_module() {
81 local _name="$1"
82 shift
83 echo "MODULE ${_name};\n\n IMPORT $(cpfront_import_list "$@");\n\nEND ${_name}."
84 }
86 cpfront_compile() {
87 "$_compiler" -outcode CodeC -outsym SymC "$@"
88 }
90 cpfront_link() {
91 local _main="$1"
92 if $_docompile; then
93 cpfront_main_module "$@" > "${_main}.cp"
94 "$_compiler" -outcode CodeC -outsym SymC -main "${_main}.cp"
95 fi
96 shift
97 if $_dolink; then
98 local _list=
99 for _module in "$@" "${_main}"
100 do
101 _list="$_list ${_out}/CodeC/${_module}.c"
102 done
103 ### !!! ADD $CC $CFLAGS $LDFLAGS ###
104 gcc -m32 -g -O0 -lm -ldl -o "$_out/$_main" \
105 -Wno-int-conversion \
106 -Wno-int-to-pointer-cast \
107 -Wno-incompatible-pointer-types \
108 -Wno-implicit-function-declaration \
109 -I "$_this/C" "$_this/C/SYSTEM.c" $_list
110 fi
113 compile() {
114 case "$_target" in
115 native) native_compile "$@" ;;
116 cpfront) cpfront_compile "$@" ;;
117 *) error "compile(): unknown target $_target" ;;
118 esac
121 link() {
122 case "$_target" in
123 native) native_link "$@" ;;
124 cpfront) cpfront_link "$@" ;;
125 *) error "link(): unknown target $_target" ;;
126 esac
129 compile_all() {
130 ###^^^^^^^^^^^^^^^^^^^^^^^^###
131 ### Compile POSIX bindings ###
132 ###________________________###
134 if $_useposix; then
135 compile Posix/Mod/Ctypes.cp \
136 Posix/Mod/Csys_types.cp \
137 Posix/Mod/Cstdlib.cp Posix/Mod/Cstdio.cp Posix/Mod/Cunistd.cp \
138 Posix/Mod/Cdirent.cp Posix/Mod/Clocale.cp Posix/Mod/Ctime.cp \
139 Posix/Mod/Csys_stat.cp Posix/Mod/Cfcntl.cp Posix/Mod/Cerrno.cp \
140 Posix/Mod/Ciconv.cp Posix/Mod/Cwctype.cp Posix/Mod/Csys_mman.cp \
141 Posix/Mod/Cdlfcn.cp Posix/Mod/Csignal.cp Posix/Mod/Csetjmp.cp \
142 Posix/Mod/Clibgen.cp \
143 Posix/Mod/Cmacro.cp
144 fi
146 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
147 ### Compile BlackBox Framework ###
148 ###____________________________###
150 compile System/Mod/Int.odc
151 if [ "$_target" = "native" ]; then
152 compile System/Mod/Long.odc
153 compile System/Mod/Math.odc System/Mod/SMath.odc
154 else
155 compile System/Mod/Math.cp System/Mod/SMath.cp
156 fi
157 compile System/Mod/Kernel.cp \
158 System/Mod/Console.odc System/Mod/Files.odc System/Mod/Dates.odc \
159 System/Mod/Log.odc System/Mod/Strings.odc System/Mod/Services.odc \
160 System/Mod/Integers.odc
162 if [ "$_target" = "native" ]; then
163 mv -t System Code Sym
164 fi
166 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
167 ### Compile Linux Host subsystem ###
168 ###______________________________###
170 compile Host/Mod/Lang.cp Host/Mod/Dates.cp Host/Mod/Console.cp \
171 Host/Mod/Files.cp
173 ###^^^^^^^^^^^^^^^^^^^^^^^###
174 ### Compile Dev subsystem ###
175 ###_______________________###
177 compile Dev/Mod/CPM.cp Dev/Mod/CPT.odc Dev/Mod/CPS.odc Dev/Mod/CPB.odc \
178 Dev/Mod/CPP.odc Dev/Mod/CPE.odc Dev/Mod/CPH.odc Dev/Mod/CPL486.odc \
179 Dev/Mod/CPC486.odc Dev/Mod/CPV486.odc
181 ###^^^^^^^^^^^^^^^^^^^^^^^^###
182 ### Compile Dev2 subsystem ###
183 ###________________________###
185 compile Dev2/Mod/LnkBase.odc Dev2/Mod/LnkChmod.odc Dev2/Mod/LnkLoad.odc \
186 Dev2/Mod/LnkWriteElf.odc Dev2/Mod/LnkWriteElfStatic.odc \
187 Dev2/Mod/LnkWritePe.odc
189 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^###
190 ### Compile CPfront subsystem ###
191 ###___________________________###
193 compile CPfront/Mod/CPG.odc CPfront/Mod/CPC.odc CPfront/Mod/CPV.odc
195 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
196 ### Compile bbdsw-specific modules ###
197 ###________________________________###
199 if [ "$_target" = "native" ]; then
200 compile Dsw/Mod/Debug.odc
201 fi
202 compile Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Compiler486Main.cp \
203 Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp
206 link_all() {
207 local _debug_module=
208 if [ "$_target" = "native" ]; then
209 _debug_module=DswDebug
210 fi
212 link cpc486 \
213 PosixCtypes PosixCmacro \
214 Kernel Console Files Dates Math Strings Services Log \
215 HostLang HostConsole HostFiles HostDates DswLog $_debug_module \
216 DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
217 DevCPL486 DevCPC486 DevCPV486 \
218 DswDocuments DswCompiler486Main
220 link cpl486 \
221 PosixCtypes PosixCmacro \
222 Kernel Console Files Math Strings Services Log \
223 HostLang HostConsole HostFiles DswLog $_debug_module \
224 Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \
225 Dev2LnkWriteElfStatic Dev2LnkWritePe \
226 DswLinker486Main
228 link cpfront \
229 PosixCtypes PosixCmacro \
230 Kernel Console Files Dates Math Strings Services Log \
231 HostLang HostConsole HostFiles HostDates DswLog $_debug_module \
232 DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
233 CPfrontCPG CPfrontCPC CPfrontCPV\
234 DswDocuments DswCompilerCPfrontMain
236 if $_dolink; then
237 chmod a+x cpc486 cpl486 cpfront
238 fi
241 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
242 ### Parse arguments and options ###
243 ###_____________________________###
245 while getopts c:l:o:bxh _name
246 do
247 case "$_name" in
248 c) _compiler="$OPTARG" ;;
249 l) _linker="$OPTARG" ;;
250 o) _out="$OPTARG" ;;
251 b) _docompile=false ;;
252 x) _dolink=false ;;
253 h|?) usage ;;
254 esac
255 done
257 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
258 usage
259 fi
261 shift $(($OPTIND - 1))
262 _cpu="$1"
263 _target="$2"
264 _system="$3"
266 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
267 ### Check for supported cpu/target/os ###
268 ###___________________________________###
270 case "$_cpu" in
271 386|486|586|686) _cpu=486 ;;
272 "") error "cpu not specified" ;;
273 *) error "unsupported cpu $_cpu" ;;
274 esac
276 case "$_target" in
277 native) _target=native ;;
278 cpfront|c) _target=cpfront ;;
279 "") error "target not specified" ;;
280 *) error "unsupported target $_target" ;;
281 esac
283 case "$_system" in
284 linux) _useposix=true ;;
285 "") error "operation system not specified" ;;
286 *) error "unsuported operation system $_system" ;;
287 esac
289 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
290 ### Select default compiler if not specified ###
291 ###__________________________________________###
293 if [ -z "$_compiler" ]; then
294 case "$_target" in
295 native)
296 case "$_cpu" in
297 486) _compiler=cpc486 ;;
298 *) error "no standard compiler for cpu $_cpu" ;;
299 esac
300 ;;
301 cpfront) _compiler=cpfront ;;
302 *) error "no standard compiler for target $_target" ;;
303 esac
304 fi
306 if [ -z "$_linker" ]; then
307 case "$_target" in
308 native)
309 case "$_cpu" in
310 486) _linker=cpl486 ;;
311 *) error "no standard linker for cpu $_cpu" ;;
312 esac
313 ;;
314 cpfront) _linker= ;;
315 *) error "no standard linker for target $_target" ;;
316 esac
317 fi
319 if $_docompile; then
320 if command -v "$_compiler" > /dev/null; then
321 _compiler="$(command -v "$_compiler")"
322 else
323 error "compiler not installed!"
324 fi
325 fi
327 if $_dolink && [ "$_target" != "cpfront" ]; then
328 if command -v "$_linker" > /dev/null; then
329 _linker="$(command -v "$_linker")"
330 else
331 error "linker not installed!"
332 fi
333 fi
335 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
336 ### Copy sources for changed system ###
337 ###_________________________________###
339 $_docompile && rm -rf -- "$_out"
341 mkdir -p -- "$_out"
342 _out="$(readlink -f "$_out")"
343 copy_source "generic" "$_cpu"
344 if $_useposix; then
345 copy_source "posix/generic" "posix/$_cpu"
346 fi
347 copy_source "$_system/generic" "$_system/$_cpu"
348 copy_source "$_target/generic" "$_target/$_cpu"
349 if $_useposix; then
350 copy_source "$_target/posix/generic" "$_target/posix/$_cpu"
351 fi
352 copy_source "$_target/$_system/generic" "$_target/$_system/$_cpu"
353 cd "$_out"
355 ###^^^^^^^^^^^^^^^###
356 ### Build modules ###
357 ###_______________###
359 if $_docompile; then
360 compile_all
361 fi
363 ###^^^^^^^^^^^^^^###
364 ### Link modules ###
365 ###______________###
367 link_all