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