-# warn about invalid drivers
-invalid_drivers := $(filter-out \
- $(classic_drivers) $(gallium_drivers), $(MESA_GPU_DRIVERS))
-ifneq ($(invalid_drivers),)
-$(warning invalid GPU drivers: $(invalid_drivers))
-# tidy up
-MESA_GPU_DRIVERS := $(filter-out $(invalid_drivers), $(MESA_GPU_DRIVERS))
+# Lists to convert driver names to boolean variables
+# in form of <driver name>.<boolean make variable>
+classic_drivers := i915.HAVE_I915_DRI i965.HAVE_I965_DRI
+gallium_drivers := \
+ swrast.HAVE_GALLIUM_SOFTPIPE \
+ freedreno.HAVE_GALLIUM_FREEDRENO \
+ i915g.HAVE_GALLIUM_I915 \
+ nouveau.HAVE_GALLIUM_NOUVEAU \
+ pl111.HAVE_GALLIUM_PL111 \
+ r300g.HAVE_GALLIUM_R300 \
+ r600g.HAVE_GALLIUM_R600 \
+ radeonsi.HAVE_GALLIUM_RADEONSI \
+ vmwgfx.HAVE_GALLIUM_VMWGFX \
+ vc4.HAVE_GALLIUM_VC4 \
+ virgl.HAVE_GALLIUM_VIRGL \
+ etnaviv.HAVE_GALLIUM_ETNAVIV \
+ imx.HAVE_GALLIUM_IMX
+
+ifeq ($(BOARD_GPU_DRIVERS),all)
+MESA_BUILD_CLASSIC := $(filter HAVE_%, $(subst ., , $(classic_drivers)))
+MESA_BUILD_GALLIUM := $(filter HAVE_%, $(subst ., , $(gallium_drivers)))
+else
+# Warn if we have any invalid driver names
+$(foreach d, $(BOARD_GPU_DRIVERS), \
+ $(if $(findstring $(d).,$(classic_drivers) $(gallium_drivers)), \
+ , \
+ $(warning invalid GPU driver: $(d)) \
+ ) \
+)
+MESA_BUILD_CLASSIC := $(strip $(foreach d, $(BOARD_GPU_DRIVERS), $(patsubst $(d).%,%, $(filter $(d).%, $(classic_drivers)))))
+MESA_BUILD_GALLIUM := $(strip $(foreach d, $(BOARD_GPU_DRIVERS), $(patsubst $(d).%,%, $(filter $(d).%, $(gallium_drivers)))))