Skip to content

Commit

Permalink
Build also as a shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka committed Apr 7, 2021
1 parent b2790f8 commit 9065567
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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).$(PG_VERSION_MAJOR)0$(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))
Expand Down Expand Up @@ -74,7 +81,7 @@ endif

all: examples test build

build: $(ARLIB)
build: $(ARLIB) $(SOLIB)

clean:
-@ $(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) $(EXAMPLES) $(TESTS)
Expand Down Expand Up @@ -146,6 +153,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
Expand Down

0 comments on commit 9065567

Please sign in to comment.