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.15 1999/09/27 20:54:56 momjian Exp $
11 #-------------------------------------------------------------------------
13 # This file should be included by any Postgres module Makefile that wants
14 # to build a shared library (if possible for the current platform).
15 # A static library is also built from the same object files.
16 # RESTRICTION: only one library can be built per makefile...
18 # Before including this file, the module Makefile must define these variables:
19 # NAME Name of library to build (no suffix nor "lib" prefix)
20 # SO_MAJOR_VERSION Major version number to use for shared library
21 # SO_MINOR_VERSION Minor version number to use for shared library
22 # OBJS List of object files to include in library
23 # SHLIB_LINK If shared library relies on other libraries, additional
24 # stuff to put in its link command
25 # (If you want a patchlevel, include it in SO_MINOR_VERSION, eg, "6.2".)
27 # The module Makefile must also include $(SRCDIR)/Makefile.global before
28 # including this file (Makefile.global sets PORTNAME and other needed symbols).
30 # The first rule in this file is a rule for "all", which causes both the
31 # static and shared libraries to be built (as well as all the object files).
32 # If you have other files that need to be made before building object files
33 # and libraries, put another rule for "all" before you include this file.
35 # Your install rule should look like
37 # install: install-headers install-lib $(install-shlib-dep)
39 # where install-headers is only needed if you have header files to install
40 # (and, of course, it has to be provided by your makefile). The rules
41 # install-lib and install-shlib are provided by this makefile --- they
42 # automatically install the plain and shared libraries into $(LIBDIR).
43 # install-shlib-dep is a variable that expands to install-shlib if the
44 # shared library needs to be installed, empty if not.
46 # Got that? Look at src/interfaces/libpq/Makefile.in for an example.
49 # shlib and install-shlib-dep default to empty, and stay that way if we're
50 # on a platform where we don't know how to build a shared library.
54 # For each platform we support shlibs on, set shlib and install-shlib-dep,
55 # and update flags as needed to build a shared lib. Note we depend on
56 # Makefile.global (or really Makefile.port) to supply DLSUFFIX and other
59 # Try to keep the sections in some kind of order, folks...
61 ifeq ($(PORTNAME), aix)
62 install-shlib-dep := install-shlib
63 shlib := lib$(NAME)$(DLSUFFIX)
67 ifeq ($(PORTNAME), bsd)
69 install-shlib-dep := install-shlib
70 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
72 LDFLAGS_SL := -x -Bshareable -soname $(shlib)
74 LDFLAGS_SL := -x -Bshareable -Bforcearchive
76 CFLAGS += $(CFLAGS_SL)
80 ifeq ($(PORTNAME), bsdi)
82 ifeq ($(DLSUFFIX), .so)
83 install-shlib-dep := install-shlib
84 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
86 CFLAGS += $(CFLAGS_SL)
88 ifeq ($(DLSUFFIX), .o)
89 install-shlib-dep := install-shlib
90 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
93 CFLAGS += $(CFLAGS_SL)
98 ifeq ($(PORTNAME), freebsd)
100 install-shlib-dep := install-shlib
102 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
103 LDFLAGS_SL := -x -shared -soname $(shlib)
105 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
106 LDFLAGS_SL := -x -Bshareable -Bforcearchive
108 CFLAGS += $(CFLAGS_SL)
112 ifeq ($(PORTNAME), hpux)
113 install-shlib-dep := install-shlib
114 # HPUX doesn't believe in version numbers for shlibs
115 shlib := lib$(NAME)$(DLSUFFIX)
117 CFLAGS += $(CFLAGS_SL)
120 ifeq ($(PORTNAME), irix5)
121 install-shlib-dep := install-shlib
122 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
123 LDFLAGS_SL := -shared -rpath $(LIBDIR)
124 CFLAGS += $(CFLAGS_SL)
127 ifeq ($(PORTNAME), linux)
128 install-shlib-dep := install-shlib
129 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
130 LDFLAGS_SL := -Bdynamic -shared -soname $(shlib)
131 LDFLAGS_ODBC := -Bsymbolic -lc -lm
133 CFLAGS += $(CFLAGS_SL)
136 ifeq ($(PORTNAME), solaris_i386)
137 install-shlib-dep := install-shlib
138 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
140 SHLIB_LINK += -ldl -lsocket -lresolv -lnsl -lm -lc
141 CFLAGS += $(CFLAGS_SL)
144 ifeq ($(PORTNAME), solaris_sparc)
145 install-shlib-dep := install-shlib
146 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
148 SHLIB_LINK += -ldl -lsocket -lresolv -lnsl -lm -lc
149 CFLAGS += $(CFLAGS_SL)
152 ifeq ($(PORTNAME), alpha)
153 install-shlib-dep := install-shlib
154 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
155 LDFLAGS_SL += -shared -expect_unresolved '*'
158 ifeq ($(PORTNAME), svr4)
159 install-shlib-dep := install-shlib
160 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
162 CFLAGS += $(CFLAGS_SL)
165 ifeq ($(PORTNAME), univel)
166 install-shlib-dep := install-shlib
167 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168 LDFLAGS_SL := -G -z text
169 CFLAGS += $(CFLAGS_SL)
172 COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
176 ifeq ($(PORTNAME), unixware)
177 install-shlib-dep := install-shlib
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), win)
188 install-shlib-dep := install-shlib
189 shlib := $(NAME)$(DLSUFFIX)
192 # Default target definition. Note shlib is empty if not building a shlib.
194 all: lib$(NAME).a $(shlib)
196 # Rules to build regular and shared libraries
198 ifneq ($(PORTNAME), win)
200 lib$(NAME).a: $(OBJS)
202 $(AR) $(AROPT) $@ $(OBJS)
204 $(AR) $(AROPT) $@ `lorder $(OBJS) | tsort`
211 ifneq ($(PORTNAME), win)
212 ifneq ($(PORTNAME), aix)
216 $(LD) $(LDFLAGS_SL) -o $@ $(OBJS) $(SHLIB_LINK)
217 if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" ]; then \
218 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
219 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
221 if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX)" ]; then \
222 rm -f lib$(NAME)$(DLSUFFIX); \
223 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \
229 $(shlib): lib$(NAME).a
230 $(MKLDEXPORT) lib$(NAME).a $(LIBDIR) > lib$(NAME)$(EXPSUFF)
231 $(LD) -H512 -bM:SRE -bI:$(SRCDIR)/backend/$(POSTGRES_IMP) -bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
238 $(shlib) lib$(NAME).a: $(OBJS) $(SRCDIR)/utils/dllinit.o
239 $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
240 $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(SRCDIR)/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
241 $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
243 $(SRCDIR)/utils/dllinit.o: $(SRCDIR)/utils/dllinit.c
244 $(MAKE) -C $(SRCDIR)/utils dllinit.o
249 # Rules to install regular and shared libraries
251 .PHONY: all install-lib install-shlib
253 install-lib: lib$(NAME).a
254 $(INSTALL) $(INSTL_LIB_OPTS) lib$(NAME).a $(LIBDIR)/lib$(NAME).a
256 install-shlib: $(shlib)
257 $(INSTALL) $(INSTL_SHLIB_OPTS) $(shlib) $(LIBDIR)/$(shlib)
258 ifneq ($(PORTNAME), win)
259 if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" ]; then \
261 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
262 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
264 if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX)" ]; then \
266 rm -f lib$(NAME)$(DLSUFFIX); \
267 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \
271 # Rule to delete shared library during "make clean"
276 rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)