-install_launcher:
- gcc -Wall contrib/autorandr_launcher/autorandr_launcher.c -o contrib/autorandr_launcher/autorandr_launcher -lxcb -lxcb-randr
- install -D -m 755 contrib/autorandr_launcher/autorandr_launcher ${DESTDIR}${PREFIX}/bin/autorandr_launcher
+# Rules for manpage
+MANDIR:=${PREFIX}/share/man/man1
+DEFAULT_TARGETS+=manpage
+
+install_manpage:
+ mkdir -p ${DESTDIR}/${MANDIR}
+ cp autorandr.1 ${DESTDIR}/${MANDIR}
+
+uninstall_manpage:
+ rm -f ${DESTDIR}/${MANDIR}/autorandr.1
+
+# Rules for launcher
+LAUNCHER_LDLIBS=$(shell pkg-config --libs pkg-config xcb xcb-randr 2>/dev/null)
+ifneq (,$(LAUNCHER_LDLIBS))
+CLEANUP_FILES+=contrib/autorandr_launcher/autorandr-launcher
+LAUNCHER_CFLAGS=$(shell pkg-config --cflags pkg-config xcb xcb-randr 2>/dev/null)
+DEF_AUTORANDR_PATH="-DAUTORANDR_PATH=\"${DESTDIR}${PREFIX}/bin/autorandr\""
+contrib/autorandr_launcher/autorandr-launcher: contrib/autorandr_launcher/autorandr_launcher.c
+ $(CC) $(CFLAGS) $(LAUNCHER_CFLAGS) $(DEF_AUTORANDR_PATH) -o $@ $+ $(LDFLAGS) $(LAUNCHER_LDLIBS) $(LDLIBS)
+
+install_launcher: contrib/autorandr_launcher/autorandr-launcher
+ mkdir -p ${DESTDIR}${PREFIX}/bin
+ install -m 755 contrib/autorandr_launcher/autorandr-launcher ${DESTDIR}${PREFIX}/bin/autorandr-launcher
+ mkdir -p ${DESTDIR}/${XDG_AUTOSTART_DIR}
+ install -m 644 contrib/etc/xdg/autostart/autorandr-launcher.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
+ifneq ($(PREFIX),/usr/)
+ sed -i -re 's#/usr/bin/autorandr-launcher#$(subst #,\#,${PREFIX})/bin/autorandr-launcher#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
+endif
+endif