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.31 2000/10/31 19:55:18 petere 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.
55 COMPILER = $(CC) $(CFLAGS)
57 COMPILER = $(CXX) $(CXXFLAGS)
61 # First, a few hacks for building *static* libraries.
63 LINK.static = $(AR) $(AROPT)
67 ifeq ($(PORTNAME), irix5)
69 LINK.static = $(CXX) -ar -o
73 ifeq ($(PORTNAME), solaris)
75 LINK.static = $(CXX) -xar -o
83 ifeq ($(enable_shared), yes)
85 # For each platform we support shared libraries on, set shlib to the
86 # name of the library, LINK.shared to the command to link the library,
87 # and adjust SHLIB_LINK if necessary.
89 # Try to keep the sections in some kind of order, folks...
91 # XXX fix Makefile.aix
92 ifneq ($(PORTNAME), aix)
94 override CFLAGS += $(CFLAGS_SL)
96 override CXXFLAGS += $(CFLAGS_SL)
101 ifeq ($(PORTNAME), aix)
102 shlib := lib$(NAME)$(DLSUFFIX)
106 ifeq ($(PORTNAME), darwin)
107 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
108 LINK.shared = $(COMPILER) $(CFLAGS_SL)
111 ifeq ($(PORTNAME), openbsd)
112 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
114 LINK.shared = $(LD) -x -Bshareable -soname $(shlib)
116 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
120 ifeq ($(PORTNAME), bsdi)
121 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
122 ifeq ($(DLSUFFIX), .so)
123 LINK.shared = $(LD) -shared -soname $(shlib)
125 ifeq ($(DLSUFFIX), .o)
126 LINK.shared = shlicc -O $(LDREL)
130 ifeq ($(PORTNAME), freebsd)
132 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
133 LINK.shared = $(LD) -x -shared -soname $(shlib)
135 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
136 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
140 ifeq ($(PORTNAME), netbsd)
141 soname := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
142 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
144 LINK.shared = $(COMPILER) -shared -Wl,-soname -Wl,$(soname)
146 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
150 ifeq ($(PORTNAME), hpux)
151 # HPUX doesn't believe in version numbers for shlibs
152 shlib := lib$(NAME)$(DLSUFFIX)
153 LINK.shared = $(LD) -b +b $(libdir)
156 ifeq ($(PORTNAME), irix5)
157 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
158 LINK.shared = $(COMPILER) -shared -set_version sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
161 ifeq ($(PORTNAME), linux)
162 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
163 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(shlib)
166 ifeq ($(PORTNAME), solaris)
167 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168 LINK.shared = $(COMPILER) -G
169 SHLIB_LINK += -ldl -lsocket -lresolv -lnsl -lm -lc
172 ifeq ($(PORTNAME), osf)
173 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
174 LINK.shared = $(LD) -shared -expect_unresolved '*'
177 ifeq ($(PORTNAME), svr4)
178 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
179 LINK.shared = $(LD) -G
182 ifeq ($(PORTNAME), univel)
183 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
184 LINK.shared = $(LD) -G -z text
187 ifeq ($(PORTNAME), unixware)
188 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
191 LINK.shared = $(CC) -shared
193 LINK.shared = $(CC) -G
197 LINK.shared = $(CXX) -shared
199 LINK.shared = $(CXX) -G
202 LINK.shared += -Wl,-z,text
205 ifeq ($(PORTNAME), win)
206 shlib := $(NAME)$(DLSUFFIX)
208 SHLIB_LINK += --driver-name g++
212 ifeq ($(PORTNAME), beos)
213 shlib := lib$(NAME)$(DLSUFFIX)
214 LINK.shared = $(LD) -nostart
215 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
218 # Pull in any extra -L options that the user might have specified.
219 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
221 ifeq ($(enable_rpath), yes)
222 SHLIB_LINK += $(rpath)
225 endif # enable_shared
234 all-lib: lib$(NAME).a $(shlib)
236 ifneq ($(PORTNAME), win)
242 lib$(NAME).a: $(OBJS)
246 $(LINK.static) $@ `$(LORDER) $^ | tsort`
252 ifeq ($(enable_shared), yes)
254 ifneq ($(PORTNAME), beos)
255 ifneq ($(PORTNAME), win)
256 ifneq ($(PORTNAME), aix)
260 $(LINK.shared) -o $@ $(OBJS) $(SHLIB_LINK)
261 # If we're using major and minor versions, then make a symlink to major-version-only.
262 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
263 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
264 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
266 # Make sure we have a link to a name without any version numbers
267 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
268 rm -f lib$(NAME)$(DLSUFFIX)
269 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
272 else # PORTNAME == aix
275 $(shlib): lib$(NAME).a
276 $(MKLDEXPORT) lib$(NAME).a $(libdir) > lib$(NAME)$(EXPSUFF)
277 $(LD) -H512 -bM:SRE -bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
279 endif # PORTNAME == aix
281 else # PORTNAME == win
284 $(shlib) lib$(NAME).a: $(OBJS) $(top_builddir)/src/utils/dllinit.o
285 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
286 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(top_builddir)/src/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
287 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
289 $(top_builddir)/src/utils/dllinit.o: $(top_srcdir)/src/utils/dllinit.c
290 $(MAKE) -C $(top_builddir)/src/utils dllinit.o
292 endif # PORTNAME == win
294 else # PORTNAME == beos
298 ln -fs $(top_srcdir)/src/backend/postgres _APP_
299 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
301 endif # PORTNAME == beos
303 endif # enable_shared
310 .PHONY: install-lib install-lib-static install-lib-shared
311 install-lib: install-lib-static install-lib-shared
313 install-lib-static: lib$(NAME).a
314 $(INSTALL_DATA) $< $(DESTDIR)$(libdir)/lib$(NAME).a
316 ifeq ($(enable_shared), yes)
317 install-lib-shared: $(shlib)
318 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
319 ifneq ($(PORTNAME), win)
320 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
321 cd $(DESTDIR)$(libdir) && \
322 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
323 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
325 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
326 cd $(DESTDIR)$(libdir) && \
327 rm -f lib$(NAME)$(DLSUFFIX) && \
328 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
332 endif # enable_shared
339 .PHONY: uninstall-lib
341 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
342 ifeq ($(enable_shared), yes)
343 rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
344 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
345 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
346 endif # enable_shared
356 ifeq ($(enable_shared), yes)
357 rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
359 ifeq ($(PORTNAME), win)