3 RPM_SPEC=contrib/packaging/rpm/autorandr.spec
7 .PHONY: all install uninstall autorandr bash_completion autostart_config pmutils systemd udev
10 @echo "Call \"make install\" to install this program."
11 @echo "Call \"make uninstall\" to remove this program."
13 @echo "The following components were autodetected and will be installed:"
14 @echo " "$(DEFAULT_TARGETS)
16 @echo "The following locations have been detected (from pkg-config):"
17 @echo " - BASH_COMPLETIONS_DIR: $(BASH_COMPLETIONS_DIR)"
18 @echo " - SYSTEMD_UNIT_DIR: $(SYSTEMD_UNIT_DIR)"
19 @echo " - UDEV_RULES_DIR: $(UDEV_RULES_DIR)"
20 @echo " - PM_SLEEPHOOKS_DIR: $(PM_SLEEPHOOKS_DIR)"
22 @echo "You can use the TARGETS variable to override this, but need to set"
23 @echo "the SYSTEMD_UNIT_DIR, PM_SLEEPHOOKS_DIR and UDEV_RULES_DIR variables"
24 @echo "in case they were not detected correctly."
26 @echo 'E.g. "make install TARGETS='autorandr pmutils' PM_UTILS_DIR=/etc/pm/sleep.d".'
28 @echo "An additional TARGETS variable \"launcher\" is available. This"
29 @echo "installs a launcher called \"autorandr_launcher\". The launcher"
30 @echo "is able to be run by the user and calls autorandr automatically"
31 @echo "without using udev rules. The launcher is an alternative to the"
32 @echo "udev/systemd setup that is more stable for some users."
34 @echo "The following additional targets are available:"
36 @echo " make deb creates a Debian package"
37 @echo " make rpm creates a RPM package"
39 # Rules for autorandr itself
40 DEFAULT_TARGETS=autorandr
43 install -D -m 755 autorandr.py ${DESTDIR}${PREFIX}/bin/autorandr
46 rm -f ${DESTDIR}${PREFIX}/bin/autorandr
48 # Rules for bash-completion
49 BASH_COMPLETIONS_DIR:=$(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null)
50 ifneq (,$(BASH_COMPLETIONS_DIR))
51 DEFAULT_TARGETS+=bash_completion
54 install_bash_completion:
55 install -D -m 644 contrib/bash_completion/autorandr ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
57 uninstall_bash_completion:
58 rm -f ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
60 # Rules for autostart config
61 XDG_AUTOSTART_DIR=/etc/xdg/autostart
62 DEFAULT_TARGETS+=autostart_config
64 install_autostart_config:
65 install -D -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
66 ifneq ($(PREFIX),/usr/)
67 sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
70 uninstall_autostart_config:
71 rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
74 SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null)
75 ifneq (,$(SYSTEMD_UNIT_DIR))
76 DEFAULT_TARGETS+=systemd
80 $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
81 install -D -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
82 ifneq ($(PREFIX),/usr/)
83 sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
86 @echo "To activate the systemd unit, run this command as root:"
87 @echo " systemctl daemon-reload"
88 @echo " systemctl enable autorandr.service"
92 $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
93 rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
96 PM_SLEEPHOOKS_DIR:=$(shell pkg-config --variable=pm_sleephooks pm-utils 2>/dev/null)
97 ifneq (,$(PM_SLEEPHOOKS_DIR))
98 ifeq (,$(SYSTEMD_UNIT_DIR))
99 DEFAULT_TARGETS+=pmutils
104 $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
105 install -D -m 755 contrib/pm-utils/40autorandr ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
106 ifneq ($(PREFIX),/usr/)
107 sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
111 $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
112 rm -f ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
116 UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d
117 ifneq (/rules.d,$(UDEV_RULES_DIR))
118 DEFAULT_TARGETS+=udev
122 $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
123 mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/
124 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
126 @echo "To activate the udev rules, run this command as root:"
127 @echo " udevadm control --reload-rules"
131 $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
132 rm -f ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
135 MANDIR:=${PREFIX}/share/man/man1
136 DEFAULT_TARGETS+=manpage
139 mkdir -p ${DESTDIR}/${MANDIR}
140 cp autorandr.1 ${DESTDIR}/${MANDIR}
143 rm -f ${DESTDIR}/${MANDIR}/autorandr.1
146 LAUNCHER_LDLIBS=$(shell pkg-config --libs pkg-config xcb xcb-randr 2>/dev/null)
147 ifneq (,$(LAUNCHER_LDLIBS))
148 CLEANUP_FILES+=contrib/autorandr_launcher/autorandr-launcher
149 LAUNCHER_CFLAGS=$(shell pkg-config --cflags pkg-config xcb xcb-randr 2>/dev/null)
150 contrib/autorandr_launcher/autorandr-launcher: contrib/autorandr_launcher/autorandr_launcher.c
151 $(CC) $(CFLAGS) $(LAUNCHER_CFLAGS) -o $@ $+ $(LDFLAGS) $(LAUNCHER_LDLIBS) $(LDLIBS)
153 install_launcher: contrib/autorandr_launcher/autorandr-launcher
154 install -D -m 755 contrib/autorandr_launcher/autorandr-launcher ${DESTDIR}${PREFIX}/bin/autorandr-launcher
155 install -D -m 644 contrib/etc/xdg/autostart/autorandr-launcher.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
156 ifneq ($(PREFIX),/usr/)
157 sed -i -re 's#/usr/bin/autorandr-launcher#$(subst #,\#,${PREFIX})/bin/autorandr-launcher#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
162 rm -f ${DESTDIR}${PREFIX}/bin/autorandr-launcher
163 rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
165 TARGETS=$(DEFAULT_TARGETS)
166 install: $(patsubst %,install_%,$(TARGETS))
167 uninstall: $(patsubst %,uninstall_%,$(TARGETS))
170 ./contrib/packaging/debian/make_deb.sh
173 spectool -g -R $(RPM_SPEC)
174 rpmbuild -ba $(RPM_SPEC)
177 rm -f $(CLEANUP_FILES)