6 [[ "$1" == /* ]] && echo "$1" ||
echo "$(pwd)/$1"
9 ###^^^^^^^^^^^^^^^^^^###
10 ### Global variables ###
11 ###__________________###
14 _this
="$(dirname "$
(abspath
"$0")")"
26 export CPCFLAGS
="$CPCFLAGS"
27 export CPLFLAGS
="$CPLFLAGS"
34 echo "Usage: make.sh [options] cpu target os"
36 echo " -c path Path to compiler binary"
37 echo " -l path Path to linker binary"
38 echo " -o path Path to output binaries"
39 echo " -b Do not compile"
40 echo " -x Do not link"
42 echo " 486 Intel 486+"
43 echo " arm ARM 32-bit"
44 echo " powerpc PowerPC 32-bit"
47 echo " cpfront Generic C"
48 echo "Operation systems:"
49 echo " linux GNU/Linux"
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"
68 if test -d "$_this/src/$_src"; then
69 find "$_this/src/$_src" -mindepth 1 -maxdepth 1 -exec cp -r {} "$_out" \
;
75 "$_compiler" $CPCFLAGS -legacy "$@"
81 local _outsystem
="$_system"
82 if [ "$_system" = "cygwin" ]; then
83 _outexe
="${_outexe}.exe"
85 elif [ "$_system" = "osx" ]; then
86 _outexe
="${_outexe}.out"
89 "$_linker" $CPLFALGS -os "$_outsystem" -kernel Kernel
-main Kernel
-legacycodedir .
-o "$_outexe" "$@"
93 cpfront_import_list
() {
99 if ! [ -z "$1" ]; then
105 cpfront_main_module
() {
108 echo "MODULE ${_name};"
110 echo " IMPORT $(cpfront_import_list "$@
");"
116 "$_compiler" $CPCFLAGS -outcode CodeC
-outsym SymC
"$@"
122 cpfront_main_module
"$@" > "${_main}.cp"
123 "$_compiler" $CPCFLAGS -outcode CodeC
-outsym SymC
-main "${_main}.cp"
128 for _module
in "$@" "${_main}"
130 _list
="$_list ${_out}/CodeC/${_module}.c"
134 *gcc
) _cc_cflags
="-std=c89 -Wno-int-conversion -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types -Wno-implicit-function-declaration" ;;
135 *gcc-4.2
) _cc_cflags
="-std=c89 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-implicit-function-declaration" ;;
136 clang|clang-
*) _cc_cflags
="-std=c89 -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-logical-op-parentheses -Wno-bitwise-op-parentheses -Wno-pointer-sign -Wno-unused-value -Wno-return-type" ;;
137 *tcc
) _cc_cflags
="-std=c89 -w -fsigned-char" ;;
142 486) _cpu_cflags
="-m32" ;;
143 arm
) _cpu_cflags
="" ;;
144 powerpc
) _cpu_cflags
="-m32" ;;
145 *) error
"cpfront_link(): unsupported cpu $_cpu" ;;
147 local _system_cflags
=
149 cygwin
) _system_cflags
="-liconv" ;;
150 osx
) _system_cflags
="-D_DARWIN_C_SOURCE -liconv" ;;
151 *) _system_cflags
="" ;;
153 local _out_exe
="${_main}"
155 cygwin
) _out_exe
="${_main}.exe" ;;
156 osx
) _out_exe
="${_main}.out" ;;
159 "$CC" -g -D_XOPEN_SOURCE=700 $_cc_cflags $_cpu_cflags $CFLAGS -o "${_out_exe}" -I "$_this/C" "$_this/C/SYSTEM.c" $_list -lm -ldl -lffi $_system_cflags
165 native
) native_compile
"$@" ;;
166 cpfront
) cpfront_compile
"$@" ;;
167 *) error
"compile(): unknown target $_target" ;;
173 native
) native_link
"$@" ;;
174 cpfront
) cpfront_link
"$@" ;;
175 *) error
"link(): unknown target $_target" ;;
180 ###^^^^^^^^^^^^^^^^^^^^^^^^###
181 ### Compile POSIX bindings ###
182 ###________________________###
185 compile Posix
/Mod
/Ctypes.
cp \
186 Posix
/Mod
/Csys_types.
cp \
187 Posix
/Mod
/Cstdlib.
cp Posix
/Mod
/Cstdio.
cp Posix
/Mod
/Cunistd.
cp \
188 Posix
/Mod
/Cdirent.
cp Posix
/Mod
/Clocale.
cp Posix
/Mod
/Ctime.
cp \
189 Posix
/Mod
/Csys_stat.
cp Posix
/Mod
/Cfcntl.
cp Posix
/Mod
/Cerrno.
cp \
190 Posix
/Mod
/Ciconv.
cp Posix
/Mod
/Cwctype.
cp Posix
/Mod
/Csys_mman.
cp \
191 Posix
/Mod
/Cdlfcn.
cp Posix
/Mod
/Csignal.
cp Posix
/Mod
/Csetjmp.
cp \
192 Posix
/Mod
/Clibgen.
cp Posix
/Mod
/Csys_wait.
cp \
194 if [ "$_target" = "cpfront" ]; then
195 compile Lib
/Mod
/FFI.
cp
199 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
200 ### Compile BlackBox Framework ###
201 ###____________________________###
203 compile System
/Mod
/Int.odc
204 if [ "$_target" = "native" ]; then
205 compile System
/Mod
/Long.odc
206 compile System
/Mod
/Math.odc System
/Mod
/SMath.odc
208 compile System
/Mod
/Math.
cp System
/Mod
/SMath.
cp
210 compile System
/Mod
/Kernel.
cp \
211 System
/Mod
/Console.odc System
/Mod
/Files.odc System
/Mod
/Dates.odc \
212 System
/Mod
/Log.odc System
/Mod
/Strings.odc System
/Mod
/Meta.odc \
213 System
/Mod
/Services.odc System
/Mod
/Integers.odc
215 if [ "$_target" = "native" ]; then
216 mv -t System Code Sym
219 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
220 ### Compile Linux Host subsystem ###
221 ###______________________________###
223 compile Host
/Mod
/Lang.
cp Host
/Mod
/Dates.
cp Host
/Mod
/Console.
cp \
226 ###^^^^^^^^^^^^^^^^^^^^^^^###
227 ### Compile Dev subsystem ###
228 ###_______________________###
230 compile Dev
/Mod
/CPM.
cp Dev
/Mod
/CPT.odc Dev
/Mod
/CPR.
cp Dev
/Mod
/CPS.odc \
231 Dev
/Mod
/CPB.odc Dev
/Mod
/CPP.odc Dev
/Mod
/CPE.odc Dev
/Mod
/CPH.odc \
232 Dev
/Mod
/CPL486.odc Dev
/Mod
/CPC486.odc Dev
/Mod
/CPV486.odc
234 ###^^^^^^^^^^^^^^^^^^^^^^^^###
235 ### Compile Dev2 subsystem ###
236 ###________________________###
238 compile Dev
2/Mod
/LnkBase.odc Dev
2/Mod
/LnkChmod.odc Dev
2/Mod
/LnkLoad.odc \
239 Dev
2/Mod
/LnkWriteElf.odc Dev
2/Mod
/LnkWriteElfStatic.odc \
240 Dev
2/Mod
/LnkWritePe.odc
242 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^###
243 ### Compile CPfront subsystem ###
244 ###___________________________###
246 compile CPfront
/Mod
/CPG.odc CPfront
/Mod
/CPC.odc CPfront
/Mod
/CPV.odc
248 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
249 ### Compile bbdsw-specific modules ###
250 ###________________________________###
252 if [ "$_target" = "native" ]; then
253 compile Dsw
/Mod
/Debug.odc
256 compile Dsw
/Mod
/Documents.
cp Dsw
/Mod
/Log.odc Dsw
/Mod
/Opts.
cp Dsw
/Mod
/Procs.
cp
257 compile Dsw
/Mod
/HostProcs.
cp
259 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^###
260 ### Compile bbdsw executables ###
261 ###___________________________###
264 Dsw
/Mod
/Compiler486Main.
cp \
265 Dsw
/Mod
/CompilerCPfrontMain.
cp \
266 Dsw
/Mod
/Linker486Main.
cp \
272 if [ "$_target" = "native" ]; then
273 _debug_module
=DswDebug
277 PosixCtypes PosixCmacro \
278 Kernel Console Files Dates Math Strings Services Log \
279 HostLang HostConsole HostFiles HostDates DswLog
$_debug_module \
280 DevCPM DevCPT DevCPR DevCPS DevCPB DevCPP DevCPE DevCPH \
281 DevCPL486 DevCPC486 DevCPV486 \
282 DswDocuments DswCompiler486Main
285 PosixCtypes PosixCmacro \
286 Kernel Console Files Math Strings Services Log \
287 HostLang HostConsole HostFiles DswLog
$_debug_module \
288 Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \
289 Dev2LnkWriteElfStatic Dev2LnkWritePe \
293 PosixCtypes PosixCmacro \
294 Kernel Console Files Dates Math Strings Services Log \
295 HostLang HostConsole HostFiles HostDates DswLog
$_debug_module \
296 DevCPM DevCPT DevCPR DevCPS DevCPB DevCPP DevCPE DevCPH \
297 CPfrontCPG CPfrontCPC CPfrontCPV\
298 DswDocuments DswCompilerCPfrontMain
301 PosixCtypes PosixCmacro \
302 Kernel Console Files Dates Math Strings Services Log \
303 HostLang HostConsole HostFiles HostDates DswLog
$_debug_module \
304 DevCPM DevCPT DevCPR DevCPS \
305 DswDocuments DswOpts DswProcs DswHostProcs DswMakeMain
308 if [ "$_system" = "osx" ]; then
309 chmod a
+x cpc486.out cpl486.out cpfront.out
311 chmod a
+x cpc486 cpl486 cpfront
316 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
317 ### Parse arguments and options ###
318 ###_____________________________###
320 while getopts c
:l
:o
:bxh _name
323 c
) _compiler
="$OPTARG" ;;
324 l
) _linker
="$OPTARG" ;;
326 b
) _docompile
=false
;;
332 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
336 shift $
(($OPTIND - 1))
341 if [ -z "$CC" ]; then
345 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
346 ### Check for supported cpu/target/os ###
347 ###___________________________________###
350 386|
486|
586|
686) _cpu
=486 ;;
351 arm|armv6|armv7
) _cpu
=arm
;;
352 powerpc|ppc|ppc32
) _cpu
=powerpc
;;
353 "") error
"cpu not specified" ;;
354 *) error
"unsupported cpu $_cpu" ;;
358 native
) _target
=native
;;
359 cpfront|c
) _target
=cpfront
;;
360 "") error
"target not specified" ;;
361 *) error
"unsupported target $_target" ;;
365 linux
) _useposix
=true
;;
366 cygwin
) _useposix
=true
;;
367 osx
) _useposix
=true
;;
368 "") error
"operation system not specified" ;;
369 *) error
"unsuported operation system $_system" ;;
372 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
373 ### Select default compiler if not specified ###
374 ###__________________________________________###
376 if [ -z "$_compiler" ]; then
380 486) _compiler
=cpc486
;;
381 *) error
"no standard compiler for cpu $_cpu" ;;
384 cpfront
) _compiler
=cpfront
;;
385 *) error
"no standard compiler for target $_target" ;;
389 if [ -z "$_linker" ]; then
393 486) _linker
=cpl486
;;
394 *) error
"no standard linker for cpu $_cpu" ;;
398 *) error
"no standard linker for target $_target" ;;
403 if command -v "$_compiler" > /dev
/null
; then
404 _compiler
="$(command -v "$_compiler")"
406 error
"compiler not installed!"
410 if $_dolink && [ "$_target" != "cpfront" ]; then
411 if command -v "$_linker" > /dev
/null
; then
412 _linker
="$(command -v "$_linker")"
414 error
"linker not installed!"
418 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
419 ### Copy sources for changed system ###
420 ###_________________________________###
427 _out
="$(abspath "$_out")"
428 copy_source
"generic" "$_cpu"
430 copy_source
"posix/generic" "posix/$_cpu"
432 copy_source
"$_system/generic" "$_system/$_cpu"
433 copy_source
"$_target/generic" "$_target/$_cpu"
435 copy_source
"$_target/posix/generic" "$_target/posix/$_cpu"
437 copy_source
"$_target/$_system/generic" "$_target/$_system/$_cpu"
440 ###^^^^^^^^^^^^^^^###
441 ### Build modules ###
442 ###_______________###