summaryrefslogtreecommitdiff
path: root/eclass/compat-drivers-3.7.eclass
blob: 58bcee623568f3838030f3fc914a61c549d4467a (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
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $


# @ECLASS: compat-drivers-3.7.eclass
# @MAINTAINER:
# wuodan@pentoo.ch
# @BLURB: Implements functionality of driver-select script for several modules
# @DESCRIPTION:
# Implements functionality of driver-select script for several modules

# compose IUSE and REQUIRED_USE from the categories
IUSE+=" +build-all-modules"
REQUIRED_USE+=" || ("
for useexp in ${CPD_USE_EXPAND}; do
	USE_TEMP="\$CPD_USE_EXPAND_$useexp"
	for iuse in `eval echo "\$USE_TEMP"`; do
		if [ "${iuse:0:1}" = '+' ]; then
			IUSE+=" ${iuse:0:1}compat_drivers_${useexp}_${iuse:1}" || die
			REQUIRED_USE+=" compat_drivers_${useexp}_${iuse:1}" || die
		else
			IUSE+=" compat_drivers_${useexp}_${iuse}" || die
			REQUIRED_USE+=" compat_drivers_${useexp}_${iuse} build-all-modules" || die
		fi
	done
done
REQUIRED_USE+=" )"

# ==============================================================================
# INTERNAL VARIABLES
# ==============================================================================

# @VARIABLE: CPD_USE_EXPAND
# @DESCRIPTION:
# This variable needs to be set in the ebuild and contains the categories for
# USE_EXPAND

# @VARIABLE: CPD_USE_EXPAND_category
# @DESCRIPTION:
# These variables need to be set in the ebuild, one per category in
# CPD_USE_EXPAND. They contain the modules of the categories.

# @ECLASS-VARIABLE: CPD_MODULE
# @DESCRIPTION:
# This internal variable contains a temporary value, the currently processed
# module.

# @ECLASS-VARIABLE: CPD_DISABLE_${CPD_MODULE}
# @DESCRIPTION:
# These internal variables contains values, the 'disable-actions' of the
# currently processed module. One variable exists for each active module.

# @ECLASS-VARIABLE: CPD_MAKEFILES
# @DESCRIPTION:
# 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"

# @ECLASS-VARIABLE: CPD_MAKEFILES_ARRAY
# @DESCRIPTION:
# 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
)

# ==============================================================================
# INTERNAL FUNCTIONS
# ==============================================================================

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

# @FUNCTION: select_drivers_from_makefile
# @DESCRIPTION:
# This internal function filters a Makefile
# It deletes all non matching lines!
function select_drivers_from_makefile
{
	local makefile=$(get_makefile "$1")
	shift
	local configs=""
	for i in $@; do
		[ "${configs}" != '' ] && configs+='|'
		configs+="${i}"
	done
	einfo "Filtering file ${makefile} for: ${configs}"
	sed -r "/${configs}/!d"  ${makefile} > ${makefile}.tmp || die
	mv ${makefile}.tmp ${makefile} || die
}

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

# @FUNCTION: disable_makefile
# @DESCRIPTION:
# This internal function clears a Makefile completely. Use with care!
function disable_makefile {
	einfo "Clearing entire file: ${1}"
	echo > $1 || die
}

# @FUNCTION: disable_staging
# @DESCRIPTION:
# This internal function disables "staging"
function disable_staging
{
	# perl -i -ne 'print if ! /CONFIG_COMPAT_STAGING/ ' "${MAKEFILE}"
	sed -i '/CONFIG_COMPAT_STAGING/d' "$(get_makefile MAKEFILE)" || die
}

# @FUNCTION: disable_update-initramfs
# @DESCRIPTION:
# This internal function disables "update-initramfs"
function disable_update-initramfs
{
	# perl -i -ne 'print if ! /update-initramfs/' "${MAKEFILE}"
	sed -i '/update-initramfs/d' "$(get_makefile MAKEFILE)" || die
}

# @FUNCTION: disable_lib80211
# @DESCRIPTION:
# This internal function disables "update-initramfs"
function disable_lib80211
{
	# perl -i -ne 'print if ! /LIB80211/ ' $NET_WIRELESS_MAKEFILE
	sed -i '/LIB80211/d' "$(get_makefile NET_WIRELESS_MAKEFILE)" || die
}

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

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

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

# @FUNCTION: disable_rfkill
# @DESCRIPTION:
# This internal function disables "rfkill"
function disable_rfkill
{
	# perl -i -ne 'print if ! /CONFIG_COMPAT_RFKILL/' "${MAKEFILE}"
	sed -i '/CONFIG_COMPAT_RFKILL/d' "$(get_makefile MAKEFILE)" || die
}

# @FUNCTION: disable_eprom
# @DESCRIPTION:
# This internal function disables "eprom"
function disable_eeprom
{
	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
}

# @FUNCTION: disable_usbnet
# @DESCRIPTION:
# This internal function disables "usbnet"
function disable_usbnet
{
	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
}

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

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

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

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

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

# @FUNCTION: disable_ath9k_rate_control
# @DESCRIPTION:
# This internal function disables "ath9k_rate_control"
# new function, not in driver-select
function disable_ath9k_rate_control {
	# perl -i -ne 'print if ! /CONFIG_COMPAT_ATH9K_RATE_CONTROL/ ' $COMPAT_CONFIG_CW
	sed -i '/CONFIG_COMPAT_ATH9K_RATE_CONTROL/d' "$(get_makefile COMPAT_CONFIG_CW)" || die
}

# @FUNCTION: select_drivers
# @DESCRIPTION:
# This internal function registers filters for the drivers Makefile
function select_drivers {
	eval "CPD_DRIVERS_MAKEFILE+=\" ${*}\"" || die
}

# @FUNCTION: select_ath_driver
# @DESCRIPTION:
# This internal function registers filters for the ath Makefile
function select_ath_driver {
	eval "CPD_ATH_MAKEFILE+=\" ${*}\"" || die
}

# @FUNCTION: select_ath_driver_common
# @DESCRIPTION:
# This internal function registers common filters for the ath Makefile
function select_ath_driver_common {
	# eval "CPD_ATH_MAKEFILE+=\" CONFIG_ATH_ ath-objs regd.o hw.o\"" || die
	select_ath_driver CONFIG_ATH_ ath-objs regd.o hw.o key.o || die
}

# @FUNCTION: select_brcm80211_driver
# @DESCRIPTION:
# This internal function registers filters for the brcm80211 Makefile
function select_brcm80211_driver {
	eval "CPD_BRCM80211_MAKEFILE+=\" ${*}\"" || die
}

# @FUNCTION: select_ti_driver
# @DESCRIPTION:
# This internal function registers filters for the ti Makefile
function select_ti_drivers {
	select_drivers CONFIG_WL_TI
	eval "CPD_TI_MAKEFILE+=\" ${*}\"" || die
}

# @FUNCTION: set_flag
# @DESCRIPTION:
# This internal function contains the configuration for each flag/module
function set_flag {
	# clear/set global vars
	CPD_MODULE=$1
	case $1 in
		ath5k)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_ATH_COMMON || die
			select_ath_driver	CONFIG_ATH5K || die
			select_ath_driver_common || die
			;;
		ath9k)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_ATH_COMMON || die
			select_ath_driver CONFIG_ATH9K_HW || die
			select_ath_driver_common || die
			;;
		ath9k_ap)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_ATH_COMMON || die
			select_ath_driver CONFIG_ATH9K_HW || die
			select_ath_driver_common || die
			disable ath9k_rate_control || die
			;;
		carl9170)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_ATH_COMMON || die
			select_ath_driver	CONFIG_CARL9170 || die
			select_ath_driver_common || die
			;;
		ath9k_htc)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_ATH_COMMON || die
			select_ath_driver CONFIG_ATH9K_HW || die
			select_ath_driver_common || die
			;;
		ath6kl)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_ATH_COMMON || die
			select_ath_driver	CONFIG_ATH6KL || die
			select_ath_driver_common || die
			;;
		brcmsmac)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_BRCMSMAC || die
			select_brcm80211_driver	CONFIG_BRCMSMAC CONFIG_BRCMUTIL || die
			;;
		brcmfmac)
			disable staging usbnet ethernet bt update-initramfs var_03 || die
			select_drivers		CONFIG_BRCMFMAC || die
			select_brcm80211_driver	CONFIG_BRCMSMAC CONFIG_BRCMUTIL || die
			;;
		zd1211rw)
			select_drivers		CONFIG_COMPAT_ZD1211RW || die
			disable staging lib80211 ssb bcma usbnet eeprom update-initramfs || die
			;;
		b43)
			disable staging usbnet ethernet bt update-initramfs || die
			disable eeprom lib80211 || die
			select_drivers		CONFIG_B43 || die
			;;
		rt2x00)
			select_drivers		CONFIG_RT2X00 || die
			disable staging usbnet ethernet bt update-initramfs || die
			disable lib80211 ssb bcma usbnet update-initramfs || die
			;;
		wl1251)
			select_ti_drivers	CONFIG_WL1251 || die
			disable staging lib80211 ssb bcma usbnet eeprom update-initramfs || die
			;;
		wl12xx)
			select_ti_drivers	CONFIG_WL12XX || die
			disable staging lib80211 ssb bcma usbnet eeprom update-initramfs || die
			;;
		wl18xx)
			select_ti_drivers	CONFIG_WL18XX || die
			disable staging lib80211 ssb bcma usbnet eeprom update-initramfs || die
			;;
	# Ethernet and Bluetooth drivers
		atl1)
			disable staging usbnet var_03 bt rfkill 80211 b44 || die
			echo -e "obj-\$(CONFIG_ATL1) += atlx/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			;;
		atl2)
			disable staging usbnet var_03 bt rfkill 80211 b44 || die
			echo -e "obj-\$(CONFIG_ATL2) += atlx/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			;;
		atl1e)
			disable staging usbnet var_03 bt rfkill 80211 b44 || die
			echo -e "obj-\$(CONFIG_ATL1E) += atl1e/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			;;
		atl1c)
			disable staging usbnet var_03 bt rfkill 80211 b44 || die
			echo -e "obj-\$(CONFIG_ATL1C) += atl1c/" > "$(get_makefile DRIVERS_NET_ATHEROS)" || die
			;;
		atlxx)
			select_drivers		CONFIG_ATL1 CONFIG_ATL2 CONFIG_ATL1E CONFIG_ALX || die
			disable staging usbnet var_03 bt rfkill 80211 b44 update-initramfs || die
			;;
		bt)
			select_drivers 		CONFIG_BT || die
			disable ssb bcma usbnet eeprom update-initramfs ethernet staging 80211 || die
			;;
		i915)
			# rfkill may be needed if you enable b44 as you may have b43
			disable ethernet staging usbnet var_03 bt rfkill 80211 || die
			;;
		drm)
			# rfkill may be needed if you enable b44 as you may have b43
			disable ethernet staging usbnet var_03 bt rfkill 80211 || die
			;;
	# Manually added options by pentoo
		usbnet)
			# disable everything else
			disable staging update-initramfs lib80211 b44 ssb bcma rfkill eeprom ethernet var_03 bt 80211 ath9k_rate_control || die
			;;
		staging)
			# disable everything else
			disable usbnet update-initramfs lib80211 b44 ssb bcma rfkill eeprom ethernet var_03 bt 80211 ath9k_rate_control || die
			;;
		b44)
			disable staging usbnet ethernet bt update-initramfs || die
			disable eeprom lib80211 || die
			select_drivers		CONFIG_B44 || die
			;;
		*)
			die "Unsupported driver: ${1}"
			exit
			;;
	esac
}

# @FUNCTION: echo_flag_settings
# @DESCRIPTION:
# This internal function outputs the "disable" actions for a flag
function echo_flag_settings {
	# example:
	# CPD_DISABLE_${iflag}="action1 action2"
	# CPD_DRIVERS_MAKEFILE="flag1 flag1"
	# CPD_ATH_MAKEFILE="flag3"
	# ...
	local iflag=$1
	eval "local disable_list=\"\${CPD_DISABLE_${iflag}}\"" || die
	einfo "Disable list for ${iflag}: ${disable_list}"
}

# ==============================================================================
# EXPORTED FUNCTIONS
# ==============================================================================

# @FUNCTION: compat-drivers-3.7_src_configure
# @DESCRIPTION:
# This function reads the configuration (disable-actions and filters) for each
# single active flag, then constructs and applies the common configuration set.
compat-drivers-3.7_src_configure() {
	# early exit, skip filtering of configuration and build all modules
	if use build-all-modules; then
		ewarn "You have chosen to build all modules!"
		ewarn "The Pentoo team strives to build only the desired modules and the"
		ewarn "use flag 'build-all-modules' should only be used when"
		ewarn "the desired modules is not available through another flag."
		ewarn "Please open an issue at the Pentoo site and let us know which"
		ewarn "module was missing!"
		return 0
	fi

	# loop over all modules
	local use_temp=''
	local use_enabled_list=''
	for useexp in ${CPD_USE_EXPAND}; do
		use_temp="\$CPD_USE_EXPAND_$useexp" || die
		for iuse in `eval echo "\$use_temp"`; do
			if [ "${iuse:0:1}" = '+' ]; then
				local iuse2=${iuse:1} || die
			else
				local iuse2=${iuse} || die
			fi
			local iflag="compat_drivers_${useexp}_${iuse2}" || die
			# check if it's enabled
			if use "${iflag}"; then
				use_enabled_list+=" ${iuse2}" || die
				# fill the disable/enable lists
				# example:
				# CPD_DISABLE_${iflag}="action1 action2"
				# CPD_DRIVERS_MAKEFILE="flag1 flag1"
				# CPD_ATH_MAKEFILE="flag3"
				# ...
				set_flag "${iuse2}" || die
				echo_flag_settings "${iuse2}" || die
			fi
		done
	done
	einfo "List of enabled modules: ${use_enabled_list}"
	# 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
	for iuse in ${use_enabled_list}; do
		if [ "${iuse}" != "${iuse1}" ]; then
			local disable_list_new='' || die
			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}" || die
		fi
	done
	# execute all filters for the Makefiles
	for file in ${CPD_MAKEFILES}; do
		eval "local filter_list=\$CPD_${file}" || die
		if [ -n "${filter_list}" ]; then
			# einfo "Filtering $(get_makefile ${file}) for: ${filter_list}"
			select_drivers_from_makefile "${file}" "${filter_list}" || die
		fi
	done
	# execute common disable list
	einfo "Common disable list: ${disable_list}"
	for dis in ${disable_list}; do
		einfo "Running disable function: disable_${dis}"
		eval "disable_${dis}" || die
	done
}

EXPORT_FUNCTIONS src_configure || die