From 76d1e8d98f1d80d24fa52a15e6b2c6fb0a5f44d0 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 15 Jun 2019 17:07:15 +0300 Subject: [PATCH] updated build scripts --- README | 23 +- make-all.sh | 154 ++++++++ make-bootstrap.sh | 231 +++-------- make-stage0.sh | 113 ------ make-stage0c.sh | 70 ---- make-stage1.sh | 123 ------ make-stage2.sh | 123 ------ make.sh | 369 ++++++++++++++++++ .../{posix => generic}/System/Mod/Math.cp | 0 .../{posix => generic}/System/Mod/SMath.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/dirent.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/dlfcn.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/errno.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/fcntl.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/iconv.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/libgen.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/locale.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/macro.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/setjmp.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/signal.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/stdio.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/stdlib.cp | 0 .../linux/{ => 486}/C99/Mod/sys_mman.cp | 0 .../linux/{ => 486}/C99/Mod/sys_stat.cp | 0 .../linux/{ => 486}/C99/Mod/sys_types.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/time.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/types.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/unistd.cp | 0 src/cpfront/linux/{ => 486}/C99/Mod/wctype.cp | 0 .../posix/{ => generic}/System/Mod/Kernel.cp | 0 .../486}/System/Mod/Long.odc | Bin .../486}/System/Mod/Math.odc | Bin .../486}/System/Mod/SMath.odc | Bin .../linux/486}/C99/Mod/dirent.cp | 0 .../linux/486}/C99/Mod/dlfcn.cp | 0 .../linux/486}/C99/Mod/errno.cp | 0 .../linux/486}/C99/Mod/fcntl.cp | 0 .../linux/486}/C99/Mod/iconv.cp | 0 .../linux/486}/C99/Mod/libgen.cp | 0 .../linux/486}/C99/Mod/locale.cp | 0 .../linux/486}/C99/Mod/macro.cp | 0 .../linux/486}/C99/Mod/setjmp.cp | 0 .../linux/486}/C99/Mod/signal.cp | 0 .../linux/486}/C99/Mod/stdio.cp | 0 .../linux/486}/C99/Mod/stdlib.cp | 0 .../linux/486}/C99/Mod/sys_mman.cp | 0 .../linux/486}/C99/Mod/sys_stat.cp | 0 .../linux/486}/C99/Mod/sys_types.cp | 0 .../linux/486}/C99/Mod/time.cp | 0 .../linux/486}/C99/Mod/types.cp | 0 .../linux/486}/C99/Mod/unistd.cp | 0 .../linux/486}/C99/Mod/wctype.cp | 0 .../linux/generic}/System/Mod/Kernel.cp | 0 .../posix/generic}/System/Mod/Kernel.cp | 0 src/posix/{ => generic}/Host/Mod/Console.cp | 0 src/posix/{ => generic}/Host/Mod/Dates.cp | 0 src/posix/{ => generic}/Host/Mod/Files.cp | 0 src/posix/{ => generic}/Host/Mod/Lang.cp | 0 58 files changed, 584 insertions(+), 622 deletions(-) create mode 100755 make-all.sh delete mode 100755 make-stage0.sh delete mode 100755 make-stage0c.sh delete mode 100755 make-stage1.sh delete mode 100755 make-stage2.sh create mode 100755 make.sh rename src/cpfront/{posix => generic}/System/Mod/Math.cp (100%) rename src/cpfront/{posix => generic}/System/Mod/SMath.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/dirent.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/dlfcn.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/errno.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/fcntl.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/iconv.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/libgen.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/locale.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/macro.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/setjmp.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/signal.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/stdio.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/stdlib.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/sys_mman.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/sys_stat.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/sys_types.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/time.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/types.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/unistd.cp (100%) rename src/cpfront/linux/{ => 486}/C99/Mod/wctype.cp (100%) rename src/cpfront/posix/{ => generic}/System/Mod/Kernel.cp (100%) rename src/{i486/generic => native/486}/System/Mod/Long.odc (100%) rename src/{i486/generic => native/486}/System/Mod/Math.odc (100%) rename src/{i486/generic => native/486}/System/Mod/SMath.odc (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/dirent.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/dlfcn.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/errno.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/fcntl.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/iconv.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/libgen.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/locale.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/macro.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/setjmp.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/signal.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/stdio.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/stdlib.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/sys_mman.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/sys_stat.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/sys_types.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/time.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/types.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/unistd.cp (100%) rename src/{i486/linux => native/linux/486}/C99/Mod/wctype.cp (100%) rename src/{i486/linux => native/linux/generic}/System/Mod/Kernel.cp (100%) rename src/{i486/posix => native/posix/generic}/System/Mod/Kernel.cp (100%) rename src/posix/{ => generic}/Host/Mod/Console.cp (100%) rename src/posix/{ => generic}/Host/Mod/Dates.cp (100%) rename src/posix/{ => generic}/Host/Mod/Files.cp (100%) rename src/posix/{ => generic}/Host/Mod/Lang.cp (100%) diff --git a/README b/README index bb2d483..e161cdc 100644 --- a/README +++ b/README @@ -12,22 +12,27 @@ Requirements: * GNU GCC * installed multilib -1. Run make-stage0.sh to bootstrap using BlackBox Cross Platform -(https://github.com/bbcb/bbcp) or run make-stage0c.sh to bootstrap from -prebuilded C source code produced by CPfront -2. Run make-stage1.sh -3. Run make-stage2.sh -4. Grab your binaries from stage2/i486 +Stable boostrap sources and builds can be grabbed from deadsoftware.ru: +https://deadsoftware.ru/projects/cpc/release -Directory crux is a good example how of package for linux distro. +To bootstrap compiler using pretranslated C code run this: + + ./make-all.sh -b 486 native linux + +Remove flag -b if you want to bootstrap using old version of cpc. +Add flag -h if you want to known which processors/compilers/os are supported. + +After building you can grab binaries from directory stage2. + +Directory crux is a good example how to make package for linux distro. Bugs _________ -Contact to me if you found some bugs. :) +Contact me if you found some bugs. :) Licensing --------- -Any code and patches under GPLv3+ (see LICENSE file). Contact to me (DEADDOOMER) if you want +Any code and patches under GPLv3+ (see LICENSE file). Contact me if you want to use some code in your BSD-licensed BlackBox/CPfront fork or project. diff --git a/make-all.sh b/make-all.sh new file mode 100755 index 0000000..a8c5b94 --- /dev/null +++ b/make-all.sh @@ -0,0 +1,154 @@ +#! /bin/sh + +set -e + +###^^^^^^^^^^^^^^^^^^### +### Global variables ### +###__________________### + +_this="$(dirname "$(readlink -f "$0")")" +_exec="make-all.sh" +_compiler= +_linker= + +_cross=false +_bootstrap=false +_verify=true + +_cpu= +_target= +_system= +_host_cpu= +_host_system= + +###^^^^^^^^^^^### +### Functions ### +###___________### + +usage() { + echo "Usage: make-all.sh [options] cpu target os" + echo "Options:" + echo " -c path Path to compiler binary" + echo " -l path Path to linker binary" + echo " -b Bootstrap compiler (result in bootstrap/-cpfront-/)" + echo " -v Do not recompile itself (result in stage2/)" +# echo " -e Cross compile (result in stage-cross)" +# echo " -u cpu Host cpu" +# echo " -s os Host operaion system" + echo "Processors:" + echo " 486 Intel 486+" + echo "Targets:" + echo " native Native" + echo " cpfront Generic C" + echo "Operation systems:" + echo " linux GNU/Linux" + exit 2 +} + +error() { + echo "$_exec:" "$@" + exit 1 +} + +make_stage() { + local _dir="$1" + local _this_cpu="$2" + local _this_target="$3" + local _this_system="$4" + shift 4 + "$_this/make.sh" -o "$_dir" -c "$_compiler" -l "$_linker" "$@" "$_this_cpu" "$_this_target" "$_this_system" + if [ "$_target" = "cpfront" ]; then + _compiler="$_dir/cpfront" + _linker= + else + if [ "$_cpu" = "486" ]; then + _compiler="$_dir/cpc486" + _linker="$_dir/cpl486" + else + error "unsupported cpu $_cpu" + fi + fi +} + +###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### +### Parse arguments and options ### +###_____________________________### + +while getopts c:l:u:s:bveh _name +do + case "$_name" in + c) _compiler="$OPTARG" ;; + l) _linker="$OPTARG" ;; + u) _host_cpu="$OPTARG" ;; + s) _host_system="$OPTARG" ;; + b) _bootstrap=true ;; + v) _verify=false ;; + e) _cross=true ;; + h|?) usage ;; + esac +done + +if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then + usage +fi + +shift $(($OPTIND - 1)) +_cpu="$1" +_target="$2" +_system="$3" + +if [ -z "$_host_cpu" ]; then + _host_cpu="$_cpu" +fi + +if [ -z "$_host_system" ]; then + _host_system="$_system" +fi + +###^^^^^^^^^^^^^^^^^^^^^^^^^### +### Link bootstrap compiler ### +###_________________________### + +if $_bootstrap; then + echo "==> Bootstrap from C" + _compiler= + _linker= + if $_cross; then + make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_host_cpu" "cpfront" "$_host_system" -b + else + make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_cpu" "cpfront" "$_system" -b + fi +fi + +###^^^^^^^^^^^^^^^^### +### Compile stages ### +###________________### + +if $_verify; then + if $_cross; then + echo "==> Stage 0" + make_stage "$_this/stage0" "$_host_cpu" "native" "$_host_system" + echo "==> Stage 1" + make_stage "$_this/stage1" "$_host_cpu" "native" "$_host_system" + echo "==> Stage 2" + make_stage "$_this/stage2" "$_host_cpu" "native" "$_host_system" + else + echo "==> Stage 0" + make_stage "$_this/stage0" "$_cpu" "$_target" "$_system" + echo "==> Stage 1" + make_stage "$_this/stage1" "$_cpu" "$_target" "$_system" + echo "==> Stage 2" + make_stage "$_this/stage2" "$_cpu" "$_target" "$_system" + fi +fi + +###^^^^^^^^^^^^^^^### +### Cross compile ### +###_______________### + +if $_cross; then + echo "==> Build for target machine" + make_stage "$_this/stage-cross/$_cpu-$_target-$_system" "$_cpu" "$_target" "$_system" +fi + +echo "==> Done" diff --git a/make-bootstrap.sh b/make-bootstrap.sh index 8fdb3fd..3c7f446 100755 --- a/make-bootstrap.sh +++ b/make-bootstrap.sh @@ -2,189 +2,52 @@ set -e -THIS="$(dirname "$(readlink -f "$0")")" -OUT="$THIS/bootstrap/i486" - -cpc() { - "$THIS/stage2/i486/cpfront" -outcode CodeC -outsym SymC "$@" -} - -importlist() { - echo - while [ "$1" != "" ]; do - echo -n "\t\t$1" - shift - if [ "$1" != "" ]; then - echo "," - fi - done -} - -mainmodule() { -local name="$1" -shift -cat < "$name.cp" - shift - - cpc -main "$name.cp" - - local list="" - for mod in "$@" "$name"; do - list="$list CodeC/$mod.c" - done -} - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Prepare bbdsw sources for LINUX/i486 ### -###______________________________________### - -rm -rf "$OUT" -mkdir -p "$OUT" -cp -r -- \ - "$THIS/src/generic/"* \ - "$THIS/src/posix/"* \ - "$THIS/src/cpfront/posix/"* \ - "$THIS/src/cpfront/linux/"* \ - "$OUT" -cd "$OUT" - -###^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile POSIX bindings ### -###________________________### - -cpc C99/Mod/types.cp \ - C99/Mod/sys_types.cp \ - C99/Mod/stdlib.cp C99/Mod/stdio.cp C99/Mod/unistd.cp \ - C99/Mod/dirent.cp C99/Mod/locale.cp C99/Mod/time.cp \ - C99/Mod/sys_stat.cp C99/Mod/fcntl.cp C99/Mod/errno.cp \ - C99/Mod/iconv.cp C99/Mod/wctype.cp C99/Mod/sys_mman.cp \ - C99/Mod/dlfcn.cp C99/Mod/signal.cp C99/Mod/setjmp.cp \ - C99/Mod/libgen.cp \ - C99/Mod/macro.cp - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile BlackBox Framework ### -###____________________________### - -cpc System/Mod/Math.cp System/Mod/SMath.cp System/Mod/Kernel.cp \ - System/Mod/Console.odc System/Mod/Files.odc System/Mod/Dates.odc \ - System/Mod/Log.odc System/Mod/Strings.odc System/Mod/Services.odc \ - System/Mod/Int.odc System/Mod/Integers.odc - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile Linux Host subsystem ### -###______________________________### - -cpc Host/Mod/Lang.cp Host/Mod/Dates.cp Host/Mod/Console.cp Host/Mod/Files.cp - -###^^^^^^^^^^^^^^^^^^^^^^^### -### Compile Dev subsystem ### -###_______________________### - -cpc Dev/Mod/CPM.cp Dev/Mod/CPT.odc Dev/Mod/CPS.odc Dev/Mod/CPB.odc \ - Dev/Mod/CPP.odc Dev/Mod/CPE.odc Dev/Mod/CPH.odc Dev/Mod/CPL486.odc \ - Dev/Mod/CPC486.odc Dev/Mod/CPV486.odc - -###^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile Dev2 subsystem ### -###________________________### - -cpc Dev2/Mod/LnkBase.odc Dev2/Mod/LnkChmod.odc Dev2/Mod/LnkLoad.odc \ - Dev2/Mod/LnkWriteElf.odc Dev2/Mod/LnkWriteElfStatic.odc \ - Dev2/Mod/LnkWritePe.odc - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile CPfront subsystem ### -###___________________________### - -cpc CPfront/Mod/CPG.odc CPfront/Mod/CPC.odc CPfront/Mod/CPV.odc - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile bbdsw-specific modules ### -###________________________________### - -cpc Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Compiler486Main.cp \ - Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp - -###^^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile other utilities ### -###_________________________### - -cpc Dsw/Mod/ListMain.cp Dsw/Mod/EchoMain.cp Dsw/Mod/LoopMain.cp - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Link Standalone Component Pascl Compiler & Dev2 Linker ### -###________________________________________________________### - -linkall cpfront \ - C99types C99macro \ - Kernel Console Files Dates Math Strings Services Log \ - HostLang HostConsole HostFiles HostDates DswLog \ - DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \ - CPfrontCPG CPfrontCPC CPfrontCPV\ - DswDocuments DswCompilerCPfrontMain - -linkall cpc486 \ - C99types C99macro \ - Kernel Console Files Dates Math Strings Services Log \ - HostLang HostConsole HostFiles HostDates DswLog \ - DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \ - DevCPL486 DevCPC486 DevCPV486 \ - DswDocuments DswCompiler486Main - -linkall cpl486 \ - C99types C99macro \ - Kernel Console Files Math Strings Services Log \ - HostLang HostConsole HostFiles DswLog \ - Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \ - Dev2LnkWriteElfStatic Dev2LnkWritePe \ - DswLinker486Main - -#linkall cplist \ -# C99types C99macro \ -# Kernel Console Files Math Strings Services Log \ -# HostLang HostConsole HostFiles DswLog \ -# DswListMain - -#linkall cpecho \ -# C99types C99macro \ -# Kernel Console Files Math Strings Services Log \ -# HostLang HostConsole HostFiles DswLog \ -# DswEchoMain - -#linkall cploop \ -# C99types C99macro \ -# Kernel Console Files Math Strings Services Log \ -# HostLang HostConsole HostFiles DswLog \ -# DswLoopMain - -rm -rf "$THIS/bootstrap-src" -mkdir -p "$THIS/bootstrap-src" -cp -r -t "$THIS/bootstrap-src" -- \ - "$THIS/CHANGELOG" \ - "$THIS/LICENSE" \ - "$THIS/README" \ - "$THIS/man" \ - "$THIS/crux" \ - "$THIS/make-bootstrap.sh" \ - "$THIS/make-stage0.sh" \ - "$THIS/make-stage0c.sh" \ - "$THIS/make-stage1.sh" \ - "$THIS/make-stage2.sh" \ - "$THIS/src" \ - "$THIS/C" \ - CodeC - -cd "$THIS" -tar czf cpc-v0.1.src.tar.gz bootstrap-src +###^^^^^^^^^^^^^^^^^^^^### +### Prebuild C sources ### +###____________________### + +rm -rf "$_this/bootstrap" +mkdir -p "$_this/bootstrap" +make_bootstrap 486 cpfront linux + +###^^^^^^^^^^^^^^^^^^^^^^### +### Package dist sources ### +###______________________### + +rm -rf "$_this/cpc-$_version" +mkdir -p "$_this/cpc-$_version" +cp -rt "$_this/cpc-$_version" -- \ + "$_this/CHANGELOG" \ + "$_this/LICENSE" \ + "$_this/README" \ + "$_this/man" \ + "$_this/crux" \ + "$_this/make.sh" \ + "$_this/make-all.sh" \ + "$_this/make-bootstrap.sh" \ + "$_this/bootstrap" \ + "$_this/src" \ + "$_this/C" +tar czf "cpc-$_version.src.tar.gz" "cpc-$_version" diff --git a/make-stage0.sh b/make-stage0.sh deleted file mode 100755 index d6a9a3e..0000000 --- a/make-stage0.sh +++ /dev/null @@ -1,113 +0,0 @@ -#! /bin/sh - -set -e - -THIS="$(dirname "$(readlink -f "$0")")" -OUT="$THIS/stage0/i486" - -###^^^^^^^^^^^^^^^^^^### -### Check BBCP files ### -###__________________### - -mkdir -p "$THIS/stage0" -if ! [ -e "$THIS/stage0/bbcp" ]; then - echo "Please, clone bbcp repo:" - echo "-> git clone --depth=1 -b crux https://git.deadsoftware.ru/bbcp.git '$(realpath --relative-to="$PWD" "$THIS/stage0/bbcp")'" - echo "Than retry building using make-stage0.sh" - exit 1 -fi -cd "$THIS/stage0/bbcp/BlackBox" - -###^^^^^^^^^^^^^^^^^^^### -### Build BBCP itself ### -###___________________### - -./switch-target Linux Interp -./build - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Copy minimal bbdsw sources ### -###____________________________### - -rm -rf "$OUT" -mkdir -p "$OUT" -cp -r -- \ - "$THIS/src/generic/"* \ - "$THIS/src/posix/"* \ - "$THIS/src/i486/generic/"* \ - "$THIS/src/i486/posix/"* \ - "$THIS/src/i486/linux/"* \ - "$OUT" - -###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### -### Compile Stage0 Compiler & Linker ### -###__________________________________### - -./blackbox < "${_main}.cp" + "$_compiler" -outcode CodeC -outsym SymC -main "${_main}.cp" + fi + shift + if $_dolink; then + local _list= + for _module in "$@" "${_main}" + do + _list="$_list ${_out}/CodeC/${_module}.c" + done + ### !!! ADD $CC $CFLAGS $LDFLAGS ### + gcc -m32 -g -O0 -lm -ldl -o "$_out/$_main" \ + -Wno-int-conversion \ + -Wno-int-to-pointer-cast \ + -Wno-incompatible-pointer-types \ + -Wno-implicit-function-declaration \ + -I "$_this/C" "$_this/C/SYSTEM.c" $_list + fi +} + +compile() { + case "$_target" in + native) native_compile "$@" ;; + cpfront) cpfront_compile "$@" ;; + *) error "compile(): unknown target $_target" ;; + esac +} + +link() { + case "$_target" in + native) native_link "$@" ;; + cpfront) cpfront_link "$@" ;; + *) error "link(): unknown target $_target" ;; + esac +} + +compile_all() { + ###^^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile POSIX bindings ### + ###________________________### + + case "$_system" in + linux) + compile C99/Mod/types.cp \ + C99/Mod/sys_types.cp \ + C99/Mod/stdlib.cp C99/Mod/stdio.cp C99/Mod/unistd.cp \ + C99/Mod/dirent.cp C99/Mod/locale.cp C99/Mod/time.cp \ + C99/Mod/sys_stat.cp C99/Mod/fcntl.cp C99/Mod/errno.cp \ + C99/Mod/iconv.cp C99/Mod/wctype.cp C99/Mod/sys_mman.cp \ + C99/Mod/dlfcn.cp C99/Mod/signal.cp C99/Mod/setjmp.cp \ + C99/Mod/libgen.cp \ + C99/Mod/macro.cp + ;; + esac + + ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile BlackBox Framework ### + ###____________________________### + + compile System/Mod/Int.odc + if [ "$_target" = "native" ]; then + compile System/Mod/Long.odc + compile System/Mod/Math.odc System/Mod/SMath.odc + else + compile System/Mod/Math.cp System/Mod/SMath.cp + fi + compile System/Mod/Kernel.cp \ + System/Mod/Console.odc System/Mod/Files.odc System/Mod/Dates.odc \ + System/Mod/Log.odc System/Mod/Strings.odc System/Mod/Services.odc \ + System/Mod/Integers.odc + + if [ "$_target" = "native" ]; then + mv -t System Code Sym + fi + + ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile Linux Host subsystem ### + ###______________________________### + + compile Host/Mod/Lang.cp Host/Mod/Dates.cp Host/Mod/Console.cp \ + Host/Mod/Files.cp + + ###^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile Dev subsystem ### + ###_______________________### + + compile Dev/Mod/CPM.cp Dev/Mod/CPT.odc Dev/Mod/CPS.odc Dev/Mod/CPB.odc \ + Dev/Mod/CPP.odc Dev/Mod/CPE.odc Dev/Mod/CPH.odc Dev/Mod/CPL486.odc \ + Dev/Mod/CPC486.odc Dev/Mod/CPV486.odc + + ###^^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile Dev2 subsystem ### + ###________________________### + + compile Dev2/Mod/LnkBase.odc Dev2/Mod/LnkChmod.odc Dev2/Mod/LnkLoad.odc \ + Dev2/Mod/LnkWriteElf.odc Dev2/Mod/LnkWriteElfStatic.odc \ + Dev2/Mod/LnkWritePe.odc + + ###^^^^^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile CPfront subsystem ### + ###___________________________### + + compile CPfront/Mod/CPG.odc CPfront/Mod/CPC.odc CPfront/Mod/CPV.odc + + ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile bbdsw-specific modules ### + ###________________________________### + + if [ "$_target" = "native" ]; then + compile Dsw/Mod/Debug.odc + fi + compile Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Compiler486Main.cp \ + Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp +} + +link_all() { + local _debug_module= + if [ "$_target" = "native" ]; then + _debug_module=DswDebug + fi + + link cpc486 \ + C99types C99macro \ + Kernel Console Files Dates Math Strings Services Log \ + HostLang HostConsole HostFiles HostDates DswLog $_debug_module \ + DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \ + DevCPL486 DevCPC486 DevCPV486 \ + DswDocuments DswCompiler486Main + + link cpl486 \ + C99types C99macro \ + Kernel Console Files Math Strings Services Log \ + HostLang HostConsole HostFiles DswLog $_debug_module \ + Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \ + Dev2LnkWriteElfStatic Dev2LnkWritePe \ + DswLinker486Main + + link cpfront \ + C99types C99macro \ + Kernel Console Files Dates Math Strings Services Log \ + HostLang HostConsole HostFiles HostDates DswLog $_debug_module \ + DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \ + CPfrontCPG CPfrontCPC CPfrontCPV\ + DswDocuments DswCompilerCPfrontMain + + if $_dolink; then + chmod a+x cpc486 cpl486 cpfront + fi +} + +###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### +### Parse arguments and options ### +###_____________________________### + +while getopts c:l:o:bxh _name +do + case "$_name" in + c) _compiler="$OPTARG" ;; + l) _linker="$OPTARG" ;; + o) _out="$OPTARG" ;; + b) _docompile=false ;; + x) _dolink=false ;; + h|?) usage ;; + esac +done + +if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then + usage +fi + +shift $(($OPTIND - 1)) +_cpu="$1" +_target="$2" +_system="$3" + +###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### +### Check for supported cpu/target/os ### +###___________________________________### + +case "$_cpu" in + 386|486|586|686) _cpu=486 ;; + "") error "cpu not specified" ;; + *) error "unsupported cpu $_cpu" ;; +esac + +case "$_target" in + native) _target=native ;; + cpfront|c) _target=cpfront ;; + "") error "target not specified" ;; + *) error "unsupported target $_target" ;; +esac + +case "$_system" in + linux) _useposix=true ;; + "") error "operation system not specified" ;; + *) error "unsuported operation system $_system" ;; +esac + +###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### +### Select default compiler if not specified ### +###__________________________________________### + +if [ -z "$_compiler" ]; then + case "$_target" in + native) + case "$_cpu" in + 486) _compiler=cpc486 ;; + *) error "no standard compiler for cpu $_cpu" ;; + esac + ;; + cpfront) _compiler=cpfront ;; + *) error "no standard compiler for target $_target" ;; + esac +fi + +if [ -z "$_linker" ]; then + case "$_target" in + native) + case "$_cpu" in + 486) _linker=cpl486 ;; + *) error "no standard linker for cpu $_cpu" ;; + esac + ;; + cpfront) _linker= ;; + *) error "no standard linker for target $_target" ;; + esac +fi + +if $_docompile; then + if command -v "$_compiler" > /dev/null; then + _compiler="$(command -v "$_compiler")" + else + error "compiler not installed!" + fi +fi + +if $_dolink && [ "$_target" != "cpfront" ]; then + if command -v "$_linker" > /dev/null; then + _linker="$(command -v "$_linker")" + else + error "linker not installed!" + fi +fi + +###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### +### Copy sources for changed system ### +###_________________________________### + +$_docompile && rm -rf -- "$_out" + +mkdir -p -- "$_out" +_out="$(readlink -f "$_out")" +copy_source "generic" "$_cpu" +if $_useposix; then + copy_source "posix/generic" "posix/$_cpu" +fi +copy_source "$_system/generic" "$_system/$_cpu" +copy_source "$_target/generic" "$_target/$_cpu" +if $_useposix; then + copy_source "$_target/posix/generic" "$_target/posix/$_cpu" +fi +copy_source "$_target/$_system/generic" "$_target/$_system/$_cpu" +cd "$_out" + +###^^^^^^^^^^^^^^^### +### Build modules ### +###_______________### + +if $_docompile; then + compile_all +fi + +###^^^^^^^^^^^^^^### +### Link modules ### +###______________### + +link_all diff --git a/src/cpfront/posix/System/Mod/Math.cp b/src/cpfront/generic/System/Mod/Math.cp similarity index 100% rename from src/cpfront/posix/System/Mod/Math.cp rename to src/cpfront/generic/System/Mod/Math.cp diff --git a/src/cpfront/posix/System/Mod/SMath.cp b/src/cpfront/generic/System/Mod/SMath.cp similarity index 100% rename from src/cpfront/posix/System/Mod/SMath.cp rename to src/cpfront/generic/System/Mod/SMath.cp diff --git a/src/cpfront/linux/C99/Mod/dirent.cp b/src/cpfront/linux/486/C99/Mod/dirent.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/dirent.cp rename to src/cpfront/linux/486/C99/Mod/dirent.cp diff --git a/src/cpfront/linux/C99/Mod/dlfcn.cp b/src/cpfront/linux/486/C99/Mod/dlfcn.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/dlfcn.cp rename to src/cpfront/linux/486/C99/Mod/dlfcn.cp diff --git a/src/cpfront/linux/C99/Mod/errno.cp b/src/cpfront/linux/486/C99/Mod/errno.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/errno.cp rename to src/cpfront/linux/486/C99/Mod/errno.cp diff --git a/src/cpfront/linux/C99/Mod/fcntl.cp b/src/cpfront/linux/486/C99/Mod/fcntl.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/fcntl.cp rename to src/cpfront/linux/486/C99/Mod/fcntl.cp diff --git a/src/cpfront/linux/C99/Mod/iconv.cp b/src/cpfront/linux/486/C99/Mod/iconv.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/iconv.cp rename to src/cpfront/linux/486/C99/Mod/iconv.cp diff --git a/src/cpfront/linux/C99/Mod/libgen.cp b/src/cpfront/linux/486/C99/Mod/libgen.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/libgen.cp rename to src/cpfront/linux/486/C99/Mod/libgen.cp diff --git a/src/cpfront/linux/C99/Mod/locale.cp b/src/cpfront/linux/486/C99/Mod/locale.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/locale.cp rename to src/cpfront/linux/486/C99/Mod/locale.cp diff --git a/src/cpfront/linux/C99/Mod/macro.cp b/src/cpfront/linux/486/C99/Mod/macro.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/macro.cp rename to src/cpfront/linux/486/C99/Mod/macro.cp diff --git a/src/cpfront/linux/C99/Mod/setjmp.cp b/src/cpfront/linux/486/C99/Mod/setjmp.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/setjmp.cp rename to src/cpfront/linux/486/C99/Mod/setjmp.cp diff --git a/src/cpfront/linux/C99/Mod/signal.cp b/src/cpfront/linux/486/C99/Mod/signal.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/signal.cp rename to src/cpfront/linux/486/C99/Mod/signal.cp diff --git a/src/cpfront/linux/C99/Mod/stdio.cp b/src/cpfront/linux/486/C99/Mod/stdio.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/stdio.cp rename to src/cpfront/linux/486/C99/Mod/stdio.cp diff --git a/src/cpfront/linux/C99/Mod/stdlib.cp b/src/cpfront/linux/486/C99/Mod/stdlib.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/stdlib.cp rename to src/cpfront/linux/486/C99/Mod/stdlib.cp diff --git a/src/cpfront/linux/C99/Mod/sys_mman.cp b/src/cpfront/linux/486/C99/Mod/sys_mman.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/sys_mman.cp rename to src/cpfront/linux/486/C99/Mod/sys_mman.cp diff --git a/src/cpfront/linux/C99/Mod/sys_stat.cp b/src/cpfront/linux/486/C99/Mod/sys_stat.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/sys_stat.cp rename to src/cpfront/linux/486/C99/Mod/sys_stat.cp diff --git a/src/cpfront/linux/C99/Mod/sys_types.cp b/src/cpfront/linux/486/C99/Mod/sys_types.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/sys_types.cp rename to src/cpfront/linux/486/C99/Mod/sys_types.cp diff --git a/src/cpfront/linux/C99/Mod/time.cp b/src/cpfront/linux/486/C99/Mod/time.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/time.cp rename to src/cpfront/linux/486/C99/Mod/time.cp diff --git a/src/cpfront/linux/C99/Mod/types.cp b/src/cpfront/linux/486/C99/Mod/types.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/types.cp rename to src/cpfront/linux/486/C99/Mod/types.cp diff --git a/src/cpfront/linux/C99/Mod/unistd.cp b/src/cpfront/linux/486/C99/Mod/unistd.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/unistd.cp rename to src/cpfront/linux/486/C99/Mod/unistd.cp diff --git a/src/cpfront/linux/C99/Mod/wctype.cp b/src/cpfront/linux/486/C99/Mod/wctype.cp similarity index 100% rename from src/cpfront/linux/C99/Mod/wctype.cp rename to src/cpfront/linux/486/C99/Mod/wctype.cp diff --git a/src/cpfront/posix/System/Mod/Kernel.cp b/src/cpfront/posix/generic/System/Mod/Kernel.cp similarity index 100% rename from src/cpfront/posix/System/Mod/Kernel.cp rename to src/cpfront/posix/generic/System/Mod/Kernel.cp diff --git a/src/i486/generic/System/Mod/Long.odc b/src/native/486/System/Mod/Long.odc similarity index 100% rename from src/i486/generic/System/Mod/Long.odc rename to src/native/486/System/Mod/Long.odc diff --git a/src/i486/generic/System/Mod/Math.odc b/src/native/486/System/Mod/Math.odc similarity index 100% rename from src/i486/generic/System/Mod/Math.odc rename to src/native/486/System/Mod/Math.odc diff --git a/src/i486/generic/System/Mod/SMath.odc b/src/native/486/System/Mod/SMath.odc similarity index 100% rename from src/i486/generic/System/Mod/SMath.odc rename to src/native/486/System/Mod/SMath.odc diff --git a/src/i486/linux/C99/Mod/dirent.cp b/src/native/linux/486/C99/Mod/dirent.cp similarity index 100% rename from src/i486/linux/C99/Mod/dirent.cp rename to src/native/linux/486/C99/Mod/dirent.cp diff --git a/src/i486/linux/C99/Mod/dlfcn.cp b/src/native/linux/486/C99/Mod/dlfcn.cp similarity index 100% rename from src/i486/linux/C99/Mod/dlfcn.cp rename to src/native/linux/486/C99/Mod/dlfcn.cp diff --git a/src/i486/linux/C99/Mod/errno.cp b/src/native/linux/486/C99/Mod/errno.cp similarity index 100% rename from src/i486/linux/C99/Mod/errno.cp rename to src/native/linux/486/C99/Mod/errno.cp diff --git a/src/i486/linux/C99/Mod/fcntl.cp b/src/native/linux/486/C99/Mod/fcntl.cp similarity index 100% rename from src/i486/linux/C99/Mod/fcntl.cp rename to src/native/linux/486/C99/Mod/fcntl.cp diff --git a/src/i486/linux/C99/Mod/iconv.cp b/src/native/linux/486/C99/Mod/iconv.cp similarity index 100% rename from src/i486/linux/C99/Mod/iconv.cp rename to src/native/linux/486/C99/Mod/iconv.cp diff --git a/src/i486/linux/C99/Mod/libgen.cp b/src/native/linux/486/C99/Mod/libgen.cp similarity index 100% rename from src/i486/linux/C99/Mod/libgen.cp rename to src/native/linux/486/C99/Mod/libgen.cp diff --git a/src/i486/linux/C99/Mod/locale.cp b/src/native/linux/486/C99/Mod/locale.cp similarity index 100% rename from src/i486/linux/C99/Mod/locale.cp rename to src/native/linux/486/C99/Mod/locale.cp diff --git a/src/i486/linux/C99/Mod/macro.cp b/src/native/linux/486/C99/Mod/macro.cp similarity index 100% rename from src/i486/linux/C99/Mod/macro.cp rename to src/native/linux/486/C99/Mod/macro.cp diff --git a/src/i486/linux/C99/Mod/setjmp.cp b/src/native/linux/486/C99/Mod/setjmp.cp similarity index 100% rename from src/i486/linux/C99/Mod/setjmp.cp rename to src/native/linux/486/C99/Mod/setjmp.cp diff --git a/src/i486/linux/C99/Mod/signal.cp b/src/native/linux/486/C99/Mod/signal.cp similarity index 100% rename from src/i486/linux/C99/Mod/signal.cp rename to src/native/linux/486/C99/Mod/signal.cp diff --git a/src/i486/linux/C99/Mod/stdio.cp b/src/native/linux/486/C99/Mod/stdio.cp similarity index 100% rename from src/i486/linux/C99/Mod/stdio.cp rename to src/native/linux/486/C99/Mod/stdio.cp diff --git a/src/i486/linux/C99/Mod/stdlib.cp b/src/native/linux/486/C99/Mod/stdlib.cp similarity index 100% rename from src/i486/linux/C99/Mod/stdlib.cp rename to src/native/linux/486/C99/Mod/stdlib.cp diff --git a/src/i486/linux/C99/Mod/sys_mman.cp b/src/native/linux/486/C99/Mod/sys_mman.cp similarity index 100% rename from src/i486/linux/C99/Mod/sys_mman.cp rename to src/native/linux/486/C99/Mod/sys_mman.cp diff --git a/src/i486/linux/C99/Mod/sys_stat.cp b/src/native/linux/486/C99/Mod/sys_stat.cp similarity index 100% rename from src/i486/linux/C99/Mod/sys_stat.cp rename to src/native/linux/486/C99/Mod/sys_stat.cp diff --git a/src/i486/linux/C99/Mod/sys_types.cp b/src/native/linux/486/C99/Mod/sys_types.cp similarity index 100% rename from src/i486/linux/C99/Mod/sys_types.cp rename to src/native/linux/486/C99/Mod/sys_types.cp diff --git a/src/i486/linux/C99/Mod/time.cp b/src/native/linux/486/C99/Mod/time.cp similarity index 100% rename from src/i486/linux/C99/Mod/time.cp rename to src/native/linux/486/C99/Mod/time.cp diff --git a/src/i486/linux/C99/Mod/types.cp b/src/native/linux/486/C99/Mod/types.cp similarity index 100% rename from src/i486/linux/C99/Mod/types.cp rename to src/native/linux/486/C99/Mod/types.cp diff --git a/src/i486/linux/C99/Mod/unistd.cp b/src/native/linux/486/C99/Mod/unistd.cp similarity index 100% rename from src/i486/linux/C99/Mod/unistd.cp rename to src/native/linux/486/C99/Mod/unistd.cp diff --git a/src/i486/linux/C99/Mod/wctype.cp b/src/native/linux/486/C99/Mod/wctype.cp similarity index 100% rename from src/i486/linux/C99/Mod/wctype.cp rename to src/native/linux/486/C99/Mod/wctype.cp diff --git a/src/i486/linux/System/Mod/Kernel.cp b/src/native/linux/generic/System/Mod/Kernel.cp similarity index 100% rename from src/i486/linux/System/Mod/Kernel.cp rename to src/native/linux/generic/System/Mod/Kernel.cp diff --git a/src/i486/posix/System/Mod/Kernel.cp b/src/native/posix/generic/System/Mod/Kernel.cp similarity index 100% rename from src/i486/posix/System/Mod/Kernel.cp rename to src/native/posix/generic/System/Mod/Kernel.cp diff --git a/src/posix/Host/Mod/Console.cp b/src/posix/generic/Host/Mod/Console.cp similarity index 100% rename from src/posix/Host/Mod/Console.cp rename to src/posix/generic/Host/Mod/Console.cp diff --git a/src/posix/Host/Mod/Dates.cp b/src/posix/generic/Host/Mod/Dates.cp similarity index 100% rename from src/posix/Host/Mod/Dates.cp rename to src/posix/generic/Host/Mod/Dates.cp diff --git a/src/posix/Host/Mod/Files.cp b/src/posix/generic/Host/Mod/Files.cp similarity index 100% rename from src/posix/Host/Mod/Files.cp rename to src/posix/generic/Host/Mod/Files.cp diff --git a/src/posix/Host/Mod/Lang.cp b/src/posix/generic/Host/Mod/Lang.cp similarity index 100% rename from src/posix/Host/Mod/Lang.cp rename to src/posix/generic/Host/Mod/Lang.cp -- 2.29.2