3 RPM_SPEC=contrib/packaging/rpm/autorandr.spec
6 .PHONY: all install uninstall autorandr bash_completion autostart_config pmutils systemd udev
9 @echo "Call \"make install\" to install this program."
10 @echo "Call \"make uninstall\" to remove this program."
12 @echo "The following components were autodetected and will be installed:"
13 @echo " "$(DEFAULT_TARGETS)
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)"
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."
25 @echo 'E.g. "make install TARGETS='autorandr pmutils' PM_UTILS_DIR=/etc/pm/sleep.d".'
27 @echo "An additional TARGETS variable \"launcher\" is available. This"
28 @echo "installs a launcher called \"autorandr_launcher\". The launcher"
29 @echo "is able to be run by the user and calls autorandr automatically"
30 @echo "without using udev rules. The launcher is an alternative to the"
31 @echo "udev/systemd setup that is more stable for some users."
33 @echo "The following additional targets are available:"
35 @echo " make deb creates a Debian package"
36 @echo " make rpm creates a RPM package"
38 # Rules for autorandr itself
39 DEFAULT_TARGETS=autorandr
42 install -D -m 755 autorandr.py ${DESTDIR}${PREFIX}/bin/autorandr
45 rm -f ${DESTDIR}${PREFIX}/bin/autorandr
47 # Rules for bash-completion
48 BASH_COMPLETIONS_DIR:=$(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null)
49 ifneq (,$(BASH_COMPLETIONS_DIR))
50 DEFAULT_TARGETS+=bash_completion
53 install_bash_completion:
54 install -D -m 644 contrib/bash_completion/autorandr ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
56 uninstall_bash_completion:
57 rm -f ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
59 # Rules for autostart config
60 XDG_AUTOSTART_DIR=/etc/xdg/autostart
61 DEFAULT_TARGETS+=autostart_config
63 install_autostart_config:
64 install -D -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
65 ifneq ($(PREFIX),/usr/)
66 sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
69 uninstall_autostart_config:
70 rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
73 SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null)
74 ifneq (,$(SYSTEMD_UNIT_DIR))
75 DEFAULT_TARGETS+=systemd
79 $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
80 install -D -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
81 ifneq ($(PREFIX),/usr/)
82 sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
85 @echo "To activate the systemd unit, run this command as root:"
86 @echo " systemctl daemon-reload"
87 @echo " systemctl enable autorandr.service"
91 $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
92 rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
95 PM_SLEEPHOOKS_DIR:=$(shell pkg-config --variable=pm_sleephooks pm-utils 2>/dev/null)
96 ifneq (,$(PM_SLEEPHOOKS_DIR))
97 ifeq (,$(SYSTEMD_UNIT_DIR))
98 DEFAULT_TARGETS+=pmutils
103 $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
104 install -D -m 755 contrib/pm-utils/40autorandr ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
105 ifneq ($(PREFIX),/usr/)
106 sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
110 $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
111 rm -f ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
115 UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d
116 ifneq (/rules.d,$(UDEV_RULES_DIR))
117 DEFAULT_TARGETS+=udev
121 $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
122 mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/
123 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
125 @echo "To activate the udev rules, run this command as root:"
126 @echo " udevadm control --reload-rules"
130 $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
131 rm -f ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
134 MANDIR:=${PREFIX}/share/man/man1
135 DEFAULT_TARGETS+=manpage
138 mkdir -p ${DESTDIR}/${MANDIR}
139 cp autorandr.1 ${DESTDIR}/${MANDIR}
142 rm -f ${DESTDIR}/${MANDIR}/autorandr.1
145 LAUNCHER_FLAGS=$(shell pkg-config --libs --cflags pkg-config xcb xcb-randr 2>/dev/null)
147 gcc -Wall $(CFLAGS) contrib/autorandr_launcher/autorandr_launcher.c -o contrib/autorandr_launcher/autorandr-launcher $(LAUNCHER_FLAGS)
148 install -D -m 755 contrib/autorandr_launcher/autorandr-launcher ${DESTDIR}${PREFIX}/bin/autorandr-launcher
150 install -D -m 644 contrib/etc/xdg/autostart/autorandr-launcher.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
151 ifneq ($(PREFIX),/usr/)
152 sed -i -re 's#/usr/bin/autorandr-launcher#$(subst #,\#,${PREFIX})/bin/autorandr-launcher#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
156 rm -f ${DESTDIR}${PREFIX}/bin/autorandr-launcher
157 rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
159 TARGETS=$(DEFAULT_TARGETS)
160 install: $(patsubst %,install_%,$(TARGETS))
161 uninstall: $(patsubst %,uninstall_%,$(TARGETS))
164 ./contrib/packaging/debian/make_deb.sh
167 spectool -g -R $(RPM_SPEC)
168 rpmbuild -ba $(RPM_SPEC)