1
- PROGRAM = pg_probackup
2
- WORKDIR ?=$(CURDIR )
3
- BUILDDIR =$(WORKDIR ) /build/
4
- PBK_GIT_REPO = https://github.com/postgrespro/pg_probackup
1
+ # pg_probackup build system
2
+ #
3
+ # You can build pg_probackup in different ways:
4
+ #
5
+ # 1. in source tree using PGXS (with already installed PG and existing PG sources)
6
+ # git clone https://github.com/postgrespro/pg_probackup pg_probackup
7
+ # cd pg_probackup
8
+ # make USE_PGXS=1 PG_CONFIG=<path_to_pg_config> top_srcdir=<path_to_PostgreSQL_source_tree>
9
+ #
10
+ # 2. out of source using PGXS
11
+ # git clone https://github.com/postgrespro/pg_probackup pg_probackup-src
12
+ # mkdir pg_probackup-build && cd pg_probackup-build
13
+ # make USE_PGXS=1 PG_CONFIG=<path_to_pg_config> top_srcdir=<path_to_PostgreSQL_source_tree> -f ../pg_probackup-src/Makefile
14
+ #
15
+ # 3. in PG source (without PGXS -- using only PG sources)
16
+ # git clone https://git.postgresql.org/git/postgresql.git postgresql
17
+ # git clone https://github.com/postgrespro/pg_probackup postgresql/contrib/pg_probackup
18
+ # cd postgresql
19
+ # ./configure ... && make
20
+ # make --no-print-directory -C contrib/pg_probackup
21
+ #
22
+ # 4. out of PG source and without PGXS
23
+ # git clone https://git.postgresql.org/git/postgresql.git postgresql-src
24
+ # git clone https://github.com/postgrespro/pg_probackup postgresql-src/contrib/pg_probackup
25
+ # mkdir postgresql-build && cd postgresql-build
26
+ # ../postgresql-src/configure ... && make
27
+ # make --no-print-directory -C contrib/pg_probackup
28
+ #
29
+ top_pbk_srcdir :=$(dir $(realpath $(firstword $(MAKEFILE_LIST ) ) ) )
5
30
6
- # utils
7
- OBJS = src/utils/configuration.o src/utils/json.o src/utils/logger.o \
8
- src/utils/parray.o src/utils/pgut.o src/utils/thread.o src/utils/remote.o src/utils/file.o
31
+ # get postgres version
32
+ PG_MAJORVER != $(MAKE) USE_PGXS=$(USE_PGXS) PG_CONFIG=$(PG_CONFIG) --silent --makefile=$(top_pbk_srcdir)get_pg_version.mk
33
+ # $(info Making with PG_MAJORVER=$(PG_MAJORVER))
9
34
35
+ PROGRAM := pg_probackup
36
+
37
+ # pg_probackup sources
38
+ OBJS := src/utils/configuration.o src/utils/json.o src/utils/logger.o\
39
+ src/utils/parray.o src/utils/pgut.o src/utils/thread.o src/utils/remote.o src/utils/file.o
10
40
OBJS += src/archive.o src/backup.o src/catalog.o src/checkdb.o src/configure.o src/data.o\
11
41
src/delete.o src/dir.o src/fetch.o src/help.o src/init.o src/merge.o\
12
42
src/parsexlog.o src/ptrack.o src/pg_probackup.o src/restore.o src/show.o src/stream.o\
13
43
src/util.o src/validate.o src/datapagemap.o src/catchup.o
14
44
15
- # borrowed files
16
- OBJS += src/pg_crc.o src/receivelog.o src/streamutil.o\
17
- src/xlogreader.o
18
-
19
- EXTRA_CLEAN = src/pg_crc.c\
20
- src/receivelog.c src/receivelog.h src/streamutil.c src/streamutil.h\
21
- src/xlogreader.c src/instr_time.h
22
-
23
- ifdef top_srcdir
24
- srchome :=$(abspath $(top_srcdir ) )
25
- else
26
- top_srcdir =../..
27
- ifneq (,$(wildcard ../../../contrib/pg_probackup) )
28
- # separate build directory support
29
- srchome :=$(abspath $(top_srcdir ) /..)
30
- else
31
- srchome :=$(abspath $(top_srcdir ) )
32
- endif
45
+ # sources borrowed from postgresql (paths are relative to pg top dir)
46
+ BORROWED_H_SRC :=\
47
+ src/include/portability/instr_time.h\
48
+ src/bin/pg_basebackup/receivelog.h\
49
+ src/bin/pg_basebackup/streamutil.h
50
+ BORROWED_C_SRC :=\
51
+ src/backend/access/transam/xlogreader.c\
52
+ src/backend/utils/hash/pg_crc.c\
53
+ src/bin/pg_basebackup/receivelog.c\
54
+ src/bin/pg_basebackup/streamutil.c
55
+ ifneq ($(PG_MAJORVER ) ,$(findstring $(PG_MAJORVER ) , 9.5 9.6) )
56
+ BORROWED_H_SRC +=\
57
+ src/bin/pg_basebackup/walmethods.h
58
+ BORROWED_C_SRC +=\
59
+ src/bin/pg_basebackup/walmethods.c
33
60
endif
34
61
35
- # OBJS variable must be finally defined before invoking the include directive
36
- ifneq (,$(wildcard $(srchome ) /src/bin/pg_basebackup/walmethods.c) )
37
- OBJS += src/walmethods.o
38
- EXTRA_CLEAN += src/walmethods.c src/walmethods.h
62
+ BORROW_DIR := src/borrowed
63
+ BORROWED_H :=$(addprefix $(BORROW_DIR ) /,$(notdir $(BORROWED_H_SRC ) ) )
64
+ BORROWED_C :=$(addprefix $(BORROW_DIR ) /,$(notdir $(BORROWED_C_SRC ) ) )
65
+ OBJS +=$(patsubst % .c,% .o,$(BORROWED_C ) )
66
+ EXTRA_CLEAN :=$(BORROWED_H ) $(BORROWED_C ) $(BORROW_DIR ) borrowed.mk
67
+
68
+ # off-source build support
69
+ ifneq ($(abspath $(CURDIR ) ) /,$(top_pbk_srcdir ) )
70
+ VPATH :=$(top_pbk_srcdir )
39
71
endif
40
72
73
+ # standard PGXS stuff
74
+ # all OBJS must be defined above this
41
75
ifdef USE_PGXS
42
76
PG_CONFIG = pg_config
43
77
PGXS :=$(shell $(PG_CONFIG ) --pgxs)
@@ -49,41 +83,47 @@ include $(top_builddir)/src/Makefile.global
49
83
include $(top_srcdir ) /contrib/contrib-global.mk
50
84
endif
51
85
52
- PG_CPPFLAGS = -I$(libpq_srcdir ) ${PTHREAD_CFLAGS} -Isrc -I$(srchome ) /$(subdir ) /src
86
+ # now we can use standard MAJORVERSION variable instead of calculated PG_MAJORVER
87
+ undefine PG_MAJORVER
88
+
89
+ #
90
+ PG_CPPFLAGS = -I$(libpq_srcdir ) ${PTHREAD_CFLAGS} -I$(top_pbk_srcdir ) /src -I$(BORROW_DIR )
91
+ ifdef VPATH
92
+ PG_CPPFLAGS += -Isrc
93
+ endif
53
94
override CPPFLAGS := -DFRONTEND$(CPPFLAGS ) $(PG_CPPFLAGS )
54
95
PG_LIBS_INTERNAL =$(libpq_pgport ) ${PTHREAD_CFLAGS}
55
96
56
- src/utils/configuration.o : src/datapagemap.h
57
- src/archive.o : src/instr_time.h
58
- src/backup.o : src/receivelog.h src/streamutil.h
59
-
60
- src/instr_time.h :$(srchome ) /src/include/portability/instr_time.h
61
- rm -f$@ && $(LN_S ) $(srchome ) /src/include/portability/instr_time.h$@
62
- src/pg_crc.c :$(srchome ) /src/backend/utils/hash/pg_crc.c
63
- rm -f$@ && $(LN_S ) $(srchome ) /src/backend/utils/hash/pg_crc.c$@
64
- src/receivelog.c :$(srchome ) /src/bin/pg_basebackup/receivelog.c
65
- rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/receivelog.c$@
66
- ifneq (,$(wildcard $(srchome ) /src/bin/pg_basebackup/walmethods.c) )
67
- src/receivelog.h : src/walmethods.h$(srchome ) /src/bin/pg_basebackup/receivelog.h
68
- else
69
- src/receivelog.h :$(srchome ) /src/bin/pg_basebackup/receivelog.h
97
+ # additional dependencies on borrowed files
98
+ src/archive.o :$(BORROW_DIR ) /instr_time.h
99
+ src/backup.o src/catchup.o src/pg_probackup.o :$(BORROW_DIR ) /streamutil.h
100
+ src/stream.o $(BORROW_DIR ) /receivelog.o$(BORROW_DIR ) /streamutil.o :$(BORROW_DIR ) /receivelog.h
101
+ ifneq ($(MAJORVERSION ) ,$(findstring $(MAJORVERSION ) , 9.5 9.6) )
102
+ $(BORROW_DIR ) /receivelog.h :$(BORROW_DIR ) /walmethods.h
103
+ $(BORROW_DIR ) /walmethods.o :$(BORROW_DIR ) /receivelog.h
70
104
endif
71
- rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/receivelog.h $@
72
- src/streamutil.c :$(srchome ) /src/bin/pg_basebackup/streamutil.c
73
- rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/streamutil.c$@
74
- src/streamutil.h :$(srchome ) /src/bin/pg_basebackup/streamutil.h
75
- rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/streamutil.h$@
76
- src/xlogreader.c :$(srchome ) /src/backend/access/transam/xlogreader.c
77
- rm -f$@ && $(LN_S ) $(srchome ) /src/backend/access/transam/xlogreader.c$@
78
- src/walmethods.c :$(srchome ) /src/bin/pg_basebackup/walmethods.c
79
- rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/walmethods.c$@
80
- src/walmethods.h :$(srchome ) /src/bin/pg_basebackup/walmethods.h
81
- rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/walmethods.h$@
82
105
83
- ifeq ($(PORTNAME ) , aix)
84
- CC=xlc_r
85
- endif
106
+ # generate separate makefile to handle borrowed files
107
+ borrowed.mk :$(firstword $(MAKEFILE_LIST ) )
108
+ $(file >$@ ,# This file is autogenerated. Do not edit!)
109
+ $(foreach borrowed_file,$(BORROWED_H_SRC ) $(BORROWED_C_SRC ) , \
110
+ $(file >>$@ ,$(addprefix $(BORROW_DIR ) /,$(notdir $(borrowed_file ) ) ) : |$(CURDIR ) /$(BORROW_DIR ) /$(realpath $(top_srcdir ) /$(borrowed_file ) ) ) \
111
+ $(file >>$@ ,$(shell echo "\t"'$$(LN_S ) $(realpath $(top_srcdir ) /$(borrowed_file ) ) $$@ ') ) \
112
+ )
113
+ include borrowed.mk
114
+
115
+ # create needed directories for borrowed files and off-source build
116
+ OBJDIRS =$(addprefix $(CURDIR ) /,$(sort $(dir $(OBJS ) ) ) )
117
+ $(OBJS ) : |$(OBJDIRS )
118
+ $(OBJDIRS ) :
119
+ mkdir -p$@
120
+
121
+ # packaging infrastructure
122
+ WORKDIR ?=$(CURDIR )
123
+ PBK_PKG_BUILDDIR =$(WORKDIR ) /pkg-build/
124
+ PBK_GIT_REPO = https://github.com/postgrespro/pg_probackup
125
+
126
+ include $(top_pbk_srcdir ) /packaging/Makefile.pkg
127
+ include $(top_pbk_srcdir ) /packaging/Makefile.repo
128
+ include $(top_pbk_srcdir ) /packaging/Makefile.test
86
129
87
- include packaging/Makefile.pkg
88
- include packaging/Makefile.repo
89
- include packaging/Makefile.test