Thought I'd give ubuntu 21.10 a go and see how it worked.
Seems to work fine with wayland.
The system only has 4GB of memory but it's a core-i5 with 2 cores * 2 threads so you can do a make -j4 but since it only has 4GB it basically freezes while thrashing the swapfile when it runs out of memory doing all the simultaneous compiles so I only do a make -j2.
The compiling mame docs say that you install these packages :
sudo apt-get install git build-essential python libsdl2-dev libsdl2-ttf-dev libfontconfig-dev libpulse-dev qt5-default
However, qt5-default doesn't work:
According to this page, https://askubuntu.com/questions/1335184/qt5-default-not-in-ubuntu-21-04
just replace qt5-default with
"sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools"
or all in one:
sudo apt-get install git build-essential python libsdl2-dev libsdl2-ttf-dev libfontconfig-dev libpulse-dev qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
I don't seem to need to do 'make CFLAGS="-U_FORTIFY_SOURCE" '.
It compiled with it and without it.
Also 21.10 will allow you to "sudo apt install clang" without any problems (wouldn't work with 20.04) if you feel like doing "make OVERRIDE_CC=clang OVERRIDE_CXX=clang++".
The only thing that I noticed that was problematic was that bgfx video would get very slow with -numscreens 2. It was fine with -numscreens 1. Regular opengl was fine.
More than one screen with bgfx would have black screens on startup (that should say the gameinfo, this game doesn't work etc) but hitting the space bar would continue (since mame was waiting for input) where the video was working but it would run video around 70% of normal speed. Also bgfx seems to segfault on exit with more than one screen (blows up in bgfx::reset(unsigned int, unsigned int, unsigned int, bgfx::TextureFormat::Enum)()
On this system I have both intel integrated video and a low profile AMD Cedar radeon video card (using ubuntu's regular drivers) with one monitor on the integrated and another on the AMD cedar. Setting the display to just use a single screen with the intel integrated video didn't seem to make any difference with regards to bgfx and multiple screens (-numscreens 2).
Unthrottled, the bgfx seems to run at 120-130% with a single screen (-numscreens 1) and the apple2e driver with the ap2000.
With -numscreens 2 that goes to 60-70% (which I guess is roughly half of what the single screen is doing).
Opengl -numscreens 1 unthrottled is 270-300%
Opengl -numscreens 2 unthrottled is 160-170%