Skip to content

Commit c314cbd

Browse files
committed
Check PostgreSQL version number as number in the makefile
Not entirely happy about the solution but I like the uniform tests.
1 parent 22762fc commit c314cbd

File tree

6 files changed

+29
-37
lines changed

6 files changed

+29
-37
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
# Portions Copyright (c) 2012, The Reorg Development Team
77
#
88

9-
USE_PGXS = 1
10-
PG_CONFIG = pg_config
11-
PGXS := $(shell $(PG_CONFIG) --pgxs)
12-
include $(PGXS)
9+
PG_CONFIG ?= pg_config
1310

1411
SUBDIRS = bin lib
1512

1613
# Pull out the version number from pg_config
17-
VERSION = $(shell $(PG_CONFIG) --version | awk '{print $$2}')
14+
VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}')
15+
16+
# version as a number, e.g. 9.1.4 -> 90104
17+
INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?(.*)/(\1*100+\2)*100+0\3/' | bc)
1818

1919
# We support PostgreSQL 8.3 and later.
20-
ifneq ($(shell echo $(VERSION) | grep -E "^7\.|^8\.[012]"),)
20+
ifeq ($(shell echo $$(($(INTVERSION) < 80300))),1)
2121
$(error pg_repack requires PostgreSQL 8.3 or later. This is $(VERSION))
2222
endif
2323

bin/Makefile

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
# Portions Copyright (c) 2011, Itagaki Takahiro
66
# Portions Copyright (c) 2012, The Reorg Development Team
77
#
8+
9+
PG_CONFIG ?= pg_config
10+
11+
# version as a number, e.g. 9.1.4 -> 90104
12+
VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}')
13+
INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?.*/(\1*100+\2)*100+0\3/' | bc)
14+
815
SRCS = pg_repack.c pgut/pgut.c pgut/pgut-fe.c
916
OBJS = $(SRCS:.c=.o)
1017
PROGRAM = pg_repack
11-
REGRESS = init repack tablespace
1218

13-
EXTRA_CLEAN = sql/init-$(MAJORVERSION).sql sql/init.sql
19+
ifeq ($(shell echo $$(($(INTVERSION) >= 90100))),1)
20+
REGRESS = init-extension
21+
else
22+
REGRESS = init-legacy
23+
endif
24+
25+
REGRESS += repack tablespace
1426

1527
# The version number of the program. It should be the same of the library.
1628
REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
@@ -33,25 +45,3 @@ include $(PGXS)
3345
LIBS := $(filter-out -lxml2, $(LIBS))
3446
LIBS := $(filter-out -lxslt, $(LIBS))
3547

36-
ifndef MAJORVERSION
37-
MAJORVERSION := $(basename $(VERSION))
38-
endif
39-
40-
sql/init.sql: sql/init-$(MAJORVERSION).sql
41-
cp sql/init-$(MAJORVERSION).sql sql/init.sql
42-
expected/init.out: expected/init-$(MAJORVERSION).out
43-
cp expected/init-$(MAJORVERSION).out expected/init.out
44-
sql/init-8.3.sql:
45-
cp sql/init-legacy.sql sql/init-8.3.sql
46-
sql/init-8.4.sql:
47-
cp sql/init-legacy.sql sql/init-8.4.sql
48-
sql/init-9.0.sql:
49-
cp sql/init-legacy.sql sql/init-9.0.sql
50-
sql/init-9.1.sql:
51-
cp sql/init-extension.sql sql/init-9.1.sql
52-
sql/init-9.2.sql:
53-
cp sql/init-extension.sql sql/init-9.2.sql
54-
sql/init-9.3.sql:
55-
cp sql/init-extension.sql sql/init-9.3.sql
56-
57-
installcheck: sql/init.sql

bin/expected/init-extension.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SET client_min_messages = warning;
2+
CREATE EXTENSION pg_repack;
3+
RESET client_min_messages;
File renamed without changes.

bin/sql/init-extension.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
SET client_min_messages = warning;
2-
\set ECHO none
32
CREATE EXTENSION pg_repack;
4-
\set ECHO all
53
RESET client_min_messages;

lib/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
# Portions Copyright (c) 2012, The Reorg Development Team
77
#
88

9-
PG_CONFIG = pg_config
9+
PG_CONFIG ?= pg_config
10+
11+
# version as a number, e.g. 9.1.4 -> 90104
12+
VERSION := $(shell $(PG_CONFIG) --version | awk '{print $$2}')
13+
INTVERSION := $(shell echo $(VERSION) | sed -E 's/([0-9]+)\.([0-9]+)\.?([0-9]+)?.*/(\1*100+\2)*100+0\3/' | bc)
1014

1115
EXTENSION = pg_repack
1216
MODULE_big = $(EXTENSION)
@@ -20,10 +24,7 @@ REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
2024
PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION)
2125

2226
# Support CREATE EXTENSION for PG >= 9.1 and a simple sql script for PG < 9.1
23-
HAVE_EXTENSION = $(shell $(PG_CONFIG) --version \
24-
| grep -qE " 8\.| 9\.0" && echo no || echo yes)
25-
26-
ifeq ($(HAVE_EXTENSION),yes)
27+
ifeq ($(shell echo $$(($(INTVERSION) >= 90100))),1)
2728
DATA_built = pg_repack--$(REPACK_VERSION).sql pg_repack.control
2829
else
2930
DATA_built = pg_repack.sql

0 commit comments

Comments
 (0)