Skip to content

build FreeBasic on macOS 13.1 with clang #409

@Dieken

Description

@Dieken

I almost successfully build FreeBasic on macOS 13.1, record the steps for your reference, hope FreeBasic can support macOS soon.

  1. patch FreeBASIC-1.09.0-source:
diff --git a/src/compiler/fbc.bas b/src/compiler/fbc.bas
index 975b60a..ecb11d3 100644
--- a/src/compiler/fbc.bas
+++ b/src/compiler/fbc.bas
@@ -1114,10 +1114,6 @@ private function hLinkFiles( ) as integer
 
        end select
 
-       if( fbGetOption( FB_COMPOPT_TARGET ) = FB_COMPTARGET_DARWIN ) then
-               ldcline += " -macosx_version_min 10.4"
-       end if
-
        '' extra options
        ldcline += " " + fbc.extopt.ld
 
@@ -3745,7 +3741,6 @@ private sub hAddDefaultLibs( )
                end if
 
        case FB_COMPTARGET_DARWIN
-               fbcAddDefLib( "gcc" )
                fbcAddDefLib( "System" )
                fbcAddDefLib( "pthread" )
                fbcAddDefLib( "ncurses" )
  1. generate bootstrap/darwin-x86_64on Linux and copy this directory to macOS
# on Linux
fbc src/compiler/*.bas -m fbc -i inc -e -r -v -target darwin-x86_64
mkdir -p bootstrap/darwin-x86_64
mv src/compiler/*.c   bootstrap/darwin-x86_64
  1. fix non-local goto, notice non-local goto is undefined behaviour even in GCC.
# this is a very rude hack, turn "goto *p" to "p()". there is no following "return"
# because the caller functions don't always return void.
perl -i -pe 's/goto \*(vr\S+);/((void (*)())(\1))();/' bootstrap/darwin-x86_64/*.c
  1. bootstrap on macOS
gmake V=1 bootstrap
  1. try the bootstrap fbc on macOS
bin/fbc -v -Wl -L`xcrun --show-sdk-path`/usr/lib examples/hello.bas

To fully build the final fbc, subroutines rtlErrorCheck and rtlErrorThrow in src/compiler/rtl-error.bas must be changed to not use non-local goto, I'm not familiar with FreeBasic code, don't have enough skill to patch that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions