summaryrefslogtreecommitdiff
path: root/sys-power/tlp/tlp-1.10.1.ebuild
blob: 57f63952f238f3c15b4378e077f2755532108cd9 (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
# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{13..14} )

inherit udev optfeature python-single-r1

DESCRIPTION="Optimize laptop battery life"
HOMEPAGE="https://linrunner.de/tlp/"
SRC_URI="https://github.com/linrunner/TLP/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/TLP-${PV}"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
REQUIRED_USE="ppd? ( ${PYTHON_REQUIRED_USE} )"

IUSE="
	+ppd
	+rdw
"

# NOTE(JayF): Upstream dep list in human-readable format:
#             https://linrunner.de/tlp/developers/dependencies.html
# NOTE(JayF): Blockers for these are not ideal, however all three
#             of these packages implement the same service on dbus
#             and have conflicting files as a result. Long-term
#             there likely needs to be a better solution. See
#             https://bugs.gentoo.org/967823.
RDEPEND="
	dev-lang/perl
	net-wireless/iw
	sys-apps/hdparm
	sys-apps/pciutils
	sys-apps/usbutils
	virtual/udev
	ppd? (
		!sys-apps/tuned[ppd]
		!sys-power/power-profiles-daemon
		$(python_gen_cond_dep 'dev-python/dbus-python[${PYTHON_USEDEP}]')
		$(python_gen_cond_dep 'dev-python/pygobject[${PYTHON_USEDEP}]')
		${PYTHON_DEPS}
	)
	rdw? ( net-misc/networkmanager )
"
DEPEND="${RDEPEND}"
DOCS=( changelog README.rst )

src_prepare() {
	# Add support for a PREFIX variable in the Makefile
	sed -e '/^TLP_[A-Z_]\+ \+?= \//s|/|$(TLP_PREFIX)/|' \
		-i Makefile || die

	default
}

src_compile() {
	# NOTE(JayF): TLP_WITH_ELOGIND/TLP_WITH_SYSTEMD are both only installing
	#             small init/config files.
	EMAKEARGS=(
		TLP_PREFIX="${EPREFIX}"
		TLP_ULIB="${EPREFIX}$(get_udevdir)"
		TLP_NO_INIT=1
		TLP_WITH_ELOGIND=1
		TLP_WITH_SYSTEMD=1
	)

	emake "${EMAKEARGS[@]}"
}

src_install() {
	local myemakeargs=(
		"${EMAKEARGS[@]}"
		DESTDIR="${D}"
		install-tlp install-man-tlp
	)

	use ppd && myemakeargs+=(
		install-pd
		install-man-pd
	)

	use rdw && myemakeargs+=(
		install-rdw
		install-man-rdw
	)

	emake "${myemakeargs[@]}"

	fperms 444 /usr/share/tlp/defaults.conf # manpage says this file should not be edited
	newinitd "${FILESDIR}/tlp.init" tlp
	newinitd "${FILESDIR}/tlp-pd.init" tlp-pd
	keepdir /var/lib/tlp # created by Makefile, probably important
	einstalldocs
}

pkg_postinst() {
	udev_reload

	optfeature "disable Wake-on-LAN" sys-apps/ethtool
	optfeature "see disk drive health info in tlp-stat" sys-apps/smartmontools
	optfeature "Sleep hooks" sys-auth/elogind sys-apps/systemd
	optfeature "Battery functions for ThinkPads prior to the Sandy Bridge generation (2011)" app-laptop/tp_smapi

	if has_version "sys-apps/tuned"; then
		ewarn
		ewarn "sys-apps/tuned is installed, but is "
		ewarn "documented by upstream sys-power/tlp to be conficting. "
		ewarn "For best results, uninstall one of these packages."
		ewarn
	fi

	if has_version "app-laptop/laptop-mode-tools"; then
		ewarn
		ewarn "app-laptop/laptop-mode-tools is installed, but is "
		ewarn "documented by upstream sys-power/tlp to be conficting. "
		ewarn "For best results, uninstall one of these packages."
		ewarn
	fi
}

pkg_postrm() {
	udev_reload
}