larsbrinkhoff / lbForth

Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
GNU General Public License v3.0
423 stars 113 forks source link

Help targeting macOS #63

Open larsbrinkhoff opened 7 years ago

larsbrinkhoff commented 7 years ago

I'd like to make a port to macOS, but it's not really viable to do that without access to a macOS machine.

If I could get ssh access to a machine for a month or so, that'd be really helpful.

LdBeth commented 5 years ago

Building with C target on latest macOS Mojave with official CommandLineTools C toolchain and Clozure CL works fine except a few trivia:

  1. macOS deprecated i386 and probably will remove it in the future, so ld would complaint the default -m32, but simply substitute it with -m64 works out without much problem.

  2. Clang does not support -fno-unit-at-a-time.

Practically testing with macOS in VirtualBox is preferred.

/Library/Developer/CommandLineTools/usr/bin/make -ftargets/c/bootstrap.mk
make[1]: Circular kernel.c <- b-forth dependency dropped.
gcc -m64 -O2 -fomit-frame-pointer -fno-unit-at-a-time -Itargets/c targets/c/params.c -o params
clang: warning: the clang compiler does not support '-fno-unit-at-a-time'
targets/c/run.sh ./params -lisp > params.lisp
cp targets/c/jump.fth jump.fth
cp targets/ctc.fth threading.fth
cp targets/c/target.fth target.fth
echo ": sysdir   s\" src/\" ;" >> target.fth
./lisp/lisp.sh '(load "lisp/meta.lisp") (compile-forth "targets/c/nucleus.fth" "src/kernel.fth")'
;; Loading file lisp/meta.lisp ...
;;  Loading file params.lisp ...
;;  Loaded file params.lisp
;;  Loading file lisp/words.lisp ...
;;  Loaded file lisp/words.lisp
;; Loaded file lisp/meta.lisp
gcc -m64 -O2 -fomit-frame-pointer -fno-unit-at-a-time -Itargets/c  -c -o kernel.o kernel.c
clang: warning: the clang compiler does not support '-fno-unit-at-a-time'
gcc -m64 kernel.o -o b-forth
rm -f kernel.c kernel.o params.lisp jump.fth threading.fth target.fth
cp b-forth forth
rm -f *-stamp
touch c-.-stamp
targets/c/run.sh ./params -forth > params.fth
cp targets/c/jump.fth jump.fth
cp targets/ctc.fth threading.fth
cp targets/c/target.fth target.fth
echo ": sysdir   s\" src/\" ;" >> target.fth
echo 'include targets/c/build.fth  bye' | targets/c/run.sh ./forth | tail -n+3 > kernel.c ; grep -a Meta-OK kernel.c
/* Meta-OK */ 
gcc -m64 -O2 -fomit-frame-pointer -fno-unit-at-a-time -Itargets/c  -c -o kernel.o kernel.c
clang: warning: the clang compiler does not support '-fno-unit-at-a-time'
gcc -m64 kernel.o -o c-forth
rm -f forth.exe
cp c-forth forth
larsbrinkhoff commented 5 years ago

Thanks for checking. The C target works, but what I'd like to do is writing the target Mach-O file image from Forth, like how the Linux target writes an ELF file and the Windows targets writes a PE file.

I tried to use Virtual Box at some point, but failed the installation. And now I have other priorities.