]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
This is the minimal version of the Darwin support patch from
[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.31 2000/10/31 19:55:18 petere Exp $
10 #
11 #-------------------------------------------------------------------------
12
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.
17 #
18 # Before including this file, the module Makefile must define these
19 # variables:
20 #
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".)
28 #
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.)
32 #
33 # This makefile provides the following (phony) targets:
34 #
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
39 #
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:
43 #
44 #     all: all-lib
45 #
46 # Similarly, the install rule might look like
47 #
48 #     install: install-lib
49 #
50 # plus any additional things you want to install. Et cetera.
51 #
52 # Got that?  Look at src/interfaces/libpq/Makefile for an example.
53
54 ifndef cplusplus
55 COMPILER = $(CC) $(CFLAGS)
56 else
57 COMPILER = $(CXX) $(CXXFLAGS)
58 endif
59
60
61 # First, a few hacks for building *static* libraries.
62
63 LINK.static = $(AR) $(AROPT)
64
65 ifdef cplusplus
66
67 ifeq ($(PORTNAME), irix5)
68   ifneq ($(GXX), yes)
69     LINK.static = $(CXX) -ar -o
70   endif
71 endif
72
73 ifeq ($(PORTNAME), solaris)
74   ifneq ($(GXX), yes)
75     LINK.static = $(CXX) -xar -o
76   endif
77 endif
78
79 endif # cplusplus
80
81
82
83 ifeq ($(enable_shared), yes)
84
85 # For each platform we support shared libraries on, set shlib to the
86 # name of the library, LINK.shared to the command to link the library,
87 # and adjust SHLIB_LINK if necessary.
88
89 # Try to keep the sections in some kind of order, folks...
90
91 # XXX fix Makefile.aix
92 ifneq ($(PORTNAME), aix)
93   ifndef cplusplus
94     override CFLAGS     += $(CFLAGS_SL)
95   else
96     override CXXFLAGS   += $(CFLAGS_SL)
97   endif
98 endif
99
100
101 ifeq ($(PORTNAME), aix)
102   shlib                 := lib$(NAME)$(DLSUFFIX)
103   SHLIB_LINK            += -lc
104 endif
105
106 ifeq ($(PORTNAME), darwin)
107   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
108   LINK.shared           = $(COMPILER) $(CFLAGS_SL)
109 endif
110
111 ifeq ($(PORTNAME), openbsd)
112   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
113   ifdef ELF_SYSTEM
114     LINK.shared         = $(LD) -x -Bshareable -soname $(shlib)
115   else
116     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
117   endif
118 endif
119
120 ifeq ($(PORTNAME), bsdi)
121   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
122   ifeq ($(DLSUFFIX), .so)
123     LINK.shared         = $(LD) -shared -soname $(shlib)
124   endif
125   ifeq ($(DLSUFFIX), .o)
126     LINK.shared         = shlicc -O $(LDREL)
127   endif
128 endif
129
130 ifeq ($(PORTNAME), freebsd)
131   ifdef ELF_SYSTEM
132     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
133     LINK.shared         = $(LD) -x -shared -soname $(shlib)
134   else
135     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
136     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
137   endif
138 endif
139
140 ifeq ($(PORTNAME), netbsd)
141   soname                := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
142   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
143   ifdef ELF_SYSTEM
144     LINK.shared         = $(COMPILER) -shared -Wl,-soname -Wl,$(soname)
145   else
146     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
147   endif
148 endif
149
150 ifeq ($(PORTNAME), hpux)
151 # HPUX doesn't believe in version numbers for shlibs
152   shlib                 := lib$(NAME)$(DLSUFFIX)
153   LINK.shared           = $(LD) -b +b $(libdir)
154 endif
155
156 ifeq ($(PORTNAME), irix5)
157   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
158   LINK.shared           = $(COMPILER) -shared -set_version sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
159 endif
160
161 ifeq ($(PORTNAME), linux)
162   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
163   LINK.shared           = $(COMPILER) -shared -Wl,-soname,$(shlib)
164 endif
165
166 ifeq ($(PORTNAME), solaris)
167   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168   LINK.shared           = $(COMPILER) -G
169   SHLIB_LINK            += -ldl -lsocket -lresolv -lnsl -lm -lc
170 endif
171
172 ifeq ($(PORTNAME), osf)
173   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
174   LINK.shared           = $(LD) -shared -expect_unresolved '*'
175 endif
176
177 ifeq ($(PORTNAME), svr4)
178   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
179   LINK.shared           = $(LD) -G
180 endif
181
182 ifeq ($(PORTNAME), univel)
183   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
184   LINK.shared           = $(LD) -G -z text
185 endif
186
187 ifeq ($(PORTNAME), unixware)
188   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
189   ifndef cplusplus
190     ifeq ($(GCC), yes)
191       LINK.shared       = $(CC) -shared
192     else
193       LINK.shared       = $(CC) -G
194     endif
195   else
196     ifeq ($(GXX), yes)
197       LINK.shared       = $(CXX) -shared
198     else
199       LINK.shared       = $(CXX) -G
200     endif
201   endif
202   LINK.shared           += -Wl,-z,text
203 endif
204
205 ifeq ($(PORTNAME), win)
206   shlib                 := $(NAME)$(DLSUFFIX)
207   ifdef cplusplus
208     SHLIB_LINK          += --driver-name g++
209   endif
210 endif
211
212 ifeq ($(PORTNAME), beos)
213   shlib                 := lib$(NAME)$(DLSUFFIX)
214   LINK.shared           = $(LD) -nostart
215   SHLIB_LINK            += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
216 endif
217
218 # Pull in any extra -L options that the user might have specified.
219 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
220
221 ifeq ($(enable_rpath), yes)
222 SHLIB_LINK += $(rpath)
223 endif
224
225 endif # enable_shared
226
227
228
229 ##
230 ## BUILD
231 ##
232
233 .PHONY: all-lib
234 all-lib: lib$(NAME).a $(shlib)
235
236 ifneq ($(PORTNAME), win)
237
238 ifndef LORDER
239 MK_NO_LORDER := true
240 endif
241
242 lib$(NAME).a: $(OBJS)
243 ifdef MK_NO_LORDER
244         $(LINK.static) $@ $^
245 else
246         $(LINK.static) $@ `$(LORDER) $^ | tsort`
247 endif
248         $(RANLIB) $@
249
250 endif # not win
251
252 ifeq ($(enable_shared), yes)
253
254 ifneq ($(PORTNAME), beos)
255 ifneq ($(PORTNAME), win)
256 ifneq ($(PORTNAME), aix)
257
258 # Normal case
259 $(shlib): $(OBJS)
260         $(LINK.shared) -o $@ $(OBJS) $(SHLIB_LINK)
261 # If we're using major and minor versions, then make a symlink to major-version-only.
262 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
263         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
264         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
265 endif
266 # Make sure we have a link to a name without any version numbers
267 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
268         rm -f lib$(NAME)$(DLSUFFIX)
269         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
270 endif
271
272 else # PORTNAME == aix
273
274 # AIX case
275 $(shlib): lib$(NAME).a
276         $(MKLDEXPORT) lib$(NAME).a $(libdir) > lib$(NAME)$(EXPSUFF)
277         $(LD) -H512 -bM:SRE -bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
278
279 endif # PORTNAME == aix
280
281 else # PORTNAME == win
282
283 # WIN case
284 $(shlib) lib$(NAME).a: $(OBJS) $(top_builddir)/src/utils/dllinit.o
285         $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
286         $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(top_builddir)/src/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
287         $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
288
289 $(top_builddir)/src/utils/dllinit.o: $(top_srcdir)/src/utils/dllinit.c
290         $(MAKE) -C $(top_builddir)/src/utils dllinit.o
291
292 endif # PORTNAME == win
293
294 else # PORTNAME == beos
295
296 # BEOS case
297 $(shlib): $(OBJS)
298         ln -fs $(top_srcdir)/src/backend/postgres _APP_
299         $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
300
301 endif # PORTNAME == beos
302
303 endif # enable_shared
304
305
306 ##
307 ## INSTALL
308 ##
309
310 .PHONY: install-lib install-lib-static install-lib-shared
311 install-lib: install-lib-static install-lib-shared
312
313 install-lib-static: lib$(NAME).a
314         $(INSTALL_DATA) $< $(DESTDIR)$(libdir)/lib$(NAME).a
315
316 ifeq ($(enable_shared), yes)
317 install-lib-shared: $(shlib)
318         $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
319 ifneq ($(PORTNAME), win)
320 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
321         cd $(DESTDIR)$(libdir) && \
322         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
323         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
324 endif
325 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
326         cd $(DESTDIR)$(libdir) && \
327         rm -f lib$(NAME)$(DLSUFFIX) && \
328         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
329 endif
330
331 endif # not win
332 endif # enable_shared
333
334
335 ##
336 ## UNINSTALL
337 ##
338
339 .PHONY: uninstall-lib
340 uninstall-lib:
341         rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
342 ifeq ($(enable_shared), yes)
343         rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
344           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
345           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
346 endif # enable_shared
347
348
349 ##
350 ## CLEAN
351 ##
352
353 .PHONY: clean-lib
354 clean-lib:
355         rm -f lib$(NAME).a
356 ifeq ($(enable_shared), yes)
357         rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
358 endif
359 ifeq ($(PORTNAME), win)
360         rm -rf $(NAME).def
361 endif