1 #-------------------------------------------------------------------------
4 # Common rules for building shared libraries
6 # Copyright (c) 1998, Regents of the University of California
9 # $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.59 2002/07/16 05:46:35 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 # The module Makefile must also include
30 # $(top_builddir)/src/Makefile.global before including this file.
31 # (Makefile.global sets PORTNAME and other needed symbols.)
33 # This makefile provides the following (phony) targets:
35 # all-lib build the static and shared (if applicable) libraries
36 # install-lib install the libraries into $(libdir)
37 # uninstall-lib remove the libraries from $(libdir)
38 # clean-lib delete the static and shared libraries from the build dir
40 # Since `all-lib' is the first rule in this file you probably want to
41 # have the `all' target before including this file. In the most simple
42 # case it would look like this:
46 # Similarly, the install rule might look like
48 # install: install-lib
50 # plus any additional things you want to install. Et cetera.
52 # Got that? Look at src/interfaces/libpq/Makefile for an example.
54 # While the linker allows creation of most shared libraries,
55 # -Bsymbolic requires resolution of all symbols, making the
56 # compiler a better choice for shared library creation on ELF platforms.
57 # With the linker, -Bsymbolic requires the crt1.o startup object file.
62 COMPILER = $(CC) $(CFLAGS)
64 COMPILER = $(CXX) $(CXXFLAGS)
68 # First, a few hacks for building *static* libraries.
70 LINK.static = $(AR) $(AROPT)
74 ifeq ($(PORTNAME), irix5)
76 LINK.static = $(CXX) -ar -o
80 ifeq ($(PORTNAME), solaris)
82 LINK.static = $(CXX) -xar -o
90 ifeq ($(enable_shared), yes)
92 # For each platform we support shared libraries on, set shlib to the
93 # name of the library, LINK.shared to the command to link the library,
94 # and adjust SHLIB_LINK if necessary.
96 # Try to keep the sections in some kind of order, folks...
99 override CFLAGS += $(CFLAGS_SL)
102 CXXFLAGS_SL = $(CFLAGS_SL)
104 override CXXFLAGS += $(CXXFLAGS_SL)
107 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
109 ifeq ($(PORTNAME), aix)
110 shlib := lib$(NAME)$(DLSUFFIX)
114 ifeq ($(PORTNAME), darwin)
115 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
116 LINK.shared = $(COMPILER) $(DARWIN_NAMESPACE_SPEC) -bundle -undefined suppress
119 ifeq ($(PORTNAME), openbsd)
120 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
122 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
125 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
129 ifeq ($(PORTNAME), bsdi)
130 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
131 ifeq ($(DLSUFFIX), .so)
132 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
135 ifeq ($(DLSUFFIX), .o)
136 LINK.shared = shlicc -O $(LDREL)
140 ifeq ($(PORTNAME), freebsd)
142 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
143 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
145 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
146 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
150 ifeq ($(PORTNAME), netbsd)
151 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
153 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
155 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
159 ifeq ($(PORTNAME), hpux)
160 # HPUX doesn't believe in version numbers for shlibs
161 shlib := lib$(NAME)$(DLSUFFIX)
162 LINK.shared = $(LD) -b +b $(libdir)
165 ifeq ($(PORTNAME), irix5)
166 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
167 LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
170 ifeq ($(PORTNAME), linux)
171 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
172 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
175 ifeq ($(PORTNAME), solaris)
176 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
179 LINK.shared = $(CC) -shared
181 LINK.shared = $(CC) -G
185 LINK.shared = $(CXX) -shared
187 LINK.shared = $(CXX) -G
190 ifeq ($(with_gnu_ld), yes)
191 LINK.shared += -Wl,-soname,$(soname)
193 LINK.shared += -h $(soname)
197 ifeq ($(PORTNAME), sunos4)
198 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
199 LINK.shared = $(LD) -assert pure-text -Bdynamic
202 ifeq ($(PORTNAME), osf)
203 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
204 LINK.shared = $(LD) -shared -expect_unresolved '*'
207 ifeq ($(PORTNAME), sco)
208 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
211 LINK.shared = $(CC) -shared
213 LINK.shared = $(CC) -G
217 LINK.shared = $(CXX) -shared
219 LINK.shared = $(CXX) -G
222 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
225 ifeq ($(PORTNAME), svr4)
226 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
227 LINK.shared = $(LD) -G
230 ifeq ($(PORTNAME), univel)
231 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
232 LINK.shared = $(LD) -G -z text
235 ifeq ($(PORTNAME), unixware)
236 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
239 LINK.shared = $(CC) -shared
241 LINK.shared = $(CC) -G
245 LINK.shared = $(CXX) -shared
247 LINK.shared = $(CXX) -G
250 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
253 ifeq ($(PORTNAME), win)
254 shlib := $(NAME)$(DLSUFFIX)
256 SHLIB_LINK += --driver-name g++
260 ifeq ($(PORTNAME), beos)
261 shlib := lib$(NAME)$(DLSUFFIX)
262 LINK.shared = $(LD) -nostart
263 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
266 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
267 ifeq ($(enable_rpath), yes)
268 SHLIB_LINK += $(rpath)
271 endif # enable_shared
280 all-lib: lib$(NAME).a $(shlib)
282 ifneq ($(PORTNAME), win)
288 lib$(NAME).a: $(OBJS)
292 $(LINK.static) $@ `$(LORDER) $^ | tsort`
298 ifeq ($(enable_shared), yes)
300 ifneq ($(PORTNAME), beos)
301 ifneq ($(PORTNAME), win)
302 ifneq ($(PORTNAME), aix)
306 $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
307 # If we're using major and minor versions, then make a symlink to major-version-only.
308 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
309 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
310 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
312 # Make sure we have a link to a name without any version numbers
313 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
314 rm -f lib$(NAME)$(DLSUFFIX)
315 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
318 else # PORTNAME == aix
321 $(shlib): lib$(NAME).a
322 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
323 $(COMPILER) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) $(LDFLAGS_SL)
325 endif # PORTNAME == aix
327 else # PORTNAME == win
330 $(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
331 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
332 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(DLLINIT) $(DLLLIBS) $(SHLIB_LINK)
333 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
336 $(MAKE) -C $(@D) $(@F)
338 endif # PORTNAME == win
340 else # PORTNAME == beos
344 ln -fs $(top_srcdir)/src/backend/postgres _APP_
345 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
347 endif # PORTNAME == beos
349 endif # enable_shared
356 .PHONY: install-lib install-lib-static install-lib-shared
357 install-lib: install-lib-static install-lib-shared
359 install-lib-static: lib$(NAME).a
360 $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
362 ifeq ($(enable_shared), yes)
363 install-lib-shared: $(shlib)
364 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
365 ifneq ($(PORTNAME), win)
366 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
367 cd $(DESTDIR)$(libdir) && \
368 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
369 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
371 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
372 cd $(DESTDIR)$(libdir) && \
373 rm -f lib$(NAME)$(DLSUFFIX) && \
374 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
378 endif # enable_shared
385 .PHONY: uninstall-lib
387 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
388 ifeq ($(enable_shared), yes)
389 rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
390 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
391 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
392 endif # enable_shared
402 ifeq ($(enable_shared), yes)
403 rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
405 rm -f lib$(NAME)$(EXPSUFF)
408 ifeq ($(PORTNAME), win)