]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blob - Makefile
add missing dependency on libinput-tools (Closes: #1035044)
[deb_pkgs/autorandr.git] / Makefile
1 DESTDIR=/
2 PREFIX=/usr/
3 RPM_SPEC=contrib/packaging/rpm/autorandr.spec
4 CFLAGS?=-O2 -Wall
5 CLEANUP_FILES=
6
7 .PHONY: all install uninstall autorandr bash_completion autostart_config pmutils systemd udev
8
9 all:
10         @echo "Call \"make install\" to install this program."
11         @echo "Call \"make uninstall\" to remove this program."
12         @echo
13         @echo "The following components were autodetected and will be installed:"
14         @echo " "$(DEFAULT_TARGETS)
15         @echo
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)"
21         @echo
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."
25         @echo
26         @echo 'E.g. "make install TARGETS='autorandr pmutils' PM_UTILS_DIR=/etc/pm/sleep.d".'
27         @echo
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."
33         @echo
34         @echo "The following additional targets are available:"
35         @echo
36         @echo "    make deb        creates a Debian package"
37         @echo "    make rpm        creates a RPM package"
38
39 # Rules for autorandr itself
40 DEFAULT_TARGETS=autorandr
41
42 install_autorandr:
43         mkdir -p ${DESTDIR}${PREFIX}/bin
44         install -m 755 autorandr.py ${DESTDIR}${PREFIX}/bin/autorandr
45
46 uninstall_autorandr:
47         rm -f ${DESTDIR}${PREFIX}/bin/autorandr
48
49 # Rules for bash-completion
50 BASH_COMPLETIONS_DIR:=$(shell pkg-config --variable=completionsdir bash-completion 2>/dev/null)
51 ifneq (,$(BASH_COMPLETIONS_DIR))
52 DEFAULT_TARGETS+=bash_completion
53 endif
54
55 install_bash_completion:
56         mkdir -p ${DESTDIR}/${BASH_COMPLETIONS_DIR}
57         install -m 644 contrib/bash_completion/autorandr ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
58
59 uninstall_bash_completion:
60         rm -f ${DESTDIR}/${BASH_COMPLETIONS_DIR}/autorandr
61
62 # Rules for autostart config
63 XDG_AUTOSTART_DIR=/etc/xdg/autostart
64 DEFAULT_TARGETS+=autostart_config
65
66 install_autostart_config:
67         mkdir -p ${DESTDIR}/${XDG_AUTOSTART_DIR}
68         install -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
69         # KDE-specific autostart (workaround for https://github.com/systemd/systemd/issues/18791)
70         install -m 644 contrib/etc/xdg/autostart/autorandr.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
71         desktop-file-edit --remove-key=X-GNOME-Autostart-Phase --add-only-show-in=KDE ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
72
73 ifneq ($(PREFIX),/usr/)
74         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
75         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
76 endif
77
78 uninstall_autostart_config:
79         rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr.desktop
80         rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-kde.desktop
81
82 # Rules for systemd
83 SYSTEMD_UNIT_DIR:=$(shell pkg-config --variable=systemdsystemunitdir systemd 2>/dev/null)
84 ifneq (,$(SYSTEMD_UNIT_DIR))
85 DEFAULT_TARGETS+=systemd
86 endif
87
88 install_systemd:
89         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
90         mkdir -p ${DESTDIR}/${SYSTEMD_UNIT_DIR}
91         install -m 644 contrib/systemd/autorandr.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
92         install -m 644 contrib/systemd/autorandr-lid-listener.service ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr-lid-listener.service
93 ifneq ($(PREFIX),/usr/)
94         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
95 endif
96         @echo
97         @echo "To activate the systemd units, run this command as root:"
98         @echo "    systemctl daemon-reload"
99         @echo "    systemctl enable autorandr.service"
100         @echo "    systemctl enable autorandr-lid-listener.service"
101         @echo
102
103 uninstall_systemd:
104         $(if $(SYSTEMD_UNIT_DIR),,$(error SYSTEMD_UNIT_DIR is not defined))
105         rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr.service
106         rm -f ${DESTDIR}/${SYSTEMD_UNIT_DIR}/autorandr-lid-listener.service
107
108 # Rules for pmutils
109 PM_SLEEPHOOKS_DIR:=$(shell pkg-config --variable=pm_sleephooks pm-utils 2>/dev/null)
110 ifneq (,$(PM_SLEEPHOOKS_DIR))
111 ifeq (,$(SYSTEMD_UNIT_DIR))
112 DEFAULT_TARGETS+=pmutils
113 endif
114 endif
115
116 install_pmutils:
117         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
118         mkdir -p ${DESTDIR}/${PM_SLEEPHOOKS_DIR}
119         install -m 755 contrib/pm-utils/40autorandr ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
120 ifneq ($(PREFIX),/usr/)
121         sed -i -re 's#/usr/bin/autorandr#$(subst #,\#,${PREFIX})/bin/autorandr#g' ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
122 endif
123
124 uninstall_pmutils:
125         $(if $(PM_SLEEPHOOKS_DIR),,$(error PM_SLEEPHOOKS_DIR is not defined))
126         rm -f ${DESTDIR}/${PM_SLEEPHOOKS_DIR}/40autorandr
127
128
129 # Rules for udev
130 UDEV_RULES_DIR:=$(shell pkg-config --variable=udevdir udev 2>/dev/null)/rules.d
131 ifneq (/rules.d,$(UDEV_RULES_DIR))
132 DEFAULT_TARGETS+=udev
133 endif
134
135 install_udev:
136         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
137         mkdir -p ${DESTDIR}/${UDEV_RULES_DIR}/
138         echo 'ACTION=="change", SUBSYSTEM=="drm", RUN+="$(if $(findstring systemd, $(DEFAULT_TARGETS)),/bin/systemctl start --no-block autorandr.service,${PREFIX}/bin/autorandr --batch --change --default default)"' > ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
139         @echo
140         @echo "To activate the udev rules, run this command as root:"
141         @echo "    udevadm control --reload-rules"
142         @echo
143
144 uninstall_udev:
145         $(if $(UDEV_RULES_DIR),,$(error UDEV_RULES_DIR is not defined))
146         rm -f ${DESTDIR}/${UDEV_RULES_DIR}/40-monitor-hotplug.rules
147
148 # Rules for manpage
149 MANDIR:=${PREFIX}/share/man/man1
150 DEFAULT_TARGETS+=manpage
151
152 install_manpage:
153         mkdir -p ${DESTDIR}/${MANDIR}
154         cp autorandr.1 ${DESTDIR}/${MANDIR}
155
156 uninstall_manpage:
157         rm -f ${DESTDIR}/${MANDIR}/autorandr.1
158
159 # Rules for launcher
160 LAUNCHER_LDLIBS=$(shell pkg-config --libs pkg-config xcb xcb-randr 2>/dev/null)
161 ifneq (,$(LAUNCHER_LDLIBS))
162 CLEANUP_FILES+=contrib/autorandr_launcher/autorandr-launcher
163 LAUNCHER_CFLAGS=$(shell pkg-config --cflags pkg-config xcb xcb-randr 2>/dev/null)
164 DEF_AUTORANDR_PATH="-DAUTORANDR_PATH=\"${DESTDIR}${PREFIX}/bin/autorandr\""
165 contrib/autorandr_launcher/autorandr-launcher: contrib/autorandr_launcher/autorandr_launcher.c
166         $(CC) $(CFLAGS) $(LAUNCHER_CFLAGS) $(DEF_AUTORANDR_PATH) -o $@ $+ $(LDFLAGS) $(LAUNCHER_LDLIBS) $(LDLIBS)
167
168 install_launcher: contrib/autorandr_launcher/autorandr-launcher
169         mkdir -p ${DESTDIR}${PREFIX}/bin
170         install -m 755 contrib/autorandr_launcher/autorandr-launcher ${DESTDIR}${PREFIX}/bin/autorandr-launcher
171         mkdir -p ${DESTDIR}/${XDG_AUTOSTART_DIR}
172         install -m 644 contrib/etc/xdg/autostart/autorandr-launcher.desktop ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
173 ifneq ($(PREFIX),/usr/)
174         sed -i -re 's#/usr/bin/autorandr-launcher#$(subst #,\#,${PREFIX})/bin/autorandr-launcher#g' ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
175 endif
176 endif
177
178 uninstall_launcher:
179         rm -f ${DESTDIR}${PREFIX}/bin/autorandr-launcher
180         rm -f ${DESTDIR}/${XDG_AUTOSTART_DIR}/autorandr-launcher.desktop
181
182 TARGETS=$(DEFAULT_TARGETS)
183 install: $(patsubst %,install_%,$(TARGETS))
184 uninstall: $(patsubst %,uninstall_%,$(TARGETS))
185
186 deb:
187         ./contrib/packaging/debian/make_deb.sh
188
189 rpm:
190         spectool -g -R $(RPM_SPEC)
191         rpmbuild -ba $(RPM_SPEC)
192
193 clean:
194         rm -f $(CLEANUP_FILES)