Don't append epoch to log_filename if no format specifier is given.
[PostgreSQL.git] / src / Makefile.shlib
bloba75d8b06ba1331bf590b7b8ae1df6bdf1139657d
1 #-------------------------------------------------------------------------
3 # Makefile.shlib
4 #    Common rules for building shared libraries
6 # Copyright (c) 1998, Regents of the University of California
8 # IDENTIFICATION
9 #    $PostgreSQL$
11 #-------------------------------------------------------------------------
13 # This file should be included by any Postgres module Makefile that
14 # wants to build a shared library (if possible for the current
15 # platform). A static library is also built from the same object
16 # files. Only one library can be built per makefile.
18 # Before including this file, the module Makefile must define these
19 # variables:
21 # NAME                  Name of library to build (no suffix nor "lib" prefix)
22 # OBJS                  List of object files to include in library
23 # SHLIB_LINK            If shared library relies on other libraries,
24 #                       additional stuff to put in its link command
25 # SHLIB_EXPORTS         (optional) Name of file containing list of symbols to
26 #                       export
28 # When building a shared library, the following version information
29 # must also be set.  It should be omitted when building a dynamically
30 # loadable module.
32 # SO_MAJOR_VERSION      Major version number to use for shared library
33 # SO_MINOR_VERSION      Minor version number to use for shared library
34 # (If you want a patchlevel, include it in SO_MINOR_VERSION, e.g., "6.2".)
36 # Optional flags when building DLL's (only applicable to win32 and cygwin
37 # platforms).
38 # DLLTOOL_DEFFLAGS      Additional flags when creating the dll .def file
39 # DLLTOOL_LIBFLAGS      Additional flags when creating the lib<module>.a file
40 # DLLWRAP_FLAGS         Additional flags to dllwrap
42 # The module Makefile must also include
43 # $(top_builddir)/src/Makefile.global before including this file.
44 # (Makefile.global sets PORTNAME and other needed symbols.)
46 # This makefile provides the following (phony) targets:
48 # all-lib               build the static and shared (if applicable) libraries
49 # install-lib           install the libraries into $(libdir)
50 # installdirs-lib       create installation directory $(libdir)
51 # uninstall-lib         remove the libraries from $(libdir)
52 # clean-lib             delete the static and shared libraries from the build dir
53 # maintainer-clean-lib  delete .def files built for win32
55 # Since `all-lib' is the first rule in this file you probably want to
56 # have the `all' target before including this file. In the most simple
57 # case it would look like this:
59 #     all: all-lib
61 # Similarly, the install rule might look like
63 #     install: install-lib
65 # plus any additional things you want to install. Et cetera.
67 # Got that?  Look at src/interfaces/libpq/Makefile for an example.
69 # While the linker allows creation of most shared libraries,
70 # -Bsymbolic requires resolution of all symbols, making the
71 # compiler a better choice for shared library creation on ELF platforms.
72 # With the linker, -Bsymbolic requires the crt1.o startup object file.
73 # bjm 2001-02-10
76 COMPILER = $(CC) $(CFLAGS)
77 LINK.static = $(AR) $(AROPT)
81 # Insert -L from LDFLAGS after any -L already present in SHLIB_LINK
82 SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) $(filter -L%, $(LDFLAGS)) $(filter-out -L%, $(SHLIB_LINK))
84 # Need a -L-free version of LDFLAGS to use in combination with SHLIB_LINK
85 LDFLAGS_NO_L = $(filter-out -L%, $(LDFLAGS))
87 ifdef SO_MAJOR_VERSION
88 # Default library naming convention used by the majority of platforms
89 ifeq ($(enable_shared), yes)
90 shlib           = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
91 shlib_major     = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
92 shlib_bare      = lib$(NAME)$(DLSUFFIX)
93 endif
94 # Testing the soname variable is a reliable way to determine whether a
95 # linkable library is being built.
96 soname          = $(shlib_major)
97 else
98 # Naming convention for dynamically loadable modules
99 ifeq ($(enable_shared), yes)
100 shlib           = $(NAME)$(DLSUFFIX)
101 endif
102 endif
103 stlib           = lib$(NAME).a
105 ifndef soname
106 # additional flags for backend modules
107 SHLIB_LINK := $(BE_DLLLIBS) $(SHLIB_LINK)
108 endif
110 # For each platform we support shared libraries on, set shlib to the
111 # name of the library (if default above is not right), set
112 # LINK.shared to the command to link the library,
113 # and adjust SHLIB_LINK if necessary.
115 # Try to keep the sections in some kind of order, folks...
117 override CFLAGS += $(CFLAGS_SL)
118 ifdef SO_MAJOR_VERSION
119 # libraries ought to use this to refer to versioned gettext domain names
120 override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
121 endif
123 ifeq ($(PORTNAME), aix)
124   ifdef SO_MAJOR_VERSION
125     shlib               = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
126   endif
127   haslibarule   = yes
128   exports_file          = lib$(NAME).exp
129 endif
131 ifeq ($(PORTNAME), darwin)
132   ifdef soname
133     # linkable library
134     DLSUFFIX            = .dylib
135     ifneq ($(SO_MAJOR_VERSION), 0)
136       version_link      = -compatibility_version $(SO_MAJOR_VERSION) -current_version $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
137     endif
138     LINK.shared         = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) $(exported_symbols_list) -multiply_defined suppress
139     shlib               = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
140     shlib_major         = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
141   else
142     # loadable module
143     DLSUFFIX            = .so
144     LINK.shared         = $(COMPILER) -bundle -multiply_defined suppress
145   endif
146   BUILD.exports         = $(AWK) '/^[^\#]/ {printf "_%s\n",$$1}' $< >$@
147   exports_file          = $(SHLIB_EXPORTS:%.txt=%.list)
148   ifneq (,$(exports_file))
149     exported_symbols_list = -exported_symbols_list $(exports_file)
150   endif
151 endif
153 ifeq ($(PORTNAME), openbsd)
154   ifdef ELF_SYSTEM
155     LINK.shared         = $(COMPILER) -shared
156     ifdef soname
157       LINK.shared       += -Wl,-x,-soname,$(soname)
158     endif
159     SHLIB_LINK          += -lc
160   else
161     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
162   endif
163 endif
165 ifeq ($(PORTNAME), bsdi)
166   ifeq ($(DLSUFFIX), .so)
167     LINK.shared         = $(COMPILER) -shared
168     ifdef soname
169       LINK.shared       += -Wl,-x,-soname,$(soname)
170     endif
171     SHLIB_LINK          += -lc
172   endif
173   ifeq ($(DLSUFFIX), .o)
174     LINK.shared         = shlicc -O $(LDREL)
175   endif
176 endif
178 ifeq ($(PORTNAME), freebsd)
179   ifdef ELF_SYSTEM
180     ifdef SO_MAJOR_VERSION
181       shlib             = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
182     endif
183     LINK.shared         = $(COMPILER) -shared
184     ifdef soname
185       LINK.shared       += -Wl,-x,-soname,$(soname)
186     endif
187   else
188     ifdef SO_MAJOR_VERSION
189       shlib             = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
190     endif
191     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
192   endif
193 endif
195 ifeq ($(PORTNAME), netbsd)
196   ifdef ELF_SYSTEM
197     LINK.shared         = $(COMPILER) -shared
198     ifdef soname
199       LINK.shared       += -Wl,-x,-soname,$(soname)
200     endif
201   else
202     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
203   endif
204 endif
206 ifeq ($(PORTNAME), hpux)
207   ifdef SO_MAJOR_VERSION
208     shlib                       = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
209   endif
210   ifeq ($(with_gnu_ld), yes)
211     LINK.shared         = $(CC) $(LDFLAGS_NO_L) -shared
212     ifdef soname
213       LINK.shared       += -Wl,-h -Wl,$(soname)
214     endif
215   else
216     # can't use the CC-syntax rpath pattern here
217     rpath =
218     LINK.shared         = $(LD) -b
219     ifdef soname
220       LINK.shared       += +h $(soname)
221     endif
222     ifeq ($(enable_rpath), yes)
223       LINK.shared       += +b '$(rpathdir)'
224     endif
225     # On HPUX platforms, gcc is usually configured to search for libraries
226     # in /usr/local/lib, but ld won't do so.  Add an explicit -L switch so
227     # ld can find the same libraries gcc does.  Make sure it goes after any
228     # -L switches provided explicitly.
229     ifeq ($(GCC), yes)
230       SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) -L/usr/local/lib $(filter-out -L%, $(SHLIB_LINK))
231     endif
232   endif
233   # do this last so above filtering doesn't pull out -L switches in LDFLAGS
234   ifeq ($(GCC), yes)
235     SHLIB_LINK          += `$(CC) $(LDFLAGS) -print-libgcc-file-name`
236   endif
237 endif
239 ifeq ($(PORTNAME), irix)
240   ifdef SO_MAJOR_VERSION
241     shlib               = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
242   endif
243   LINK.shared           = $(COMPILER) -shared
244   ifdef soname
245     LINK.shared         += -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
246   endif
247 endif
249 ifeq ($(PORTNAME), linux)
250   LINK.shared           = $(COMPILER) -shared
251   ifdef soname
252     LINK.shared         += -Wl,-soname,$(soname)
253   endif
254   BUILD.exports         = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
255   exports_file          = $(SHLIB_EXPORTS:%.txt=%.list)
256   ifneq (,$(exports_file))
257     LINK.shared         += -Wl,--version-script=$(exports_file)
258   endif
259 endif
261 ifeq ($(PORTNAME), solaris)
262   ifeq ($(GCC), yes)
263     LINK.shared         = $(COMPILER) -shared
264   else
265     LINK.shared         = $(COMPILER) -G
266   endif
267   ifdef soname
268     ifeq ($(with_gnu_ld), yes)
269       LINK.shared       += -Wl,-soname,$(soname)
270     else
271       LINK.shared       += -h $(soname)
272     endif
273   endif
274 endif
276 ifeq ($(PORTNAME), sunos4)
277   LINK.shared           = $(LD) -assert pure-text -Bdynamic
278 endif
280 ifeq ($(PORTNAME), osf)
281   LINK.shared           = $(LD) -shared -expect_unresolved '*'
282 endif
284 ifeq ($(PORTNAME), sco)
285   ifeq ($(GCC), yes)
286     LINK.shared         = $(CC) -shared
287   else
288     LINK.shared         = $(CC) -G
289     endif
290   LINK.shared           += -Wl,-z,text
291   ifdef soname
292     LINK.shared         += -Wl,-h,$(soname)
293   endif
294 endif
296 ifeq ($(PORTNAME), svr4)
297   LINK.shared           = $(LD) -G
298 endif
300 ifeq ($(PORTNAME), univel)
301   LINK.shared           = $(LD) -G -z text
302 endif
304 ifeq ($(PORTNAME), unixware)
305   ifeq ($(GCC), yes)
306     LINK.shared         = $(CC) -shared
307   else
308     LINK.shared         = $(CC) -G
309   endif
310   LINK.shared           += -Wl,-z,text
311   ifdef soname
312     LINK.shared         += -Wl,-h,$(soname)
313   endif
314 endif
316 ifeq ($(PORTNAME), cygwin)
317   ifdef SO_MAJOR_VERSION
318     shlib               = cyg$(NAME)$(DLSUFFIX)
319   endif
320   haslibarule   = yes
321 endif
323 ifeq ($(PORTNAME), win32)
324   ifdef SO_MAJOR_VERSION
325     shlib               = lib$(NAME)$(DLSUFFIX)
326   endif
327   haslibarule   = yes
328 endif
330 ifeq ($(enable_rpath), yes)
331 SHLIB_LINK += $(rpath)
332 endif
337 ## BUILD
340 .PHONY: all-lib all-static-lib all-shared-lib
342 all-lib: all-shared-lib
343 ifdef soname
344 # no static library when building a dynamically loadable module
345 all-lib: all-static-lib
346 endif
348 all-static-lib: $(stlib)
350 all-shared-lib: $(shlib)
352 ifndef haslibarule
353 $(stlib): $(OBJS)
354         $(LINK.static) $@ $^
355         $(RANLIB) $@
356 endif #haslibarule
358 ifeq ($(enable_shared), yes)
360 ifeq (,$(filter cygwin win32,$(PORTNAME)))
361 ifneq ($(PORTNAME), aix)
363 # Normal case
364 $(shlib): $(OBJS)
365         $(LINK.shared) $(LDFLAGS_SL) $(OBJS) $(SHLIB_LINK) -o $@
366 ifdef shlib_major
367 # If we're using major and minor versions, then make a symlink to major-version-only.
368 ifneq ($(shlib), $(shlib_major))
369         rm -f $(shlib_major)
370         $(LN_S) $(shlib) $(shlib_major)
371 endif
372 # Make sure we have a link to a name without any version numbers
373 ifneq ($(shlib), $(shlib_bare))
374         rm -f $(shlib_bare)
375         $(LN_S) $(shlib) $(shlib_bare)
376 endif
377 endif # shlib_major
379 # Where possible, restrict the symbols exported by the library to just the
380 # official list, so as to avoid unintentional ABI changes.  On recent Darwin
381 # this also quiets multiply-defined-symbol warnings in programs that use
382 # libpgport along with libpq.
383 ifneq (,$(SHLIB_EXPORTS))
384 ifdef BUILD.exports
385 $(shlib): $(SHLIB_EXPORTS:%.txt=%.list)
387 $(SHLIB_EXPORTS:%.txt=%.list): %.list: %.txt
388         $(BUILD.exports)
389 endif
390 endif
392 else # PORTNAME == aix
394 # AIX case
395 $(shlib) $(stlib): $(OBJS)
396         $(LINK.static) $(stlib) $^
397         $(RANLIB) $(stlib)
398         $(MKLDEXPORT) $(stlib) >$(exports_file)
399         $(COMPILER) $(LDFLAGS_NO_L) $(LDFLAGS_SL) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(SHLIB_LINK)
400         rm -f $(stlib)
401         $(AR) $(AROPT) $(stlib) $(shlib)
403 endif # PORTNAME == aix
405 else # PORTNAME == cygwin || PORTNAME == win32
407 # Cygwin or Win32 case
409 # If SHLIB_EXPORTS is set, the rules below will build a .def file from
410 # that.  Else we build a temporary one here.
411 ifeq (,$(SHLIB_EXPORTS))
412 DLL_DEFFILE = lib$(NAME)dll.def
413 exports_file = $(DLL_DEFFILE)
415 $(exports_file): $(OBJS)
416         $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $@ $^
417 else
418 DLL_DEFFILE = $(srcdir)/lib$(NAME)dll.def
419 endif
421 $(shlib): $(OBJS) $(DLL_DEFFILE)
422         $(DLLWRAP) $(LDFLAGS_SL) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
424 $(stlib): $(shlib) $(DLL_DEFFILE)
425         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib $@
427 endif # PORTNAME == cygwin || PORTNAME == win32
429 endif # enable_shared
432 # We need several not-quite-identical variants of .DEF files to build
433 # DLLs for Windows.  These are made from the single source file
434 # exports.txt.  Since we can't assume that Windows boxes will have
435 # sed, the .DEF files are always built and included in distribution
436 # tarballs.
438 ifneq (,$(SHLIB_EXPORTS))
439 distprep: $(srcdir)/lib$(NAME)dll.def $(srcdir)/lib$(NAME)ddll.def $(srcdir)/blib$(NAME)dll.def
441 UC_NAME = $(shell echo $(NAME) | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
443 $(srcdir)/lib$(NAME)dll.def: $(SHLIB_EXPORTS)
444         echo '; DEF file for MS VC++' >$@
445         echo 'LIBRARY LIB$(UC_NAME)' >>$@
446         echo 'EXPORTS' >>$@
447         sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/    \1@ \2/' $< >>$@
449 $(srcdir)/lib$(NAME)ddll.def: $(SHLIB_EXPORTS)
450         echo '; DEF file for MS VC++' >$@
451         echo 'LIBRARY LIB$(UC_NAME)D' >>$@
452         echo 'EXPORTS' >>$@
453         sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/    \1@ \2/' $< >>$@
455 $(srcdir)/blib$(NAME)dll.def: $(SHLIB_EXPORTS)
456         echo '; DEF file for Borland C++ Builder' >$@
457         echo 'LIBRARY BLIB$(UC_NAME)' >>$@
458         echo 'EXPORTS' >>$@
459         sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/    _\1@ \2/' $< >>$@
460         echo >>$@
461         echo '; Aliases for MS compatible names' >> $@
462         sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/    \1= _\1/' $< | sed 's/ *$$//' >>$@
463 endif # SHLIB_EXPORTS
467 ## INSTALL
470 .PHONY: install-lib install-lib-static install-lib-shared installdirs-lib
471 install-lib: install-lib-shared
472 ifdef soname
473 install-lib: install-lib-static
474 endif
476 install-lib-static: $(stlib) installdirs-lib
477         $(INSTALL_STLIB) $< '$(DESTDIR)$(libdir)/$(stlib)'
478 ifeq ($(PORTNAME), darwin)
479         cd '$(DESTDIR)$(libdir)' && \
480         ranlib $(stlib)
481 endif
483 ifeq ($(enable_shared), yes)
484 install-lib-shared: $(shlib) installdirs-lib
485 ifdef soname
486 # we don't install $(shlib) on AIX
487 # (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
488 ifneq ($(PORTNAME), aix)
489         $(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
490 ifneq ($(PORTNAME), cygwin)
491 ifneq ($(PORTNAME), win32)
492 ifneq ($(shlib), $(shlib_major))
493         cd '$(DESTDIR)$(libdir)' && \
494         rm -f $(shlib_major) && \
495         $(LN_S) $(shlib) $(shlib_major)
496 endif
497 ifneq ($(shlib), $(shlib_bare))
498         cd '$(DESTDIR)$(libdir)' && \
499         rm -f $(shlib_bare) && \
500         $(LN_S) $(shlib) $(shlib_bare)
501 endif
502 endif # not win32
503 endif # not cygwin
504 endif # not aix
505 else # no soname
506         $(INSTALL_SHLIB) $< '$(DESTDIR)$(pkglibdir)/$(shlib)'
507 endif
508 else # not enable_shared
509 ifndef soname
510 install-lib-shared:
511         @echo "*****"; \
512          echo "* Module $(NAME) was not installed due to lack of shared library support."; \
513          echo "*****"
514 endif
515 endif # enable_shared
518 installdirs-lib:
519 ifdef soname
520         $(mkinstalldirs) '$(DESTDIR)$(libdir)'
521 else
522         $(mkinstalldirs) '$(DESTDIR)$(pkglibdir)'
523 endif
527 ## UNINSTALL
530 .PHONY: uninstall-lib
531 uninstall-lib:
532 ifdef soname
533         rm -f '$(DESTDIR)$(libdir)/$(stlib)'
534 ifeq ($(enable_shared), yes)
535         rm -f '$(DESTDIR)$(libdir)/$(shlib_bare)' \
536           '$(DESTDIR)$(libdir)/$(shlib_major)' \
537           '$(DESTDIR)$(libdir)/$(shlib)'
538 endif # enable_shared
539 else # no soname
540         rm -f '$(DESTDIR)$(pkglibdir)/$(shlib)'
541 endif # no soname
545 ## CLEAN
548 .PHONY: clean-lib
549 clean-lib:
550         rm -f $(shlib) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file)
552 ifneq (,$(SHLIB_EXPORTS))
553 maintainer-clean-lib:
554         rm -f $(srcdir)/lib$(NAME)dll.def $(srcdir)/lib$(NAME)ddll.def $(srcdir)/blib$(NAME)dll.def
555 endif