macOS 12.1 - aarch64 - attempt to rebuild the IDE from within itself fails with:
Build IDE: Exit code 2, Errors: 2
Error: mkdir: ../units/aarch64-darwin/cocoa: Permission denied
make[1]: *** [../units/aarch64-darwin/cocoa] Error 1
Error: make: *** [idepkg] Error 2
Directory permissions as installed:
drwxr-xr-x 3 503 admin 96 2 Jan 21:20 units
drwxr-xr-x 4 503 admin 128 2 Jan 21:22 x86_64-darwin
drwxr-xr-x 896 503 admin 28672 2 Jan 21:24 cocoa
I checked my stable of Mac minis and my user always has an id of 501.
In comparison, my Firefox installation is owned by trev:admin
The workaround:
cd /Applications
sudo chown -R your_username Lazarus
Then I was met with:
make[2]: *** [lazarus] Error 1
make[1]: *** [idepkg] Error 2
Error: make: *** [idepkg] Error 2
Error: resource compiler "fpcres" not found, switching to external mode
The fix for this is to create a
.fpc.cfg (note the initial dot) file in your home directory and add these lines to it:
#include /etc/fpc.cfg
-FD/usr/local/bin
so that
fpcres can be found where it was installed.
The next hurdle:
make[2]: *** [lazarus] Error 1
make[1]: *** [idepkg] Error 2
Error: make: *** [idepkg] Error 2
Error: Unsupported target architecture -Paarch64, invoke the "fpc" compiler driver instead.
which is a little weird because it was happy earlier and the Preferences > Compiler executable is set to
/usr/local/bin/fpc. The solution is to change that to
/usr/local/lib/fpc/3.2.2/ppca64 instead.
The IDE is successfully rebuilt but does not restart automatically:
Build IDE: Success, Warnings: 25, Hints 792
Warning: svn not in path.
possibly due to the warning about svn? Quit the IDE.
Unfortunately trying to then start Lazarus from either the startlazarus.app icon or lazarus.app icon in /Applications/Lazarus still results in the original Intel lazarus binary being launched.
The correct aarch64 binary can be found in
~/.lazarus/bin/aarch64-darwin/lazarus. So the final solution is to:
mv /Applications/Lazarus/lazarus /Applications/Lazarus/lazarus.old
mv ~/.lazarus/bin/aarch64-darwin/lazarus /Applications/Lazarus/
You can then start the IDE with either the StartLazarus or Lazarus icons.
I came across this while trying to re-compile the IDE from within itself to produce a native aarch64 version of the IDE as the delivered release IDE is an X86_64 binary.
If anyone does try this, then be aware you need to go to Tools > Configure "Build Lazarus" and change the Target CPU to aarch64, check the Clean common files option and then Build.