The Raspberry Pi and its most popular operating systems have quite a steep learning curve with a lot of the available information on the web being incorrect or out of date almost from the day it was written. Here the pages are kept current and correct.
apt-get install git build-essentials libsdl2-dev libsdl2-ttf-dev libfontconfig-dev qt5-default and
This will give you a build of MAME that works but I don't think anyone would call it usable on a board as slow as a Raspberry Pi. So what can we do to speed things up a bit?