1 #-------------------------------------------------------------------------
4 # Common rules for building shared libraries
6 # Copyright (c) 1998, Regents of the University of California
9 # $PostgreSQL: pgsql/src/Makefile.shlib,v 1.85 2004/10/15 05:11:00 momjian Exp $
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
21 # NAME Name of library to build (no suffix nor "lib" prefix)
22 # SO_MAJOR_VERSION Major version number to use for shared library
23 # SO_MINOR_VERSION Minor version number to use for shared library
24 # OBJS List of object files to include in library
25 # SHLIB_LINK If shared library relies on other libraries,
26 # additional stuff to put in its link command
27 # (If you want a patchlevel, include it in SO_MINOR_VERSION, e.g., "6.2".)
29 # Optional flags when building DLL's (only applicable to win32 and cygwin
31 # DLLTOOL_DEFFLAGS Additional flags when creating the dll .def file
32 # DLLTOOL_LIBFLAGS Additional flags when creating the lib<module>.a file
33 # DLLWRAP_FLAGS Additional flags to dllwrap
35 # The module Makefile must also include
36 # $(top_builddir)/src/Makefile.global before including this file.
37 # (Makefile.global sets PORTNAME and other needed symbols.)
39 # This makefile provides the following (phony) targets:
41 # all-lib build the static and shared (if applicable) libraries
42 # install-lib install the libraries into $(libdir)
43 # uninstall-lib remove the libraries from $(libdir)
44 # clean-lib delete the static and shared libraries from the build dir
46 # Since `all-lib' is the first rule in this file you probably want to
47 # have the `all' target before including this file. In the most simple
48 # case it would look like this:
52 # Similarly, the install rule might look like
54 # install: install-lib
56 # plus any additional things you want to install. Et cetera.
58 # Got that? Look at src/interfaces/libpq/Makefile for an example.
60 # While the linker allows creation of most shared libraries,
61 # -Bsymbolic requires resolution of all symbols, making the
62 # compiler a better choice for shared library creation on ELF platforms.
63 # With the linker, -Bsymbolic requires the crt1.o startup object file.
67 COMPILER = $(CC) $(CFLAGS)
68 LINK.static = $(AR) $(AROPT)
72 ifeq ($(enable_shared), yes)
74 # Default shlib naming convention used by the majority of platforms
75 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
76 shlib_major = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
77 shlib_bare = lib$(NAME)$(DLSUFFIX)
79 # For each platform we support shared libraries on, set shlib to the
80 # name of the library (if default above is not right), set
81 # LINK.shared to the command to link the library,
82 # and adjust SHLIB_LINK if necessary.
84 # Try to keep the sections in some kind of order, folks...
86 override CFLAGS += $(CFLAGS_SL)
88 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
90 ifeq ($(PORTNAME), aix)
91 shlib = lib$(NAME)$(DLSUFFIX)
95 ifeq ($(PORTNAME), darwin)
96 ifneq ($(SO_MAJOR_VERSION), 0)
97 version_link := -compatibility_version $(SO_MAJOR_VERSION) -current_version $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
99 ifeq ($(DLTYPE), library)
102 LINK.shared = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) -multiply_defined suppress
104 # loadable module (default case)
106 LINK.shared = $(COMPILER) -bundle
108 shlib = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
109 shlib_major = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
112 ifeq ($(PORTNAME), openbsd)
114 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
117 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
121 ifeq ($(PORTNAME), bsdi)
122 ifeq ($(DLSUFFIX), .so)
123 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
126 ifeq ($(DLSUFFIX), .o)
127 LINK.shared = shlicc -O $(LDREL)
131 ifeq ($(PORTNAME), freebsd)
133 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
134 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
136 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
137 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
141 ifeq ($(PORTNAME), netbsd)
143 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
145 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
149 ifeq ($(PORTNAME), hpux)
150 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
152 SHLIB_LINK += `$(CC) $(LDFLAGS) -print-libgcc-file-name`
154 ifeq ($(with_gnu_ld), yes)
155 LINK.shared = $(CC) $(LDFLAGS) -shared -Wl,-h -Wl,$(soname) -Wl,+b -Wl,$(libdir)
157 LINK.shared = $(LD) +h $(soname) -b +b $(libdir)
161 ifeq ($(PORTNAME), irix)
162 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
163 LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
166 ifeq ($(PORTNAME), linux)
167 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
170 ifeq ($(PORTNAME), solaris)
172 LINK.shared = $(CC) -shared
174 LINK.shared = $(CC) -G
176 ifeq ($(with_gnu_ld), yes)
177 LINK.shared += -Wl,-soname,$(soname)
179 LINK.shared += -h $(soname)
183 ifeq ($(PORTNAME), sunos4)
184 LINK.shared = $(LD) -assert pure-text -Bdynamic
187 ifeq ($(PORTNAME), osf)
188 LINK.shared = $(LD) -shared -expect_unresolved '*'
191 ifeq ($(PORTNAME), sco)
193 LINK.shared = $(CC) -shared
195 LINK.shared = $(CC) -G
197 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
200 ifeq ($(PORTNAME), svr4)
201 LINK.shared = $(LD) -G
204 ifeq ($(PORTNAME), univel)
205 LINK.shared = $(LD) -G -z text
208 ifeq ($(PORTNAME), unixware)
210 LINK.shared = $(CC) -shared
212 LINK.shared = $(CC) -G
214 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
217 ifeq ($(PORTNAME), cygwin)
218 shlib = $(NAME)$(DLSUFFIX)
219 # needed for /contrib modules, not sure why
220 SHLIB_LINK += -lpgport
223 ifeq ($(PORTNAME), win32)
224 shlib = lib$(NAME)$(DLSUFFIX)
227 ifeq ($(PORTNAME), beos)
228 shlib = lib$(NAME)$(DLSUFFIX)
229 LINK.shared = $(LD) -nostart
230 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
233 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
234 ifeq ($(enable_rpath), yes)
235 SHLIB_LINK += $(rpath)
238 endif # enable_shared
246 .PHONY: all-lib all-static-lib all-shared-lib
248 all-lib: all-static-lib all-shared-lib
250 all-static-lib: $(PTHREAD_H_WIN32) $(top_builddir)/src/port/pg_config_paths.h lib$(NAME).a
252 all-shared-lib: $(PTHREAD_H_WIN32) $(top_builddir)/src/port/pg_config_paths.h $(shlib)
258 lib$(NAME).a: $(OBJS)
262 $(LINK.static) $@ `$(LORDER) $^ | tsort`
266 ifeq ($(enable_shared), yes)
268 ifneq ($(PORTNAME), win32)
269 ifneq ($(PORTNAME), cygwin)
270 ifneq ($(PORTNAME), beos)
271 ifneq ($(PORTNAME), aix)
275 $(LINK.shared) $(LDFLAGS_SL) $(OBJS) $(SHLIB_LINK) -o $@
276 # If we're using major and minor versions, then make a symlink to major-version-only.
277 ifneq ($(shlib), $(shlib_major))
279 $(LN_S) $(shlib) $(shlib_major)
281 # Make sure we have a link to a name without any version numbers
282 ifneq ($(shlib), $(shlib_bare))
284 $(LN_S) $(shlib) $(shlib_bare)
287 else # PORTNAME == aix
290 $(shlib): lib$(NAME).a
291 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
292 $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
294 endif # PORTNAME == aix
296 else # PORTNAME == beos
300 ln -fs $(top_srcdir)/src/backend/postgres _APP_
301 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
303 endif # PORTNAME == beos
305 else # PORTNAME == cygwin
308 $(shlib) lib$(NAME).a: $(OBJS)
309 $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
310 $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
311 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
313 endif # PORTNAME == cygwin
315 else # PORTNAME == win32
318 $(shlib) lib$(NAME).a: $(OBJS)
319 $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
320 $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
321 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
323 endif # PORTNAME == win32
325 endif # enable_shared
332 .PHONY: install-lib install-lib-static install-lib-shared
333 install-lib: install-lib-static install-lib-shared
335 install-lib-static: lib$(NAME).a
336 $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
337 ifeq ($(PORTNAME), darwin)
338 cd $(DESTDIR)$(libdir) && \
342 ifeq ($(enable_shared), yes)
343 install-lib-shared: $(shlib)
344 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
345 ifneq ($(PORTNAME), cygwin)
346 ifneq ($(PORTNAME), win32)
347 ifneq ($(shlib), $(shlib_major))
348 cd $(DESTDIR)$(libdir) && \
349 rm -f $(shlib_major) && \
350 $(LN_S) $(shlib) $(shlib_major)
352 ifneq ($(shlib), $(shlib_bare))
353 cd $(DESTDIR)$(libdir) && \
354 rm -f $(shlib_bare) && \
355 $(LN_S) $(shlib) $(shlib_bare)
359 endif # enable_shared
366 .PHONY: uninstall-lib
368 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
369 ifeq ($(enable_shared), yes)
370 rm -f $(DESTDIR)$(libdir)/$(shlib_bare) \
371 $(DESTDIR)$(libdir)/$(shlib_major) \
372 $(DESTDIR)$(libdir)/$(shlib)
373 endif # enable_shared
383 ifeq ($(enable_shared), yes)
384 rm -f $(shlib_bare) $(shlib_major) $(shlib)
386 rm -f lib$(NAME)$(EXPSUFF)
389 ifeq ($(PORTNAME), cygwin)
390 rm -f $(NAME).dll $(NAME).def
393 ifeq ($(PORTNAME), win32)
394 rm -f $(NAME).dll $(NAME).def