Closed daniel214 closed 2 years ago
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
This trace doesn’t look right to me. Will investigate.
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.
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
Confirmed successful, warning-free compilation.
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
pkg-config
without -march=native
pkg-config
with -march=native
Summary
This change
-march
flag from the compilation commandpkg-config
usage to the makefileDetails
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:-mcpu=apple-m1
in a conditional makefile-march=native
from the makefile and don't replace itThe 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. Introducingpkg-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.