Recent

Author Topic: How to set up cross compile to z80?  (Read 1116 times)

Cascade

  • Jr. Member
  • **
  • Posts: 73
How to set up cross compile to z80?
« on: January 03, 2026, 04:52:02 pm »
I’d quite like to try cross-compiling to z80 with FPC/Lazarus, so I need to build the cross-compiler.  I’ve cloned the source into GitHub Desktop from:
https://gitlab.com/freepascal.org/fpc/source.git

…and I have a build script from the FreePascal Wiki:

Code: [Select]
#!/bin/sh

set -e

FPC_Z80_DIR= ... /some/new/folder
STARTPP= ... /fpc/bin/aarch64-darwin/fpc
BINUTILSPREFIX=

CROSSOPT=-O-1
export CROSSOPT
OPT="-CX -XXs"
if [ -n "$EXTRAOPT" ]
then
    OPT+=" $EXTRAOPT"
fi
export OPT
export CPU_TARGET=z80
export OS_TARGET=zxspectrum
export OS_SOURCE=`$STARTPP -iSO`
export CPU_SOURCE=`$STARTPP -iSP`

cd $FPC_Z80_DIR/fpc
alias nproc="sysctl -n hw.logicalcpu"
make -j `nproc` clean PP=$STARTPP BINUTILSPREFIX=$BINUTILSPREFIX
make -j `nproc` all PP=$STARTPP BINUTILSPREFIX=$BINUTILSPREFIX
make -j `nproc` crossinstall PP=$FPC_Z80_DIR/fpc/compiler/ppcrossz80 INSTALL_PREFIX=$FPC_Z80_DIR/zxspectrum-snapshot BINUTILSPREFIX=$BINUTILSPREFIX

…but after a couple of hours rubbing them both together I’ve yet to see any smoke, let alone fire.

I added an alias to workaround lack of nproc:

alias nproc="sysctl -n hw.logicalcpu" (thank you Google)

STARTAPP is set to …/MyNativeFpc/fpc/bin/aarch64-darwin/fpc - I'm running on an M4 chip, so that's the location of the native fpc compiler previously set up with FpcUpDeluxe - is that correct?

I’ve tried copying and executing the above build script in various folders in the fpc source code, but wherever I put it, it chokes on line 24 with the error:

make: *** No rule to make target 'clean'.  Stop.

What should the variable FPC_Z80_DIR be set to?  It needs to be a folder containing an 'fpc' subfolder in order to satisfy line 22 of the build script (cd $FPC_Z80_DIR/fpc), so either an existing fpc folder, or a new empty folder for output (?).

Any insight welcome :)
« Last Edit: January 03, 2026, 04:54:45 pm by Cascade »


Cascade

  • Jr. Member
  • **
  • Posts: 73
Re: How to set up cross compile to z80?
« Reply #2 on: January 03, 2026, 08:18:53 pm »
That's brilliant - thank you!

I haven't got it to work yet, but I can definitely see the z80 options in the Cross Compiler section of FpcUpDeluxe.  FPC Trunk (3.3.1) isn't building for me at the moment, but I guess Trunk will not always build - it doesn't look like an issue with FpcUpDeluxe.

Good news is FPC Fixes (3.2.x) installs fine with FpcUpDeluxe 2.4.0ip - though installing the z80 cross-compiler complains:

Code: [Select]
3-1-26 19:14:09: fpcupdeluxe: V511 (20251116) started.
FPCUPdeluxe V2.4.0ip for aarch64-darwin running on macOS 15.7.1
Build with: FPC 3.2.3 on Win11 x86_64

Found valid bsdtar application.
Found valid make application.
fpcupdeluxe: ERROR: FPC Cross Installer (CleanModule: FPC): Makefile does not support z80-zxspectrum as cross-target. Expect errors.


fpcupdeluxe: ERROR: Cross-target not supported by FPC Makefile.

ERROR: Building cross-tools failed. Aborting.

Could it be that FPC 3.3.1 is minimum version for z80 target support (3.2.x might support z80, but not sure).  If that is the issue I might just have to wait a bit for FPC Trunk to stabilise and then try again.

Cascade

  • Jr. Member
  • **
  • Posts: 73
Re: How to set up cross compile to z80?
« Reply #3 on: January 03, 2026, 08:40:24 pm »
I've found an older version of FPC 3.3.1 already built on my system, so although it's a few months old, I had a go at installing the cross-compiler there.  FpcUpDeluxe 2.4.0ip got further then - the errors I'm seeing are:

Code: [Select]
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `…/fpcsrc/compiler/ppcrossz80 -Tzxspectrum -Pz80 -XPz80-zxspectrum- -Ur -Xs -O2 -n -Fi../inc -Fi../z80 -FDError: cross compiler extension must set FBinUtilsPath: the cross compile binutils (as, ld etc). Could be the same as regular path if a binutils prefix is used. -FE. -FU/…/fpcsrc/rtl/units/z80-zxspectrum -CX -XX -Fl/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -XR/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -vw-n-h-l-d-u-t-p-c- -ap -dz80 -dRELEASE -CX -XX  -Us -Sg system.pp'
...
make[2]: *** [system.ppu] Error 2
make[1]: *** [zxspectrum_all] Error 2
make: *** [rtl_all] Error 2
/Library/Developer/CommandLineTools/usr/bin/make -C rtl all
/Library/Developer/CommandLineTools/usr/bin/make -C zxspectrum all
...
fpcupdeluxe: ERROR: FPC Cross Installer (BuildModuleCustom: FPC): Running cross compiler fpc /usr/bin/make for z80-zxspectrum failed with an error code.


ERROR: Fpcupdeluxe fatal error !
Sequencer (FPCCleanBuildOnly): Failure running fpcupdeluxe: error executing sequence FPCCleanBuildOnly
Sequencer (Only): Failure running fpcupdeluxe: error executing sequence Only
ERROR: Building cross-tools failed. Aborting.

Please let me know if you need more detail - as I've just copied certain lines above that seemed relevant.

Cascade

  • Jr. Member
  • **
  • Posts: 73
Re: How to set up cross compile to z80?
« Reply #4 on: January 03, 2026, 09:34:51 pm »
Speculation:  The unexpected '(' token is because no path is assigned to CROSSBINDIR:

Code: [Select]
fpcupdeluxe: info: FPC Cross Installer (BuildModuleCustom: FPC): Executing: make [Rtl Build] (FPC crosscompiler: z80-zxspectrum) with CROSSOPT: -CX -XX.
fpcupdeluxe: Executing: /usr/bin/make RELEASE=1 ... CPU_TARGET=z80 CROSSINSTALL=1 CROSSBINDIR=Error: cross compiler extension must set FBinUtilsPath: the cross compile binutils (as, ld etc). Could be the same as regular path if a binutils prefix is used. BINUTILSPREFIX=...etc...

CROSSBINDIR=Error: cross compiler extension must set FBinUtilsPath: the cross compile binutils (as, ld etc)

...so a directory path is expected, but instead the parser reads an Error message containing a bracket '('
« Last Edit: January 03, 2026, 09:42:35 pm by Cascade »

Thausand

  • Sr. Member
  • ****
  • Posts: 458
Re: How to set up cross compile to z80?
« Reply #5 on: January 04, 2026, 03:35:42 am »
I have check Linux 64-bit fpc 3.3.1 main and have error msg when compile cross hello for spectrum:
Code: [Select]
[0.016] Searching file ./fpc/3.3.1/units/z80-zxspectrum/tplylib/system.rel... not found
[0.016] Searching file ./fpc/3.3.1/units/z80-zxspectrum/tplylib/SYSTEM.REL... not found
[0.016] Searching file ./fpc/3.3.1/units/z80-zxspectrum/system.rel... not found
[0.016] Searching file ./fpc/3.3.1/units/z80-zxspectrum/SYSTEM.REL... not found
[0.016] Searching file ./fpc/3.3.1/bin/system.rel... not found
[0.016] Searching file ./fpc/3.3.1/bin/SYSTEM.REL... not found
[0.016] Searching file /bs-vms/misc/work/fpc/3.3.1/bin/system.rel... not found
[0.016] Searching file /bs-vms/misc/work/fpc/3.3.1/bin/SYSTEM.REL... not found
[0.016] hello_world.pas(1,51) Warning: Object system.rel not found, Linking may fail !
[0.016] Reading object system.rel
[0.016] hello_world.pas(1,51) Error: Can't open object file: system.rel
[0.016] Searching file /bs-vms/misc/work/bin/z80-zxspectrum-ihxutil... found
[0.016] Using util /bs-vms/misc/work/bin/z80-zxspectrum-ihxutil
[0.016] Executing "/bs-vms/misc/work/bin/z80-zxspectrum-ihxutil" with command line " hello_world.z80-zxspectrum"
Exception at 0000000000499840: EInOutError:
File not found.
[0.017] hello_world.pas(1,51) Fatal: There were 1 errors compiling module, stopping
[0.017] Fatal: Compilation aborted
Error: /bs-vms/misc/work/fpc/3.3.1/bin/ppcz80 returned an error exitcode
Command exited with non-zero status 1

I not know command ihxutil and why have fail. I have use ihxutil terminal cmd and have also error when try. I not know what ihxutil is want/expect for input. Compiler have make hello_world.rel.


Cascade

  • Jr. Member
  • **
  • Posts: 73
Re: How to set up cross compile to z80?
« Reply #7 on: January 04, 2026, 07:23:30 pm »
Yes - it's working! :)  Thank you!!

See attachments below...

 

TinyPortal © 2005-2018