forked from donniebreve/touchcursor-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (108 loc) · 3.56 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Overridable variables
INSTALLPATH ?= /usr/bin
SERVICEPATH ?= $(HOME)/.config/systemd/user
CONFIGPATH ?= $(HOME)/.config/touchcursor
# Application variables
service = touchcursor.service
config = touchcursor.conf
# Build variables
src_path = ./src
obj_path = ./obj
out_path = ./out
binary = touchcursor
# LIBS = -lm
cc = gcc
cflags = -Wall
ldflags = -pthread
# All .h files
headers = $(wildcard $(src_path)/*.h)
# All .c files, excluding test.c
sources = $(filter-out $(src_path)/test.c, $(wildcard $(src_path)/*.c))
# Replace .c files with obj/filename.o from sources
objects = $(patsubst $(src_path)/%.c, $(obj_path)/%.o, $(sources))
# This is the main target of the make file
$(out_path)/$(binary): $(objects)
@mkdir --parents $(out_path)
$(cc) $(objects) $(ldflags) -o $@
# Each .o file depends on its .c file and .h file (we include all headers)
$(obj_path)/%.o: $(src_path)/%.c $(headers)
@mkdir --parents $(obj_path)
$(cc) $(cflags) -c $< -o $@
# This is the test binary target of the make file
test_binary = touchcursor_test
test_sources = $(filter-out $(src_path)/emit.c $(src_path)/main.c, $(wildcard $(src_path)/*.c))
test_objects = $(patsubst $(src_path)/%.c, $(obj_path)/%.o, $(test_sources))
$(out_path)/$(test_binary): $(test_objects)
@mkdir --parents $(out_path)
$(cc) $(test_objects) $(ldflags) -o $@
check: $(out_path)/$(test_binary)
$(out_path)/$(test_binary)
clean:
-rm --force obj/*.o
-rm --force $(out_path)/*
debug: $(out_path)/$(binary)
@echo "# Stopping the service"
-systemctl --user stop $(service)
@echo ""
@echo "# Chown root $(out_path)/$(binary)"
sudo chown root $(out_path)/$(binary)
@echo "# Chmod u+s $(out_path)/$(binary)"
sudo chmod u+s $(out_path)/$(binary)
@echo "# Run $(out_path)/$(binary)"
$(out_path)/$(binary)
install:
@echo "# Stopping and disabling the service"
-systemctl --user disable --now $(service)
@echo ""
@echo "# Copying application to $(INSTALLPATH)"
@echo "# This action requires sudo."
sudo cp --force $(out_path)/$(binary) $(INSTALLPATH)
sudo chmod u+s $(INSTALLPATH)/$(binary)
@echo ""
@echo "# Copying service file to $(SERVICEPATH)"
mkdir --parents $(SERVICEPATH)
cp --force $(service) $(SERVICEPATH)
@echo ""
@echo "# Copying default configuration file to $(CONFIGPATH)/$(config)"
mkdir --parents $(CONFIGPATH)
-cp --no-clobber $(config) $(CONFIGPATH)
@echo ""
@echo "# Enabling and starting the service"
systemctl --user daemon-reload
systemctl --user enable --now $(service)
uninstall:
@echo "# The configuration file will not be removed:"
@echo "# $(CONFIGPATH)/$(config)"
@echo ""
@echo "# To uninstall everything (including the configuration file)"
@echo "# run 'make uninstall-full'"
@echo ""
@echo "# Stopping and disabling the service"
-systemctl --user disable --now $(service)
systemctl --user daemon-reload
@echo ""
@echo "# Removing service file from $(SERVICEPATH)"
-rm $(SERVICEPATH)/$(service)
-rm --dir $(SERVICEPATH)
@echo ""
@echo "# Removing application from $(INSTALLPATH)"
@echo "# This action requires sudo."
-sudo rm $(INSTALLPATH)/$(binary)
@echo ""
uninstall-full:
@echo "# Stopping and disabling the service"
-systemctl --user disable --now $(service)
systemctl --user daemon-reload
@echo ""
@echo "# Removing service file from $(SERVICEPATH)"
-rm $(SERVICEPATH)/$(service)
-rm --dir $(SERVICEPATH)
@echo ""
@echo "# Removing application from $(INSTALLPATH)"
@echo "# This action requires sudo."
-sudo rm $(INSTALLPATH)/$(binary)
@echo ""
@echo "# Removing configuration file $(CONFIGPATH)/$(config)"
-rm $(CONFIGPATH)/$(config)
-rm --dir $(CONFIGPATH)
@echo ""