-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmakefile
105 lines (92 loc) · 2.59 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# globals
default: build
freshen: clean build
clean:
rm -rf dist apexctl
# vars
SHELL := /bin/bash
INSTALL_ROOT ?= /
# lists
hs_files = src/Main.hs
config_files = \
config/90-apexctl.rules \
config/90-apex.hwdb \
config/Xmodmap
binary = dist/build/apexctl/apexctl
binary_install_dir = /usr/local/bin
# build defs
$(binary): $(hs_files)
cabal configure
cabal build
apexctl: $(binary)
cp $(binary) $@
# checks
check-build:
[ -f apexctl ]
[ -f $(binary) ]
check-root:
[[ `whoami` = "root" ]]
check-installed:
[ -f $(INSTALL_ROOT)$(binary_install_dir)/apexctl ]
[ -f $(INSTALL_ROOT)/etc/udev/hwdb.d/90-apex.hwdb ]
[ -f $(INSTALL_ROOT)/etc/udev/rules.d/90-apexctl.rules ]
[ -f $(INSTALL_ROOT)/etc/X11/Xmodmap.bak ]
echo -en "ApexCtl is fully installed\n"
# basic commands
build: $(binary) apexctl
enable: check-root
# enable keys
./apexctl
# reload udev rules
udevadm hwdb --update
udevadm control --reload
# apply xmodmap
xmodmap config/Xmodmap
# global installation
install: check-build
# make dirs
mkdir -p $(INSTALL_ROOT)/etc/udev/hwdb.d
mkdir -p $(INSTALL_ROOT)/etc/udev/rules.d
# install binary
install -m 755 apexctl $(INSTALL_ROOT)$(binary_install_dir)/apexctl
# install udev rules
install config/90-apex.hwdb $(INSTALL_ROOT)/etc/udev/hwdb.d/
install config/90-apexctl.rules $(INSTALL_ROOT)/etc/udev/rules.d/
# install Xmodmap globally
[[ -f $(INSTALL_ROOT)/etc/X11/Xmodmap ]] && \
cp $(INSTALL_ROOT)/etc/X11/Xmodmap $(INSTALL_ROOT)/etc/X11/Xmodmap.bak || :
cat config/Xmodmap >> $(INSTALL_ROOT)/etc/X11/Xmodmap
uninstall:
# remove binary, scripts, and udev rules
rm -f \
$(INSTALL_ROOT)$(binary_install_dir)/apexctl \
$(INSTALL_ROOT)/etc/udev/hwdb.d/90-apex.hwdb \
$(INSTALL_ROOT)/etc/udev/rules.d/90-apexctl.rules
# unapply Xmodmap using backup made during install
[[ -f $(INSTALL_ROOT)/etc/X11/Xmodmap.bak ]] && \
cp $(INSTALL_ROOT)/etc/X11/Xmodmap $(INSTALL_ROOT)/etc/X11/Xmodmap.bak2 && \
mv $(INSTALL_ROOT)/etc/X11/Xmodmap.bak $(INSTALL_ROOT)/etc/X11/Xmodmap || :
# reload udev rules
udevadm hwdb --update
udevadm control --reload
reinstall: \
check-build \
uninstall install
# local installation
local-install: check-build
# make dirs
mkdir -p ~/.local/bin
# install binary
install -m 755 apexctl ~/.local/bin/apexctl
# install Xmodmap locally
[[ -f ~/.Xmodmap ]] && \
cp ~/.Xmodmap ~/.Xmodmap.bak || :
cat config/Xmodmap >> /etc/X11/Xmodmap
install config/Xmodmap ~/.Xmodmap
local-uninstall:
# remove binary, scripts, and Xmodmap
rm -f ~/.local/bin/apexctl ~/.Xmodmap
local-reinstall: check-build \
local-uninstall local-install
test:
echo $(INSTALL_ROOT)