forked from Ideonella-sakaiensis/lib_mysqludf_redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (103 loc) · 3.15 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# lib_mysqludf_redis Makefile
PLUGIN_SOURCE = lib_mysqludf_redis.c
PLUGIN_NAME = lib_mysqludf_redis
# Environment variants
WITH_COMPILE_HIREDIS ?=1
WITH_COMPILE_CJSON ?=1
HIREDIS_MODULE_VER ?=0.13.3
CJSON_MODULE_VER ?=1.6.0
INCLUDE_PATH ?=
PLUGIN_PATH ?=
CURRENT_PATH =$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Constant variants
CC = gcc
CFLAGS := -shared -fPIC
CRPATH = -Wl,-rpath,$(PLUGIN_PATH)
COPTIONS = -I$(INCLUDE_PATH) -I./include $(CRPATH)
MAKE_CC=$(QUIET_CC)$(CC)
MAKE_LD=$(QUIET_LINK)$(CC)
MAKE_INSTALL=$(QUIET_INSTALL)$(INSTALL)
CCCOLOR ="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR ="\033[33m"
BINCOLOR ="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR ="\033[0m"
ifndef V
QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
QUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
endif
DYLIBSUFFIX=so
PLUGIN_LIBNAME=$(PLUGIN_NAME).$(DYLIBSUFFIX)
# Initialize variants
ifeq ("","$(INCLUDE_PATH)")
INCLUDE_PATH=$(shell mysql_config --variable=pkgincludedir)/server
endif
ifeq ("","$(PLUGIN_PATH)")
PLUGIN_PATH=$(shell mysql_config --plugindir)
endif
DEP_MODULES:=
DEP_LIBRARY:=
ifeq (1,$(WITH_COMPILE_HIREDIS))
DEP_MODULES:=$(DEP_MODULES) hiredis
DEP_LIBRARY:=$(DEP_LIBRARY) $(PLUGIN_PATH)/libhiredis.so
endif
ifeq (1,$(WITH_COMPILE_CJSON))
DEP_MODULES:=$(DEP_MODULES) cJSON
DEP_LIBRARY:=$(DEP_LIBRARY) $(PLUGIN_PATH)/libcjson.so
endif
all: $(PLUGIN_LIBNAME)
#Deps
$(PLUGIN_LIBNAME): $(DEP_MODULES)
ifeq ("","$(PLUGIN_PATH)")
@echo ""
@echo "Cannot find Mysql/MariaDB plugin_dir. Please specified the PLUGIN_PATH argument and try again."
@echo ""
@false
else
@echo "PLUGIN_PATH=$(PLUGIN_PATH)" > .makeconf
endif
cp -a ./lib/libhiredis.* $(PLUGIN_PATH)
-(restorecon $(PLUGIN_PATH)/libhiredis.*)
cp -a ./lib/libcjson.* $(PLUGIN_PATH)
-(restorecon $(PLUGIN_PATH)/libcjson.*)
$(MAKE_CC) $(PLUGIN_SOURCE) $(DEP_LIBRARY) $(CFLAGS) $(COPTIONS) -o $@
hiredis:
@(cd deps && $(MAKE) $@ HIREDIS_MODULE_VER=$(HIREDIS_MODULE_VER) INSTALL_PATH=$(CURRENT_PATH) INCLUDE_PATH=include/hiredis)
cJSON:
@(cd deps && $(MAKE) $@ CJSON_MODULE_VER=$(CJSON_MODULE_VER) INSTALL_PATH=$(CURRENT_PATH) INCLUDE_PATH=include/cjson)
.PHONY: all
INSTALL?= cp -a
ifneq ("$(wildcard .makeconf)", "")
PLUGIN_PATH=$(shell grep 'PLUGIN_PATH=' .makeconf | awk -F'=' '{print $$2}')
endif
install:
$(INSTALL) $(PLUGIN_LIBNAME) $(PLUGIN_PATH)
-(cd $(PLUGIN_PATH) && restorecon $(PLUGIN_LIBNAME))
-(setsebool -P mysql_connect_any 1)
@printf "\033[1;33m"
@echo ""
@echo "To register UDF, executing the following command:"
@printf "\033[0m""\033[1m"
@echo ""
@echo "$(MAKE) installdb"
@echo ""
@printf "\033[0m"
.PHONY: install
MYSQL_PORT?=$(shell mysql_config --port)
MYSQL=mysql -P $(MYSQL_PORT) -u root -p
installdb:
$(MYSQL) < installdb.sql
.PHONY: installdb
uninstalldb:
$(MYSQL) < uninstalldb.sql
.PHONY: uninstalldb
clean:
@-(rm -f .makeconf)
-rm -f $(PLUGIN_LIBNAME)
-rm -rf include lib
.PHONY: clean
distclean: clean
-cd ./deps && $(MAKE) distclean
.PHONY: reset