]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
Irix fix from Mark Dalphin
[postgresql] / src / Makefile.shlib
1 #-------------------------------------------------------------------------
2 #
3 # Makefile.shlib
4 #    Common rules for building shared libraries
5 #
6 # Copyright (c) 1998, Regents of the University of California
7 #
8 # IDENTIFICATION
9 #    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.15 1999/09/27 20:54:56 momjian Exp $
10 #
11 #-------------------------------------------------------------------------
12
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...
17
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".)
26 #
27 # The module Makefile must also include $(SRCDIR)/Makefile.global before
28 # including this file (Makefile.global sets PORTNAME and other needed symbols).
29 #
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.
34 #
35 # Your install rule should look like
36 #
37 #       install: install-headers install-lib $(install-shlib-dep)
38 #
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.
45 #
46 # Got that?  Look at src/interfaces/libpq/Makefile.in for an example.
47
48
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.
51 shlib := 
52 install-shlib-dep :=
53
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
57 # symbols.
58
59 # Try to keep the sections in some kind of order, folks...
60
61 ifeq ($(PORTNAME), aix)
62   install-shlib-dep     := install-shlib
63   shlib                         := lib$(NAME)$(DLSUFFIX)
64   SHLIB_LINK            += -lc
65 endif
66
67 ifeq ($(PORTNAME), bsd)
68   ifdef BSD_SHLIB
69     install-shlib-dep   := install-shlib
70     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
71     ifdef ELF_SYSTEM
72       LDFLAGS_SL        := -x -Bshareable -soname $(shlib)
73     else
74       LDFLAGS_SL        := -x -Bshareable -Bforcearchive
75     endif
76     CFLAGS              += $(CFLAGS_SL)
77   endif
78 endif
79
80 ifeq ($(PORTNAME), bsdi)
81   ifdef BSD_SHLIB
82     ifeq ($(DLSUFFIX), .so)
83       install-shlib-dep := install-shlib
84       shlib                     := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
85       LDFLAGS_SL                += -shared
86       CFLAGS                    += $(CFLAGS_SL)
87     endif
88     ifeq ($(DLSUFFIX), .o)
89       install-shlib-dep := install-shlib
90       shlib                     := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
91       LD                        := shlicc
92       LDFLAGS_SL                += -O -r
93       CFLAGS                    += $(CFLAGS_SL)
94     endif
95   endif
96 endif
97
98 ifeq ($(PORTNAME), freebsd)
99   ifdef BSD_SHLIB
100     install-shlib-dep   := install-shlib
101     ifdef ELF_SYSTEM
102       shlib             := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
103       LDFLAGS_SL        := -x -shared -soname $(shlib)
104     else
105       shlib             := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
106       LDFLAGS_SL        := -x -Bshareable -Bforcearchive
107     endif
108     CFLAGS              += $(CFLAGS_SL)
109   endif
110 endif
111
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)
116   LDFLAGS_SL            := -b
117   CFLAGS                        += $(CFLAGS_SL)
118 endif
119
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)
125 endif
126
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
132   SHLIB_LINK            += -lc
133   CFLAGS                        += $(CFLAGS_SL)
134 endif
135
136 ifeq ($(PORTNAME), solaris_i386)
137   install-shlib-dep     := install-shlib
138   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
139   LDFLAGS_SL            := -G
140   SHLIB_LINK            += -ldl -lsocket -lresolv -lnsl -lm -lc
141   CFLAGS                        += $(CFLAGS_SL)
142 endif
143
144 ifeq ($(PORTNAME), solaris_sparc)
145   install-shlib-dep     := install-shlib
146   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
147   LDFLAGS_SL            := -G
148   SHLIB_LINK            += -ldl -lsocket -lresolv -lnsl -lm -lc
149   CFLAGS                        += $(CFLAGS_SL)
150 endif
151
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 '*'
156 endif
157
158 ifeq ($(PORTNAME), svr4)
159   install-shlib-dep     := install-shlib
160   shlib                         := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
161   LDFLAGS_SL            := -G
162   CFLAGS                        += $(CFLAGS_SL)
163 endif
164
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)
170   ifeq ($(CXX), CC)
171     CXXFLAGS += -Xw
172     COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
173   endif
174 endif
175
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)
181   ifeq ($(CXX), CC)
182     CXXFLAGS += -Xw
183     COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
184   endif
185 endif
186
187 ifeq ($(PORTNAME), win)
188   install-shlib-dep     := install-shlib
189   shlib                         := $(NAME)$(DLSUFFIX)
190 endif
191
192 # Default target definition.  Note shlib is empty if not building a shlib.
193
194 all: lib$(NAME).a $(shlib)
195
196 # Rules to build regular and shared libraries
197
198 ifneq ($(PORTNAME), win)
199
200 lib$(NAME).a: $(OBJS)
201 ifdef MK_NO_LORDER
202         $(AR) $(AROPT) $@ $(OBJS) 
203 else
204         $(AR) $(AROPT) $@ `lorder $(OBJS) | tsort`
205 endif
206         $(RANLIB) $@
207
208 endif
209
210 ifneq ($(shlib),)
211 ifneq ($(PORTNAME), win)
212 ifneq ($(PORTNAME), aix)
213
214 # Normal case
215 $(shlib): $(OBJS)
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); \
220         fi
221         if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX)" ]; then \
222                 rm -f lib$(NAME)$(DLSUFFIX); \
223                 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \
224         fi
225
226 else
227
228 # AIX case
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)
232
233 endif
234
235 else
236
237 # WIN case
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
242
243 $(SRCDIR)/utils/dllinit.o: $(SRCDIR)/utils/dllinit.c
244         $(MAKE) -C $(SRCDIR)/utils dllinit.o
245
246 endif
247 endif
248
249 # Rules to install regular and shared libraries
250
251 .PHONY: all install-lib install-shlib
252
253 install-lib: lib$(NAME).a
254         $(INSTALL) $(INSTL_LIB_OPTS) lib$(NAME).a $(LIBDIR)/lib$(NAME).a
255
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 \
260                 cd $(LIBDIR); \
261                 rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
262                 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
263         fi
264         if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX)" ]; then \
265                 cd $(LIBDIR); \
266                 rm -f lib$(NAME)$(DLSUFFIX); \
267                 $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \
268         fi
269 endif
270
271 # Rule to delete shared library during "make clean"
272
273 .PHONY: clean-shlib
274
275 clean-shlib:
276         rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)