DEADSOFTWARE

updated build scripts
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sat, 15 Jun 2019 14:07:15 +0000 (17:07 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Sat, 15 Jun 2019 14:07:15 +0000 (17:07 +0300)
58 files changed:
README
make-all.sh [new file with mode: 0755]
make-bootstrap.sh
make-stage0.sh [deleted file]
make-stage0c.sh [deleted file]
make-stage1.sh [deleted file]
make-stage2.sh [deleted file]
make.sh [new file with mode: 0755]
src/cpfront/generic/System/Mod/Math.cp [moved from src/cpfront/posix/System/Mod/Math.cp with 100% similarity]
src/cpfront/generic/System/Mod/SMath.cp [moved from src/cpfront/posix/System/Mod/SMath.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/dirent.cp [moved from src/cpfront/linux/C99/Mod/dirent.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/dlfcn.cp [moved from src/cpfront/linux/C99/Mod/dlfcn.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/errno.cp [moved from src/cpfront/linux/C99/Mod/errno.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/fcntl.cp [moved from src/cpfront/linux/C99/Mod/fcntl.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/iconv.cp [moved from src/cpfront/linux/C99/Mod/iconv.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/libgen.cp [moved from src/cpfront/linux/C99/Mod/libgen.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/locale.cp [moved from src/cpfront/linux/C99/Mod/locale.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/macro.cp [moved from src/cpfront/linux/C99/Mod/macro.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/setjmp.cp [moved from src/cpfront/linux/C99/Mod/setjmp.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/signal.cp [moved from src/cpfront/linux/C99/Mod/signal.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/stdio.cp [moved from src/cpfront/linux/C99/Mod/stdio.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/stdlib.cp [moved from src/cpfront/linux/C99/Mod/stdlib.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/sys_mman.cp [moved from src/cpfront/linux/C99/Mod/sys_mman.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/sys_stat.cp [moved from src/cpfront/linux/C99/Mod/sys_stat.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/sys_types.cp [moved from src/cpfront/linux/C99/Mod/sys_types.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/time.cp [moved from src/cpfront/linux/C99/Mod/time.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/types.cp [moved from src/cpfront/linux/C99/Mod/types.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/unistd.cp [moved from src/cpfront/linux/C99/Mod/unistd.cp with 100% similarity]
src/cpfront/linux/486/C99/Mod/wctype.cp [moved from src/cpfront/linux/C99/Mod/wctype.cp with 100% similarity]
src/cpfront/posix/generic/System/Mod/Kernel.cp [moved from src/cpfront/posix/System/Mod/Kernel.cp with 100% similarity]
src/native/486/System/Mod/Long.odc [moved from src/i486/generic/System/Mod/Long.odc with 100% similarity]
src/native/486/System/Mod/Math.odc [moved from src/i486/generic/System/Mod/Math.odc with 100% similarity]
src/native/486/System/Mod/SMath.odc [moved from src/i486/generic/System/Mod/SMath.odc with 100% similarity]
src/native/linux/486/C99/Mod/dirent.cp [moved from src/i486/linux/C99/Mod/dirent.cp with 100% similarity]
src/native/linux/486/C99/Mod/dlfcn.cp [moved from src/i486/linux/C99/Mod/dlfcn.cp with 100% similarity]
src/native/linux/486/C99/Mod/errno.cp [moved from src/i486/linux/C99/Mod/errno.cp with 100% similarity]
src/native/linux/486/C99/Mod/fcntl.cp [moved from src/i486/linux/C99/Mod/fcntl.cp with 100% similarity]
src/native/linux/486/C99/Mod/iconv.cp [moved from src/i486/linux/C99/Mod/iconv.cp with 100% similarity]
src/native/linux/486/C99/Mod/libgen.cp [moved from src/i486/linux/C99/Mod/libgen.cp with 100% similarity]
src/native/linux/486/C99/Mod/locale.cp [moved from src/i486/linux/C99/Mod/locale.cp with 100% similarity]
src/native/linux/486/C99/Mod/macro.cp [moved from src/i486/linux/C99/Mod/macro.cp with 100% similarity]
src/native/linux/486/C99/Mod/setjmp.cp [moved from src/i486/linux/C99/Mod/setjmp.cp with 100% similarity]
src/native/linux/486/C99/Mod/signal.cp [moved from src/i486/linux/C99/Mod/signal.cp with 100% similarity]
src/native/linux/486/C99/Mod/stdio.cp [moved from src/i486/linux/C99/Mod/stdio.cp with 100% similarity]
src/native/linux/486/C99/Mod/stdlib.cp [moved from src/i486/linux/C99/Mod/stdlib.cp with 100% similarity]
src/native/linux/486/C99/Mod/sys_mman.cp [moved from src/i486/linux/C99/Mod/sys_mman.cp with 100% similarity]
src/native/linux/486/C99/Mod/sys_stat.cp [moved from src/i486/linux/C99/Mod/sys_stat.cp with 100% similarity]
src/native/linux/486/C99/Mod/sys_types.cp [moved from src/i486/linux/C99/Mod/sys_types.cp with 100% similarity]
src/native/linux/486/C99/Mod/time.cp [moved from src/i486/linux/C99/Mod/time.cp with 100% similarity]
src/native/linux/486/C99/Mod/types.cp [moved from src/i486/linux/C99/Mod/types.cp with 100% similarity]
src/native/linux/486/C99/Mod/unistd.cp [moved from src/i486/linux/C99/Mod/unistd.cp with 100% similarity]
src/native/linux/486/C99/Mod/wctype.cp [moved from src/i486/linux/C99/Mod/wctype.cp with 100% similarity]
src/native/linux/generic/System/Mod/Kernel.cp [moved from src/i486/linux/System/Mod/Kernel.cp with 100% similarity]
src/native/posix/generic/System/Mod/Kernel.cp [moved from src/i486/posix/System/Mod/Kernel.cp with 100% similarity]
src/posix/generic/Host/Mod/Console.cp [moved from src/posix/Host/Mod/Console.cp with 100% similarity]
src/posix/generic/Host/Mod/Dates.cp [moved from src/posix/Host/Mod/Dates.cp with 100% similarity]
src/posix/generic/Host/Mod/Files.cp [moved from src/posix/Host/Mod/Files.cp with 100% similarity]
src/posix/generic/Host/Mod/Lang.cp [moved from src/posix/Host/Mod/Lang.cp with 100% similarity]

diff --git a/README b/README
index bb2d4837ec1040199c788a5924cd9b164b1043fe..e161cdc1a76556c1e6385f45decd5be624ae73ff 100644 (file)
--- 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 (executable)
index 0000000..a8c5b94
--- /dev/null
@@ -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/<cpu>-cpfront-<os>/)"
+  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"
index 8fdb3fdc4d3904db0fa7bf201f58fa7a09b5f377..3c7f446a84f1303afaf0a7430e83a0e32ce10ecc 100755 (executable)
 
 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 <<!
-MODULE ${name};
-
-       IMPORT $(importlist "$@");
-
-END ${name}.
-!
+###^^^^^^^^^^^^^^^^^^###
+### Global variables ###
+###__________________###
+
+_exec="make-bootstrap.sh"
+_this="$(dirname "$(readlink -f "$0")")"
+_version="v0.2"
+
+###^^^^^^^^^^^###
+### Functions ###
+###___________###
+
+make_bootstrap() {
+  local _cpu="$1"
+  local _target="$2"
+  local _system="$3"
+  "$_this/make.sh" -x -o "$_this/bootstrap/$_cpu-$_target-$_system" \
+    "$_cpu" "$_target" "$_system"
+  find "$_this/bootstrap/$_cpu-$_target-$_system" -mindepth 1 -maxdepth 1 \
+    -type d -name 'CodeC' -prune -o -exec rm -rf {} +
 }
 
-linkall() {
-       local name="$1";
-       mainmodule "$@" > "$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 (executable)
index d6a9a3e..0000000
+++ /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 <<!
-
-Kernel.LoadMod('DevCompiler')
-Kernel.LoadMod('ConsCompiler')
-Kernel.LoadMod('Dev2Linker1')
-Kernel.LoadMod('Dev2LnkChmod')
-
-HostFiles.SetRootDir('$OUT')
-
-ConsCompiler.Compile('C99/Mod', 'types.cp')
-ConsCompiler.Compile('C99/Mod', 'sys_types.cp')
-ConsCompiler.Compile('C99/Mod', 'stdlib.cp')
-ConsCompiler.Compile('C99/Mod', 'stdio.cp')
-ConsCompiler.Compile('C99/Mod', 'unistd.cp')
-ConsCompiler.Compile('C99/Mod', 'dirent.cp')
-ConsCompiler.Compile('C99/Mod', 'locale.cp')
-ConsCompiler.Compile('C99/Mod', 'time.cp')
-ConsCompiler.Compile('C99/Mod', 'sys_stat.cp')
-ConsCompiler.Compile('C99/Mod', 'fcntl.cp')
-ConsCompiler.Compile('C99/Mod', 'errno.cp')
-ConsCompiler.Compile('C99/Mod', 'iconv.cp')
-ConsCompiler.Compile('C99/Mod', 'wctype.cp')
-ConsCompiler.Compile('C99/Mod', 'sys_mman.cp')
-ConsCompiler.Compile('C99/Mod', 'dlfcn.cp')
-ConsCompiler.Compile('C99/Mod', 'signal.cp')
-ConsCompiler.Compile('C99/Mod', 'setjmp.cp')
-ConsCompiler.Compile('C99/Mod', 'libgen.cp')
-ConsCompiler.Compile('C99/Mod', 'macro.cp')
-
-ConsCompiler.Compile('System/Mod', 'Kernel.cp')
-DevCompiler.CompileThis Console Dates Files Int Long Math SMath Strings Log Services
-
-ConsCompiler.Compile('Host/Mod', 'Lang.cp')
-ConsCompiler.Compile('Host/Mod', 'Dates.cp')
-ConsCompiler.Compile('Host/Mod', 'Console.cp')
-ConsCompiler.Compile('Host/Mod', 'Files.cp')
-
-DevCompiler.CompileThis \
-       DswLog DswDebug \
-       Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf Dev2LnkWriteElfStatic Dev2LnkWritePe
-ConsCompiler.Compile('Dsw/Mod','Linker486Main.cp')
-Dev2Linker1.LinkElf Linux cpl486 := Kernel$+ \
-       C99types C99macro \
-       Kernel \
-       Console Files Math Strings Services Log Int Long \
-       HostLang HostConsole HostFiles DswLog DswDebug \
-       Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \
-       Dev2LnkWriteElfStatic Dev2LnkWritePe \
-       DswLinker486Main
-
-ConsCompiler.Compile('Dev/Mod','CPM.cp')
-DevCompiler.CompileThis DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH DevCPL486 DevCPC486 DevCPV486
-ConsCompiler.Compile('Dsw/Mod','Documents.cp')
-ConsCompiler.Compile('Dsw/Mod','Compiler486Main.cp')
-Dev2Linker1.LinkElf Linux cpc486 := Kernel$+ \
-       C99types C99macro \
-       Kernel \
-       Console Files Math Strings Services Log Int Long \
-       HostLang HostConsole HostFiles HostDates DswLog DswDebug \
-       DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH DevCPL486 DevCPC486 DevCPV486 \
-       DswDocuments DswCompiler486Main
-
-Kernel.Quit(0)
-
-!
-
-cd "$OUT"
-chmod a+x cpc486 cpl486
diff --git a/make-stage0c.sh b/make-stage0c.sh
deleted file mode 100755 (executable)
index d035870..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-#! /bin/sh
-
-set -e
-
-THIS="$(dirname "$(readlink -f "$0")")"
-OUT="$THIS/stage0/i486"
-
-linkall() {
-       local name="$1";
-       shift
-
-       local list=""
-       for mod in "$@" "$name"; do
-               list="$list $THIS/CodeC/$mod.c"
-       done
-
-       gcc -m32 -g -O0 -lm -ldl -o "$OUT/$name" \
-               -Wno-int-conversion \
-               -Wno-int-to-pointer-cast \
-               -Wno-incompatible-pointer-types \
-               -Wno-implicit-function-declaration \
-               -I "$THIS/C" "$THIS/C/SYSTEM.c" $list
-}
-
-rm -rf "$OUT"
-mkdir -p "$OUT"
-
-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 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 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
-
-chmod a+x "$OUT/cpfront" "$OUT/cpc486" "$OUT/cpl486"
diff --git a/make-stage1.sh b/make-stage1.sh
deleted file mode 100755 (executable)
index d290212..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-#! /bin/sh
-
-set -e
-
-THIS="$(dirname "$(readlink -f "$0")")"
-OUT="$THIS/stage1/i486"
-
-cpc() {
-       "$THIS/stage0/i486/cpc486" -legacy "$@"
-}
-
-cpl() {
-       "$THIS/stage0/i486/cpl486" "$@"
-}
-
-###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
-### Prepare bbdsw sources for LINUX/i486 ###
-###______________________________________###
-
-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"
-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/Int.odc System/Mod/Long.odc \
-       System/Mod/Math.odc System/Mod/SMath.odc 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
-mv Code Sym System
-
-###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
-### 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/Debug.odc Dsw/Mod/Compiler486Main.cp \
-       Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp
-
-###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
-### Link Standalone Component Pascl Compiler & Dev2 Linker ###
-###________________________________________________________###
-
-cpl -os linux -kernel Kernel -main Kernel -legacycodedir . -o cpc486 \
-       Long \
-       C99types C99macro \
-       Kernel Console Files Dates Math Strings Services Log \
-       HostLang HostConsole HostFiles HostDates DswLog DswDebug \
-       DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
-       DevCPL486 DevCPC486 DevCPV486 \
-       DswDocuments DswCompiler486Main
-
-cpl -os linux -kernel Kernel -main Kernel -legacycodedir . -o cpfront \
-       Long \
-       C99types C99macro \
-       Kernel Console Files Dates Math Strings Services Log \
-       HostLang HostConsole HostFiles HostDates DswLog DswDebug \
-       DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
-       CPfrontCPG CPfrontCPC CPfrontCPV\
-       DswDocuments DswCompilerCPfrontMain
-
-cpl -os linux -kernel Kernel -main Kernel -legacycodedir . -o cpl486 \
-       Long \
-       C99types C99macro \
-       Kernel Console Files Math Strings Services Log \
-       HostLang HostConsole HostFiles DswLog DswDebug \
-       Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \
-       Dev2LnkWriteElfStatic Dev2LnkWritePe \
-       DswLinker486Main
-
-#chmod a+x "$OUT/cpfront" "$OUT/cpc486" "$OUT/cpl486"
diff --git a/make-stage2.sh b/make-stage2.sh
deleted file mode 100755 (executable)
index 9a5b4b9..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-#! /bin/sh
-
-set -e
-
-THIS="$(dirname "$(readlink -f "$0")")"
-OUT="$THIS/stage2/i486"
-
-cpc() {
-       "$THIS/stage1/i486/cpc486" -legacy "$@"
-}
-
-cpl() {
-       "$THIS/stage1/i486/cpl486" "$@"
-}
-
-###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
-### Prepare bbdsw sources for LINUX/i486 ###
-###______________________________________###
-
-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"
-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/Int.odc System/Mod/Long.odc \
-       System/Mod/Math.odc System/Mod/SMath.odc 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
-mv Code Sym System
-
-###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
-### 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/Debug.odc Dsw/Mod/Compiler486Main.cp \
-       Dsw/Mod/CompilerCPfrontMain.cp Dsw/Mod/Linker486Main.cp
-
-###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^###
-### Link Standalone Component Pascl Compiler & Dev2 Linker ###
-###________________________________________________________###
-
-cpl -os linux -kernel Kernel -main Kernel -legacycodedir . -o cpc486 \
-       Long \
-       C99types C99macro \
-       Kernel Console Files Dates Math Strings Services Log \
-       HostLang HostConsole HostFiles HostDates DswLog DswDebug \
-       DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
-       DevCPL486 DevCPC486 DevCPV486 \
-       DswDocuments DswCompiler486Main
-
-cpl -os linux -kernel Kernel -main Kernel -legacycodedir . -o cpfront \
-       Long \
-       C99types C99macro \
-       Kernel Console Files Dates Math Strings Services Log \
-       HostLang HostConsole HostFiles HostDates DswLog DswDebug \
-       DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \
-       CPfrontCPG CPfrontCPC CPfrontCPV\
-       DswDocuments DswCompilerCPfrontMain
-
-cpl -os linux -kernel Kernel -main Kernel -legacycodedir . -o cpl486 \
-       Long \
-       C99types C99macro \
-       Kernel Console Files Math Strings Services Log \
-       HostLang HostConsole HostFiles DswLog DswDebug \
-       Dev2LnkBase Dev2LnkChmod Dev2LnkLoad Dev2LnkWriteElf \
-       Dev2LnkWriteElfStatic Dev2LnkWritePe \
-       DswLinker486Main
-
-#chmod a+x "$OUT/cpfront" "$OUT/cpc486" "$OUT/cpl486"
diff --git a/make.sh b/make.sh
new file mode 100755 (executable)
index 0000000..ecd46c3
--- /dev/null
+++ b/make.sh
@@ -0,0 +1,369 @@
+#! /bin/sh
+
+set -e
+
+###^^^^^^^^^^^^^^^^^^###
+### Global variables ###
+###__________________###
+
+_exec="make.sh"
+_this="$(dirname "$(readlink -f "$0")")"
+_cpu=
+_target=
+_system=
+_compiler=
+_linker=
+_docompile=true
+_dolink=true
+_out="$_this/bin"
+
+_useposix=false
+
+###^^^^^^^^^^^###
+### Functions ###
+###___________###
+
+usage() {
+  echo "Usage: make.sh [options] cpu target os"
+  echo "Options:"
+  echo "    -c path           Path to compiler binary"
+  echo "    -l path           Path to linker binary"
+  echo "    -o path           Path to output binaries"
+  echo "    -b                Do not compile"
+  echo "    -x                Do not link"
+  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
+}
+
+copy_source() {
+  for _src
+  do
+    if test -d "$_this/src/$_src"; then
+      find "$_this/src/$_src" -mindepth 1 -maxdepth 1 -exec cp -rt "$_out" -- {} +
+    fi
+  done
+}
+
+native_compile() {
+  "$_compiler" -legacy "$@"
+}
+
+native_link() {
+  if $_dolink; then
+    "$_linker" -os "$_system" -kernel Kernel -main Kernel -legacycodedir . -o "$@"
+  fi
+}
+
+cpfront_import_list() {
+  echo
+  while [ "$1" != "" ]
+  do
+    echo -n "    $1"
+    shift
+    if ! [ -z "$1" ]; then
+      echo ","
+    fi
+  done
+}
+
+cpfront_main_module() {
+   local _name="$1"
+   shift
+   echo "MODULE ${_name};\n\n  IMPORT $(cpfront_import_list "$@");\n\nEND ${_name}."
+}
+
+cpfront_compile() {
+  "$_compiler" -outcode CodeC -outsym SymC "$@"
+}
+
+cpfront_link() {
+  local _main="$1"
+  if $_docompile; then
+    cpfront_main_module "$@" > "${_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