5 ###^^^^^^^^^^^^^^^^^^###
6 ### Global variables ###
7 ###__________________###
10 _this
="$(dirname "$(readlink -f "$0")")"
22 export CPCFLAGS="$CPCFLAGS"
23 export CPLFLAGS="$CPLFLAGS"
30 echo "Usage
: make.sh
[options
] cpu target os
"
32 echo " -c path Path to compiler binary
"
33 echo " -l path Path to linker binary
"
34 echo " -o path Path to output binaries
"
35 echo " -b Do not compile
"
36 echo " -x Do not link
"
38 echo " 486 Intel
486+"
39 echo " arm ARM
32-bit"
42 echo " cpfront Generic C
"
43 echo "Operation systems
:"
44 echo " linux GNU
/Linux
"
46 echo "Environment variables
:"
47 echo " CC C compiler binary
"
48 echo " CFLAGS C compiler options
"
49 echo " CPCFLAGS CPC compiler options
"
50 echo " CPLFLAGS CPL linker options
"
62 if test -d "$_this/src
/$_src"; then
63 find "$_this/src
/$_src" -mindepth 1 -maxdepth 1 -exec cp -rt "$_out" -- {} +
69 "$_compiler" $CPCFLAGS -legacy "$@
"
75 local _outsystem="$_system"
76 if [ "$_system" = "cygwin
" ]; then
77 _outexe="${_outexe}.exe
"
81 "$_linker" $CPLFALGS -os "$_outsystem" -kernel Kernel -main Kernel -legacycodedir . -o "$_outexe" "$@
"
85 cpfront_import_list() {
91 if ! [ -z "$1" ]; then
97 cpfront_main_module() {
100 echo "MODULE
${_name};"
102 echo " IMPORT
$(cpfront_import_list "$@");"
108 "$_compiler" $CPCFLAGS -outcode CodeC -outsym SymC "$@
"
114 cpfront_main_module "$@
" > "${_main}.
cp"
115 "$_compiler" $CPCFLAGS -outcode CodeC -outsym SymC -main "${_main}.
cp"
120 for _module in "$@
" "${_main}"
122 _list="$_list ${_out}/CodeC
/${_module}.c
"
126 *gcc) _cc_cflags="-std=c89
-Wno-int-conversion -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types -Wno-implicit-function-declaration" ;;
127 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" ;;
128 *tcc) _cc_cflags="-std=c89
-w -fsigned-char" ;;
133 486) _cpu_cflags="-m32" ;;
134 arm) _cpu_cflags="" ;;
135 *) error "cpfront_link
(): unsupported cpu
$_cpu" ;;
137 local _system_cflags=
139 cygwin) _system_cflags="-liconv" ;;
140 *) _system_cflags="" ;;
142 "$CC" -g -D_XOPEN_SOURCE=700 $_cc_cflags $_cpu_cflags $CFLAGS -o "${_main}" -I "$_this/C
" "$_this/C
/SYSTEM.c
" $_list -lm -ldl -lffi $_system_cflags
148 native) native_compile "$@
" ;;
149 cpfront) cpfront_compile "$@
" ;;
150 *) error "compile
(): unknown target
$_target" ;;
156 native) native_link "$@
" ;;
157 cpfront) cpfront_link "$@
" ;;
158 *) error "link
(): unknown target
$_target" ;;
163 ###^^^^^^^^^^^^^^^^^^^^^^^^###
164 ### Compile POSIX bindings ###
165 ###________________________###
168 compile Posix/Mod/Ctypes.cp \
169 Posix/Mod/Csys_types.cp \
170 Posix/Mod/Cstdlib.cp Posix/Mod/Cstdio.cp Posix/Mod/Cunistd.cp \
171 Posix/Mod/Cdirent.cp Posix/Mod/Clocale.cp Posix/Mod/Ctime.cp \
172 Posix/Mod/Csys_stat.cp Posix/Mod/Cfcntl.cp Posix/Mod/Cerrno.cp \
173 Posix/Mod/Ciconv.cp Posix/Mod/Cwctype.cp Posix/Mod/Csys_mman.cp \
174 Posix/Mod/Cdlfcn.cp Posix/Mod/Csignal.cp Posix/Mod/Csetjmp.cp \
175 Posix/Mod/Clibgen.cp \
177 if [ "$_target" = "cpfront
" ]; then
178 compile Lib/Mod/FFI.cp
182 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
183 ### Compile BlackBox Framework ###
184 ###____________________________###
186 compile System/Mod/Int.odc
187 if [ "$_target" = "native
" ]; then
188 compile System/Mod/Long.odc
189 compile System/Mod/Math.odc System/Mod/SMath.odc
191 compile System/Mod/Math.cp System/Mod/SMath.cp
193 compile System/Mod/Kernel.cp \
194 System/Mod/Console.odc System/Mod/Files.odc System/Mod/Dates.odc \
195 System/Mod/Log.odc System/Mod/Strings.odc System/Mod/Meta.odc \
196 System/Mod/Services.odc System/Mod/Integers.odc
198 if [ "$_target" = "native
" ]; then
199 mv -t System Code Sym
202 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
203 ### Compile Linux Host subsystem ###
204 ###______________________________###
206 compile Host/Mod/Lang.cp Host/Mod/Dates.cp Host/Mod/Console.cp \
209 ###^^^^^^^^^^^^^^^^^^^^^^^###
210 ### Compile Dev subsystem ###
211 ###_______________________###
213 compile Dev/Mod/CPM.cp Dev/Mod/CPT.odc Dev/Mod/CPS.odc Dev/Mod/CPB.odc \
214 Dev/Mod/CPP.odc Dev/Mod/CPE.odc Dev/Mod/CPH.odc Dev/Mod/CPL486.odc \
215 Dev/Mod/CPC486.odc Dev/Mod/CPV486.odc
217 ###^^^^^^^^^^^^^^^^^^^^^^^^###
218 ### Compile Dev2 subsystem ###
219 ###________________________###
221 compile Dev2/Mod/LnkBase.odc Dev2/Mod/LnkChmod.odc Dev2/Mod/LnkLoad.odc \
222 Dev2/Mod/LnkWriteElf.odc Dev2/Mod/LnkWriteElfStatic.odc \
223 Dev2/Mod/LnkWritePe.odc
225 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^###
226 ### Compile CPfront subsystem ###
227 ###___________________________###
229 compile CPfront/Mod/CPG.odc CPfront/Mod/CPC.odc CPfront/Mod/CPV.odc
231 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
232 ### Compile bbdsw-specific modules ###
233 ###________________________________###
235 if [ "$_target" = "native
" ]; then
236 compile Dsw/Mod/Debug.odc
238 compile Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Compiler486Main.cp \
239 Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp
244 if [ "$_target" = "native
" ]; then
245 _debug_module=DswDebug
249 PosixCtypes PosixCmacro \
250 Kernel Console Files Dates Math Strings Services Log \
251 HostLang HostConsole HostFiles HostDates DswLog $_debug_module \
252 DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
253 DevCPL486 DevCPC486 DevCPV486 \
254 DswDocuments DswCompiler486Main
257 PosixCtypes PosixCmacro \
258 Kernel Console Files Math Strings Services Log \
259 HostLang HostConsole HostFiles DswLog $_debug_module \
260 Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \
261 Dev2LnkWriteElfStatic Dev2LnkWritePe \
265 PosixCtypes PosixCmacro \
266 Kernel Console Files Dates Math Strings Services Log \
267 HostLang HostConsole HostFiles HostDates DswLog $_debug_module \
268 DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
269 CPfrontCPG CPfrontCPC CPfrontCPV\
270 DswDocuments DswCompilerCPfrontMain
273 chmod a+x cpc486 cpl486 cpfront
277 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
278 ### Parse arguments and options ###
279 ###_____________________________###
281 while getopts c:l:o:bxh _name
284 c) _compiler="$OPTARG" ;;
285 l) _linker="$OPTARG" ;;
287 b) _docompile=false ;;
293 if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then
297 shift $(($OPTIND - 1))
302 if [ -z "$CC" ]; then
306 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
307 ### Check for supported cpu/target/os ###
308 ###___________________________________###
311 386|486|586|686) _cpu=486 ;;
312 arm|armv6|armv7) _cpu=arm ;;
313 "") error "cpu not specified
" ;;
314 *) error "unsupported cpu
$_cpu" ;;
318 native) _target=native ;;
319 cpfront|c) _target=cpfront ;;
320 "") error "target not specified
" ;;
321 *) error "unsupported target
$_target" ;;
325 linux) _useposix=true ;;
326 cygwin) _useposix=true ;;
327 "") error "operation system not specified
" ;;
328 *) error "unsuported operation system
$_system" ;;
331 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
332 ### Select default compiler if not specified ###
333 ###__________________________________________###
335 if [ -z "$_compiler" ]; then
339 486) _compiler=cpc486 ;;
340 *) error "no standard compiler
for cpu
$_cpu" ;;
343 cpfront) _compiler=cpfront ;;
344 *) error "no standard compiler
for target
$_target" ;;
348 if [ -z "$_linker" ]; then
352 486) _linker=cpl486 ;;
353 *) error "no standard linker
for cpu
$_cpu" ;;
357 *) error "no standard linker
for target
$_target" ;;
362 if command -v "$_compiler" > /dev/null; then
363 _compiler="$(command -v "$_compiler")"
365 error "compiler not installed
!"
369 if $_dolink && [ "$_target" != "cpfront
" ]; then
370 if command -v "$_linker" > /dev/null; then
371 _linker="$(command -v "$_linker")"
373 error "linker not installed
!"
377 ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
378 ### Copy sources for changed system ###
379 ###_________________________________###
386 _out="$(readlink -f "$_out")"
387 copy_source "generic
" "$_cpu"
389 copy_source "posix
/generic
" "posix
/$_cpu"
391 copy_source "$_system/generic
" "$_system/$_cpu"
392 copy_source "$_target/generic
" "$_target/$_cpu"
394 copy_source "$_target/posix
/generic
" "$_target/posix
/$_cpu"
396 copy_source "$_target/$_system/generic
" "$_target/$_system/$_cpu"
399 ###^^^^^^^^^^^^^^^###
400 ### Build modules ###
401 ###_______________###