X-Git-Url: https://deadsoftware.ru/gitweb?p=cpc.git;a=blobdiff_plain;f=make.sh;h=f7dab7da7822f842c5088647d1f7a00c78d487f9;hp=d466d2773aa85ecb1d7c2f6331ab7cbb6c455f21;hb=f96102d32aebccddc1cc7bcf295ba4c833e29a46;hpb=92aff0fa77569efb2d8cd1b3703370cb61137173 diff --git a/make.sh b/make.sh index d466d27..f7dab7d 100755 --- a/make.sh +++ b/make.sh @@ -1,13 +1,17 @@ -#! /bin/sh +#! /bin/bash set -e +abspath() { + [[ "$1" == /* ]] && echo "$1" || echo "$(pwd)/$1" +} + ###^^^^^^^^^^^^^^^^^^### ### Global variables ### ###__________________### _exec="make.sh" -_this="$(dirname "$(readlink -f "$0")")" +_this="$(dirname "$(abspath "$0")")" _cpu= _target= _system= @@ -19,6 +23,9 @@ _out="$_this/bin" _useposix=false +export CPCFLAGS="$CPCFLAGS" +export CPLFLAGS="$CPLFLAGS" + ###^^^^^^^^^^^### ### Functions ### ###___________### @@ -33,11 +40,20 @@ usage() { echo " -x Do not link" 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 } @@ -50,19 +66,28 @@ copy_source() { for _src do if test -d "$_this/src/$_src"; then - find "$_this/src/$_src" -mindepth 1 -maxdepth 1 -exec cp -rt "$_out" -- {} + + find "$_this/src/$_src" -mindepth 1 -maxdepth 1 -exec cp -r {} "$_out" \; fi done } native_compile() { - "$_compiler" -legacy "$@" + "$_compiler" $CPCFLAGS -legacy "$@" } native_link() { if $_dolink; then - "$_linker" -os "$_system" -kernel Kernel -main Kernel -legacycodedir . -o "$@" - fi + local _outexe="$1"; + local _outsystem="$_system" + if [ "$_system" = "cygwin" ]; then + _outexe="${_outexe}.exe" + _outsystem="win32" + elif [ "$_system" = "osx" ]; then + _outexe="${_outexe}.out" + fi + shift + "$_linker" $CPLFALGS -os "$_outsystem" -kernel Kernel -main Kernel -legacycodedir . -o "$_outexe" "$@" + fi } cpfront_import_list() { @@ -80,18 +105,22 @@ cpfront_import_list() { cpfront_main_module() { local _name="$1" shift - echo "MODULE ${_name};\n\n IMPORT $(cpfront_import_list "$@");\n\nEND ${_name}." + echo "MODULE ${_name};" + echo + echo " IMPORT $(cpfront_import_list "$@");" + echo + echo "END ${_name}." } cpfront_compile() { - "$_compiler" -outcode CodeC -outsym SymC "$@" + "$_compiler" $CPCFLAGS -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" + "$_compiler" $CPCFLAGS -outcode CodeC -outsym SymC -main "${_main}.cp" fi shift if $_dolink; then @@ -100,13 +129,34 @@ cpfront_link() { 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 + local _cc_cflags= + case "$CC" in + *gcc) _cc_cflags="-std=c89 -Wno-int-conversion -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types -Wno-implicit-function-declaration" ;; + *gcc-4.2) _cc_cflags="-std=c89 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-implicit-function-declaration" ;; + 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" ;; + *tcc) _cc_cflags="-std=c89 -w -fsigned-char" ;; + *) _cc_cflags="" ;; + esac + local _cpu_cflags= + case "$_cpu" in + 486) _cpu_cflags="-m32" ;; + arm) _cpu_cflags="" ;; + powerpc) _cpu_cflags="-m32" ;; + *) error "cpfront_link(): unsupported cpu $_cpu" ;; + esac + local _system_cflags= + case "$_system" in + cygwin) _system_cflags="-liconv" ;; + osx) _system_cflags="-D_DARWIN_C_SOURCE -liconv" ;; + *) _system_cflags="" ;; + esac + local _out_exe="${_main}" + case "$_system" in + cygwin) _out_exe="${_main}.exe" ;; + osx) _out_exe="${_main}.out" ;; + *) ;; + esac + "$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 fi } @@ -139,8 +189,11 @@ compile_all() { Posix/Mod/Csys_stat.cp Posix/Mod/Cfcntl.cp Posix/Mod/Cerrno.cp \ Posix/Mod/Ciconv.cp Posix/Mod/Cwctype.cp Posix/Mod/Csys_mman.cp \ Posix/Mod/Cdlfcn.cp Posix/Mod/Csignal.cp Posix/Mod/Csetjmp.cp \ - Posix/Mod/Clibgen.cp \ + Posix/Mod/Clibgen.cp Posix/Mod/Csys_wait.cp \ Posix/Mod/Cmacro.cp + if [ "$_target" = "cpfront" ]; then + compile Lib/Mod/FFI.cp + fi fi ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^### @@ -156,8 +209,8 @@ compile_all() { 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 + System/Mod/Log.odc System/Mod/Strings.odc System/Mod/Meta.odc \ + System/Mod/Services.odc System/Mod/Integers.odc if [ "$_target" = "native" ]; then mv -t System Code Sym @@ -174,9 +227,9 @@ compile_all() { ### 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 Dev/Mod/CPM.cp Dev/Mod/CPT.odc Dev/Mod/CPR.cp 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 ### @@ -199,8 +252,19 @@ compile_all() { 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 + + compile Dsw/Mod/Documents.cp Dsw/Mod/Log.odc Dsw/Mod/Opts.cp Dsw/Mod/Procs.cp + compile Dsw/Mod/HostProcs.cp + + ###^^^^^^^^^^^^^^^^^^^^^^^^^^^### + ### Compile bbdsw executables ### + ###___________________________### + + compile \ + Dsw/Mod/Compiler486Main.cp \ + Dsw/Mod/CompilerCPfrontMain.cp \ + Dsw/Mod/Linker486Main.cp \ + Dsw/Mod/MakeMain.cp } link_all() { @@ -213,7 +277,7 @@ link_all() { PosixCtypes PosixCmacro \ Kernel Console Files Dates Math Strings Services Log \ HostLang HostConsole HostFiles HostDates DswLog $_debug_module \ - DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \ + DevCPM DevCPT DevCPR DevCPS DevCPB DevCPP DevCPE DevCPH \ DevCPL486 DevCPC486 DevCPV486 \ DswDocuments DswCompiler486Main @@ -229,10 +293,17 @@ link_all() { PosixCtypes PosixCmacro \ Kernel Console Files Dates Math Strings Services Log \ HostLang HostConsole HostFiles HostDates DswLog $_debug_module \ - DevCPM DevCPT DevCPS DevCPB DevCPP DevCPE DevCPH \ + DevCPM DevCPT DevCPR DevCPS DevCPB DevCPP DevCPE DevCPH \ CPfrontCPG CPfrontCPC CPfrontCPV\ DswDocuments DswCompilerCPfrontMain + link cpmake \ + PosixCtypes PosixCmacro \ + Kernel Console Files Dates Math Strings Services Log \ + HostLang HostConsole HostFiles HostDates DswLog $_debug_module \ + DevCPM DevCPT DevCPR DevCPS \ + DswDocuments DswOpts DswProcs DswHostProcs DswMakeMain + if $_dolink; then chmod a+x cpc486 cpl486 cpfront fi @@ -263,12 +334,18 @@ _cpu="$1" _target="$2" _system="$3" +if [ -z "$CC" ]; then + export CC=cc +fi + ###^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^### ### Check for supported cpu/target/os ### ###___________________________________### case "$_cpu" in 386|486|586|686) _cpu=486 ;; + arm|armv6|armv7) _cpu=arm ;; + powerpc|ppc|ppc32) _cpu=powerpc ;; "") error "cpu not specified" ;; *) error "unsupported cpu $_cpu" ;; esac @@ -282,6 +359,8 @@ esac case "$_system" in linux) _useposix=true ;; + cygwin) _useposix=true ;; + osx) _useposix=true ;; "") error "operation system not specified" ;; *) error "unsuported operation system $_system" ;; esac @@ -336,10 +415,12 @@ fi ### Copy sources for changed system ### ###_________________________________### -$_docompile && rm -rf -- "$_out" +if $_docompile; then + rm -rf -- "$_out" +fi mkdir -p -- "$_out" -_out="$(readlink -f "$_out")" +_out="$(abspath "$_out")" copy_source "generic" "$_cpu" if $_useposix; then copy_source "posix/generic" "posix/$_cpu"