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