-
Notifications
You must be signed in to change notification settings - Fork 52
/
configure
executable file
·142 lines (125 loc) · 2.73 KB
/
configure
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
#!/bin/sh
# We don't support out of tree builds
cd "$(dirname -- "$0")"
# Default values
prefix="${PREFIX:-/usr/local}"
pudev="${UDEVDIR:-/lib/udev/rules.d}"
udev="auto"
logind="disabled"
sdbus="auto"
mode="auto"
help() {
cat <<EOF
Usage $0 [options]
Options: [defaults in brackets after description]
--help print this message
--prefix=PREFIX install in PREFIX [$prefix]
--install-mode=MODE brightnessctl installation mode [$mode]
--udev-dir=PATH installation path of the udev rules
[$pudev]
--dbus-provider=PROVIDER DBus library for logind one of systemd,
elogind, basu [$sdbus]
Optional features, enabled with --enable-FEATURE and disabled with
--disable-FEATURE: [default state in brackets after description]
udev Install udev rules [if logind is disabled]
logind Enable logind brighness API [$logind]
EOF
}
# Command line parsing, `getopt` is not used because long options are not in the
# posix interface
for opt do
optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
case "$opt" in
--help|-h)
help
exit 0
;;
--prefix=*) prefix="$optarg"
;;
--install-mode=*) mode="$optarg"
;;
--udev-dir=*) pudev="$optarg"
;;
--enable-udev) udev="enabled"
;;
--disable-udev) udev="disabled"
;;
--enable-logind) logind="enabled"
;;
--disable-logind) logind="disabled"
;;
--dbus-provider=*) sdbus="$optarg"
;;
*)
echo "Unknown option $opt" >&2
help >&2
exit 1
;;
esac
done
# Specialize automatic options
if [ "$udev" = "auto" ]; then
if [ "$logind" = "disabled" ]; then
udev="enabled"
else
udev="disabled"
fi
fi
if [ "$mode" = "auto" ]; then
if [ "$udev" = "disabled" ] && [ "$logind" = "disabled" ]; then
mode="4711"
else
mode="0755"
fi
fi
# Generate `config.mk`
cat >config.mk <<EOF
# auto-generated by configure
PREFIX = $prefix
MODE = $mode
UDEVDIR = $pudev
EOF
if [ "$udev" = "enabled" ]; then
echo 'INSTALL_UDEV_RULES = 1' >> config.mk
fi
if [ "$logind" = "enabled" ]; then
case "$sdbus" in
auto)
for prov in basu libelogind libsystemd; do
if pkg-config --exists "$prov"; then
bus_provider="$prov"
sdbus="$prov"
break
fi
done
if [ -z "$bus_provider" ]; then
echo "Unable to find a workind dbus provider"
exit 1
fi
;;
systemd) bus_provider=libsystemd
;;
elogind) bus_provider=libelogind
;;
basu) bus_provider=basu
;;
*)
echo "Unexpected dbus provider: $sdbus" >&2
exit 1
;;
esac
cat >> config.mk <<EOF
CFLAGS += $(pkg-config --cflags "$bus_provider")
LDLIBS += $(pkg-config --libs "$bus_provider")
CPPFLAGS += -DENABLE_LOGIND -DHAVE_$(echo "$bus_provider" | tr '[:lower:]' '[:upper:]')
EOF
fi
# Dump config to user
cat <<EOF
Build configuration:
PREFIX: $prefix
MODE: $mode
UDEV_DIR: $pudev
udev: $udev
logind: $logind [$sdbus]
EOF