OSDN Git Service

Give left_oper() and right_oper() noError parameters like oper() (the
[pg-rex/syncrep.git] / 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.57 2002/04/10 16:45:25 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 # 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) $(DARWIN_NAMESPACE_SPEC) -bundle -undefined suppress
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   else
145     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
146     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
147   endif
148 endif
149
150 ifeq ($(PORTNAME), netbsd)
151   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
152   ifdef ELF_SYSTEM
153     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
154   else
155     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
156   endif
157 endif
158
159 ifeq ($(PORTNAME), hpux)
160 # HPUX doesn't believe in version numbers for shlibs
161   shlib                 := lib$(NAME)$(DLSUFFIX)
162   LINK.shared           = $(LD) -b +b $(libdir)
163 endif
164
165 ifeq ($(PORTNAME), irix5)
166   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
167   LINK.shared           = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168 endif
169
170 ifeq ($(PORTNAME), linux)
171   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
172   LINK.shared           = $(COMPILER) -shared -Wl,-soname,$(soname)
173 endif
174
175 ifeq ($(PORTNAME), solaris)
176   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
177   ifndef cplusplus
178     ifeq ($(GCC), yes)
179       LINK.shared       = $(CC) -shared
180     else
181       LINK.shared       = $(CC) -G
182     endif
183   else
184     ifeq ($(GXX), yes)
185       LINK.shared       = $(CXX) -shared
186     else
187       LINK.shared       = $(CXX) -G
188     endif
189   endif
190   ifeq ($(with_gnu_ld), yes)
191     LINK.shared         += -Wl,-soname,$(soname)
192   else
193     LINK.shared         += -h $(soname)
194   endif
195 endif
196
197 ifeq ($(PORTNAME), sunos4)
198   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
199   LINK.shared           = $(LD) -assert pure-text -Bdynamic
200 endif
201  
202 ifeq ($(PORTNAME), osf)
203   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
204   LINK.shared           = $(LD) -shared -expect_unresolved '*'
205 endif
206
207 ifeq ($(PORTNAME), sco)
208   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
209   ifndef cplusplus
210     ifeq ($(GCC), yes)
211       LINK.shared       = $(CC) -shared
212     else
213       LINK.shared       = $(CC) -G
214     endif
215   else
216     ifeq ($(GXX), yes)
217       LINK.shared       = $(CXX) -shared
218     else
219       LINK.shared       = $(CXX) -G
220     endif
221   endif
222   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
223 endif
224
225 ifeq ($(PORTNAME), svr4)
226   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
227   LINK.shared           = $(LD) -G
228 endif
229
230 ifeq ($(PORTNAME), univel)
231   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
232   LINK.shared           = $(LD) -G -z text
233 endif
234
235 ifeq ($(PORTNAME), unixware)
236   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
237   ifndef cplusplus
238     ifeq ($(GCC), yes)
239       LINK.shared       = $(CC) -shared
240     else
241       LINK.shared       = $(CC) -G
242     endif
243   else
244     ifeq ($(GXX), yes)
245       LINK.shared       = $(CXX) -shared
246     else
247       LINK.shared       = $(CXX) -G
248     endif
249   endif
250   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
251 endif
252
253 ifeq ($(PORTNAME), win)
254   shlib                 := $(NAME)$(DLSUFFIX)
255   ifdef cplusplus
256     SHLIB_LINK          += --driver-name g++
257   endif
258 endif
259
260 ifeq ($(PORTNAME), beos)
261   shlib                 := lib$(NAME)$(DLSUFFIX)
262   LINK.shared           = $(LD) -nostart
263   SHLIB_LINK            += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
264 endif
265
266 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
267 ifeq ($(enable_rpath), yes)
268 SHLIB_LINK += $(rpath)
269 endif
270
271 endif # enable_shared
272
273
274
275 ##
276 ## BUILD
277 ##
278
279 .PHONY: all-lib
280 all-lib: lib$(NAME).a $(shlib)
281
282 ifneq ($(PORTNAME), win)
283
284 ifndef LORDER
285 MK_NO_LORDER := true
286 endif
287
288 lib$(NAME).a: $(OBJS)
289 ifdef MK_NO_LORDER
290         $(LINK.static) $@ $^
291 else
292         $(LINK.static) $@ `$(LORDER) $^ | tsort`
293 endif
294         $(RANLIB) $@
295
296 endif # not win
297
298 ifeq ($(enable_shared), yes)
299
300 ifneq ($(PORTNAME), beos)
301 ifneq ($(PORTNAME), win)
302 ifneq ($(PORTNAME), aix)
303
304 # Normal case
305 $(shlib): $(OBJS)
306         $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
307 # If we're using major and minor versions, then make a symlink to major-version-only.
308 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
309         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
310         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
311 endif
312 # Make sure we have a link to a name without any version numbers
313 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
314         rm -f lib$(NAME)$(DLSUFFIX)
315         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
316 endif
317
318 else # PORTNAME == aix
319
320 # AIX case
321 $(shlib): lib$(NAME).a
322         $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
323         $(COMPILER) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) $(LDFLAGS_SL)
324
325 endif # PORTNAME == aix
326
327 else # PORTNAME == win
328
329 # WIN case
330 $(shlib) lib$(NAME).a: $(OBJS) $(top_builddir)/src/utils/dllinit.o
331         $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
332         $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(top_builddir)/src/utils/dllinit.o $(DLLINIT) $(DLLLIBS) $(SHLIB_LINK)
333         $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
334
335 $(top_builddir)/src/utils/dllinit.o: $(top_srcdir)/src/utils/dllinit.c
336         $(MAKE) -C $(top_builddir)/src/utils dllinit.o
337
338 endif # PORTNAME == win
339
340 else # PORTNAME == beos
341
342 # BEOS case
343 $(shlib): $(OBJS)
344         ln -fs $(top_srcdir)/src/backend/postgres _APP_
345         $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
346
347 endif # PORTNAME == beos
348
349 endif # enable_shared
350
351
352 ##
353 ## INSTALL
354 ##
355
356 .PHONY: install-lib install-lib-static install-lib-shared
357 install-lib: install-lib-static install-lib-shared
358
359 install-lib-static: lib$(NAME).a
360         $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
361
362 ifeq ($(enable_shared), yes)
363 install-lib-shared: $(shlib)
364         $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
365 ifneq ($(PORTNAME), win)
366 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
367         cd $(DESTDIR)$(libdir) && \
368         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
369         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
370 endif
371 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
372         cd $(DESTDIR)$(libdir) && \
373         rm -f lib$(NAME)$(DLSUFFIX) && \
374         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
375 endif
376
377 endif # not win
378 endif # enable_shared
379
380
381 ##
382 ## UNINSTALL
383 ##
384
385 .PHONY: uninstall-lib
386 uninstall-lib:
387         rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
388 ifeq ($(enable_shared), yes)
389         rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
390           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
391           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
392 endif # enable_shared
393
394
395 ##
396 ## CLEAN
397 ##
398
399 .PHONY: clean-lib
400 clean-lib:
401         rm -f lib$(NAME).a
402 ifeq ($(enable_shared), yes)
403         rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
404 endif
405 ifeq ($(PORTNAME), win)
406         rm -rf $(NAME).def
407 endif