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.21 2000/06/28 18:29:13 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 # shlib is empty by default. If we know how to build a shared library
56 # it will contain the name of the file, otherwise it will remain
57 # empty. Thus `ifdef shlib' could be used in the containing make file
58 # to test whether shared libraries are available.
61 # For each platform we support shared libraries on, set shlib and
62 # update flags as needed to build a shared lib. Note we depend on
63 # Makefile.global (or really Makefile.port) to supply DLSUFFIX and
66 # Try to keep the sections in some kind of order, folks...
68 ifeq ($(PORTNAME), aix)
69 shlib := lib$(NAME)$(DLSUFFIX)
73 ifeq ($(PORTNAME), bsd)
75 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
77 LDFLAGS_SL := -x -Bshareable -soname $(shlib)
79 LDFLAGS_SL := -x -Bshareable -Bforcearchive
81 CFLAGS += $(CFLAGS_SL)
85 ifeq ($(PORTNAME), bsdi)
87 ifeq ($(DLSUFFIX), .so)
88 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
89 LDFLAGS_SL += -shared -soname $(shlib)
90 CFLAGS += $(CFLAGS_SL)
92 ifeq ($(DLSUFFIX), .o)
93 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
95 LDFLAGS_SL += -O $(LDREL)
96 CFLAGS += $(CFLAGS_SL)
101 ifeq ($(PORTNAME), freebsd)
104 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
105 LDFLAGS_SL := -x -shared -soname $(shlib)
107 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
108 LDFLAGS_SL := -x -Bshareable -Bforcearchive
110 CFLAGS += $(CFLAGS_SL)
114 ifeq ($(PORTNAME), netbsd)
116 soname := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
117 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
120 LDFLAGS_SL := -shared -Wl,-soname -Wl,$(soname)
121 ifneq ($(SHLIB_LINK),)
122 LDFLAGS_SL += -Wl,-R$(libdir)
125 LDFLAGS_SL := -x -Bshareable -Bforcearchive
127 CFLAGS += $(CFLAGS_SL)
131 ifeq ($(PORTNAME), hpux)
132 # HPUX doesn't believe in version numbers for shlibs
133 shlib := lib$(NAME)$(DLSUFFIX)
135 CFLAGS += $(CFLAGS_SL)
138 ifeq ($(PORTNAME), irix5)
139 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
140 LDFLAGS_SL := -shared -rpath $(libdir) -set_version sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
141 CFLAGS += $(CFLAGS_SL)
144 ifeq ($(PORTNAME), linux)
145 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
146 LDFLAGS_SL := -Bdynamic -shared -soname $(shlib)
147 LDFLAGS_ODBC := -Bsymbolic -lc -lm
149 CFLAGS += $(CFLAGS_SL)
152 ifeq ($(PORTNAME), solaris_i386)
153 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
155 SHLIB_LINK += -ldl -lsocket -lresolv -lnsl -lm -lc
156 CFLAGS += $(CFLAGS_SL)
159 ifeq ($(PORTNAME), solaris_sparc)
160 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
162 SHLIB_LINK += -ldl -lsocket -lresolv -lnsl -lm -lc
163 CFLAGS += $(CFLAGS_SL)
166 ifeq ($(PORTNAME), alpha)
167 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168 LDFLAGS_SL += -shared -expect_unresolved '*'
171 ifeq ($(PORTNAME), svr4)
172 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
174 CFLAGS += $(CFLAGS_SL)
177 ifeq ($(PORTNAME), univel)
178 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
179 LDFLAGS_SL := -G -z text
180 CFLAGS += $(CFLAGS_SL)
183 COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
187 ifeq ($(PORTNAME), unixware)
188 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
189 LDFLAGS_SL := -G -z text
190 CFLAGS += $(CFLAGS_SL)
193 COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
197 ifeq ($(PORTNAME), win)
198 shlib := $(NAME)$(DLSUFFIX)
202 # Note that in what follows, shlib is empty when not building a shared
211 all-lib: lib$(NAME).a $(shlib)
213 # Rules to build regular and shared libraries
215 ifneq ($(PORTNAME), win)
217 lib$(NAME).a: $(OBJS)
219 $(AR) $(AROPT) $@ $(OBJS)
221 $(AR) $(AROPT) $@ `lorder $(OBJS) | tsort`
228 ifneq ($(PORTNAME), win)
229 ifneq ($(PORTNAME), aix)
233 $(LD) $(LDFLAGS_SL) -o $@ $(OBJS) $(SHLIB_LINK)
234 # If we're using major and minor versions, then make a symlink to major-version-only.
235 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
236 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
237 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
239 # Make sure we have a link to a name without any version numbers
240 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
241 rm -f lib$(NAME)$(DLSUFFIX)
242 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
245 else # PORTNAME == aix
248 $(shlib): lib$(NAME).a
249 $(MKLDEXPORT) lib$(NAME).a $(libdir) > lib$(NAME)$(EXPSUFF)
250 $(LD) -H512 -bM:SRE -bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
252 endif # PORTNAME == aix
254 else # PORTNAME == win
257 $(shlib) lib$(NAME).a: $(OBJS) $(top_builddir)/src/utils/dllinit.o
258 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
259 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(top_builddir)/src/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
260 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
262 $(top_builddir)/src/utils/dllinit.o: $(top_srcdir)/src/utils/dllinit.c
263 $(MAKE) -C $(top_builddir)/src/utils dllinit.o
265 endif # PORTNAME == win
273 .PHONY: install-lib install-lib-static install-lib-shared
274 install-lib: install-lib-static install-lib-shared
276 install-lib-static: lib$(NAME).a
277 $(INSTALL_DATA) $< $(libdir)/lib$(NAME).a
280 install-lib-shared: $(shlib)
281 $(INSTALL_SHLIB) $< $(libdir)/$(shlib)
282 ifneq ($(PORTNAME), win)
283 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
285 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
286 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
288 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
290 rm -f lib$(NAME)$(DLSUFFIX) && \
291 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
302 .PHONY: uninstall-lib
304 rm -f $(libdir)/lib$(NAME).a
306 rm -f $(libdir)/lib$(NAME)$(DLSUFFIX) \
307 $(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
308 $(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
319 rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
320 ifeq ($(PORTNAME), win)