summaryrefslogtreecommitdiff
path: root/sys-kernel/compat-drivers/files/compat-drivers-3.8-driver-select
blob: bafaf35250edc4f360f77f732bfbb22bc34542ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
#!/usr/bin/env bash
# Copyright 2009        Luis R. Rodriguez <mcgrof@gmail.com>
#
# This script allows you to select your compat-drivers driver and
# reduce compilation time.

# Heavily modified by Stefan Kuhn <wuodan@pentoo.ch>
# Configures compat-drivers for multiple drivers at once
# Suited for package managers

# This internal variable contains a list of all 'Makefile's
CPD_MAKEFILES="
	MAKEFILE
	COMPAT_CONFIG_CW
	DRIVERS_MAKEFILE
	ATH_MAKEFILE
	ATH9K_MAKEFILE
	BRCM80211_MAKEFILE
	RT2X00_MAKEFILE
	TI_MAKEFILE
	NET_WIRELESS_MAKEFILE
	EEPROM_MAKEFILE
	DRIVERS_NET_ATHEROS
	DRIVERS_NET_BROADCOM
	DRIVERS_NET_USB_MAKEFILE
	SSB_MAKEFILE
	BCMA_MAKEFILE"

# This internal variable contains an array with paths to all files
CPD_MAKEFILES_ARRAY=(
	MAKEFILE=Makefile
	COMPAT_CONFIG_CW=config.mk
	DRIVERS_MAKEFILE=drivers/net/wireless/Makefile
	ATH_MAKEFILE=drivers/net/wireless/ath/Makefile
	ATH9K_MAKEFILE=drivers/net/wireless/ath/ath9k/Makefile
	BRCM80211_MAKEFILE=drivers/net/wireless/brcm80211/Makefile
	RT2X00_MAKEFILE=drivers/net/wireless/rt2x00/Makefile
	TI_MAKEFILE=drivers/net/wireless/ti/Makefile
	NET_WIRELESS_MAKEFILE=net/wireless/Makefile
	EEPROM_MAKEFILE=drivers/misc/eeprom/Makefile
	DRIVERS_NET_ATHEROS=drivers/net/ethernet/atheros/Makefile
	DRIVERS_NET_BROADCOM=drivers/net/ethernet/broadcom/Makefile
	DRIVERS_NET_USB_MAKEFILE=drivers/net/usb/Makefile
	SSB_MAKEFILE=drivers/ssb/Makefile
	BCMA_MAKEFILE=drivers/bcma/Makefile
)

# This internal variable holds modules to be added to the atheros Makefile
CPD_ADD_ATHEROS=""

# This internal variable controls the execution phase (and write protection)
# phases: 0=start, 1=configure, 2=write, 3=restore
# no file should be touched below phase 2
CPD_PHASE=0

# CPD_MODULE
# This internal variable contains a temporary value, the currently processed
# argument

# CPD_DISABLE_${CPD_MODULE}
# These internal variables contains the 'disable-actions' of the # currently
# processed argument

# This internal variable stores selected drivers (and groups)
CPD_SELECTED_DRIVERS=''

function die {
	echo "$1" 1>&2
	exit 1
}

function check_phase {
	[ ${CPD_PHASE} -lt ${1} ] && \
		die "Current phase ${CPD_PHASE} lower then ${1}. Check failed"
}

# This internal function returns the path to a file from CPD_MAKEFILES_ARRAY
function get_makefile {
	local file
	for file in "${CPD_MAKEFILES_ARRAY[@]}"; do
		if [ "${file%%=*}"	= "${1}" ]; then
			echo "${file#*=}"
			return 0
		fi
	done
	die "File ${1} not found"
}


# used to backup files from foo to foo.${BACKUP_EXT}
BACKUP_EXT="bk"

# Pretty colors
GREEN="\033[01;32m"
YELLOW="\033[01;33m"
NORMAL="\033[00m"
BLUE="\033[34m"
RED="\033[31m"
PURPLE="\033[35m"
CYAN="\033[36m"
UNDERLINE="\033[02m"

# this internal function disables colors
function unset_colors {
	GREEN=
	YELLOW=
	NORMAL=
	BLUE=
	RED=
	PURPLE=
	CYAN=
	UNDERLINE=
}

SUPPORTED_80211_DRIVERS="ath5k ath9k ath9k_ap ath9k_htc carl9170 ath6kl wil6210 b43 zd1211rw rt2x00 wl1251 wl12xx brcmsmac brcmfmac"

# b43 needs some more work for driver-select, the SSB stuff, plus
# what if you update b44 but not b43? It will bust.
SUPPORTED_ETH_DRIVERS="atl1 atl2 atl1e atl1c alx"

SUPPORTED_DRM_DRIVERS="i915"

SUPPORTED_DRIVERS="${SUPPORTED_80211_DRIVERS} ${SUPPORTED_ETH_DRIVERS} ${SUPPORTED_DRM_DRIVERS}"

function usage {
	echo -e "${GREEN}Usage${NORMAL}: ${BOLD}$0${NORMAL} [${PURPLE}-q${NORMAL}] [ ${PURPLE}<driver-name>${NORMAL} | ${CYAN}<driver-group-name>${NORMAL} | ${GREEN}restore${NORMAL} ]"

	# These should match the switch below.
	echo -e "Supported 802.11 drivers:"
	local i
	for i in $SUPPORTED_80211_DRIVERS; do
		echo -e "\t${PURPLE}${i}${NORMAL}"
	done

	echo
	echo -e "Supported Ethernet drivers:"
	for i in $SUPPORTED_ETH_DRIVERS; do
		echo -e "\t${PURPLE}${i}${NORMAL}"
	done

	echo -e "Supported DRM drivers:"
	for i in $SUPPORTED_DRM_DRIVERS; do
		echo -e "\t${PURPLE}${i}${NORMAL}"
	done

	# These should match the switch below.
	echo -e "\nSupported group drivers:"
	echo -e "\t${CYAN}atheros${NORMAL} < ${PURPLE} ath5k ath9k carl9170 zd1211rw ath6kl wil6210${NORMAL}>"
	echo -e "\t${CYAN}ath${NORMAL} < ${PURPLE} ath5k ath9k carl9170 ath6kl wil6210${NORMAL}>"
	echo -e "\t${CYAN}brcm80211${NORMAL} < ${PURPLE} brcmsmac brcmfmac ${NORMAL}>"
	echo -e "\t${CYAN}intel${NORMAL} < ${PURPLE} iwlwifi, iwlegacy ${NORMAL}>"
	echo -e "\t${CYAN}rtl818x${NORMAL} < ${PURPLE} rtl8180 rtl8187 ${NORMAL}>"
	echo -e "\t${CYAN}rtlwifi${NORMAL} < ${PURPLE} rtl8192ce ${NORMAL}>"
	echo -e "\t${CYAN}ti${NORMAL} < ${PURPLE} wl1251 wl12xx (SPI and SDIO)${NORMAL}>"
	
	echo -e "\nSupported group drivers: Bluetooth & Ethernet:"
	echo -e "\t${CYAN}atlxx${NORMAL} < ${PURPLE} atl1 atl2 atl1e alx${NORMAL}>"
	echo -e "\t${CYAN}bt${NORMAL} < ${PURPLE} Linux bluetooth drivers ${NORMAL}>"

	echo -e "\nSupported group drivers: DRM:"
	echo -e "\t${CYAN}drm${NORMAL} < ${PURPLE} i915${NORMAL}>"

	echo
	echo -e "Restoring compat-drivers:"
	echo -e "\t${GREEN}restore${NORMAL}: you can use this option to restore compat-drivers to the original state"

	echo
	echo -e "Options:"
	echo -e "\t${PURPLE}-q${NORMAL}:\tDisables colored output"
}

function backup_file {
	check_phase 2
	if [ -f $1.${BACKUP_EXT} ]; then
		echo -e "Backup exists: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
		return
	fi
	echo -e "Backing up makefile: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
	cp "${1}" "${1}.${BACKUP_EXT}" || die
}

# This internal function registers a 'disable' action for a module.
# It writes to a variable CPD_DISABLE_${CPD_MODULE}
function disable {
	check_phase 1
	eval "CPD_DISABLE_${CPD_MODULE}+=\" ${*}\"" || die
}

# This internal function clears a Makefile completely.
function disable_makefile
{
	check_phase 2
	backup_file $1
	echo > $1
}

function select_drivers_from_makefile
{
	check_phase 2
	local MAKEFILE=$(get_makefile "$1")
	shift
	backup_file $MAKEFILE
	local CONFIGS=""
	local i
	for i in $@; do
		if [[ "$CONFIGS" = "" ]]; then
			CONFIGS="$i"
		else
			CONFIGS="${CONFIGS}|$i"
		fi
	done
	egrep "$CONFIGS" $MAKEFILE > ${MAKEFILE}.tmp
	mv ${MAKEFILE}.tmp ${MAKEFILE}
}

# This internal function registers filters for the drivers Makefile
function select_drivers {
	check_phase 1
	eval "CPD_DRIVERS_MAKEFILE+=\" ${*}\"" || die
}

# This internal function disables "lib80211"
function disable_lib80211
{
	check_phase 2
	backup_file "$(get_makefile NET_WIRELESS_MAKEFILE)"
	# perl -i -ne 'print if ! /LIB80211/ ' $NET_WIRELESS_MAKEFILE
	sed -i '/LIB80211/d' "$(get_makefile NET_WIRELESS_MAKEFILE)" || die
}

# This internal function disables "b44"
function disable_b44 {
	check_phase 2
	backup_file "$(get_makefile DRIVERS_NET_BROADCOM)"
	# perl -i -ne 'print if ! /CONFIG_B44/ ' $DRIVERS_NET_BROADCOM
	sed -i '/CONFIG_B44/d' "$(get_makefile DRIVERS_NET_BROADCOM)" || die
}

# This internal function disables "ssb"
function disable_ssb
{
	check_phase 2
	disable_makefile "$(get_makefile ${SSB_MAKEFILE})"
	# perl -i -ne 'print if ! /drivers\/ssb\//' Makefile
	sed -i '/drivers\/ssb\//d' "$(get_makefile MAKEFILE)" || die
}

# This internal function disables "bcma"
function disable_bcma
{
	check_phase 2
	disable_makefile "$(get_makefile ${BCMA_MAKEFILE})"
	# perl -i -ne 'print if ! /drivers\/bcma\//' Makefile
	sed -i '/drivers\/bcma\//d' "$(get_makefile MAKEFILE)" || die
}

# This internal function disables "rfkill"
function disable_rfkill
{
	check_phase 2
	backup_file "$(get_makefile MAKEFILE)"
	# perl -i -ne 'print if ! /CONFIG_COMPAT_RFKILL/' Makefile
	sed -i '/CONFIG_COMPAT_RFKILL/d' "$(get_makefile MAKEFILE)" || die
}

# This internal function disables "eprom"
function disable_eeprom
{
	check_phase 2
	disable_makefile "$(get_makefile ${EEPROM_MAKEFILE})" || die
	# perl -i -ne 'print if ! /drivers\/misc\/eeprom\//' Makefile
	sed -i '/drivers\/misc\/eeprom\//d' "$(get_makefile MAKEFILE)" || die
}

# This internal function disables "usbnet"
# TODO: this function is twice in driver-select script!?! Why?
function disable_usbnet
{
	check_phase 2
	disable_makefile ${DRIVERS_NET_USB_MAKEFILE} || die
	# perl -i -ne 'print if ! /drivers\/net\/usb\//' Makefile
	sed -i '/drivers\/net\/usb\//d' "$(get_makefile MAKEFILE)" || die
}

# This internal function disables "usbnet"
# TODO: this function is twice in driver-select script!?! Why?
function disable_usbnet {
	check_phase 2
	# perl -i -ne 'print if ! /CONFIG_COMPAT_NET_USB_MODULES/' Makefile
	sed -i '/CONFIG_COMPAT_NET_USB_MODULES/d' "$(get_makefile MAKEFILE)" || die
} 

# This internal function disables "ethernet"
function disable_ethernet {
	check_phase 2
	# perl -i -ne 'print if ! /CONFIG_COMPAT_NETWORK_MODULES/' Makefile
	sed -i '/CONFIG_COMPAT_NETWORK_MODULES/d' "$(get_makefile MAKEFILE)" || die
} 

# This internal function disables "var_03"
function disable_var_03 {
	check_phase 2
	# perl -i -ne 'print if ! /CONFIG_COMPAT_VAR_MODULES/' Makefile
	sed -i '/CONFIG_COMPAT_VAR_MODULES/d' "$(get_makefile MAKEFILE)" || die
} 

# This internal function disables "bt"
function disable_bt {
	check_phase 2
	# perl -i -ne 'print if ! /CONFIG_COMPAT_BLUETOOTH/' Makefile
	sed -i '/CONFIG_COMPAT_BLUETOOTH/d' "$(get_makefile MAKEFILE)" || die
} 

# This internal function disables "80211"
function disable_80211 {
	check_phase 2
	# perl -i -ne 'print if ! /CONFIG_COMPAT_WIRELESS/' Makefile
	sed -i '/CONFIG_COMPAT_WIRELESS/d' "$(get_makefile MAKEFILE)" || die
}

# This internal function disables "drm"
function disable_drm {
	check_phase 2
	# perl -i -ne 'print if ! /CONFIG_COMPAT_VIDEO_MODULES/' Makefile
	sed -i '/CONFIG_COMPAT_VIDEO_MODULES/d' "$(get_makefile MAKEFILE)" || die
}

function disable_bt_usb_ethernet {
	check_phase 1
	# backup_file Makefile
	disable usbnet
	disable ethernet
	disable bt
	disable update-initramfs
	disable drm
}

function disable_bt_usb_ethernet_var {
	check_phase 1
	# backup_file Makefile
	disable bt_usb_ethernet
	disable var_03
}

function enable_only_ethernet {
	check_phase 1
	# backup_file Makefile
	# backup_file $DRIVERS_NET_BROADCOM
	# backup_file $DRIVERS_NET_ATHEROS
	disable staging
	disable usbnet
	disable var_03
	disable bt
	disable drm
	# rfkill may be needed if you enable b44 as you may have b43
	disable rfkill
	disable 80211
}

function disable_var {
	check_phase 1
	disable ssb
	disable bcma
	disable usbnet
	disable eeprom
	disable update-initramfs
} 

function disable_var_01 {
	check_phase 1
	disable lib80211
	disable var
}

function disable_var_02 {
	check_phase 1
	#var_01 with eeprom not disabled
	disable lib80211
	disable ssb
	disable bcma
	disable usbnet
	disable update-initramfs
}

# This internal function disables "staging"
function disable_staging {
	check_phase 2
	backup_file "$(get_makefile MAKEFILE)"
	# perl -i -ne 'print if ! /CONFIG_COMPAT_STAGING/ ' Makefile
	sed -i '/CONFIG_COMPAT_STAGING/d' "$(get_makefile MAKEFILE)" || die
}

# This internal function disables "update-initramfs"
function disable_update-initramfs
{
	check_phase 2
	backup_file "$(get_makefile MAKEFILE)"
	# perl -i -ne 'print if ! /update-initramfs/' Makefile
	sed -i '/update-initramfs/d' "$(get_makefile MAKEFILE)" || die
}

function enable_only_drm {
	check_phase 1
	# backup_file Makefile
	disable ethernet
	disable staging
	disable usbnet
	disable var_03
	disable bt
	# rfkill may be needed if you enable b44 as you may have b43
	disable rfkill
	disable 80211
}

# This internal function registers filters for the ath Makefile
function select_ath_driver 
{
	check_phase 1
	# backup_file $ATH_MAKEFILE
	# perl -i -ne 'print if /'$1'/ || /CONFIG_ATH_/ || /ath-objs/ || /regd.o/ || /hw.o/ || /key.o/' $ATH_MAKEFILE
	eval "CPD_ATH_MAKEFILE+=\" ${*} CONFIG_ATH_ ath-objs regd.o hw.o key.o\"" || die
	disable var_01
}

# This internal function registers no-common filters for the ath Makefile
function select_ath_no_common
{
	check_phase 1
	# backup_file $ATH_MAKEFILE
	# perl -i -ne 'print if /'$1'/' $ATH_MAKEFILE
	eval "CPD_ATH_MAKEFILE+=\" ${*}\"" || die
	disable var_01
}

function select_ath9k_driver
{
	check_phase 1
	select_ath_driver CONFIG_ATH9K_HW
	# In the future here we'll add stuff to disable ath9k_htc
}

function select_ath9k_driver_ap
{
	check_phase 1
	select_ath9k_driver
	# backup_file $COMPAT_CONFIG_CW
	# perl -i -ne 'print if ! /CONFIG_COMPAT_ATH9K_RATE_CONTROL/ ' $COMPAT_CONFIG_CW
	# this does not work with multipe drivers, since it's the only filter to that file
	# It is only applied when only the ath9k_ap driver is selected and nothing else
	# eval "CPD_COMPAT_CONFIG_CW+=\" CONFIG_COMPAT_ATH9K_RATE_CONTROL\"" || die
}

# This internal function registers filters for the ti Makefile
function select_ti_drivers
{
	check_phase 1
	select_drivers CONFIG_WL_TI
	# select_drivers_from_makefile $TI_MAKEFILE $@
	eval "CPD_TI_MAKEFILE+=\" ${*}\"" || die
}

# This internal function registers filters for the brcm80211 Makefile
function select_brcm80211_driver 
{
	check_phase 1
	# backup_file $BRCM80211_MAKEFILE
	# perl -i -ne 'print if /'$1'/ || /CONFIG_BRCMUTIL/ ' $BRCM80211_MAKEFILE
	eval "CPD_BRCM80211_MAKEFILE+=\" ${*} CONFIG_BRCMUTIL\"" || die
}

function restore_file {
	check_phase 3
	local ORIG="${1%%.${BACKUP_EXT}}" || die
	cp $1 $ORIG || die
	rm -f $1 || die
	echo -e "Restored makefile: ${CYAN}${ORIG}${NORMAL} (and removed backup)"
}

function restore_compat {
	check_phase 3
	local FILES=$(find ./ -type f -name *\."${BACKUP_EXT}") || die
	local i
	for i in $FILES; do
		restore_file $i
	done
}

if [ ! -f .compat_version ]; then
	die "Must run $0 from the compat-drivers top level directory"
fi

# set phase to configure
CPD_PHASE=1

# loop over all arguments
# This sets the configuration for each flag/module
for arg in "$@"; do
	# clear/set global vars
	CPD_MODULE="$arg"
	CPD_SELECTED_DRIVERS+=" $arg"
	case "$arg" in
		restore)
			CPD_PHASE=3
			restore_compat
			exit 0
			;;
		usage)
			usage
			exit 0
			;;
		-q)
			unset_colors || die
			CPD_SELECTED_DRIVERS="${CPD_SELECTED_DRIVERS% -q}"
			;;
	# Group drivers
		atheros)
			select_drivers		CONFIG_ATH_CARDS \
						CONFIG_COMPAT_ZD1211RW
			disable staging
			disable_bt_usb_ethernet_var
			disable var_01
			;;
		ath)
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			disable var_01
			;;
		intel)
			select_drivers		CONFIG_IWLWIFI \
						CONFIG_IWLEGACY \
						CONFIG_IPW
			disable staging
			disable var
			disable bt
			disable ethernet
			disable usbnet
			;;
		iwlwifi)
			select_drivers		CONFIG_IWLWIFI
			disable staging
			disable var_01
			disable bt
			disable ethernet
			disable usbnet
			;;
		iwlegacy)
			select_drivers		CONFIG_IWLEGACY
			disable staging
			disable var_01
			disable bt
			disable ethernet
			disable usbnet
			;;
		rtl818x)
			select_drivers		CONFIG_RTL8180 CONFIG_RTL8187
			disable staging
			disable bt_usb_ethernet
			disable ssb
			disable bcma
			disable lib80211
			;;
		rtlwifi)
			select_drivers		CONFIG_RTL8192CE CONFIG_RTLWIFI
			disable staging
			disable_bt_usb_ethernet_var
			disable lib80211
			;;
		ti)
			select_drivers		CONFIG_WL_TI
			disable_bt_usb_ethernet_var
			disable staging
			disable var_01
			;;
		brcm80211)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_BRCMUTIL \
						CONFIG_BRCMFMAC \
						CONFIG_BRCMSMAC
			;;
	# Singular modules
		ath5k)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			select_ath_driver	CONFIG_ATH5K
			#patch -p1 < enable-older-kernels/enable-2.6.23.patch
			;;
		ath9k)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			select_ath9k_driver
			;;
		ath9k_ap)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			select_ath9k_driver_ap
			;;
		carl9170)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			select_ath_driver	CONFIG_CARL9170
			;;
		ath9k_htc)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			select_ath9k_driver
			;;
		ath6kl)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			select_ath_driver	CONFIG_ATH6KL
			;;
		wil6210)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_ATH_CARDS
			select_ath_no_common	CONFIG_WIL6210
			;;
		brcmsmac)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_BRCMSMAC
			select_brcm80211_driver	CONFIG_BRCMSMAC CONFIG_BRCMUTIL
			;;
		brcmfmac)
			disable staging
			disable_bt_usb_ethernet_var
			select_drivers		CONFIG_BRCMFMAC
			select_brcm80211_driver	CONFIG_BRCMFMAC CONFIG_BRCMUTIL
			;;
		zd1211rw)
			select_drivers		CONFIG_COMPAT_ZD1211RW
			disable staging
			disable var_01
			;;
		b43)
			disable staging
			disable bt_usb_ethernet
			disable eeprom
			disable lib80211
			select_drivers		CONFIG_B43
			;;
		rt2x00)
			select_drivers		CONFIG_RT2X00
			disable staging
			disable_bt_usb_ethernet
			disable var_02
			;;
		wl1251)
			select_ti_drivers	CONFIG_WL1251
			disable staging
			disable var_01
			;;
		wl12xx)
			select_ti_drivers	CONFIG_WL12XX
			disable staging
			disable var_01
			;;
		wl18xx)
			select_ti_drivers	CONFIG_WL18XX
			disable staging
			disable var_01
			;;
	# Ethernet and Bluetooth drivers
		atl1)
			enable_only_ethernet
			disable b44
			# echo -e "obj-\$(CONFIG_ATL1) += atlx/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			CPD_ADD_ATHEROS+="obj-\$(CONFIG_ATL1) += atlx/\n"
			;;
		atl2)
			enable_only_ethernet
			disable b44
			# echo -e "obj-\$(CONFIG_ATL2) += atlx/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			CPD_ADD_ATHEROS+="obj-\$(CONFIG_ATL2) += atlx/\n"
			;;
		atl1e)
			enable_only_ethernet
			disable b44
			# echo -e "obj-\$(CONFIG_ATL1E) += atl1e/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			CPD_ADD_ATHEROS+="obj-\$(CONFIG_ATL1E) += atl1e/\n"
			;;
		atl1c)
			enable_only_ethernet
			disable b44
			# echo -e "obj-\$(CONFIG_ATL1C) += atl1c/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			CPD_ADD_ATHEROS+="obj-\$(CONFIG_ATL1C) += atl1c/\n"
			;;
		alx)
			enable_only_ethernet
			disable b44
			# echo -e "obj-\$(CONFIG_ALX) += alx/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			CPD_ADD_ATHEROS+="obj-\$(CONFIG_ALX) += alx/\n"
			;;
		atlxx)
			select_drivers		CONFIG_ATL1 CONFIG_ATL2 CONFIG_ATL1E CONFIG_ALX
			enable_only_ethernet
			disable b44
			disable update-initramfs
			;;
		bt)
			select_drivers 		CONFIG_BT
			disable var
			disable ethernet
			disable staging
			disable 80211
			;;
		i915)
			enable_only_drm
			;;
		drm)
			enable_only_drm
			;;
		*)
			./$0 usage
			die "Unsupported driver: ${arg}"
			exit 1
			;;
	esac
done

# special for ath9k_ap
# this filter is only applied when no other driver is selected
if [ "${CPD_SELECTED_DRIVERS}" == " ath9k_ap" ]; then
	eval "CPD_COMPAT_CONFIG_CW+=\" CONFIG_COMPAT_ATH9K_RATE_CONTROL\"" \
		|| die "Failed to apply special filter for ath9k_ap"
fi

if [[ ! -f built-in.o ]]; then
	if [[ "$1" != "restore" ]]; then
		echo -e "${PURPLE}Processing new driver-select request...${NORMAL}"
	fi
fi

# This internal function checks if the first argument is contained in the rest
# of the arguments
function has {
    local x=$1
    shift
    local y
    for y in "$@"; do
        [ "${y}" = "${x}" ] && return 0
    done
    return 1
}

# this internal function checks if both groups and single modules were selected
# this is not supported
function check_groups {
	local mods=
	local grps=
	for CPD_MODULE in ${CPD_SELECTED_DRIVERS}; do
		if has "${CPD_MODULE}" ${SUPPORTED_DRIVERS}; then
			mods+=" ${CPD_MODULE}"
		else
			grps+=" ${CPD_MODULE}"
		fi
	done
	[ ! "${mods}" == '' ] && [ ! "${grps}" == '' ] && \
		die "Mixing group and single drivers is not supported by this script! Groups: <${grps}> Drivers: <${mods}>"
}
check_groups

# set phase to write
CPD_PHASE=2

# Always backup the top level Makefile, unless restoring
if [[ "$1" != "restore" ]]; then
	backup_file Makefile
fi

# If a user selects a new driver make sure we clean up for them
# first and also restore the backup makefiles then. Otherwise
# we'll be trying to leave drivers on Makefiles which are not
# already there from a previous run.
if [ -f built-in.o ]; then
	echo -e "${PURPLE}Old build found, going to clean this up first...${NORMAL}"
	make clean
	echo -e "${PURPLE}Restoring Makefiles...${NORMAL}"
	./$0 restore
fi

# This function reads the configuration (disable-actions and filters) for each
# single active flag, then constructs and applies the common configuration set.
function src_configure {
	local use_enabled_list="${CPD_SELECTED_DRIVERS}"
	# compose common disable list for all flags
	# 1st module/flag
	local iuse1="$(echo $use_enabled_list | cut -d ' ' -f 1)" || die
	eval "local disable_list=\$CPD_DISABLE_${iuse1}" || die
	local iuse
	local dis
	for iuse in ${use_enabled_list}; do
		if [ "${iuse}" != "${iuse1}" ]; then
			local disable_list_new=''
			eval "local disable_list_other=\$CPD_DISABLE_${iuse}" || die
			for dis in ${disable_list}; do
				has "${dis}" ${disable_list_other} && \
					disable_list_new+=" ${dis}"
			done
			disable_list="${disable_list_new}"
		fi
	done
	# sort and remove duplicates
	disable_list=$(printf '%s\n' ${disable_list} | sort -u | tr '\n' ' ') || die

	# prepend to atheros Makefile
	if [ "${CPD_ADD_ATHEROS}" != '' ]; then
		# ensure that backup file exists
		backup_file "$(get_makefile DRIVERS_NET_ATHEROS)"
		# prepend using backup
		echo -e "${CPD_ADD_ATHEROS}"|cat - \
			"$(get_makefile DRIVERS_NET_ATHEROS).${BACKUP_EXT}" > \
			"$(get_makefile DRIVERS_NET_ATHEROS)" \
			|| die "Failed to prepend to atheros Makefile"
		echo -e "Prepended to atheros Makefile ...${NORMAL}"
	fi
	# execute all filters for the Makefiles
	local file
	for file in ${CPD_MAKEFILES}; do
		eval "local filter_list=\$CPD_${file}" || die
		if [ -n "${filter_list}" ]; then
			# sort and remove duplicates
			filter_list=$(printf '%s\n' ${filter_list} | sort -u | tr '\n' ' ')\
				|| die
			echo -e "Filtering ${CYAN}$(get_makefile ${file})${NORMAL} for: ${CYAN}${filter_list}${NORMAL}"
			select_drivers_from_makefile "${file}" "${filter_list}" || die
		fi
	done
	# execute common disable list
	echo -e "Common disable list: ${CYAN}${disable_list}${NORMAL}"
	for dis in ${disable_list}; do
		echo -e "Running disable function: ${CYAN}disable_${dis}${NORMAL}"
		eval "disable_${dis}" || die
	done
}

# call src_configure ...
src_configure || die "Failed on src_configure ..."