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.76 2004/05/19 21:37:43 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 # Optional flags when building DLL's (only applicable to win32 and cygwin
31 # DLLTOOL_DEFFLAGS Additional flags when creating the dll .def file
32 # DLLTOOL_LIBFLAGS Additional flags when creating the lib<module>.a file
33 # DLLWRAP_FLAGS Additional flags to dllwrap
35 # The module Makefile must also include
36 # $(top_builddir)/src/Makefile.global before including this file.
37 # (Makefile.global sets PORTNAME and other needed symbols.)
39 # This makefile provides the following (phony) targets:
41 # all-lib build the static and shared (if applicable) libraries
42 # install-lib install the libraries into $(libdir)
43 # uninstall-lib remove the libraries from $(libdir)
44 # clean-lib delete the static and shared libraries from the build dir
46 # Since `all-lib' is the first rule in this file you probably want to
47 # have the `all' target before including this file. In the most simple
48 # case it would look like this:
52 # Similarly, the install rule might look like
54 # install: install-lib
56 # plus any additional things you want to install. Et cetera.
58 # Got that? Look at src/interfaces/libpq/Makefile for an example.
60 # While the linker allows creation of most shared libraries,
61 # -Bsymbolic requires resolution of all symbols, making the
62 # compiler a better choice for shared library creation on ELF platforms.
63 # With the linker, -Bsymbolic requires the crt1.o startup object file.
67 COMPILER = $(CC) $(CFLAGS)
68 LINK.static = $(AR) $(AROPT)
72 ifeq ($(enable_shared), yes)
74 # For each platform we support shared libraries on, set shlib to the
75 # name of the library, LINK.shared to the command to link the library,
76 # and adjust SHLIB_LINK if necessary.
78 # Try to keep the sections in some kind of order, folks...
80 override CFLAGS += $(CFLAGS_SL)
82 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
84 ifeq ($(PORTNAME), aix)
85 shlib := lib$(NAME)$(DLSUFFIX)
89 ifeq ($(PORTNAME), darwin)
90 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
91 LINK.shared = $(COMPILER) -bundle
94 ifeq ($(PORTNAME), openbsd)
95 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
97 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
100 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
104 ifeq ($(PORTNAME), bsdi)
105 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
106 ifeq ($(DLSUFFIX), .so)
107 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
110 ifeq ($(DLSUFFIX), .o)
111 LINK.shared = shlicc -O $(LDREL)
115 ifeq ($(PORTNAME), freebsd)
117 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
118 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
120 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
121 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
125 ifeq ($(PORTNAME), netbsd)
126 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
128 LINK.shared = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
130 LINK.shared = $(LD) -x -Bshareable -Bforcearchive
134 ifeq ($(PORTNAME), hpux)
135 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
136 LINK.shared = $(LD) +h $(soname) -b +b $(libdir)
138 SHLIB_LINK += `$(CC) -print-libgcc-file-name`
142 ifeq ($(PORTNAME), irix)
143 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
144 LINK.shared = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
147 ifeq ($(PORTNAME), linux)
148 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
149 LINK.shared = $(COMPILER) -shared -Wl,-soname,$(soname)
152 ifeq ($(PORTNAME), solaris)
153 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
155 LINK.shared = $(CC) -shared
157 LINK.shared = $(CC) -G
159 ifeq ($(with_gnu_ld), yes)
160 LINK.shared += -Wl,-soname,$(soname)
162 LINK.shared += -h $(soname)
166 ifeq ($(PORTNAME), sunos4)
167 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168 LINK.shared = $(LD) -assert pure-text -Bdynamic
171 ifeq ($(PORTNAME), osf)
172 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
173 LINK.shared = $(LD) -shared -expect_unresolved '*'
176 ifeq ($(PORTNAME), sco)
177 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
179 LINK.shared = $(CC) -shared
181 LINK.shared = $(CC) -G
183 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
186 ifeq ($(PORTNAME), svr4)
187 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
188 LINK.shared = $(LD) -G
191 ifeq ($(PORTNAME), univel)
192 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
193 LINK.shared = $(LD) -G -z text
196 ifeq ($(PORTNAME), unixware)
197 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
199 LINK.shared = $(CC) -shared
201 LINK.shared = $(CC) -G
203 LINK.shared += -Wl,-z,text -Wl,-h,$(soname)
206 ifeq ($(PORTNAME), cygwin)
207 shlib := $(NAME)$(DLSUFFIX)
210 ifeq ($(PORTNAME), win32)
211 shlib := lib$(NAME)$(DLSUFFIX)
214 ifeq ($(PORTNAME), beos)
215 shlib := lib$(NAME)$(DLSUFFIX)
216 LINK.shared = $(LD) -nostart
217 SHLIB_LINK += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
220 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
221 ifeq ($(enable_rpath), yes)
222 SHLIB_LINK += $(rpath)
225 endif # enable_shared
233 .PHONY: all-lib all-static-lib all-shared-lib
235 all-lib: all-static-lib all-shared-lib
237 all-static-lib: lib$(NAME).a
239 all-shared-lib: $(shlib)
241 ifneq ($(PORTNAME), cygwin)
242 ifneq ($(PORTNAME), win32)
248 lib$(NAME).a: $(OBJS)
252 $(LINK.static) $@ `$(LORDER) $^ | tsort`
259 ifeq ($(enable_shared), yes)
261 ifneq ($(PORTNAME), beos)
262 ifneq ($(PORTNAME), cygwin)
263 ifneq ($(PORTNAME), win32)
264 ifneq ($(PORTNAME), aix)
268 $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
269 # If we're using major and minor versions, then make a symlink to major-version-only.
270 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
271 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
272 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
274 # Make sure we have a link to a name without any version numbers
275 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
276 rm -f lib$(NAME)$(DLSUFFIX)
277 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
280 else # PORTNAME == aix
283 $(shlib): lib$(NAME).a
284 $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
285 $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
287 endif # PORTNAME == aix
289 else # PORTNAME == win32
292 $(shlib) lib$(NAME).a: $(OBJS)
293 $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
294 $(DLLWRAP) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
295 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
297 endif # PORTNAME == win32
299 else # PORTNAME == cygwin
302 $(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
303 $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
304 $(DLLWRAP) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(DLLINIT) $(SHLIB_LINK)
305 $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
307 $(DLLINIT): $(DLLINIT:%.o=%.c)
308 $(MAKE) -C $(@D) $(@F)
310 endif # PORTNAME == cygwin
312 else # PORTNAME == beos
316 ln -fs $(top_srcdir)/src/backend/postgres _APP_
317 $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
319 endif # PORTNAME == beos
321 endif # enable_shared
328 .PHONY: install-lib install-lib-static install-lib-shared
329 install-lib: install-lib-static install-lib-shared
331 install-lib-static: lib$(NAME).a
332 $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
333 ifeq ($(PORTNAME), darwin)
334 cd $(DESTDIR)$(libdir) && \
338 ifeq ($(enable_shared), yes)
339 install-lib-shared: $(shlib)
340 $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
341 ifneq ($(PORTNAME), cygwin)
342 ifneq ($(PORTNAME), win32)
343 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
344 cd $(DESTDIR)$(libdir) && \
345 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
346 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
348 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
349 cd $(DESTDIR)$(libdir) && \
350 rm -f lib$(NAME)$(DLSUFFIX) && \
351 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
356 endif # enable_shared
363 .PHONY: uninstall-lib
365 rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
366 ifeq ($(enable_shared), yes)
367 rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
368 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
369 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
370 endif # enable_shared
380 ifeq ($(enable_shared), yes)
381 rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
383 rm -f lib$(NAME)$(EXPSUFF)
386 ifeq ($(PORTNAME), cygwin)
387 rm -f $(NAME).dll $(NAME).def
390 ifeq ($(PORTNAME), win32)
391 rm -f $(NAME).dll $(NAME).def