-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (70 loc) · 2.55 KB
/
Makefile
File metadata and controls
91 lines (70 loc) · 2.55 KB
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
CC = gcc
DEBUG = -g
CFLAGS_COMMON = -O2 -Wall -fPIC -c $(DEBUG)
CFLAGS = $(CFLAGS_COMMON)
CFLAGS_PLUGINS = $(CFLAGS_COMMON)
EXTRA_CFLAGS = $(shell pkg-config --cflags libnotify)
LFLAGS_COMMON = -O2 -Wall $(DEBUG)
LFLAGS = $(shell pkg-config --libs libnotify) -lncurses -lz -ldl -lm $(LFLAGS_COMMON)
LFLAGS_PLUGINS = -shared $(LFLAGS_COMMON)
PROGRAM = chatsow
LOCAL = ~/.$(PROGRAM)/
SOURCE = source/
BUILD = build/
RELEASE = release/
PLUGINS = $(SOURCE)plugins/
BUILD_PLUGINS = $(BUILD)plugins/
RELEASE_PLUGINS = $(RELEASE)plugins/
THIS = Makefile
CFILES = $(wildcard $(SOURCE)*.c)
MODULES = $(patsubst $(SOURCE)%.c,%,$(CFILES))
OBJS = $(addprefix $(BUILD),$(addsuffix .o,$(MODULES)))
$(shell mkdir -p $(BUILD))
CFILES_PLUGINS = $(wildcard $(PLUGINS)*.c)
MODULES_PLUGINS = $(patsubst $(PLUGINS)%.c,%,$(CFILES_PLUGINS))
OBJS_PLUGINS = $(addprefix $(BUILD_PLUGINS),$(addsuffix .o,$(MODULES_PLUGINS)))
LIBS_PLUGINS = $(addprefix $(RELEASE_PLUGINS),$(addsuffix .so,$(MODULES_PLUGINS)))
$(shell mkdir -p $(BUILD))
$(shell mkdir -p $(BUILD_PLUGINS))
default: program plugins
program: $(RELEASE)$(PROGRAM)
plugins: $(LIBS_PLUGINS)
clean:
rm -rf $(BUILD)
test: program plugins
./$(RELEASE)$(PROGRAM)
loop:
while true; do make test; done
updateloop:
while true; do git pull && make test; done
$(RELEASE)$(PROGRAM): $(OBJS)
$(CC) $^ $(LFLAGS) -o $@
define module_depender
$(shell touch $(BUILD)$(1).d)
$(shell makedepend -f $(BUILD)$(1).d -- $(CFLAGS) -- $(SOURCE)$(1).c
2>/dev/null)
$(shell sed -i 's~^$(SOURCE)~$(BUILD)~g' $(BUILD)$(1).d)
-include $(BUILD)$(1).d
endef
define module_compiler
$(BUILD)$(1).o: $(SOURCE)$(1).c $(THIS)
$(CC) $(EXTRA_CFLAGS) $(CFLAGS) $$< -o $$@
endef
$(foreach module, $(MODULES), $(eval $(call module_depender,$(module))))
$(foreach module, $(MODULES), $(eval $(call module_compiler,$(module))))
define plugin_module_depender
$(shell touch $(BUILD_PLUGINS)$(1).d)
$(shell makedepend -f $(BUILD_PLUGINS)$(1).d -- $(CFLAGS_PLUGINS) -- $(PLUGINS)$(1).c
2>/dev/null)
$(shell sed -i 's~^$(PLUGINS)~$(BUILD_PLUGINS)~g' $(BUILD_PLUGINS)$(1).d)
-include $(BUILD_PLUGINS)$(1).d
endef
define plugin_module_compiler
$(BUILD_PLUGINS)$(1).o: $(PLUGINS)$(1).c $(THIS)
$(CC) $(CFLAGS_PLUGINS) $$< -o $$@
$(RELEASE_PLUGINS)$(1).so: $(BUILD_PLUGINS)$(1).o $(BUILD)import.o $(BUILD)utils.o $(BUILD)cs.o
$(CC) $$^ $(LFLAGS_PLUGINS) -o $$@
endef
$(foreach module, $(MODULES_PLUGINS), $(eval $(call plugin_module_depender,$(module))))
$(foreach module, $(MODULES_PLUGINS), $(eval $(call plugin_module_compiler,$(module))))
.PHONY: default program plugins clean test loop updateloop