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.38 2001/02/04 14:09:33 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...
92 override CFLAGS += $(CFLAGS_SL)
95 CXXFLAGS_SL = $(CFLAGS_SL)
97 override CXXFLAGS += $(CXXFLAGS_SL)
100 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
102 ifeq ($(PORTNAME), aix)
103 shlib := lib$(NAME)$(DLSUFFIX)
107 ifeq ($(PORTNAME), darwin)
108 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
109 LINK.shared = $(COMPILER) $(CFLAGS_SL)
112 ifeq ($(PORTNAME), openbsd)
113 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
115 LINK.shared = $(LD) -x -Bshareable -soname $(soname)
117 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
121 ifeq ($(PORTNAME), bsdi)
122 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
123 ifeq ($(DLSUFFIX), .so)
124 LINK.shared = $(LD) -shared -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 = $(LD) -x -shared -soname $(soname)
136 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
137 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
141 ifeq ($(PORTNAME), netbsd)
142 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
144 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(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 -Wl,-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,$(soname)
166 ifeq ($(PORTNAME), solaris)
167 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168 LINK.shared = $(COMPILER) -G
169 ifeq ($(with_gnu_ld), yes)
170 LINK.shared += -Wl,-soname,$(soname)
172 LINK.shared += -Wl,-h,$(soname)
174 SHLIB_LINK += -lm -lc
177 ifeq ($(PORTNAME), osf)
178 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
179 LINK.shared = $(LD) -shared -expect_unresolved '*'
182 ifeq ($(PORTNAME), svr4)
183 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
184 LINK.shared = $(LD) -G
187 ifeq ($(PORTNAME), univel)
188 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
189 LINK.shared = $(LD) -G -z text
192 ifeq ($(PORTNAME), unixware)
193 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
196 LINK.shared = $(CC) -shared
198 LINK.shared = $(CC) -G
202 LINK.shared = $(CXX) -shared
204 LINK.shared = $(CXX) -G
207 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
210 ifeq ($(PORTNAME), win)
211 shlib := $(NAME)$(DLSUFFIX)
213 SHLIB_LINK += --driver-name g++
217 ifeq ($(PORTNAME), beos)
218 shlib := lib$(NAME)$(DLSUFFIX)
219 LINK.shared = $(LD) -nostart
220 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
223 # Pull in any extra -L options that the user might have specified.
224 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
226 ifeq ($(enable_rpath), yes)
227 SHLIB_LINK += $(rpath)
230 endif # enable_shared
239 all-lib: lib$(NAME).a $(shlib)
241 ifneq ($(PORTNAME), win)
247 lib$(NAME).a: $(OBJS)
251 $(LINK.static) $@ `$(LORDER) $^ | tsort`
257 ifeq ($(enable_shared), yes)
259 ifneq ($(PORTNAME), beos)
260 ifneq ($(PORTNAME), win)
261 ifneq ($(PORTNAME), aix)
265 $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
266 # If we're using major and minor versions, then make a symlink to major-version-only.
267 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
268 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
269 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
271 # Make sure we have a link to a name without any version numbers
272 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
273 rm -f lib$(NAME)$(DLSUFFIX)
274 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
277 else # PORTNAME == aix
280 $(shlib): lib$(NAME).a
281 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
282 $(CC) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
284 endif # PORTNAME == aix
286 else # PORTNAME == win
289 $(shlib) lib$(NAME).a: $(OBJS) $(top_builddir)/src/utils/dllinit.o
290 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
291 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(top_builddir)/src/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
292 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
294 $(top_builddir)/src/utils/dllinit.o: $(top_srcdir)/src/utils/dllinit.c
295 $(MAKE) -C $(top_builddir)/src/utils dllinit.o
297 endif # PORTNAME == win
299 else # PORTNAME == beos
303 ln -fs $(top_srcdir)/src/backend/postgres _APP_
304 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
306 endif # PORTNAME == beos
308 endif # enable_shared
315 .PHONY: install-lib install-lib-static install-lib-shared
316 install-lib: install-lib-static install-lib-shared
318 install-lib-static: lib$(NAME).a
319 $(INSTALL_DATA) $< $(DESTDIR)$(libdir)/lib$(NAME).a
321 ifeq ($(enable_shared), yes)
322 install-lib-shared: $(shlib)
323 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
324 ifneq ($(PORTNAME), win)
325 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
326 cd $(DESTDIR)$(libdir) && \
327 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
328 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
330 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
331 cd $(DESTDIR)$(libdir) && \
332 rm -f lib$(NAME)$(DLSUFFIX) && \
333 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
337 endif # enable_shared
344 .PHONY: uninstall-lib
346 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
347 ifeq ($(enable_shared), yes)
348 rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
349 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
350 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
351 endif # enable_shared
361 ifeq ($(enable_shared), yes)
362 rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
364 ifeq ($(PORTNAME), win)