From 7d6e8118e03cbdcd8cd742ac083bf1ec72f522e4 Mon Sep 17 00:00:00 2001
From: Michael Shigorin <mike@altlinux.org>
Date: Mon, 16 May 2016 18:32:25 +0300
Subject: [PATCH] x11: rework free/proprietary driver support

The problem at hand was that use/x11/xorg has been final,
and zerg@ just couldn't switch from nouveau to nvidia
when kdesktop needs that one.

Initial approach included a "big" FREE/PROP switch that
chose the particular KMODULES/PACKAGES to get added to
THE_* but that fails to achieve e.g. nvidia+radeon combo;
looks like these need individual switches.
---
 features.in/x11/README           | 12 ++++++------
 features.in/x11/config.mk        | 28 +++++++++++++++++-----------
 pkg.in/lists/tagged/desktop+xorg |  1 -
 3 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/features.in/x11/README b/features.in/x11/README
index 51f3a62..c9c9af1 100644
--- a/features.in/x11/README
+++ b/features.in/x11/README
@@ -14,9 +14,9 @@
   а заодно обычно рано теряющие поддержку "устаревших"
   видеокарт.
 
-Их применение возможно совмещать, но в этом случае следует
-понимать, что автоопределение в X.org предпочитает свободный
-драйвер и nvidia при наличии nouveau не будет автоматически
-выбран, т.е. потребуется дополнительное конфигурирование
-(вручную или при помощи alterator-x11) -- для live-систем
-это может быть лишено практического смысла.
+Возможно предоставлять в образе одновременно свободные и закрытые
+драйверы, но в этом случае следует понимать, что автоопределение
+в X.org предпочитает свободный драйвер и nvidia при наличии nouveau
+не будет автоматически выбран, т.е. потребуется дополнительное
+конфигурирование (вручную или при помощи alterator-x11) --
+для live-систем это может быть лишено практического смысла.
diff --git a/features.in/x11/config.mk b/features.in/x11/config.mk
index e9bc0a5..c6977ca 100644
--- a/features.in/x11/config.mk
+++ b/features.in/x11/config.mk
@@ -6,13 +6,14 @@
 # the very minimal driver set
 use/x11:
 	@$(call add_feature)
-	@$(call add,THE_KMODULES,drm)	# required by recent nvidia.ko as well
 	@$(call add,THE_LISTS,$(call tags,base xorg))
+	@$(call add,THE_KMODULES,drm)	# required by recent nvidia.ko as well
+	@$(call add,THE_KMODULES,$$(NVIDIA_KMODULES) $$(RADEON_KMODULES))
+	@$(call add,THE_PACKAGES,$$(NVIDIA_PACKAGES) $$(RADEON_PACKAGES))
 
 # x86: free drivers for various hardware (might lack acceleration)
 ifeq (,$(filter-out i586 x86_64,$(ARCH)))
-use/x11/xorg: use/x11 use/x11/intel use/firmware
-	@$(call add,THE_KMODULES,drm-radeon drm-nouveau)
+use/x11/xorg: use/x11/intel use/x11/nouveau use/x11/radeon
 	@$(call add,THE_LISTS,$(call tags,desktop xorg))
 else
 use/x11/xorg: use/x11; @:
@@ -24,20 +25,25 @@ use/x11/intel: use/x11
 	@$(call add,THE_PACKAGES,xorg-dri-intel)	### #25044
 
 # for those cases when no 3D means no use at all
-# NB: blobs won't Just Work (TM) with use/x11/xorg,
-#     nouveau gets prioritized during autodetection
+# NB: blobs won't Just Work (TM) along with nouveau/radeon
+#     as free drivers get prioritized during autodetection
 #use/x11/3d: use/x11/intel use/x11/nvidia use/x11/fglrx; @:
 use/x11/3d: use/x11/intel use/x11/nvidia/optimus use/x11/radeon; @:
 
+# somewhat lacking compared to radeon but still
+use/x11/nouveau: use/x11 use/firmware
+	@$(call set,NVIDIA_KMODULES,drm-nouveau)
+	@$(call set,NVIDIA_PACKAGES,xorg-drv-nouveau)
+
 # has performance problems but is getting better, just not there yet
 use/x11/radeon: use/x11 use/firmware
-	@$(call add,THE_KMODULES,drm-radeon)
-	@$(call add,THE_PACKAGES,xorg-drv-ati xorg-drv-radeon)
+	@$(call set,RADEON_KMODULES,drm-radeon)
+	@$(call set,RADEON_PACKAGES,xorg-drv-ati xorg-drv-radeon)
 
 # sometimes broken with current xorg-server
 use/x11/nvidia: use/x11
-	@$(call add,THE_KMODULES,nvidia)
-	@$(call add,THE_PACKAGES,nvidia-settings nvidia-xconfig)
+	@$(call set,NVIDIA_KMODULES,nvidia)
+	@$(call set,NVIDIA_PACKAGES,nvidia-settings nvidia-xconfig)
 
 use/x11/nvidia/optimus: use/x11/nvidia
 	@$(call add,THE_KMODULES,bbswitch)
@@ -45,8 +51,8 @@ use/x11/nvidia/optimus: use/x11/nvidia
 
 # oftenly broken with current xorg-server, use radeon then
 use/x11/fglrx: use/x11
-	@$(call add,THE_KMODULES,fglrx)
-	@$(call add,THE_PACKAGES,fglrx_glx fglrx-tools)
+	@$(call set,RADEON_KMODULES,fglrx)
+	@$(call set,RADEON_PACKAGES,fglrx_glx fglrx-tools)
 
 use/x11/wacom: use/x11
 	@$(call add,THE_PACKAGES,xorg-drv-wacom xorg-drv-wizardpen)
diff --git a/pkg.in/lists/tagged/desktop+xorg b/pkg.in/lists/tagged/desktop+xorg
index 2515e66..ec1209b 100644
--- a/pkg.in/lists/tagged/desktop+xorg
+++ b/pkg.in/lists/tagged/desktop+xorg
@@ -2,7 +2,6 @@ xorg-drv-ati
 xorg-drv-cirrus
 xorg-drv-mga
 xorg-drv-modesetting
-xorg-drv-nouveau
 xorg-drv-nv
 xorg-drv-qxl
 #xorg-drv-s3
-- 
2.7.4