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.44 2001/02/10 18:46:34 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) $(CFLAGS_SL)
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)
146 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
147 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
151 ifeq ($(PORTNAME), netbsd)
152 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
154 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
156 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
160 ifeq ($(PORTNAME), hpux)
161 # HPUX doesn't believe in version numbers for shlibs
162 shlib := lib$(NAME)$(DLSUFFIX)
163 LINK.shared = $(LD) -b +b $(libdir)
166 ifeq ($(PORTNAME), irix5)
167 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
168 LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
171 ifeq ($(PORTNAME), linux)
172 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
173 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
176 ifeq ($(PORTNAME), solaris)
177 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
178 LINK.shared = $(COMPILER) -G
179 ifeq ($(with_gnu_ld), yes)
180 LINK.shared += -Wl,-soname,$(soname)
182 LINK.shared += -Wl,-h,$(soname)
184 SHLIB_LINK += -lm -lc
187 ifeq ($(PORTNAME), osf)
188 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
189 LINK.shared = $(LD) -shared -expect_unresolved '*'
192 ifeq ($(PORTNAME), svr4)
193 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
194 LINK.shared = $(LD) -G
197 ifeq ($(PORTNAME), univel)
198 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
199 LINK.shared = $(LD) -G -z text
202 ifeq ($(PORTNAME), unixware)
203 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
206 LINK.shared = $(CC) -shared
208 LINK.shared = $(CC) -G
212 LINK.shared = $(CXX) -shared
214 LINK.shared = $(CXX) -G
217 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
220 ifeq ($(PORTNAME), win)
221 shlib := $(NAME)$(DLSUFFIX)
223 SHLIB_LINK += --driver-name g++
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 # Pull in any extra -L options that the user might have specified.
234 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
236 ifeq ($(enable_rpath), yes)
237 SHLIB_LINK += $(rpath)
240 endif # enable_shared
249 all-lib: lib$(NAME).a $(shlib)
251 ifneq ($(PORTNAME), win)
257 lib$(NAME).a: $(OBJS)
261 $(LINK.static) $@ `$(LORDER) $^ | tsort`
267 ifeq ($(enable_shared), yes)
269 ifneq ($(PORTNAME), beos)
270 ifneq ($(PORTNAME), win)
271 ifneq ($(PORTNAME), aix)
275 $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
276 # If we're using major and minor versions, then make a symlink to major-version-only.
277 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
278 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
279 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
281 # Make sure we have a link to a name without any version numbers
282 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
283 rm -f lib$(NAME)$(DLSUFFIX)
284 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
287 else # PORTNAME == aix
290 $(shlib): lib$(NAME).a
291 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
292 $(CC) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
294 endif # PORTNAME == aix
296 else # PORTNAME == win
299 $(shlib) lib$(NAME).a: $(OBJS) $(top_builddir)/src/utils/dllinit.o
300 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
301 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(top_builddir)/src/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
302 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
304 $(top_builddir)/src/utils/dllinit.o: $(top_srcdir)/src/utils/dllinit.c
305 $(MAKE) -C $(top_builddir)/src/utils dllinit.o
307 endif # PORTNAME == win
309 else # PORTNAME == beos
313 ln -fs $(top_srcdir)/src/backend/postgres _APP_
314 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
316 endif # PORTNAME == beos
318 endif # enable_shared
325 .PHONY: install-lib install-lib-static install-lib-shared
326 install-lib: install-lib-static install-lib-shared
328 install-lib-static: lib$(NAME).a
329 $(INSTALL_DATA) $< $(DESTDIR)$(libdir)/lib$(NAME).a
331 ifeq ($(enable_shared), yes)
332 install-lib-shared: $(shlib)
333 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
334 ifneq ($(PORTNAME), win)
335 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
336 cd $(DESTDIR)$(libdir) && \
337 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
338 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
340 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
341 cd $(DESTDIR)$(libdir) && \
342 rm -f lib$(NAME)$(DLSUFFIX) && \
343 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
347 endif # enable_shared
354 .PHONY: uninstall-lib
356 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
357 ifeq ($(enable_shared), yes)
358 rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
359 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
360 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
361 endif # enable_shared
371 ifeq ($(enable_shared), yes)
372 rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
374 ifeq ($(PORTNAME), win)