]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blob - Makefile
Fix two minor issues with the Makefile
[deb_pkgs/autorandr.git] / Makefile
1 DESTDIR=/
2 PREFIX=/usr/
3 RPM_SPEC=contrib/packaging/rpm/autorandr.spec
4 CFLAGS=-O2
5
6 .PHONY: all install uninstall autorandr bash_completion autostart_config pmutils systemd udev
7
8 all:
9         @echo "Call \"make install\" to install this program."
10         @echo "Call \"make uninstall\" to remove this program."
11         @echo
12         @echo "The following components were autodetected and will be installed:"
13         @echo " "$(DEFAULT_TARGETS)
14         @echo
15         @echo "The following locations have been detected (from pkg-config):"
16         @echo " - BASH_COMPLETIONS_DIR: $(BASH_COMPLETIONS_DIR)"
17         @echo " - SYSTEMD_UNIT_DIR: $(SYSTEMD_UNIT_DIR)"
18         @echo " - UDEV_RULES_DIR: $(UDEV_RULES_DIR)"
19         @echo " - PM_SLEEPHOOKS_DIR: $(PM_SLEEPHOOKS_DIR)"
20         @echo
21         @echo "You can use the TARGETS variable to override this, but need to set"
22         @echo "the SYSTEMD_UNIT_DIR, PM_SLEEPHOOKS_DIR and UDEV_RULES_DIR variables"
23         @echo "in case they were not detected correctly."
24         @echo
25         @echo 'E.g. "make install TARGETS='autorandr pmutils' PM_UTILS_DIR=/etc/pm/sleep.d".'
26         @echo
27         @echo "By default, if xcb libraries are available, autorandr prefers to"
28         @echo "install a launcher that listens for X11 randr events and runs"
29         @echo "autorandr whenever something changes, over udev/systemd rules."
30         @echo
31         @echo "The following additional targets are available:"
32         @echo
33         @echo "    make deb        creates a Debian package"
34         @echo "    make rpm        creates a RPM package"
35
36 # Rules for autorandr itself
37 DEFAULT_TARGETS=autorandr
38
39 install_autorandr:
40         install -D -m 755 autorandr.py ${DESTDIR}${PREFIX}/bin/autorandr
41
42 uninstall_autorandr:
43         rm -f ${DESTDIR}${PREFIX}/bin/autorandr
44
45 # Rules for bash-completion
46 BASH_COMPLETIONS_DIR:=$(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null)
47 ifneq (,$(BASH_COMPLETIONS_DIR))
48 DEFAULT_TARGETS+=bash_completion
49 endif
50
51 install_bash_completion:
52         install -D -m 644 contrib/bash_completion/autorandr ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
53
54 uninstall_bash_completion:
55         rm -f ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
56
57 # Rules for autostart config
58 XDG_AUTOSTART_DIR=/etc/xdg/autostart
59 DEFAULT_TARGETS+=autostart_config
60
61 install_autostart_config:
62         install -D -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
63 ifneq ($(PREFIX),/usr/)
64         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
65 endif
66
67 uninstall_autostart_config:
68         rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
69
70 # Rules for systemd
71 SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null)
72 ifneq (,$(SYSTEMD_UNIT_DIR))
73 DEFAULT_TARGETS+=systemd
74 endif
75
76 install_systemd:
77         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
78         install -D -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
79 ifneq ($(PREFIX),/usr/)
80         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
81 endif
82         @echo
83         @echo "To activate the systemd unit, run this command as root:"
84         @echo "    systemctl daemon-reload"
85         @echo "    systemctl enable autorandr.service"
86         @echo
87
88 uninstall_systemd:
89         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
90         rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
91
92 # Rules for pmutils
93 PM_SLEEPHOOKS_DIR:=$(shell pkg-config --variable=pm_sleephooks pm-utils 2>/dev/null)
94 ifneq (,$(PM_SLEEPHOOKS_DIR))
95 ifeq (,$(SYSTEMD_UNIT_DIR))
96 DEFAULT_TARGETS+=pmutils
97 endif
98 endif
99
100 install_pmutils:
101         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
102         install -D -m 755 contrib/pm-utils/40autorandr ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
103 ifneq ($(PREFIX),/usr/)
104         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
105 endif
106
107 uninstall_pmutils:
108         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
109         rm -f ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
110
111
112 # Rules for udev
113 UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d
114 ifneq (/rules.d,$(UDEV_RULES_DIR))
115 DEFAULT_TARGETS+=udev
116 endif
117
118 install_udev:
119         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
120         mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/
121         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
122         @echo
123         @echo "To activate the udev rules, run this command as root:"
124         @echo "    udevadm control --reload-rules"
125         @echo
126
127 uninstall_udev:
128         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
129         rm -f ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
130
131 # Rules for manpage
132 MANDIR:=${PREFIX}/share/man/man1
133 DEFAULT_TARGETS+=manpage
134
135 install_manpage:
136         mkdir -p ${DESTDIR}/${MANDIR}
137         cp autorandr.1 ${DESTDIR}/${MANDIR}
138
139 uninstall_manpage:
140         rm -f ${DESTDIR}/${MANDIR}/autorandr.1
141
142 # Rules for launcher
143 LAUNCHER_FLAGS=$(shell pkg-config --libs --cflags pkg-config xcb xcb-randr 2>/dev/null)
144 ifneq (,$(LAUNCHER_FLAGS))
145 DEFAULT_TARGETS+=launcher
146 DEFAULT_TARGETS:=$(filter-out systemd udev,$(DEFAULT_TARGETS))
147 endif
148
149 install_launcher:
150         gcc -Wall $(CFLAGS) contrib/autorandr_launcher/autorandr_launcher.c -o contrib/autorandr_launcher/autorandr-launcher $(LAUNCHER_FLAGS)
151         install -D -m 755 contrib/autorandr_launcher/autorandr_launcher ${DESTDIR}${PREFIX}/bin/autorandr-launcher
152
153         install -D -m 644 contrib/etc/xdg/autostart/autorandr-launcher.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
154 ifneq ($(PREFIX),/usr/)
155         sed -i -re 's#/usr/bin/autorandr-launcher#$(subst #,\#,${PREFIX})/bin/autorandr-launcher#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
156 endif
157
158 uninstall_launcher:
159         rm -f ${DESTDIR}${PREFIX}/bin/autorandr-launcher
160         rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
161
162 TARGETS=$(DEFAULT_TARGETS)
163 install: $(patsubst %,install_%,$(TARGETS))
164 uninstall: $(patsubst %,uninstall_%,$(TARGETS))
165
166 deb:
167         ./contrib/packaging/debian/make_deb.sh
168
169 rpm:
170         spectool -g -R $(RPM_SPEC)
171         rpmbuild -ba $(RPM_SPEC)