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.5 1998/11/30 00:30:03 tgl 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 ifeq ($(PORTNAME), freebsd)
61 install-shlib-dep := install-shlib
62 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
64 LDFLAGS_SL := -x -Bshareable
66 LDFLAGS_SL := -x -Bshareable -Bforcearchive
68 CFLAGS += $(CFLAGS_SL)
72 ifeq ($(PORTNAME), bsd)
74 install-shlib-dep := install-shlib
75 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
76 LDFLAGS_SL := -x -Bshareable -Bforcearchive
77 CFLAGS += $(CFLAGS_SL)
81 ifeq ($(PORTNAME), bsdi)
83 ifeq ($(DLSUFFIX), .so)
84 install-shlib-dep := install-shlib
85 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
87 CFLAGS += $(CFLAGS_SL)
89 ifeq ($(DLSUFFIX), .o)
90 install-shlib-dep := install-shlib
91 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
94 CFLAGS += $(CFLAGS_SL)
99 ifeq ($(PORTNAME), hpux)
100 install-shlib-dep := install-shlib
101 # HPUX doesn't believe in version numbers for shlibs
102 shlib := lib$(NAME)$(DLSUFFIX)
104 CFLAGS += $(CFLAGS_SL)
107 ifeq ($(PORTNAME), linux)
108 install-shlib-dep := install-shlib
109 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
110 LDFLAGS_SL := -Bdynamic -shared -soname $(shlib)
111 LDFLAGS_ODBC := -Bsymbolic -lc -lm
113 CFLAGS += $(CFLAGS_SL)
116 ifeq ($(PORTNAME), solaris_i386)
117 install-shlib-dep := install-shlib
118 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
120 CFLAGS += $(CFLAGS_SL)
123 ifeq ($(PORTNAME), solaris_sparc)
124 install-shlib-dep := install-shlib
125 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
127 CFLAGS += $(CFLAGS_SL)
130 ifeq ($(PORTNAME), svr4)
131 install-shlib-dep := install-shlib
132 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
134 CFLAGS += $(CFLAGS_SL)
137 ifeq ($(PORTNAME), univel)
138 install-shlib-dep := install-shlib
139 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
140 LDFLAGS_SL := -G -z text
141 CFLAGS += $(CFLAGS_SL)
144 COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
148 ifeq ($(PORTNAME), unixware)
149 install-shlib-dep := install-shlib
150 shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
151 LDFLAGS_SL := -G -z text
152 CFLAGS += $(CFLAGS_SL)
155 COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
160 # Default target definition. Note shlib is empty if not building a shlib.
162 all: lib$(NAME).a $(shlib)
164 # Rules to build regular and shared libraries
166 lib$(NAME).a: $(OBJS)
168 $(AR) $(AROPT) $@ $(OBJS)
170 $(AR) $(AROPT) $@ `lorder $(OBJS) | tsort`
176 $(LD) $(LDFLAGS_SL) -o $@ $(OBJS) $(SHLIB_LINK)
179 # Rules to install regular and shared libraries
181 .PHONY: all install-lib install-shlib
183 install-lib: lib$(NAME).a
184 $(INSTALL) $(INSTL_LIB_OPTS) lib$(NAME).a $(LIBDIR)/lib$(NAME).a
186 install-shlib: $(shlib)
187 $(INSTALL) $(INSTL_SHLIB_OPTS) $(shlib) $(LIBDIR)/$(shlib)
188 if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" ]; then \
190 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
191 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
193 if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX)" ]; then \
195 rm -f lib$(NAME)$(DLSUFFIX); \
196 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \