@@ -17,92 +17,78 @@ EXTRA_CLEAN = src/pg_crc.c src/datapagemap.c src/datapagemap.h \
1717src/receivelog.c src/receivelog.h src/streamutil.c src/streamutil.h\
1818src/xlogreader.c src/instr_time.h
1919
20- INCLUDES = src/datapagemap.h src/streamutil.h src/receivelog.h src/instr_time.h
20+ ifdef top_srcdir
21+ srchome :=$(abspath $(top_srcdir ) )
22+ else
23+ top_srcdir =../..
24+ ifneq (,$(wildcard ../../../contrib/pg_probackup) )
25+ # separate build directory support
26+ srchome :=$(abspath $(top_srcdir ) /..)
27+ else
28+ srchome :=$(abspath $(top_srcdir ) )
29+ endif
30+ endif
31+
32+ # OBJS variable must be finally defined before invoking the include directive
33+ ifneq (,$(wildcard $(srchome ) /src/bin/pg_basebackup/walmethods.c) )
34+ OBJS += src/walmethods.o
35+ EXTRA_CLEAN += src/walmethods.c src/walmethods.h
36+ endif
37+ ifneq (,$(wildcard $(srchome ) /src/bin/pg_rewind/logging.h) )
38+ EXTRA_CLEAN += src/logging.h
39+ endif
2140
2241ifdef USE_PGXS
2342PG_CONFIG = pg_config
2443PGXS :=$(shell $(PG_CONFIG ) --pgxs)
2544include $(PGXS )
26- # !USE_PGXS
2745else
2846subdir =contrib/pg_probackup
2947top_builddir =../..
3048include $(top_builddir ) /src/Makefile.global
3149include $(top_srcdir ) /contrib/contrib-global.mk
32- endif # USE_PGXS
33-
34- ifeq ($(top_srcdir ) ,../..)
35- ifeq ($(LN_S),ln -s)
36- srchome=$(top_srcdir)/..
37- endif
38- else
39- srchome =$(top_srcdir )
40- endif
41-
42- # ifneq (,$(filter 9.5 9.6 10 11,$(MAJORVERSION)))
43- ifneq (12,$(MAJORVERSION ) )
44- EXTRA_CLEAN += src/logging.h
45- INCLUDES += src/logging.h
4650endif
4751
48- ifeq (,$(filter 9.5 9.6,$(MAJORVERSION ) ) )
49- OBJS += src/walmethods.o
50- EXTRA_CLEAN += src/walmethods.c src/walmethods.h
51- INCLUDES += src/walmethods.h
52- endif
53-
54-
55- PG_CPPFLAGS = -I$(libpq_srcdir ) ${PTHREAD_CFLAGS} -Isrc -I$(top_srcdir ) /$(subdir ) /src
52+ PG_CPPFLAGS = -I$(libpq_srcdir ) ${PTHREAD_CFLAGS} -Isrc -I$(srchome ) /$(subdir ) /src
5653override CPPFLAGS := -DFRONTEND$(CPPFLAGS ) $(PG_CPPFLAGS )
5754PG_LIBS_INTERNAL =$(libpq_pgport ) ${PTHREAD_CFLAGS}
5855
59- all : checksrcdir$(INCLUDES ) ;
60-
61- $(PROGRAM ) :$(OBJS )
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+ ifneq (,$(wildcard $(srchome ) /src/bin/pg_rewind/logging.h) )
60+ src/datapagemap.o : src/logging.h
61+ endif
6262
63- src/instr_time.h :$(top_srcdir ) /src/include/portability/instr_time.h
63+ src/instr_time.h :$(srchome ) /src/include/portability/instr_time.h
6464rm -f$@ && $(LN_S ) $(srchome ) /src/include/portability/instr_time.h$@
65- src/datapagemap.c :$(top_srcdir ) /src/bin/pg_rewind/datapagemap.c
65+ src/datapagemap.c :$(srchome ) /src/bin/pg_rewind/datapagemap.c
6666rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_rewind/datapagemap.c$@
67- src/datapagemap.h :$(top_srcdir ) /src/bin/pg_rewind/datapagemap.h
67+ src/datapagemap.h :$(srchome ) /src/bin/pg_rewind/datapagemap.h
6868rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_rewind/datapagemap.h$@
69- src/pg_crc.c :$(top_srcdir ) /src/backend/utils/hash/pg_crc.c
69+ src/pg_crc.c :$(srchome ) /src/backend/utils/hash/pg_crc.c
7070rm -f$@ && $(LN_S ) $(srchome ) /src/backend/utils/hash/pg_crc.c$@
71- src/receivelog.c :$(top_srcdir ) /src/bin/pg_basebackup/receivelog.c
71+ src/receivelog.c :$(srchome ) /src/bin/pg_basebackup/receivelog.c
7272rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/receivelog.c$@
73- src/receivelog.h :$(top_srcdir ) /src/bin/pg_basebackup/receivelog.h
73+ ifneq (,$(wildcard $(srchome ) /src/bin/pg_basebackup/walmethods.c) )
74+ src/receivelog.h : src/walmethods.h$(srchome ) /src/bin/pg_basebackup/receivelog.h
75+ else
76+ src/receivelog.h :$(srchome ) /src/bin/pg_basebackup/receivelog.h
77+ endif
7478rm -f $@ && $(LN_S) $(srchome)/src/bin/pg_basebackup/receivelog.h $@
75- src/streamutil.c :$(top_srcdir ) /src/bin/pg_basebackup/streamutil.c
79+ src/streamutil.c :$(srchome ) /src/bin/pg_basebackup/streamutil.c
7680rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/streamutil.c$@
77- src/streamutil.h :$(top_srcdir ) /src/bin/pg_basebackup/streamutil.h
81+ src/streamutil.h :$(srchome ) /src/bin/pg_basebackup/streamutil.h
7882rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/streamutil.h$@
79- src/xlogreader.c :$(top_srcdir ) /src/backend/access/transam/xlogreader.c
83+ src/xlogreader.c :$(srchome ) /src/backend/access/transam/xlogreader.c
8084rm -f$@ && $(LN_S ) $(srchome ) /src/backend/access/transam/xlogreader.c$@
81-
82- # ifneq (,$(filter 9.5 9.6 10 11,$(MAJORVERSION)))
83- ifneq (12,$(MAJORVERSION ) )
84- src/logging.h :$(top_srcdir ) /src/bin/pg_rewind/logging.h
85+ src/logging.h :$(srchome ) /src/bin/pg_rewind/logging.h
8586rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_rewind/logging.h$@
86- endif
87-
88- ifeq (,$(filter 9.5 9.6,$(MAJORVERSION ) ) )
89- src/walmethods.c :$(top_srcdir ) /src/bin/pg_basebackup/walmethods.c
87+ src/walmethods.c :$(srchome ) /src/bin/pg_basebackup/walmethods.c
9088rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/walmethods.c$@
91- src/walmethods.h :$(top_srcdir ) /src/bin/pg_basebackup/walmethods.h
89+ src/walmethods.h :$(srchome ) /src/bin/pg_basebackup/walmethods.h
9290rm -f$@ && $(LN_S ) $(srchome ) /src/bin/pg_basebackup/walmethods.h$@
93- endif
9491
9592ifeq ($(PORTNAME ) , aix)
9693CC=xlc_r
9794endif
98-
99- # This rule's only purpose is to give the user instructions on how to pass
100- # the path to PostgreSQL source tree to the makefile.
101- .PHONY : checksrcdir
102- checksrcdir :
103- ifndef top_srcdir
104- @echo "You must have PostgreSQL source tree available to compile."
105- @echo "Pass the path to the PostgreSQL source tree to make, in the top_srcdir"
106- @echo "variable: \"make top_srcdir=<path to PostgreSQL source tree>\""
107- @exit 1
108- endif