]> granicus.if.org Git - postgresql/blob - src/backend/Makefile
Move relpath() to libpgcommon
[postgresql] / src / backend / Makefile
1 #-------------------------------------------------------------------------
2 #
3 # Makefile for the postgres backend
4 #
5 # Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
6 # Portions Copyright (c) 1994, Regents of the University of California
7 #
8 # src/backend/Makefile
9 #
10 #-------------------------------------------------------------------------
11
12 PGFILEDESC = "PostgreSQL Server"
13 # This is a daemon process, which is why it is not labeled as an executable
14 #PGAPPICON=win32
15
16 subdir = src/backend
17 top_builddir = ../..
18 include $(top_builddir)/src/Makefile.global
19
20 SUBDIRS = access bootstrap catalog parser commands executor foreign lib libpq \
21         main nodes optimizer port postmaster regex replication rewrite \
22         storage tcop tsearch utils $(top_builddir)/src/timezone
23
24 include $(srcdir)/common.mk
25
26 # As of 1/2010:
27 # The probes.o file is necessary for dtrace support on Solaris, and on recent
28 # versions of systemtap.  (Older systemtap releases just produce an empty
29 # file, but that's okay.)  However, OS X's dtrace doesn't use it and doesn't
30 # even recognize the -G option.  So, build probes.o except on Darwin.
31 # This might need adjustment as other platforms add dtrace support.
32 ifneq ($(PORTNAME), darwin)
33 ifeq ($(enable_dtrace), yes)
34 LOCALOBJS += utils/probes.o
35 endif
36 endif
37
38 OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a \
39        $(top_builddir)/src/common/libpgcommon_srv.a
40
41 # We put libpgport and libpgcommon into OBJS, so remove it from LIBS; also add
42 # libldap
43 LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE)
44
45 # The backend doesn't need everything that's in LIBS, however
46 LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
47
48 ##########################################################################
49
50 all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
51
52 ifneq ($(PORTNAME), cygwin)
53 ifneq ($(PORTNAME), win32)
54 ifneq ($(PORTNAME), aix)
55
56 postgres: $(OBJS)
57         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
58
59 endif
60 endif
61 endif
62
63 ifeq ($(PORTNAME), cygwin)
64
65 postgres: $(OBJS) postgres.def libpostgres.a
66         $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
67         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
68         $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
69         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
70         rm -f $@.exp $@.base
71
72 postgres.def: $(OBJS)
73         $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
74
75 libpostgres.a: postgres.def
76         $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
77
78 endif # cygwin
79
80 ifeq ($(PORTNAME), win32)
81 LIBS += -lsecur32
82
83 postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
84         $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
85         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
86         $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
87         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
88         rm -f $@.exp $@.base
89
90 postgres.def: $(OBJS)
91         $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
92
93 libpostgres.a: postgres.def
94         $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
95
96 endif # win32
97
98 ifeq ($(PORTNAME), aix)
99
100 postgres: $(POSTGRES_IMP)
101         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
102
103 $(POSTGRES_IMP): $(OBJS)
104         $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
105 ifeq ($(host_os), aix3.2.5)
106         $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
107 else
108 ifneq (,$(findstring aix4.1, $(host_os)))
109         $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
110 else
111         $(MKLDEXPORT) SUBSYS.o . > $@
112 endif
113 endif
114         @rm -f SUBSYS.o
115
116 endif # aix
117
118 # Update the commonly used headers before building the subdirectories
119 $(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/probes.h
120
121 # run this unconditionally to avoid needing to know its dependencies here:
122 submake-schemapg:
123         $(MAKE) -C catalog schemapg.h
124
125 # src/port needs a convenient way to force errcodes.h to get built
126 submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h
127
128 .PHONY: submake-schemapg submake-errcodes
129
130 catalog/schemapg.h: | submake-schemapg
131
132 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
133
134
135 # The postgres.o target is needed by the rule in Makefile.global that
136 # creates the exports file when MAKE_EXPORTS = true.
137 postgres.o: $(OBJS)
138         $(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@
139
140
141 # The following targets are specified in make commands that appear in
142 # the make files in our subdirectories. Note that it's important we
143 # match the dependencies shown in the subdirectory makefiles!
144
145 parser/gram.h: parser/gram.y
146         $(MAKE) -C parser gram.h
147
148 utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
149         $(MAKE) -C utils fmgroids.h
150
151 utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
152         $(MAKE) -C utils errcodes.h
153
154 utils/probes.h: utils/probes.d
155         $(MAKE) -C utils probes.h
156
157 # Make symlinks for these headers in the include directory. That way
158 # we can cut down on the -I options. Also, a symlink is automatically
159 # up to date when we update the base file.
160 #
161 # The point of the prereqdir incantation in some of the rules below is to
162 # force the symlink to use an absolute path rather than a relative path.
163 # For headers which are generated by make distprep, the actual header within
164 # src/backend will be in the source tree, while the symlink in src/include
165 # will be in the build tree, so a simple ../.. reference won't work.
166 # For headers generated during regular builds, we prefer a relative symlink.
167
168 $(top_builddir)/src/include/parser/gram.h: parser/gram.h
169         prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
170           cd '$(dir $@)' && rm -f $(notdir $@) && \
171           $(LN_S) "$$prereqdir/$(notdir $<)" .
172
173 $(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
174         prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
175           cd '$(dir $@)' && rm -f $(notdir $@) && \
176           $(LN_S) "$$prereqdir/$(notdir $<)" .
177
178 $(top_builddir)/src/include/utils/errcodes.h: utils/errcodes.h
179         prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
180           cd '$(dir $@)' && rm -f $(notdir $@) && \
181           $(LN_S) "$$prereqdir/$(notdir $<)" .
182
183 $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
184         prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
185           cd '$(dir $@)' && rm -f $(notdir $@) && \
186           $(LN_S) "$$prereqdir/$(notdir $<)" .
187
188 $(top_builddir)/src/include/utils/probes.h: utils/probes.h
189         cd '$(dir $@)' && rm -f $(notdir $@) && \
190             $(LN_S) "../../../$(subdir)/utils/probes.h" .
191
192
193 utils/probes.o: utils/probes.d $(SUBDIROBJS)
194         $(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@
195
196
197 ##########################################################################
198
199 # Be sure that these files get removed by the maintainer-clean target
200 distprep:
201         $(MAKE) -C parser       gram.c gram.h scan.c
202         $(MAKE) -C bootstrap    bootparse.c bootscanner.c
203         $(MAKE) -C catalog      schemapg.h postgres.bki postgres.description postgres.shdescription
204         $(MAKE) -C replication  repl_gram.c repl_scanner.c
205         $(MAKE) -C utils        fmgrtab.c fmgroids.h errcodes.h
206         $(MAKE) -C utils/misc   guc-file.c
207         $(MAKE) -C utils/sort   qsort_tuple.c
208
209
210 ##########################################################################
211
212 install: all installdirs install-bin
213 ifeq ($(PORTNAME), cygwin)
214 ifeq ($(MAKE_DLL), true)
215         $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
216 endif
217 endif
218 ifeq ($(PORTNAME), win32)
219 ifeq ($(MAKE_DLL), true)
220         $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
221 endif
222 endif
223         $(MAKE) -C catalog install-data
224         $(MAKE) -C tsearch install-data
225         $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample'
226         $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample'
227         $(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample'
228         $(INSTALL_DATA) $(srcdir)/access/transam/recovery.conf.sample '$(DESTDIR)$(datadir)/recovery.conf.sample'
229
230 install-bin: postgres $(POSTGRES_IMP) installdirs
231         $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
232 ifneq ($(PORTNAME), win32)
233         @rm -f '$(DESTDIR)$(bindir)/postmaster$(X)'
234         ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
235 else
236         $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
237 endif
238 ifeq ($(MAKE_EXPORTS), true)
239         $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
240         $(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
241 endif
242
243 .PHONY: install-bin
244
245 installdirs:
246         $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
247 ifeq ($(PORTNAME), cygwin)
248 ifeq ($(MAKE_DLL), true)
249         $(MKDIR_P) '$(DESTDIR)$(libdir)'
250 endif
251 endif
252 ifeq ($(PORTNAME), win32)
253 ifeq ($(MAKE_DLL), true)
254         $(MKDIR_P) '$(DESTDIR)$(libdir)'
255 endif
256 endif
257 ifeq ($(MAKE_EXPORTS), true)
258         $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
259         $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
260 endif
261
262
263 ##########################################################################
264
265 uninstall:
266         rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster'
267 ifeq ($(MAKE_EXPORTS), true)
268         rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
269         rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
270 endif
271 ifeq ($(PORTNAME), cygwin)
272 ifeq ($(MAKE_DLL), true)
273         rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
274 endif
275 endif
276 ifeq ($(PORTNAME), win32)
277 ifeq ($(MAKE_DLL), true)
278         rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
279 endif
280 endif
281         $(MAKE) -C catalog uninstall-data
282         $(MAKE) -C tsearch uninstall-data
283         rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \
284               '$(DESTDIR)$(datadir)/pg_ident.conf.sample' \
285               '$(DESTDIR)$(datadir)/postgresql.conf.sample' \
286               '$(DESTDIR)$(datadir)/recovery.conf.sample'
287
288
289 ##########################################################################
290
291 clean:
292         rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
293                 $(top_builddir)/src/include/parser/gram.h \
294                 $(top_builddir)/src/include/catalog/schemapg.h \
295                 $(top_builddir)/src/include/utils/fmgroids.h \
296                 $(top_builddir)/src/include/utils/probes.h
297 ifeq ($(PORTNAME), cygwin)
298         rm -f postgres.dll postgres.def libpostgres.a
299 endif
300 ifeq ($(PORTNAME), win32)
301         rm -f postgres.dll postgres.def libpostgres.a $(WIN32RES)
302 endif
303
304 distclean: clean
305         rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c \
306               port/pg_latch.c
307
308 maintainer-clean: distclean
309         rm -f bootstrap/bootparse.c \
310               bootstrap/bootscanner.c \
311               parser/gram.c \
312               parser/gram.h \
313               parser/scan.c \
314               catalog/schemapg.h \
315               catalog/postgres.bki \
316               catalog/postgres.description \
317               catalog/postgres.shdescription \
318               replication/repl_gram.c \
319               replication/repl_scanner.c \
320               utils/fmgroids.h \
321               utils/fmgrtab.c \
322               utils/errcodes.h \
323               utils/misc/guc-file.c \
324               utils/sort/qsort_tuple.c
325
326
327 ##########################################################################
328 #
329 # Support for code development.
330 #
331 # Use target "quick" to build "postgres" when you know all the subsystems
332 # are up to date.  It saves the time of doing all the submakes.
333 .PHONY: quick
334 quick: $(OBJS)
335         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres