OSDN Git Service

6506d6d5b92be1292c423ae4113d06297199663b
[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.38 2001/02/04 14:09:33 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 ifndef cplusplus
92   override CFLAGS       += $(CFLAGS_SL)
93 else
94   ifndef CXXFLAGS_SL
95     CXXFLAGS_SL = $(CFLAGS_SL)
96   endif
97   override CXXFLAGS     += $(CXXFLAGS_SL)
98 endif
99
100 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
101
102 ifeq ($(PORTNAME), aix)
103   shlib                 := lib$(NAME)$(DLSUFFIX)
104   SHLIB_LINK            += -lc
105 endif
106
107 ifeq ($(PORTNAME), darwin)
108   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
109   LINK.shared           = $(COMPILER) $(CFLAGS_SL)
110 endif
111
112 ifeq ($(PORTNAME), openbsd)
113   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
114   ifdef ELF_SYSTEM
115     LINK.shared         = $(LD) -x -Bshareable -soname $(soname)
116   else
117     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
118   endif
119 endif
120
121 ifeq ($(PORTNAME), bsdi)
122   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
123   ifeq ($(DLSUFFIX), .so)
124     LINK.shared         = $(LD) -shared -soname $(soname)
125   endif
126   ifeq ($(DLSUFFIX), .o)
127     LINK.shared         = shlicc -O $(LDREL)
128   endif
129 endif
130
131 ifeq ($(PORTNAME), freebsd)
132   ifdef ELF_SYSTEM
133     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
134     LINK.shared         = $(LD) -x -shared -soname $(soname)
135   else
136     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
137     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
138   endif
139 endif
140
141 ifeq ($(PORTNAME), netbsd)
142   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
143   ifdef ELF_SYSTEM
144     LINK.shared         = $(COMPILER) -shared -Wl,-soname,$(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 -Wl,-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,$(soname)
164 endif
165
166 ifeq ($(PORTNAME), solaris)
167   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168   LINK.shared           = $(COMPILER) -G
169   ifeq ($(with_gnu_ld), yes)
170     LINK.shared         += -Wl,-soname,$(soname)
171   else
172     LINK.shared         += -Wl,-h,$(soname)
173   endif
174   SHLIB_LINK            += -lm -lc
175 endif
176
177 ifeq ($(PORTNAME), osf)
178   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
179   LINK.shared           = $(LD) -shared -expect_unresolved '*'
180 endif
181
182 ifeq ($(PORTNAME), svr4)
183   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
184   LINK.shared           = $(LD) -G
185 endif
186
187 ifeq ($(PORTNAME), univel)
188   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
189   LINK.shared           = $(LD) -G -z text
190 endif
191
192 ifeq ($(PORTNAME), unixware)
193   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
194   ifndef cplusplus
195     ifeq ($(GCC), yes)
196       LINK.shared       = $(CC) -shared
197     else
198       LINK.shared       = $(CC) -G
199     endif
200   else
201     ifeq ($(GXX), yes)
202       LINK.shared       = $(CXX) -shared
203     else
204       LINK.shared       = $(CXX) -G
205     endif
206   endif
207   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
208 endif
209
210 ifeq ($(PORTNAME), win)
211   shlib                 := $(NAME)$(DLSUFFIX)
212   ifdef cplusplus
213     SHLIB_LINK          += --driver-name g++
214   endif
215 endif
216
217 ifeq ($(PORTNAME), beos)
218   shlib                 := lib$(NAME)$(DLSUFFIX)
219   LINK.shared           = $(LD) -nostart
220   SHLIB_LINK            += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
221 endif
222
223 # Pull in any extra -L options that the user might have specified.
224 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
225
226 ifeq ($(enable_rpath), yes)
227 SHLIB_LINK += $(rpath)
228 endif
229
230 endif # enable_shared
231
232
233
234 ##
235 ## BUILD
236 ##
237
238 .PHONY: all-lib
239 all-lib: lib$(NAME).a $(shlib)
240
241 ifneq ($(PORTNAME), win)
242
243 ifndef LORDER
244 MK_NO_LORDER := true
245 endif
246
247 lib$(NAME).a: $(OBJS)
248 ifdef MK_NO_LORDER
249         $(LINK.static) $@ $^
250 else
251         $(LINK.static) $@ `$(LORDER) $^ | tsort`
252 endif
253         $(RANLIB) $@
254
255 endif # not win
256
257 ifeq ($(enable_shared), yes)
258
259 ifneq ($(PORTNAME), beos)
260 ifneq ($(PORTNAME), win)
261 ifneq ($(PORTNAME), aix)
262
263 # Normal case
264 $(shlib): $(OBJS)
265         $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
266 # If we're using major and minor versions, then make a symlink to major-version-only.
267 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
268         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
269         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
270 endif
271 # Make sure we have a link to a name without any version numbers
272 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
273         rm -f lib$(NAME)$(DLSUFFIX)
274         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
275 endif
276
277 else # PORTNAME == aix
278
279 # AIX case
280 $(shlib): lib$(NAME).a
281         $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
282         $(CC) -Wl,-H512 -Wl,-bM:SRE -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
283
284 endif # PORTNAME == aix
285
286 else # PORTNAME == win
287
288 # WIN case
289 $(shlib) lib$(NAME).a: $(OBJS) $(top_builddir)/src/utils/dllinit.o
290         $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
291         $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(top_builddir)/src/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
292         $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
293
294 $(top_builddir)/src/utils/dllinit.o: $(top_srcdir)/src/utils/dllinit.c
295         $(MAKE) -C $(top_builddir)/src/utils dllinit.o
296
297 endif # PORTNAME == win
298
299 else # PORTNAME == beos
300
301 # BEOS case
302 $(shlib): $(OBJS)
303         ln -fs $(top_srcdir)/src/backend/postgres _APP_
304         $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
305
306 endif # PORTNAME == beos
307
308 endif # enable_shared
309
310
311 ##
312 ## INSTALL
313 ##
314
315 .PHONY: install-lib install-lib-static install-lib-shared
316 install-lib: install-lib-static install-lib-shared
317
318 install-lib-static: lib$(NAME).a
319         $(INSTALL_DATA) $< $(DESTDIR)$(libdir)/lib$(NAME).a
320
321 ifeq ($(enable_shared), yes)
322 install-lib-shared: $(shlib)
323         $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
324 ifneq ($(PORTNAME), win)
325 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
326         cd $(DESTDIR)$(libdir) && \
327         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
328         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
329 endif
330 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
331         cd $(DESTDIR)$(libdir) && \
332         rm -f lib$(NAME)$(DLSUFFIX) && \
333         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
334 endif
335
336 endif # not win
337 endif # enable_shared
338
339
340 ##
341 ## UNINSTALL
342 ##
343
344 .PHONY: uninstall-lib
345 uninstall-lib:
346         rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
347 ifeq ($(enable_shared), yes)
348         rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
349           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
350           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
351 endif # enable_shared
352
353
354 ##
355 ## CLEAN
356 ##
357
358 .PHONY: clean-lib
359 clean-lib:
360         rm -f lib$(NAME).a
361 ifeq ($(enable_shared), yes)
362         rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
363 endif
364 ifeq ($(PORTNAME), win)
365         rm -rf $(NAME).def
366 endif