$M should be the kernel machine src directory, ${MACHINE}. In most cases ${MACHINE} and ${MACHINE_CPUARCH} are the same, except for pc98 and arm64.
It appears we previously set M=${MACHINE_CPUARCH} as a workaround for pc98. arm64 relies on this being set correctly, so update $M and add explicit workarounds for pc98.