]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blob - Makefile
use pkg-config for bash-completion completions dir
[deb_pkgs/autorandr.git] / Makefile
1 DESTDIR=/
2 PREFIX=/usr/
3
4 .PHONY: all install uninstall autorandr bash_completion autostart_config pmutils systemd udev
5
6 all:
7         @echo "Call \"make install\" to install this program."
8         @echo "Call \"make uninstall\" to remove this program."
9         @echo
10         @echo "The following components were autodetected and will be installed:"
11         @echo " "$(DEFAULT_TARGETS)
12         @echo
13         @echo "The following locations have been detected (from pkg-config):"
14         @echo " - SYSTEMD_UNIT_DIR: $(SYSTEMD_UNIT_DIR)"
15         @echo " - UDEV_RULES_DIR: $(UDEV_RULES_DIR)"
16         @echo " - PM_SLEEPHOOKS_DIR: $(PM_SLEEPHOOKS_DIR)"
17         @echo
18         @echo "You can use the TARGETS variable to override this, but need to set"
19         @echo "the SYSTEMD_UNIT_DIR, PM_SLEEPHOOKS_DIR and UDEV_RULES_DIR variables"
20         @echo "in case they were not detected correctly."
21         @echo
22         @echo 'E.g. "make install TARGETS='autorandr pmutils' PM_UTILS_DIR=/etc/pm/sleep.d".'
23         @echo
24         @echo "The following additional targets are available:"
25         @echo
26         @echo "    make deb        creates a Debian package"
27
28 # Rules for autorandr itself
29 DEFAULT_TARGETS=autorandr
30
31 install_autorandr:
32         install -D -m 755 autorandr.py ${DESTDIR}${PREFIX}/bin/autorandr
33
34 uninstall_autorandr:
35         rm -f ${DESTDIR}${PREFIX}/bin/autorandr
36
37 # Rules for bash_completion
38 BASH_COMPLETION_DIR:=$(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null)
39 ifneq (,$(BASH_COMPLETION_DIR))
40 DEFAULT_TARGETS+=bash_completion
41 endif
42
43 install_bash_completion:
44         install -D -m 644 contrib/bash_completion/autorandr ${DESTDIR}/${BASH_COMPLETION_DIR}/autorandr
45
46 uninstall_bash_completion:
47         rm -f ${DESTDIR}/${BASH_COMPLETION_DIR}/autorandr
48
49 # Rules for autostart config
50 XDG_AUTOSTART_DIR=/etc/xdg/autostart
51 DEFAULT_TARGETS+=autostart_config
52
53 install_autostart_config:
54         install -D -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
55 ifneq ($(PREFIX),/usr/)
56         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
57 endif
58
59 uninstall_autostart_config:
60         rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
61
62 # Rules for systemd
63 SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null)
64 ifneq (,$(SYSTEMD_UNIT_DIR))
65 DEFAULT_TARGETS+=systemd
66 endif
67
68 install_systemd:
69         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
70         install -D -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
71 ifneq ($(PREFIX),/usr/)
72         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
73 endif
74         @echo
75         @echo "To activate the systemd unit, run this command as root:"
76         @echo "    systemctl daemon-reload"
77         @echo "    systemctl enable autorandr.service"
78         @echo
79
80 uninstall_systemd:
81         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
82         rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
83
84 # Rules for pmutils
85 PM_SLEEPHOOKS_DIR:=$(shell pkg-config --variable=pm_sleephooks pm-utils 2>/dev/null)
86 ifneq (,$(PM_SLEEPHOOKS_DIR))
87 ifeq (,$(SYSTEMD_UNIT_DIR))
88 DEFAULT_TARGETS+=pmutils
89 endif
90 endif
91
92 install_pmutils:
93         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
94         install -D -m 755 contrib/pm-utils/40autorandr ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
95 ifneq ($(PREFIX),/usr/)
96         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
97 endif
98
99 uninstall_pmutils:
100         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
101         rm -f ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
102
103
104 # Rules for udev
105 UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d
106 ifneq (,$(UDEV_RULES_DIR),y)
107 DEFAULT_TARGETS+=udev
108 endif
109
110 install_udev:
111         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
112         mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/
113         echo 'ACTION=="change", SUBSYSTEM=="drm", RUN+="$(if $(findstring systemd, $(TARGETS)),/bin/systemctl start --no-block autorandr.service,${PREFIX}/bin/autorandr --batch --change --default default)"' > ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
114         @echo
115         @echo "To activate the udev rules, run this command as root:"
116         @echo "    udevadm control --reload-rules"
117         @echo
118
119 uninstall_udev:
120         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
121         rm -f ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
122
123
124 TARGETS=$(DEFAULT_TARGETS)
125 install: $(patsubst %,install_%,$(TARGETS))
126 uninstall: $(patsubst %,uninstall_%,$(TARGETS))
127
128 deb:
129         ./contrib/packaging/debian/make_deb.sh