1- PROGRAM = pg_backup
2- WORKDIR ?= $(CURDIR )
3- BUILDDIR = $(WORKDIR ) /build/
4- PBK_GIT_REPO = https://github.com/pgtoolz/pg_backup
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 ) ) ) )
530
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))
934
35+ PROGRAM := pg_backup
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
1040OBJS += src/archive.o src/backup.o src/catalog.o src/checkdb.o src/configure.o src/data.o \
1141 src/delete.o src/dir.o src/fetch.o src/help.o src/init.o src/merge.o \
1242 src/parsexlog.o src/ptrack.o src/pg_probackup.o src/restore.o src/show.o src/stream.o \
1343 src/util.o src/validate.o src/datapagemap.o src/catchup.o
1444
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_backup) )
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
3360endif
3461
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 )
3971endif
4072
73+ # standard PGXS stuff
74+ # all OBJS must be defined above this
4175ifdef USE_PGXS
4276PG_CONFIG = pg_config
4377PGXS := $(shell $(PG_CONFIG ) --pgxs)
@@ -49,41 +83,47 @@ include $(top_builddir)/src/Makefile.global
4983include $(top_srcdir ) /contrib/contrib-global.mk
5084endif
5185
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
5394override CPPFLAGS := -DFRONTEND $(CPPFLAGS ) $(PG_CPPFLAGS )
5495PG_LIBS_INTERNAL = $(libpq_pgport ) ${PTHREAD_CFLAGS}
5596
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
70104endif
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 $@
82105
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/pgtoolz/pg_backup
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
86129
87- include packaging/Makefile.pkg
88- include packaging/Makefile.repo
89- include packaging/Makefile.test
0 commit comments