1 #-------------------------------------------------------------------------
4 # Common rules for building shared libraries
6 # Copyright (c) 1998, Regents of the University of California
9 # $PostgreSQL: pgsql/src/Makefile.shlib,v 1.74 2003/12/01 22:23:06 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.
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) -bundle
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)
132 SHLIB_LINK += `$(CC) -print-libgcc-file-name`
136 ifeq ($(PORTNAME), irix5)
137 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
138 LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
141 ifeq ($(PORTNAME), linux)
142 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
143 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
146 ifeq ($(PORTNAME), solaris)
147 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
149 LINK.shared = $(CC) -shared
151 LINK.shared = $(CC) -G
153 ifeq ($(with_gnu_ld), yes)
154 LINK.shared += -Wl,-soname,$(soname)
156 LINK.shared += -h $(soname)
160 ifeq ($(PORTNAME), sunos4)
161 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
162 LINK.shared = $(LD) -assert pure-text -Bdynamic
165 ifeq ($(PORTNAME), osf)
166 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
167 LINK.shared = $(LD) -shared -expect_unresolved '*'
170 ifeq ($(PORTNAME), sco)
171 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
173 LINK.shared = $(CC) -shared
175 LINK.shared = $(CC) -G
177 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
180 ifeq ($(PORTNAME), svr4)
181 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
182 LINK.shared = $(LD) -G
185 ifeq ($(PORTNAME), univel)
186 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
187 LINK.shared = $(LD) -G -z text
190 ifeq ($(PORTNAME), unixware)
191 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
193 LINK.shared = $(CC) -shared
195 LINK.shared = $(CC) -G
197 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
200 ifeq ($(PORTNAME), cygwin)
201 shlib := $(NAME)$(DLSUFFIX)
204 ifeq ($(PORTNAME), win32)
205 shlib := lib$(NAME)$(DLSUFFIX)
208 ifeq ($(PORTNAME), beos)
209 shlib := lib$(NAME)$(DLSUFFIX)
210 LINK.shared = $(LD) -nostart
211 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
214 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
215 ifeq ($(enable_rpath), yes)
216 SHLIB_LINK += $(rpath)
219 endif # enable_shared
227 .PHONY: all-lib all-static-lib all-shared-lib
229 all-lib: all-static-lib all-shared-lib
231 all-static-lib: lib$(NAME).a
233 all-shared-lib: $(shlib)
235 ifneq ($(PORTNAME), cygwin)
236 ifneq ($(PORTNAME), win32)
242 lib$(NAME).a: $(OBJS)
246 $(LINK.static) $@ `$(LORDER) $^ | tsort`
253 ifeq ($(enable_shared), yes)
255 ifneq ($(PORTNAME), beos)
256 ifneq ($(PORTNAME), cygwin)
257 ifneq ($(PORTNAME), win32)
258 ifneq ($(PORTNAME), aix)
262 $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
263 # If we're using major and minor versions, then make a symlink to major-version-only.
264 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
265 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
266 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
268 # Make sure we have a link to a name without any version numbers
269 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
270 rm -f lib$(NAME)$(DLSUFFIX)
271 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
274 else # PORTNAME == aix
277 $(shlib): lib$(NAME).a
278 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
279 $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
281 endif # PORTNAME == aix
283 else # PORTNAME == win32
286 $(shlib) lib$(NAME).a: $(OBJS)
287 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
288 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
289 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
291 endif # PORTNAME == win32
293 else # PORTNAME == cygwin
296 $(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
297 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
298 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(DLLINIT) $(SHLIB_LINK)
299 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
301 $(DLLINIT): $(DLLINIT:%.o=%.c)
302 $(MAKE) -C $(@D) $(@F)
304 endif # PORTNAME == cygwin
306 else # PORTNAME == beos
310 ln -fs $(top_srcdir)/src/backend/postgres _APP_
311 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
313 endif # PORTNAME == beos
315 endif # enable_shared
322 .PHONY: install-lib install-lib-static install-lib-shared
323 install-lib: install-lib-static install-lib-shared
325 install-lib-static: lib$(NAME).a
326 $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
327 ifeq ($(PORTNAME), darwin)
328 cd $(DESTDIR)$(libdir) && \
332 ifeq ($(enable_shared), yes)
333 install-lib-shared: $(shlib)
334 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
335 ifneq ($(PORTNAME), cygwin)
336 ifneq ($(PORTNAME), win32)
337 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
338 cd $(DESTDIR)$(libdir) && \
339 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
340 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
342 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
343 cd $(DESTDIR)$(libdir) && \
344 rm -f lib$(NAME)$(DLSUFFIX) && \
345 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
350 endif # enable_shared
357 .PHONY: uninstall-lib
359 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
360 ifeq ($(enable_shared), yes)
361 rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
362 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
363 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
364 endif # enable_shared
374 ifeq ($(enable_shared), yes)
375 rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
377 rm -f lib$(NAME)$(EXPSUFF)
380 ifeq ($(PORTNAME), cygwin)
381 rm -f $(NAME).dll $(NAME).def
384 ifeq ($(PORTNAME), win32)
385 rm -f $(NAME).dll $(NAME).def