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.70 2003/09/20 21:26:20 tgl 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.
61 COMPILER = $(CC) $(CFLAGS)
62 LINK.static = $(AR) $(AROPT)
66 ifeq ($(enable_shared), yes)
68 # For each platform we support shared libraries on, set shlib to the
69 # name of the library, LINK.shared to the command to link the library,
70 # and adjust SHLIB_LINK if necessary.
72 # Try to keep the sections in some kind of order, folks...
74 override CFLAGS += $(CFLAGS_SL)
76 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
78 ifeq ($(PORTNAME), aix)
79 shlib := lib$(NAME)$(DLSUFFIX)
83 ifeq ($(PORTNAME), darwin)
84 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
85 LINK.shared = $(COMPILER) $(DARWIN_NAMESPACE_SPEC) -bundle -undefined suppress
88 ifeq ($(PORTNAME), openbsd)
89 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
91 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
94 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
98 ifeq ($(PORTNAME), bsdi)
99 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
100 ifeq ($(DLSUFFIX), .so)
101 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
104 ifeq ($(DLSUFFIX), .o)
105 LINK.shared = shlicc -O $(LDREL)
109 ifeq ($(PORTNAME), freebsd)
111 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
112 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
114 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
115 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
119 ifeq ($(PORTNAME), netbsd)
120 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
122 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
124 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
128 ifeq ($(PORTNAME), hpux)
129 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
130 LINK.shared = $(LD) +h $(soname) -b +b $(libdir)
133 ifeq ($(PORTNAME), irix5)
134 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
135 LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
138 ifeq ($(PORTNAME), linux)
139 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
140 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
143 ifeq ($(PORTNAME), solaris)
144 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
146 LINK.shared = $(CC) -shared
148 LINK.shared = $(CC) -G
150 ifeq ($(with_gnu_ld), yes)
151 LINK.shared += -Wl,-soname,$(soname)
153 LINK.shared += -h $(soname)
157 ifeq ($(PORTNAME), sunos4)
158 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
159 LINK.shared = $(LD) -assert pure-text -Bdynamic
162 ifeq ($(PORTNAME), osf)
163 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
164 LINK.shared = $(LD) -shared -expect_unresolved '*'
167 ifeq ($(PORTNAME), sco)
168 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
170 LINK.shared = $(CC) -shared
172 LINK.shared = $(CC) -G
174 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
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)
190 LINK.shared = $(CC) -shared
192 LINK.shared = $(CC) -G
194 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
197 ifeq ($(PORTNAME), cygwin)
198 shlib := $(NAME)$(DLSUFFIX)
201 ifeq ($(PORTNAME), beos)
202 shlib := lib$(NAME)$(DLSUFFIX)
203 LINK.shared = $(LD) -nostart
204 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
207 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
208 ifeq ($(enable_rpath), yes)
209 SHLIB_LINK += $(rpath)
212 endif # enable_shared
220 .PHONY: all-lib all-static-lib all-shared-lib
222 all-lib: all-static-lib all-shared-lib
224 all-static-lib: lib$(NAME).a
226 all-shared-lib: $(shlib)
228 ifneq ($(PORTNAME), cygwin)
234 lib$(NAME).a: $(OBJS)
238 $(LINK.static) $@ `$(LORDER) $^ | tsort`
244 ifeq ($(enable_shared), yes)
246 ifneq ($(PORTNAME), beos)
247 ifneq ($(PORTNAME), cygwin)
248 ifneq ($(PORTNAME), aix)
252 $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
253 # If we're using major and minor versions, then make a symlink to major-version-only.
254 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
255 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
256 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
258 # Make sure we have a link to a name without any version numbers
259 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
260 rm -f lib$(NAME)$(DLSUFFIX)
261 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
264 else # PORTNAME == aix
267 $(shlib): lib$(NAME).a
268 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
269 $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
271 endif # PORTNAME == aix
273 else # PORTNAME == cygwin
276 $(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
277 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
278 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(DLLINIT) $(SHLIB_LINK)
279 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
281 $(DLLINIT): $(DLLINIT:%.o=%.c)
282 $(MAKE) -C $(@D) $(@F)
284 endif # PORTNAME == cygwin
286 else # PORTNAME == beos
290 ln -fs $(top_srcdir)/src/backend/postgres _APP_
291 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
293 endif # PORTNAME == beos
295 endif # enable_shared
302 .PHONY: install-lib install-lib-static install-lib-shared
303 install-lib: install-lib-static install-lib-shared
305 install-lib-static: lib$(NAME).a
306 $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
307 ifeq ($(PORTNAME), darwin)
308 cd $(DESTDIR)$(libdir) && \
312 ifeq ($(enable_shared), yes)
313 install-lib-shared: $(shlib)
314 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
315 ifneq ($(PORTNAME), cygwin)
316 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
317 cd $(DESTDIR)$(libdir) && \
318 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
319 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
321 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
322 cd $(DESTDIR)$(libdir) && \
323 rm -f lib$(NAME)$(DLSUFFIX) && \
324 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
328 endif # enable_shared
335 .PHONY: uninstall-lib
337 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
338 ifeq ($(enable_shared), yes)
339 rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
340 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
341 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
342 endif # enable_shared
352 ifeq ($(enable_shared), yes)
353 rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
355 rm -f lib$(NAME)$(EXPSUFF)
358 ifeq ($(PORTNAME), cygwin)
359 rm -f $(NAME).dll $(NAME).def