Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to build clean on macOS 10.11 with M1 cpu #41

Merged
merged 2 commits into from
Mar 9, 2022

Conversation

daniel214
Copy link
Contributor

@daniel214 daniel214 commented Feb 28, 2022

Summary

This change

  • removes the -march flag from the compilation command
  • adds pkg-config usage to the makefile

Details

This commit fixes one major and a few minor compilation issues on macOS 10.11 on M1 silicon.

-march Directive

The biggest issue is that gcc on M1 doesn't seem to support -march=native (or the -march flag at all..)
There are two ways to approach this:

  • replace with -mcpu=apple-m1 in a conditional makefile
  • remove -march=native from the makefile and don't replace it

The first option may be preferable for RPi targets, since you probably want to squeeze every bit of performance out of what you have. Processor-specific compilation may improve battery performance on the M1 as well-- no testing done there.

If you want to keep processor-specific builds, a conditional compilation or multiple makefiles need to be set up to keep this aspect from breaking builds.

pkg-config Integration

pkg-config is a tool that is aware of installed library locations and configurations and produces the appropriate compilation and linker flags for the platform.

Moving to pkg-config should be more portable, but that definitely needs testing. Introducing pkg-config silences a bunch of warnings on my setup, but is more specific about the SDL directory location than the previous method which required changes to header file references in several .c files.

@distek
Copy link

distek commented Mar 1, 2022

Checked on the pi with Raspbian; Worked fine for me:

pi@raspberrypi:~/git-clones/daniel214-m8c$ uname -a
Linux raspberrypi 5.10.63-v7+ #1496 SMP Wed Dec 1 15:58:11 GMT 2021 armv7l GNU/Linux
pi@raspberrypi:~/git-clones/daniel214-m8c$ make
gcc -c -o main.o main.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o serial.o serial.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o slip.o slip.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o command.o command.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o write.o write.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o render.o render.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o ini.o ini.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o config.o config.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -c -o input.o input.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
[~cat] inline_font.h inprint2.c > font.c
gcc -c -o font.o font.c `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I.
gcc -o m8c main.o serial.o slip.o command.o write.o render.o ini.o config.o input.o font.o `sdl2-config --libs --cflags` -march=native -Wall -O2 -pipe -I. -lserialport
pi@raspberrypi:~/git-clones/daniel214-m8c$ pkill m8c
pi@raspberrypi:~/git-clones/daniel214-m8c$ ./m8c
INFO: Reading config /home/pi/.local/share/m8c/config.ini
INFO: Looking for USB serial devices.
INFO: Found M8 in /dev/ttyACM0.
INFO: Opening port.
INFO: Enabling and resetting M8 display

@daniel214
Copy link
Contributor Author

daniel214 commented Mar 1, 2022

This trace doesn’t look right to me. Will investigate.

@laamaa laamaa merged commit 4ca038f into laamaa:main Mar 9, 2022
@laamaa
Copy link
Owner

laamaa commented Mar 9, 2022

The client probably doesn't benefit much from march=native in reality. I'd say it's generally better this way, let's merge and adjust again if this doesn't turn out to be a good idea for some reason.

@daniel214
Copy link
Contributor Author

This is what compilation should look like under Raspbian. @distek, you may have forgotten to git switch apple-m1.

pi@raspberrypi:~/github/m8c $ make
gcc -c -o main.o main.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o serial.o serial.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o slip.o slip.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o command.o command.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o write.o write.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o render.o render.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o ini.o ini.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o config.o config.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -c -o input.o input.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
[~cat] inline_font.h inprint2.c > font.c
gcc -c -o font.o font.c -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I.
gcc -o m8c main.o serial.o slip.o command.o write.o render.o ini.o config.o input.o font.o -D_REENTRANT -I/usr/include/SDL2 -Wall -O2 -pipe -I. -lSDL2 -lserialport

Results:

Confirmed successful, warning-free compilation.

Performance:

Very sluggish, until I enabled the GL (Full KMS) driver and Glamor acceleration in raspi-config.
I have not figured out how to enable fps logging, but there appears to be similar performance between

  • original build configuration
  • pkg-config without -march=native
  • pkg-config with -march=native

laamaa added a commit that referenced this pull request May 27, 2022
Update to build clean on macOS 10.11 with M1 cpu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants