5 ###^^^^^^^^^^^^^^^^^^###
6 ### Global variables ###
7 ###__________________###
10 _this
="$(dirname "$(readlink -f "$0")")"
27 echo "Usage
: make.sh
[options
] cpu target os
"
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
"
35 echo " 486 Intel
486+"
36 echo " arm ARM
32-bit"
39 echo " cpfront Generic C
"
40 echo "Operation systems
:"
41 echo " linux GNU
/Linux
"
43 echo "Environment variables
:"
44 echo " CC C compiler binary
"
45 echo " CFLAGS C compiler options
"
57 if test -d "$_this/src
/$_src"; then
58 find "$_this/src
/$_src" -mindepth 1 -maxdepth 1 -exec cp -rt "$_out" -- {} +
64 "$_compiler" -legacy "$@
"
70 local _outsystem="$_system"
71 if [ "$_system" = "cygwin
" ]; then
72 _outexe="${_outexe}.exe
"
76 "$_linker" -os "$_outsystem" -kernel Kernel -main Kernel -legacycodedir . -o "$_outexe" "$@
"
80 cpfront_import_list() {
86 if ! [ -z "$1" ]; then
92 cpfront_main_module() {
95 echo "MODULE
${_name};"
97 echo " IMPORT
$(cpfront_import_list "$@");"
103 "$_compiler" -outcode CodeC -outsym SymC "$@
"
109 cpfront_main_module "$@
" > "${_main}.
cp"
110 "$_compiler" -outcode CodeC -outsym SymC -main "${_main}.
cp"
115 for _module in "$@
" "${_main}"
117 _list="$_list ${_out}/CodeC
/${_module}.c
"
121 *gcc) _cc_cflags="-Wno-int-conversion -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types -Wno-implicit-function-declaration" ;;
126 486) _cpu_cflags="-m32" ;;
127 arm) _cpu_cflags="" ;;
128 *) error "cpfront_link
(): unsupported cpu
$_cpu" ;;
130 local _system_cflags=
132 cygwin) _system_cflags="-liconv" ;;
133 *) _system_cflags="" ;;
135 "$CC" $_cc_cflags $_cpu_cflags $CFLAGS -o "${_main}" -I "$_this/C
" "$_this/C
/SYSTEM.c
" $_list -lm -ldl $_system_cflags
141 native) native_compile "$@
" ;;
142 cpfront) cpfront_compile "$@
" ;;
143 *) error "compile
(): unknown target
$_target" ;;
149 native) native_link "$@
" ;;
150 cpfront) cpfront_link "$@
" ;;
151 *) error "link
(): unknown target
$_target" ;;
156 ###^^^^^^^^^^^^^^^^^^^^^^^^###
157 ### Compile POSIX bindings ###
158 ###________________________###
161 compile Posix/Mod/Ctypes.cp \
162 Posix/Mod/Csys_types.cp \
163 Posix/Mod/Cstdlib.cp Posix/Mod/Cstdio.cp Posix/Mod/Cunistd.cp \
164 Posix/Mod/Cdirent.cp Posix/Mod/Clocale.cp Posix/Mod/Ctime.cp \
165 Posix/Mod/Csys_stat.cp Posix/Mod/Cfcntl.cp Posix/Mod/Cerrno.cp \
166 Posix/Mod/Ciconv.cp Posix/Mod/Cwctype.cp Posix/Mod/Csys_mman.cp \
167 Posix/Mod/Cdlfcn.cp Posix/Mod/Csignal.cp Posix/Mod/Csetjmp.cp \
168 Posix/Mod/Clibgen.cp \
172 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
173 ### Compile BlackBox Framework ###
174 ###____________________________###
176 compile System/Mod/Int.odc
177 if [ "$_target" = "native
" ]; then
178 compile System/Mod/Long.odc
179 compile System/Mod/Math.odc System/Mod/SMath.odc
181 compile System/Mod/Math.cp System/Mod/SMath.cp
183 compile System/Mod/Kernel.cp \
184 System/Mod/Console.odc System/Mod/Files.odc System/Mod/Dates.odc \
185 System/Mod/Log.odc System/Mod/Strings.odc System/Mod/Services.odc \
186 System/Mod/Integers.odc
188 if [ "$_target" = "native
" ]; then
189 compile System/Mod/Meta.odc
190 mv -t System Code Sym
193 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
194 ### Compile Linux Host subsystem ###
195 ###______________________________###
197 compile Host/Mod/Lang.cp Host/Mod/Dates.cp Host/Mod/Console.cp \
200 ###^^^^^^^^^^^^^^^^^^^^^^^###
201 ### Compile Dev subsystem ###
202 ###_______________________###
204 compile Dev/Mod/CPM.cp Dev/Mod/CPT.odc Dev/Mod/CPS.odc Dev/Mod/CPB.odc \
205 Dev/Mod/CPP.odc Dev/Mod/CPE.odc Dev/Mod/CPH.odc Dev/Mod/CPL486.odc \
206 Dev/Mod/CPC486.odc Dev/Mod/CPV486.odc
208 ###^^^^^^^^^^^^^^^^^^^^^^^^###
209 ### Compile Dev2 subsystem ###
210 ###________________________###
212 compile Dev2/Mod/LnkBase.odc Dev2/Mod/LnkChmod.odc Dev2/Mod/LnkLoad.odc \
213 Dev2/Mod/LnkWriteElf.odc Dev2/Mod/LnkWriteElfStatic.odc \
214 Dev2/Mod/LnkWritePe.odc
216 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^###
217 ### Compile CPfront subsystem ###
218 ###___________________________###
220 compile CPfront/Mod/CPG.odc CPfront/Mod/CPC.odc CPfront/Mod/CPV.odc
222 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
223 ### Compile bbdsw-specific modules ###
224 ###________________________________###
226 if [ "$_target" = "native
" ]; then
227 compile Dsw/Mod/Debug.odc
229 compile Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Compiler486Main.cp \
230 Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp
235 if [ "$_target" = "native
" ]; then
236 _debug_module=DswDebug
240 PosixCtypes PosixCmacro \
241 Kernel Console Files Dates Math Strings Services Log \
242 HostLang HostConsole HostFiles HostDates DswLog $_debug_module \
243 DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
244 DevCPL486 DevCPC486 DevCPV486 \
245 DswDocuments DswCompiler486Main
248 PosixCtypes PosixCmacro \
249 Kernel Console Files Math Strings Services Log \
250 HostLang HostConsole HostFiles DswLog $_debug_module \
251 Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \
252 Dev2LnkWriteElfStatic Dev2LnkWritePe \
256 PosixCtypes PosixCmacro \
257 Kernel Console Files Dates Math Strings Services Log \
258 HostLang HostConsole HostFiles HostDates DswLog $_debug_module \
259 DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
260 CPfrontCPG CPfrontCPC CPfrontCPV\
261 DswDocuments DswCompilerCPfrontMain
264 chmod a+x cpc486 cpl486 cpfront
268 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
269 ### Parse arguments and options ###
270 ###_____________________________###
272 while getopts c:l:o:bxh _name
275 c) _compiler="$OPTARG" ;;
276 l) _linker="$OPTARG" ;;
278 b) _docompile=false ;;
284 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
288 shift $(($OPTIND - 1))
293 if [ -z "$CC" ]; then
297 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
298 ### Check for supported cpu/target/os ###
299 ###___________________________________###
302 386|486|586|686) _cpu=486 ;;
303 arm|armv6|armv7) _cpu=arm ;;
304 "") error "cpu not specified
" ;;
305 *) error "unsupported cpu
$_cpu" ;;
309 native) _target=native ;;
310 cpfront|c) _target=cpfront ;;
311 "") error "target not specified
" ;;
312 *) error "unsupported target
$_target" ;;
316 linux) _useposix=true ;;
317 cygwin) _useposix=true ;;
318 "") error "operation system not specified
" ;;
319 *) error "unsuported operation system
$_system" ;;
322 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
323 ### Select default compiler if not specified ###
324 ###__________________________________________###
326 if [ -z "$_compiler" ]; then
330 486) _compiler=cpc486 ;;
331 *) error "no standard compiler
for cpu
$_cpu" ;;
334 cpfront) _compiler=cpfront ;;
335 *) error "no standard compiler
for target
$_target" ;;
339 if [ -z "$_linker" ]; then
343 486) _linker=cpl486 ;;
344 *) error "no standard linker
for cpu
$_cpu" ;;
348 *) error "no standard linker
for target
$_target" ;;
353 if command -v "$_compiler" > /dev/null; then
354 _compiler="$(command -v "$_compiler")"
356 error "compiler not installed
!"
360 if $_dolink && [ "$_target" != "cpfront
" ]; then
361 if command -v "$_linker" > /dev/null; then
362 _linker="$(command -v "$_linker")"
364 error "linker not installed
!"
368 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
369 ### Copy sources for changed system ###
370 ###_________________________________###
377 _out="$(readlink -f "$_out")"
378 copy_source "generic
" "$_cpu"
380 copy_source "posix
/generic
" "posix
/$_cpu"
382 copy_source "$_system/generic
" "$_system/$_cpu"
383 copy_source "$_target/generic
" "$_target/$_cpu"
385 copy_source "$_target/posix
/generic
" "$_target/posix
/$_cpu"
387 copy_source "$_target/$_system/generic
" "$_target/$_system/$_cpu"
390 ###^^^^^^^^^^^^^^^###
391 ### Build modules ###
392 ###_______________###