+ rm -f ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
+
+# Rules for autostart config
+XDG_AUTOSTART_DIR=/etc/xdg/autostart
+DEFAULT_TARGETS+=autostart_config
+
+install_autostart_config:
+ mkdir -p ${DESTDIR}/${XDG_AUTOSTART_DIR}
+ install -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
+ # KDE-specific autostart (workaround for https://github.com/systemd/systemd/issues/18791)
+ install -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
+ desktop-file-edit --remove-key=X-GNOME-Autostart-Phase --add-only-show-in=KDE ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
+
+ifneq ($(PREFIX),/usr/)
+ sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
+ sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
+endif
+
+uninstall_autostart_config:
+ rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
+ rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
+
+# Rules for systemd
+SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null)
+ifneq (,$(SYSTEMD_UNIT_DIR))
+DEFAULT_TARGETS+=systemd
+endif
+
+install_systemd:
+ $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
+ mkdir -p ${DESTDIR}/${SYSTEMD_UNIT_DIR}
+ install -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
+ install -m 644 contrib/systemd/autorandr-lid-listener.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr-lid-listener.service
+ifneq ($(PREFIX),/usr/)
+ sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
+endif
+ @echo
+ @echo "To activate the systemd units, run this command as root:"
+ @echo " systemctl daemon-reload"
+ @echo " systemctl enable autorandr.service"
+ @echo " systemctl enable autorandr-lid-listener.service"
+ @echo
+
+uninstall_systemd:
+ $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
+ rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
+ rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr-lid-listener.service