FreeOberon icon indicating copy to clipboard operation
FreeOberon copied to clipboard

How to build on macOS ?

Open ijean opened this issue 2 years ago • 17 comments
trafficstars

Hi, I learned about FreeOberon from a HN post. I was able to to build and run the code in a x86_64 VM, but my main computing device is an arm64 MacBook from 2021 and I was wondering if it will be possible to build and use FreeOberon on macOS. I installed liballegro 5 using Homebrew on my Mac, but the docs of FreeOberon seem to target mostly x86_64 Linux. It would be great if you could write a short intro of how to build it on macOS. Regards, Jean

ijean avatar Nov 16 '23 03:11 ijean

In case you do not have access to macOS, instructions for building for a Debian system for arm64 (aarch64) would be great also. It is much easier for me to run arm64 Linux virtualized on macOS than to run x86_64. Regards, Jean

ijean avatar Nov 16 '23 18:11 ijean

Hi @ijean Yes, I don't have access to MacOS, but I know Ofront+ (this repo's submodule) can be compiled for MacOS. Free Oberon is also cross-platform, so should compile well.

Neither I have access to arm64 computer. Can I virtualize it on an ordinary x86_64 Linux or Windows?

kekcleader avatar Nov 17 '23 00:11 kekcleader

Hello, I tried to build Ofront+ on macOS, but it crashed at some point due to missing some SDL dependencies (I did not had time dig too much into what caused the crash). I think you can virtualize an arm64 if you use QEMU on a powerful x86_64 machine. Alternatively, if you have a Raspberry Pi around (3B or 4B) you can use it if you install the 64 bits version of Raspberry OS. Regards, Jean

ijean avatar Nov 17 '23 00:11 ijean

An old version of Free Oberon had SDL as a dependency, but now it is based on Allegro 5. SDL is not a dependency any more. I think I'll try QEMU

kekcleader avatar Nov 17 '23 00:11 kekcleader

I tried building on a Debian arm64 machine and failed. Than I tried to build just Ofront+, failed again. I opened a new issue on Ofront+ if you want to have a look https://github.com/Oleg-N-Cher/OfrontPlus/issues/122

Thanks, Jean

ijean avatar Nov 17 '23 02:11 ijean

Hello, I tried to build Ofront+ on macOS, but it crashed at some point due to missing some SDL dependencies

SDL support is only needed to build examples (Target/macOS/Examples) that work with the graphics window. The Ofront+ itself does not need SDL and does not require it.

Oleg-N-Cher avatar Nov 19 '23 12:11 Oleg-N-Cher

@Oleg-N-Cher Yes, I realized that later, SDL is not needed to build the translator.

Biggest problem on macOS is that your provided ofront+ executable can't be run no matter what I tried (chmod +x and so on ...).

I assume there is no way to build without having this ofront+ binary ?

ijean avatar Nov 19 '23 13:11 ijean

Biggest problem on macOS is that your provided ofront+ executable can't be run no matter what I tried (chmod +x and so on ...).

As you know, there is Intel-macOS and there is Motorola-macOS platforms. I offer a built binary for Motorola-Mac only.

I assume there is no way to build without having this ofront+ binary ?

No, you can still build your own binary for the platform you need using a host Linux system or Wine.

  • Transfer the cloned repository to the host Linux, copy ofront+ (for your host Linux) binary instead of Target/macOS/ofront+ and run Target/macOS/Lib/Bin/o2c and Target/macOS/Bin/o2c
  • Move this repository back to your mac again and run Target/macOS/Lib/Bin/cc and Target/macOS/Bin/cc there

After that you will get the executables ofront+ and all utilities and you can rebuild ofront directly on your mac.

The Wine method is a little simpler. If you have Wine installed on your mac, run Target/macOS/Lib/Bin/o2c.bat and Target/macOS/Bin/o2c.bat, after this, run Target/macOS/Lib/Bin/cc and Target/macOS/Bin/cc

Oleg-N-Cher avatar Nov 20 '23 00:11 Oleg-N-Cher

Hi, I did as you suggested, I run o2c on Debian arm64 in Target/macOS/Lib/Bin/o2c and Target/macOS/Bin/o2c. Moved the repo to my Mac and tried to run cc. Like before it failed while trying to link the SDL2, I wonder if your cc script tries to build the Examples.

Screenshot 2023-11-20 at 10 31 35 AM

ijean avatar Nov 20 '23 15:11 ijean

Yep, check the cc script from Target/macOS/Lib/Bin, your script tries to build and link with SDL2.

## Free Oberon

$CC SDL2.c SDL2mixer.c In.c Out.c Graph.c Sound.c Turtle.c -w
if [ $? != 0 ]; then exit 1; fi
$AR SDL2.o SDL2mixer.o In.o Out.o Graph.o Sound.o Turtle.o

ijean avatar Nov 20 '23 15:11 ijean

Well, you saw for yourself that your Linux on aarch64 compiled that.

What a C compiler (version) did you use on your mac?

Oleg-N-Cher avatar Nov 20 '23 20:11 Oleg-N-Cher

On macOS Ventura (aarch64/arm64) I used the default C compiler - Clang:

~ % clang --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

ijean avatar Nov 20 '23 21:11 ijean

Hmmm... I didn't know there was a macOS on the arm architecture.

I don't see a quick way to help you, as although I have made Clang support for Ofront+, its various versions (especially newer ones) can have unexpected behavior.

The module "Sound" that is causing the problems is not critical for Ofront+ builds. Try to remove it from Target/Lib/Bin/cc

Ignore the warnings for now. Send me the full log with warnings as a text file. But I don't know where I can run exactly your version of Clang. What are your comments on this problem?

Oleg-N-Cher avatar Nov 20 '23 21:11 Oleg-N-Cher

After I removed Sound.c and Sound.o from the cc script I was able to build the library and executable !

(As a side note Apple moved all their laptops and desktops to the arm architecture since 2020.)

I don't think Clang is the problem, C code is C code and it should be the same on both GCC and Clang. What is interesting is that same code behaves a bit different on Linux and macOS (both in principle POSIX systems).

If you don't have access to a Mac produced after 2020, I think best approximation would be FreeBSD aarch64. FreeBSD also uses Clang as the default system compiler.

An alternative is to use GitHub Actions which let you build software for various architectures. Apparently it is free for open source projects, but I never used it so I don't know exactly how it works:

https://github.com/features/actions

I've attached a file with the warnings I get when I run "cc" in Lib/Bin. warns.txt

ijean avatar Nov 20 '23 22:11 ijean

I think I fixed the bugs. If you still have them, that would be weird. But I didn't do anything about the warrnings.

Plz, re-download the repository. See if these warnings happen again?

Oleg-N-Cher avatar Nov 21 '23 02:11 Oleg-N-Cher

Thanks, I was able to build it, still got the warnings but I built the ofront+ executable.

ijean avatar Nov 21 '23 03:11 ijean

I'll figure out what to do about the warnings when I can reproduce it at my place.

If you manage to build examples (macOS/Examples), let me know. I haven't been able to do something with SDL.

Oleg-N-Cher avatar Nov 21 '23 03:11 Oleg-N-Cher

Hi @ijean, the macOS port is ready. It works on my arm64 (M3). Please clone the repo and run ./install.sh (see the dependency list that will pop up).

kekcleader avatar Apr 25 '25 23:04 kekcleader