]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blob - Makefile
fd35f6a4ff702e3c592fc4c23037f32e678ea999
[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 "An additional TARGETS variable \"launcher\" is available. This"
26         @echo "installs a launcher called \"autorandr_launcher\". The launcher"
27         @echo "is able to be run by the user and calls autorandr automatically"
28         @echo "without using udev rules."
29         @echo
30         @echo "The following additional targets are available:"
31         @echo
32         @echo "    make deb        creates a Debian package"
33
34 # Rules for autorandr itself
35 DEFAULT_TARGETS=autorandr
36
37 install_autorandr:
38         install -D -m 755 autorandr.py ${DESTDIR}${PREFIX}/bin/autorandr
39
40 uninstall_autorandr:
41         rm -f ${DESTDIR}${PREFIX}/bin/autorandr
42
43 # Rules for bash-completion
44 BASH_COMPLETIONS_DIR:=$(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null)
45 ifneq (,$(BASH_COMPLETIONS_DIR))
46 DEFAULT_TARGETS+=bash_completion
47 endif
48
49 install_bash_completion:
50         install -D -m 644 contrib/bash_completion/autorandr ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
51
52 uninstall_bash_completion:
53         rm -f ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
54
55 # Rules for autostart config
56 XDG_AUTOSTART_DIR=/etc/xdg/autostart
57 DEFAULT_TARGETS+=autostart_config
58
59 install_autostart_config:
60         install -D -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
61 ifneq ($(PREFIX),/usr/)
62         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
63 endif
64
65 uninstall_autostart_config:
66         rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
67
68 # Rules for systemd
69 SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null)
70 ifneq (,$(SYSTEMD_UNIT_DIR))
71 DEFAULT_TARGETS+=systemd
72 endif
73
74 install_systemd:
75         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
76         install -D -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
77 ifneq ($(PREFIX),/usr/)
78         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
79 endif
80         @echo
81         @echo "To activate the systemd unit, run this command as root:"
82         @echo "    systemctl daemon-reload"
83         @echo "    systemctl enable autorandr.service"
84         @echo
85
86 uninstall_systemd:
87         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
88         rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
89
90 # Rules for pmutils
91 PM_SLEEPHOOKS_DIR:=$(shell pkg-config --variable=pm_sleephooks pm-utils 2>/dev/null)
92 ifneq (,$(PM_SLEEPHOOKS_DIR))
93 ifeq (,$(SYSTEMD_UNIT_DIR))
94 DEFAULT_TARGETS+=pmutils
95 endif
96 endif
97
98 install_pmutils:
99         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
100         install -D -m 755 contrib/pm-utils/40autorandr ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
101 ifneq ($(PREFIX),/usr/)
102         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
103 endif
104
105 uninstall_pmutils:
106         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
107         rm -f ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
108
109
110 # Rules for udev
111 UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d
112 ifneq (,$(UDEV_RULES_DIR),y)
113 DEFAULT_TARGETS+=udev
114 endif
115
116 install_udev:
117         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
118         mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/
119         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
120         @echo
121         @echo "To activate the udev rules, run this command as root:"
122         @echo "    udevadm control --reload-rules"
123         @echo
124
125 uninstall_udev:
126         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
127         rm -f ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
128
129 # Rules for manpage
130 MANDIR:=${PREFIX}/share/man/man1
131 DEFAULT_TARGETS+=manpage
132
133 install_manpage:
134         mkdir -p ${DESTDIR}/${MANDIR}
135         cp autorandr.1 ${DESTDIR}/${MANDIR}
136
137 uninstall_manpage:
138         rm -f ${DESTDIR}/${MANDIR}/autorandr.1
139
140 # Rules for launcher
141 install_launcher:
142         gcc -Wall contrib/autorandr_launcher/autorandr_launcher.c -o contrib/autorandr_launcher/autorandr_launcher -lxcb -lxcb-randr
143         install -D -m 755 contrib/autorandr_launcher/autorandr_launcher ${DESTDIR}${PREFIX}/bin/autorandr_launcher
144
145 uninstall_launcher:
146         rm -f ${DESTDIR}${PREFIX}/bin/autorandr_launcher
147
148 TARGETS=$(DEFAULT_TARGETS)
149 install: $(patsubst %,install_%,$(TARGETS))
150 uninstall: $(patsubst %,uninstall_%,$(TARGETS))
151
152 deb:
153         ./contrib/packaging/debian/make_deb.sh