forked from uber-archive/vertica-aesgcm-udx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
131 lines (102 loc) · 4.02 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
CURL = curl
CXX = g++
SHA256SUM = shasum -a256 -p
RM = rm -f
TAR = tar
VSQL = vsql
# Optional vsql flags
VSQL_FLAGS =
# The target UDx library
LIBNAME=aesgcm.so
all: $(LIBNAME)
# Expect the Vertica SDK to be installed.
VERTICA_SDK = /opt/vertica/sdk
VERTICA_INCLUDES = $(VERTICA_SDK)/include
BUILD_REVISION = $(shell git log -1 --pretty=format:"%H" || echo "unknown")
# Optional compiler and linker arguments
CXXFLAGS = -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-unused-result
LDFLAGS =
LDLIBS =
# Necessary compiler and linker arguments
override CXXFLAGS += -fPIC
override CXXFLAGS += -I $(VERTICA_INCLUDES) -I include
override CXXFLAGS += -D HAVE_LONG_LONG_INT_64
override CXXFLAGS += -D BUILD_REVISION=\"$(BUILD_REVISION)\"
override LDFLAGS += -shared
override LDLIBS += -L lib -l:libsodium.a
# libsodium targets & variables.
LIBSODIUM_VERSION=1.0.15
LIBSODIUM_BN=libsodium-$(LIBSODIUM_VERSION)
LIBSODIUM_TAR_GZ=$(LIBSODIUM_BN).tar.gz
LIBSODIUM_URLS += "https://download.libsodium.org/libsodium/releases/$(LIBSODIUM_TAR_GZ)"
LIBSODIUM_URLS += "https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}/${LIBSODIUM_TAR_GZ}"
# SHA256 hash calculated with: shasum -a256 -p $FILE | cut -d' ' -f1
LIBSODIUM_SHA256=fb6a9e879a2f674592e4328c5d9f79f082405ee4bb05cb6e679b90afe9e178f4
libsodium_deps += lib/libsodium.a
libsodium_deps += include/sodium.h
LIBSODIUM_INSTALL_DIR =
deps += $(patsubst %, $(LIBSODIUM_INSTALL_DIR)/%, $(libsodium_deps))
deps: $(deps)
$(LIBSODIUM_TAR_GZ):
for URL in $(LIBSODIUM_URLS); do \
$(CURL) -L -o $@.tmp "$$URL" && \
echo "$(LIBSODIUM_SHA256) ?$@.tmp" | $(SHA256SUM) -c - && \
mv $@.tmp $@ && \
break; \
done
$(libsodium_deps): $(LIBSODIUM_TAR_GZ)
$(TAR) -xzf $<
cd $(LIBSODIUM_BN) && ./configure --disable-pie
make -C $(LIBSODIUM_BN) install prefix=${PWD}
src:
mkdir -p $@
distclean: clean
@$(RM) -r include lib $(LIBSODIUM_BN)
@$(RM) $(LIBSODIUM_TAR_GZ) $(LIBSODIUM_TAR_GZ).tmp
objects += AESGCMDecrypt.o
objects += AESGCMEncrypt.o
objects += AESGCMFunction.o
objects += metadata.o
# Vertica requires compiling some of their SDK
objects += Vertica.o
$(objects): $(deps)
Vertica.o: $(VERTICA_INCLUDES)/Vertica.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(LIBNAME): $(objects)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
install install-ddl: install.sql | $(LIBNAME)
$(VSQL) $(VSQL_FLAGS) -f $<
uninstall uninstall-ddl: uninstall.sql
$(VSQL) $(VSQL_FLAGS) -f $<
test-key.hex: test-key.txt
xxd -pu -c 32 -l 32 >$@ <$<
test: test.sql | test-key.hex $(LIBNAME)
$(VSQL) -q -t -A $(VSQL_FLAGS) -f $< 2>&1 \
| ./parse-tests.sh
clean-test:
$(RM) test_key.hex
clean: clean-test
$(RM) $(objects) $(LIBNAME)
help:
@echo "Targets:"
@echo " all, $(LIBNAME) Build the AESGCM UDx."
@echo " clean Removes all build artifacts, excluding libsodium."
@echo " deps Downloads and compiles libsodium, if necessary."
@echo " See the LIBSODIUM_INSTALL variable below."
@echo " distclean Removes all build artifacts."
@echo " install-ddl Runs vsql to install the UDx to the local server."
@echo " test Installs..."
@echo " uninstall-ddl Runs vsql to remove the UDx from the local server."
@echo
@echo "Variables:"
@echo " LIBSODIUM_INSTALL Path to libsodium installation (e.g. /usr/lib)."
@echo " The default behavior is to download, compile, and"
@echo " link against an external version ($(LIBSODIUM_VERSION))."
@echo " VERTICA_SDK Path to Vertica SDK installation."
@echo " ($(VERTICA_SDK))"
@echo " VSQL_FLAGS Flags to pass to vsql during install-ddl,"
@echo " uninstall-ddl, and test. In particular -e"
@echo " (echo commands sent to server) may be useful to"
@echo " diagnose errors encountered when building these"
@echo " targets."
.PHONY: all clean clean-test deps distclean help install install-ddl test uninstall uninstall-ddl