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.86 2004/10/16 03:26:43 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
34 # DLL_DEFFILE Use pre-existing .def file instead of auto-generating
35 # one with all exports in it (win32 only).
37 # The module Makefile must also include
38 # $(top_builddir)/src/Makefile.global before including this file.
39 # (Makefile.global sets PORTNAME and other needed symbols.)
41 # This makefile provides the following (phony) targets:
43 # all-lib build the static and shared (if applicable) libraries
44 # install-lib install the libraries into $(libdir)
45 # uninstall-lib remove the libraries from $(libdir)
46 # clean-lib delete the static and shared libraries from the build dir
48 # Since `all-lib' is the first rule in this file you probably want to
49 # have the `all' target before including this file. In the most simple
50 # case it would look like this:
54 # Similarly, the install rule might look like
56 # install: install-lib
58 # plus any additional things you want to install. Et cetera.
60 # Got that? Look at src/interfaces/libpq/Makefile for an example.
62 # While the linker allows creation of most shared libraries,
63 # -Bsymbolic requires resolution of all symbols, making the
64 # compiler a better choice for shared library creation on ELF platforms.
65 # With the linker, -Bsymbolic requires the crt1.o startup object file.
69 COMPILER = $(CC) $(CFLAGS)
70 LINK.static = $(AR) $(AROPT)
74 ifeq ($(enable_shared), yes)
76 # Default shlib naming convention used by the majority of platforms
77 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
78 shlib_major = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
79 shlib_bare = lib$(NAME)$(DLSUFFIX)
81 # For each platform we support shared libraries on, set shlib to the
82 # name of the library (if default above is not right), set
83 # LINK.shared to the command to link the library,
84 # and adjust SHLIB_LINK if necessary.
86 # Try to keep the sections in some kind of order, folks...
88 override CFLAGS += $(CFLAGS_SL)
90 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
92 ifeq ($(PORTNAME), aix)
93 shlib = lib$(NAME)$(DLSUFFIX)
97 ifeq ($(PORTNAME), darwin)
98 ifneq ($(SO_MAJOR_VERSION), 0)
99 version_link := -compatibility_version $(SO_MAJOR_VERSION) -current_version $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
101 ifeq ($(DLTYPE), library)
104 LINK.shared = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) -multiply_defined suppress
106 # loadable module (default case)
108 LINK.shared = $(COMPILER) -bundle
110 shlib = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
111 shlib_major = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
114 ifeq ($(PORTNAME), openbsd)
116 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
119 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
123 ifeq ($(PORTNAME), bsdi)
124 ifeq ($(DLSUFFIX), .so)
125 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
128 ifeq ($(DLSUFFIX), .o)
129 LINK.shared = shlicc -O $(LDREL)
133 ifeq ($(PORTNAME), freebsd)
135 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
136 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
138 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
139 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
143 ifeq ($(PORTNAME), netbsd)
145 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
147 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
151 ifeq ($(PORTNAME), hpux)
152 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
154 SHLIB_LINK += `$(CC) $(LDFLAGS) -print-libgcc-file-name`
156 ifeq ($(with_gnu_ld), yes)
157 LINK.shared = $(CC) $(LDFLAGS) -shared -Wl,-h -Wl,$(soname) -Wl,+b -Wl,$(libdir)
159 LINK.shared = $(LD) +h $(soname) -b +b $(libdir)
163 ifeq ($(PORTNAME), irix)
164 shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
165 LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168 ifeq ($(PORTNAME), linux)
169 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
172 ifeq ($(PORTNAME), solaris)
174 LINK.shared = $(CC) -shared
176 LINK.shared = $(CC) -G
178 ifeq ($(with_gnu_ld), yes)
179 LINK.shared += -Wl,-soname,$(soname)
181 LINK.shared += -h $(soname)
185 ifeq ($(PORTNAME), sunos4)
186 LINK.shared = $(LD) -assert pure-text -Bdynamic
189 ifeq ($(PORTNAME), osf)
190 LINK.shared = $(LD) -shared -expect_unresolved '*'
193 ifeq ($(PORTNAME), sco)
195 LINK.shared = $(CC) -shared
197 LINK.shared = $(CC) -G
199 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
202 ifeq ($(PORTNAME), svr4)
203 LINK.shared = $(LD) -G
206 ifeq ($(PORTNAME), univel)
207 LINK.shared = $(LD) -G -z text
210 ifeq ($(PORTNAME), unixware)
212 LINK.shared = $(CC) -shared
214 LINK.shared = $(CC) -G
216 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
219 ifeq ($(PORTNAME), cygwin)
220 shlib = $(NAME)$(DLSUFFIX)
221 # needed for /contrib modules, not sure why
222 SHLIB_LINK += -lpgport
225 ifeq ($(PORTNAME), win32)
226 shlib = lib$(NAME)$(DLSUFFIX)
229 ifeq ($(PORTNAME), beos)
230 shlib = lib$(NAME)$(DLSUFFIX)
231 LINK.shared = $(LD) -nostart
232 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
235 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
236 ifeq ($(enable_rpath), yes)
237 SHLIB_LINK += $(rpath)
240 endif # enable_shared
248 .PHONY: all-lib all-static-lib all-shared-lib
250 all-lib: all-static-lib all-shared-lib
252 all-static-lib: $(PTHREAD_H_WIN32) $(top_builddir)/src/port/pg_config_paths.h lib$(NAME).a
254 all-shared-lib: $(PTHREAD_H_WIN32) $(top_builddir)/src/port/pg_config_paths.h $(shlib)
260 lib$(NAME).a: $(OBJS)
264 $(LINK.static) $@ `$(LORDER) $^ | tsort`
268 ifeq ($(enable_shared), yes)
270 ifneq ($(PORTNAME), win32)
271 ifneq ($(PORTNAME), cygwin)
272 ifneq ($(PORTNAME), beos)
273 ifneq ($(PORTNAME), aix)
277 $(LINK.shared) $(LDFLAGS_SL) $(OBJS) $(SHLIB_LINK) -o $@
278 # If we're using major and minor versions, then make a symlink to major-version-only.
279 ifneq ($(shlib), $(shlib_major))
281 $(LN_S) $(shlib) $(shlib_major)
283 # Make sure we have a link to a name without any version numbers
284 ifneq ($(shlib), $(shlib_bare))
286 $(LN_S) $(shlib) $(shlib_bare)
289 else # PORTNAME == aix
292 $(shlib): lib$(NAME).a
293 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
294 $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
296 endif # PORTNAME == aix
298 else # PORTNAME == beos
302 ln -fs $(top_srcdir)/src/backend/postgres _APP_
303 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
305 endif # PORTNAME == beos
307 else # PORTNAME == cygwin
310 $(shlib) lib$(NAME).a: $(OBJS)
312 $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
313 $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
314 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
316 $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
317 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
320 endif # PORTNAME == cygwin
322 else # PORTNAME == win32
325 $(shlib) lib$(NAME).a: $(OBJS)
327 $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
328 $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
329 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
331 $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
332 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
335 endif # PORTNAME == win32
337 endif # enable_shared
344 .PHONY: install-lib install-lib-static install-lib-shared
345 install-lib: install-lib-static install-lib-shared
347 install-lib-static: lib$(NAME).a
348 $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
349 ifeq ($(PORTNAME), darwin)
350 cd $(DESTDIR)$(libdir) && \
354 ifeq ($(enable_shared), yes)
355 install-lib-shared: $(shlib)
356 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
357 ifneq ($(PORTNAME), cygwin)
358 ifneq ($(PORTNAME), win32)
359 ifneq ($(shlib), $(shlib_major))
360 cd $(DESTDIR)$(libdir) && \
361 rm -f $(shlib_major) && \
362 $(LN_S) $(shlib) $(shlib_major)
364 ifneq ($(shlib), $(shlib_bare))
365 cd $(DESTDIR)$(libdir) && \
366 rm -f $(shlib_bare) && \
367 $(LN_S) $(shlib) $(shlib_bare)
371 endif # enable_shared
378 .PHONY: uninstall-lib
380 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
381 ifeq ($(enable_shared), yes)
382 rm -f $(DESTDIR)$(libdir)/$(shlib_bare) \
383 $(DESTDIR)$(libdir)/$(shlib_major) \
384 $(DESTDIR)$(libdir)/$(shlib)
385 endif # enable_shared
395 ifeq ($(enable_shared), yes)
396 rm -f $(shlib_bare) $(shlib_major) $(shlib)
398 rm -f lib$(NAME)$(EXPSUFF)
401 ifeq ($(PORTNAME), cygwin)
402 rm -f $(NAME).dll $(NAME).def
405 ifeq ($(PORTNAME), win32)
406 rm -f $(NAME).dll $(NAME).def