-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
85 lines (64 loc) · 2.07 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
EXTENSION = jsoncdc
EXTVERSION = $(shell egrep '^default_version += +' *.control | cut -d"'" -f2)
DATA = $(filter-out $(wildcard sql/*--*.sql),$(wildcard sql/*.sql))
DOCS = $(wildcard doc/*.md)
TESTS = $(wildcard test/sql/*.sql)
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
REGRESS_OPTS = --inputdir=test --load-language=plpgsql
PG_CONFIG = pg_config
PG91 = $(shell $(PG_CONFIG) --version | \
grep -qE " 8[.]| 9[.]0" && echo no || echo yes)
PG96 = $(shell $(PG_CONFIG) --version | \
grep -qE " 8[.]| 9[.][0-5]" && echo no || echo yes)
ifeq ($(PG91),yes)
all: sql/$(EXTENSION)--$(EXTVERSION).sql
sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
cp $< $@
EXTRA_CLEAN = sql/$(EXTENSION)--$(EXTVERSION).sql
endif
# Note that `MODULES = jsoncdc` implies a dependency on `jsoncdc.so`.
MODULES := jsoncdc
PGXX := $(shell util/get_version)
HAZRUST := $(shell which cargo >/dev/null && echo yes || echo no)
ifeq ($(shell uname -s),Darwin)
LINK_FLAGS := -C link-args='-Wl,-undefined,dynamic_lookup'
endif
ifeq ($(PG96),yes)
FEATURES := --features pg-ldc-messages
else
REGRESS := $(subst message,,$(REGRESS))
endif
ifeq ($(HAZRUST),yes)
.PHONY: cargo
cargo:
cargo rustc $(FEATURES) --release -- $(LINK_FLAGS)
.PHONY: jsoncdc.so
jsoncdc.so: base := target/release
jsoncdc.so: lib = $(wildcard $(base)/libjsoncdc.so $(base)/libjsoncdc.dylib)
jsoncdc.so: cargo
cp $(lib) $@
.PHONY: cargoclean
cargoclean:
find . -name Cargo.lock -exec rm {} \;
cargo clean
else
define CAN_HAZ_RUST
We need a Rust toolchain (rustc and cargo) to compile this extension.
See: https://www.rust-lang.org/downloads.html
endef
# NB: Not phony so if they build the extension somehow, the rest of the
# install can be completed.
jsoncdc.so:
$(error $(CAN_HAZ_RUST))
.PHONY: cargoclean
cargoclean:
$(warning No Rust toolchain so not cleaning anything.)
endif
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
clean: cargoclean
all: jsoncdc.so
.PHONY: test
test:
pgxn check ./
util/checkstyle