test_build: Use Meson if present

If Meson is available, do a release build. Allow ${CPUS} to override
the number of Ninja jobs.

Change-Id: Ie2afa3ceb31396822ac9a127011cb9a7fc92e988
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/73574
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/test_build.sh b/test_build.sh
index b9af39c..81ea3a2 100755
--- a/test_build.sh
+++ b/test_build.sh
@@ -4,9 +4,15 @@
 TEMP_DIR=$(mktemp -d)
 trap "rm -rf ${TEMP_DIR}" EXIT
 
-${MAKECMD:-make} clean
-${MAKECMD:-make} -j${CPUS:-$(nproc)} CC="${CC:-ccache cc}" CONFIG_EVERYTHING=yes
-FLASHROM=./flashrom
+if command -v meson >/dev/null 2>&1; then
+	meson setup --buildtype release ${TEMP_DIR}/build
+	ninja ${CPUS:+-j${CPUS}} -C ${TEMP_DIR}/build
+	FLASHROM=${TEMP_DIR}/build/flashrom
+else
+	${MAKECMD:-make} clean
+	${MAKECMD:-make} -j${CPUS:-$(nproc)} CC="${CC:-ccache cc}" CONFIG_EVERYTHING=yes
+	FLASHROM=./flashrom
+fi
 
 dd bs=128K count=1 </dev/urandom >${TEMP_DIR}/rand
 ${FLASHROM} -p dummy:emulate=M25P10.RES,image=${TEMP_DIR}/image -w ${TEMP_DIR}/rand