X-Git-Url: https://deadsoftware.ru/gitweb?p=cpc.git;a=blobdiff_plain;f=make-all.sh;h=1b5bb20789a6342839cf6d052db3b029fa27c53d;hp=a8c5b943ebfa4bf8f226702a590f03749775a843;hb=25c73fbcd04d973272e0f8939a9de956fa9afbeb;hpb=76d1e8d98f1d80d24fa52a15e6b2c6fb0a5f44d0 diff --git a/make-all.sh b/make-all.sh index a8c5b94..1b5bb20 100755 --- a/make-all.sh +++ b/make-all.sh @@ -1,26 +1,34 @@ -#! /bin/sh +#! /bin/bash set -e +abspath() { + [[ "$1" == /* ]] && echo "$1" || echo "$(pwd)/$1" +} + ###^^^^^^^^^^^^^^^^^^### ### Global variables ### ###__________________### -_this="$(dirname "$(readlink -f "$0")")" +_this="$(dirname "$(abspath "$0")")" _exec="make-all.sh" _compiler= _linker= _cross=false _bootstrap=false -_verify=true +_stages=2 _cpu= _target= _system= _host_cpu= +_host_target= _host_system= +export CPCFLAGS="$CPCFLAGS" +export CPLFLAGS="$CPLFLAGS" + ###^^^^^^^^^^^### ### Functions ### ###___________### @@ -31,17 +39,27 @@ usage() { 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 " -g num Set max verify stages (0..2)" # echo " -e Cross compile (result in stage-cross)" # echo " -u cpu Host cpu" +# echo " -t target Host compiler" # echo " -s os Host operaion system" echo "Processors:" echo " 486 Intel 486+" + echo " arm ARM 32-bit" + echo " powerpc PowerPC 32-bit" echo "Targets:" echo " native Native" echo " cpfront Generic C" echo "Operation systems:" echo " linux GNU/Linux" + echo " cygwin Cygwin" + echo " osx Mac OS X" + echo "Environment variables:" + echo " CC C compiler binary" + echo " CFLAGS C compiler options" + echo " CPCFLAGS CPC compiler options" + echo " CPLFLAGS CPL linker options" exit 2 } @@ -57,37 +75,58 @@ make_stage() { local _this_system="$4" shift 4 "$_this/make.sh" -o "$_dir" -c "$_compiler" -l "$_linker" "$@" "$_this_cpu" "$_this_target" "$_this_system" + local _ext= + if [ "$_host_system" = "cygwin" ]; then + _ext=".exe" + elif [ "$_host_system" = "osx" ]; then + _ext=".out" + fi if [ "$_target" = "cpfront" ]; then - _compiler="$_dir/cpfront" + _compiler="$_dir/cpfront${_ext}" _linker= else if [ "$_cpu" = "486" ]; then - _compiler="$_dir/cpc486" - _linker="$_dir/cpl486" + _compiler="$_dir/cpc486${_ext}" + _linker="$_dir/cpl486${_ext}" else error "unsupported cpu $_cpu" fi fi } +make_verify_stage() { + local _N="$1" + shift + if $_cross; then + make_stage "$_this/stage$_N" "$@" "$_host_cpu" "$_host_target" "$_host_system" + else + make_stage "$_this/stage$_N" "$@" "$_cpu" "$_target" "$_system" + fi +} + ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### ### Parse arguments and options ### ###_____________________________### -while getopts c:l:u:s:bveh _name +while getopts c:l:u:t:s:g:beh _name do case "$_name" in c) _compiler="$OPTARG" ;; l) _linker="$OPTARG" ;; u) _host_cpu="$OPTARG" ;; + t) _host_target="$OPTARG" ;; s) _host_system="$OPTARG" ;; + g) _stages="$OPTARG" ;; b) _bootstrap=true ;; - v) _verify=false ;; e) _cross=true ;; h|?) usage ;; esac done +if [ "$_stages" -lt "0" -o "$_stages" -gt "2" ]; then + usage +fi + if [ "$(expr $# - $OPTIND + 1)" != "3" ]; then usage fi @@ -101,16 +140,20 @@ if [ -z "$_host_cpu" ]; then _host_cpu="$_cpu" fi +if [ -z "$_host_target" ]; then + _host_target="$_target" +fi + if [ -z "$_host_system" ]; then _host_system="$_system" fi -###^^^^^^^^^^^^^^^^^^^^^^^^^### -### Link bootstrap compiler ### -###_________________________### +###^^^^^^^^^^^^^^^^^^^^### +### Bootstrap compiler ### +###____________________### if $_bootstrap; then - echo "==> Bootstrap from C" + echo "==> Bootstrap" _compiler= _linker= if $_cross; then @@ -118,28 +161,23 @@ if $_bootstrap; then else make_stage "$_this/bootstrap/$_host_cpu-cpfront-$_host_system" "$_cpu" "cpfront" "$_system" -b fi +else + echo "==> Stage 0" + make_verify_stage 0 fi -###^^^^^^^^^^^^^^^^### -### Compile stages ### -###________________### +###^^^^^^^^^^^^^^^^^^### +### Recompile itself ### +###__________________### + +if [ "1" -le "$_stages" ]; then + echo "==> Stage 1" + make_verify_stage 1 +fi -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 +if [ "2" -le "$_stages" ]; then + echo "==> Stage 2" + make_verify_stage 2 fi ###^^^^^^^^^^^^^^^### @@ -147,7 +185,7 @@ fi ###_______________### if $_cross; then - echo "==> Build for target machine" + echo "==> Cross compile" make_stage "$_this/stage-cross/$_cpu-$_target-$_system" "$_cpu" "$_target" "$_system" fi