From 788323f6f309bf0a9b20a2b3b60edac1e66e1a6f Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Tue, 6 Apr 2021 23:05:17 +0200 Subject: [PATCH 1/4] Build also as a shared library --- Makefile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3ef335bb..bf63e011 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,21 @@ root_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +word-dot = $(word $2,$(subst ., ,$1)) TARGET = pg_query ARLIB = lib$(TARGET).a +SOLIB = lib$(TARGET).so PGDIR = $(root_dir)/tmp/postgres PGDIRBZ2 = $(root_dir)/tmp/postgres.tar.bz2 PG_VERSION = 13.2 +PG_VERSION_MAJOR = $(call word-dot,$(PG_VERSION),1) PROTOC_VERSION = 3.14.0 +VERSION = 2.0.4 +VERSION_MAJOR = $(call word-dot,$(VERSION),1) + +SONAME = $(SOLIB).$(shell printf '%02d%02d' $(PG_VERSION_MAJOR) $(VERSION_MAJOR)) + SRC_FILES := $(wildcard src/*.c src/postgres/*.c) vendor/protobuf-c/protobuf-c.c vendor/xxhash/xxhash.c protobuf/pg_query.pb-c.c NOT_OBJ_FILES := src/pg_query_enum_defs.o src/pg_query_fingerprint_defs.o src/pg_query_fingerprint_conds.o src/pg_query_outfuncs_defs.o src/pg_query_outfuncs_conds.o src/pg_query_readfuncs_defs.o src/pg_query_readfuncs_conds.o src/postgres/guc-file.o src/postgres/scan.o src/pg_query_json_helper.o OBJ_FILES := $(filter-out $(NOT_OBJ_FILES), $(SRC_FILES:.c=.o)) @@ -74,7 +82,7 @@ endif all: examples test build -build: $(ARLIB) +build: $(ARLIB) $(SOLIB) clean: -@ $(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) $(EXAMPLES) $(TESTS) @@ -146,6 +154,9 @@ extract_source: $(PGDIR) $(ARLIB): $(OBJ_FILES) Makefile @$(AR) $@ $(OBJ_FILES) +$(SOLIB): $(OBJ_FILES) Makefile + @$(CC) $(CFLAGS) -shared -Wl,-soname,$(SONAME) $(LDFLAGS) -o $@ $(OBJ_FILES) $(LIBS) + protobuf/pg_query.pb-c.c protobuf/pg_query.pb-c.h: protobuf/pg_query.proto ifneq ($(shell which protoc-gen-c), ) protoc --c_out=. protobuf/pg_query.proto From b5ce056549cc9bf429be5e9b836cd5413a3239a3 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Wed, 7 Apr 2021 21:32:05 +0200 Subject: [PATCH 2/4] Add install target to Makefile --- Makefile | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bf63e011..222681a9 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,11 @@ PROTOC_VERSION = 3.14.0 VERSION = 2.0.4 VERSION_MAJOR = $(call word-dot,$(VERSION),1) +VERSION_MINOR = $(call word-dot,$(VERSION),2) +VERSION_PATCH = $(call word-dot,$(VERSION),3) SONAME = $(SOLIB).$(shell printf '%02d%02d' $(PG_VERSION_MAJOR) $(VERSION_MAJOR)) +SOLIBVER = $(SONAME).$(VERSION_MINOR).$(VERSION_PATCH) SRC_FILES := $(wildcard src/*.c src/postgres/*.c) vendor/protobuf-c/protobuf-c.c vendor/xxhash/xxhash.c protobuf/pg_query.pb-c.c NOT_OBJ_FILES := src/pg_query_enum_defs.o src/pg_query_fingerprint_defs.o src/pg_query_fingerprint_conds.o src/pg_query_outfuncs_defs.o src/pg_query_outfuncs_conds.o src/pg_query_readfuncs_defs.o src/pg_query_readfuncs_conds.o src/postgres/guc-file.o src/postgres/scan.o src/pg_query_json_helper.o @@ -50,6 +53,8 @@ CLEANOBJS = $(OBJ_FILES) CLEANFILES = $(PGDIRBZ2) AR = ar rs +INSTALL = install +LN_S = ln -s RM = rm -f ECHO = echo @@ -89,7 +94,7 @@ clean: -@ $(RM) -rf {test,examples}/*.dSYM -@ $(RM) -r $(PGDIR) $(PGDIRBZ2) -.PHONY: all clean build extract_source examples test +.PHONY: all clean build extract_source examples test install $(PGDIR): curl -o $(PGDIRBZ2) https://ftp.postgresql.org/pub/source/v$(PG_VERSION)/postgresql-$(PG_VERSION).tar.bz2 @@ -262,3 +267,17 @@ test/scan: test/scan.c test/scan_tests.c $(ARLIB) test/split: test/split.c test/split_tests.c $(ARLIB) $(CC) $(TEST_CFLAGS) -o $@ test/split.c $(ARLIB) $(TEST_LDFLAGS) + +prefix = /usr/local +libdir = $(prefix)/lib +includedir = $(prefix)/include + +install: $(ARLIB) $(SOLIB) + $(INSTALL) -d "$(DESTDIR)"$(libdir) + $(INSTALL) -m 644 $(ARLIB) "$(DESTDIR)"$(libdir)/$(ARLIB) + $(INSTALL) -m 755 $(SOLIB) "$(DESTDIR)"$(libdir)/$(SOLIBVER) + $(LN_S) $(SOLIBVER) "$(DESTDIR)"$(libdir)/$(SONAME) + $(LN_S) $(SOLIBVER) "$(DESTDIR)"$(libdir)/$(SOLIB) + $(INSTALL) -d "$(DESTDIR)"$(includedir)/$(TARGET) + $(INSTALL) -m 644 pg_query.h "$(DESTDIR)"$(includedir)/pg_query.h + $(INSTALL) -m 644 protobuf/pg_query.proto "$(DESTDIR)"$(includedir)/$(TARGET)/pg_query.proto From 931a0b5038e2f9d869d7989c53b21f09509e6e3e Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Fri, 7 May 2021 21:26:54 +0200 Subject: [PATCH 3/4] Don't build shared lib by default Requested in https://github.com/pganalyze/libpg_query/pull/100#discussion_r628403551 --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 222681a9..2e82ce87 100644 --- a/Makefile +++ b/Makefile @@ -87,14 +87,16 @@ endif all: examples test build -build: $(ARLIB) $(SOLIB) +build: $(ARLIB) + +build_shared: $(SOLIB) clean: -@ $(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) $(EXAMPLES) $(TESTS) -@ $(RM) -rf {test,examples}/*.dSYM -@ $(RM) -r $(PGDIR) $(PGDIRBZ2) -.PHONY: all clean build extract_source examples test install +.PHONY: all clean build build_shared extract_source examples test install $(PGDIR): curl -o $(PGDIRBZ2) https://ftp.postgresql.org/pub/source/v$(PG_VERSION)/postgresql-$(PG_VERSION).tar.bz2 From ade04b03f1e3955558d9489a0e1b5604c0210802 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Fri, 7 May 2021 21:29:16 +0200 Subject: [PATCH 4/4] Include minor version in SONAME Requested in https://github.com/pganalyze/libpg_query/pull/100#discussion_r628402291 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2e82ce87..30fa52a5 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,8 @@ VERSION_MAJOR = $(call word-dot,$(VERSION),1) VERSION_MINOR = $(call word-dot,$(VERSION),2) VERSION_PATCH = $(call word-dot,$(VERSION),3) -SONAME = $(SOLIB).$(shell printf '%02d%02d' $(PG_VERSION_MAJOR) $(VERSION_MAJOR)) -SOLIBVER = $(SONAME).$(VERSION_MINOR).$(VERSION_PATCH) +SONAME = $(SOLIB).$(shell printf '%02d%02d' $(PG_VERSION_MAJOR) $(VERSION_MAJOR)).$(VERSION_MINOR) +SOLIBVER = $(SONAME).$(VERSION_PATCH) SRC_FILES := $(wildcard src/*.c src/postgres/*.c) vendor/protobuf-c/protobuf-c.c vendor/xxhash/xxhash.c protobuf/pg_query.pb-c.c NOT_OBJ_FILES := src/pg_query_enum_defs.o src/pg_query_fingerprint_defs.o src/pg_query_fingerprint_conds.o src/pg_query_outfuncs_defs.o src/pg_query_outfuncs_conds.o src/pg_query_readfuncs_defs.o src/pg_query_readfuncs_conds.o src/postgres/guc-file.o src/postgres/scan.o src/pg_query_json_helper.o