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