]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
Message editing: remove gratuitous variations in message wording, standardize
[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.70 2003/09/20 21:26:20 tgl 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 COMPILER = $(CC) $(CFLAGS)
62 LINK.static = $(AR) $(AROPT)
63
64
65
66 ifeq ($(enable_shared), yes)
67
68 # For each platform we support shared libraries on, set shlib to the
69 # name of the library, LINK.shared to the command to link the library,
70 # and adjust SHLIB_LINK if necessary.
71
72 # Try to keep the sections in some kind of order, folks...
73
74 override CFLAGS += $(CFLAGS_SL)
75
76 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
77
78 ifeq ($(PORTNAME), aix)
79   shlib                 := lib$(NAME)$(DLSUFFIX)
80 #   SHLIB_LINK          += -lc
81 endif
82
83 ifeq ($(PORTNAME), darwin)
84   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
85   LINK.shared           = $(COMPILER) $(DARWIN_NAMESPACE_SPEC) -bundle -undefined suppress
86 endif
87
88 ifeq ($(PORTNAME), openbsd)
89   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
90   ifdef ELF_SYSTEM
91     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
92     SHLIB_LINK          += -lc
93   else
94     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
95   endif
96 endif
97
98 ifeq ($(PORTNAME), bsdi)
99   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
100   ifeq ($(DLSUFFIX), .so)
101     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
102     SHLIB_LINK          += -lc
103   endif
104   ifeq ($(DLSUFFIX), .o)
105     LINK.shared         = shlicc -O $(LDREL)
106   endif
107 endif
108
109 ifeq ($(PORTNAME), freebsd)
110   ifdef ELF_SYSTEM
111     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
112     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
113   else
114     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
115     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
116   endif
117 endif
118
119 ifeq ($(PORTNAME), netbsd)
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   else
124     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
125   endif
126 endif
127
128 ifeq ($(PORTNAME), hpux)
129   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
130   LINK.shared           = $(LD) +h $(soname) -b +b $(libdir)
131 endif
132
133 ifeq ($(PORTNAME), irix5)
134   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
135   LINK.shared           = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
136 endif
137
138 ifeq ($(PORTNAME), linux)
139   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
140   LINK.shared           = $(COMPILER) -shared -Wl,-soname,$(soname)
141 endif
142
143 ifeq ($(PORTNAME), solaris)
144   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
145   ifeq ($(GCC), yes)
146     LINK.shared         = $(CC) -shared
147   else
148     LINK.shared         = $(CC) -G
149   endif
150   ifeq ($(with_gnu_ld), yes)
151     LINK.shared         += -Wl,-soname,$(soname)
152   else
153     LINK.shared         += -h $(soname)
154   endif
155 endif
156
157 ifeq ($(PORTNAME), sunos4)
158   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
159   LINK.shared           = $(LD) -assert pure-text -Bdynamic
160 endif
161  
162 ifeq ($(PORTNAME), osf)
163   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
164   LINK.shared           = $(LD) -shared -expect_unresolved '*'
165 endif
166
167 ifeq ($(PORTNAME), sco)
168   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
169   ifeq ($(GCC), yes)
170     LINK.shared         = $(CC) -shared
171   else
172     LINK.shared         = $(CC) -G
173     endif
174   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
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   ifeq ($(GCC), yes)
190     LINK.shared         = $(CC) -shared
191   else
192     LINK.shared         = $(CC) -G
193   endif
194   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname) 
195 endif
196
197 ifeq ($(PORTNAME), cygwin)
198   shlib                 := $(NAME)$(DLSUFFIX)
199 endif
200
201 ifeq ($(PORTNAME), beos)
202   shlib                 := lib$(NAME)$(DLSUFFIX)
203   LINK.shared           = $(LD) -nostart
204   SHLIB_LINK            += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
205 endif
206
207 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
208 ifeq ($(enable_rpath), yes)
209 SHLIB_LINK += $(rpath)
210 endif
211
212 endif # enable_shared
213
214
215
216 ##
217 ## BUILD
218 ##
219
220 .PHONY: all-lib all-static-lib all-shared-lib
221
222 all-lib: all-static-lib all-shared-lib
223
224 all-static-lib: lib$(NAME).a
225
226 all-shared-lib: $(shlib)
227
228 ifneq ($(PORTNAME), cygwin)
229
230 ifndef LORDER
231 MK_NO_LORDER := true
232 endif
233
234 lib$(NAME).a: $(OBJS)
235 ifdef MK_NO_LORDER
236         $(LINK.static) $@ $^
237 else
238         $(LINK.static) $@ `$(LORDER) $^ | tsort`
239 endif
240         $(RANLIB) $@
241
242 endif # not cygwin
243
244 ifeq ($(enable_shared), yes)
245
246 ifneq ($(PORTNAME), beos)
247 ifneq ($(PORTNAME), cygwin)
248 ifneq ($(PORTNAME), aix)
249
250 # Normal case
251 $(shlib): $(OBJS)
252         $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
253 # If we're using major and minor versions, then make a symlink to major-version-only.
254 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
255         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
256         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
257 endif
258 # Make sure we have a link to a name without any version numbers
259 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
260         rm -f lib$(NAME)$(DLSUFFIX)
261         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
262 endif
263
264 else # PORTNAME == aix
265
266 # AIX case
267 $(shlib): lib$(NAME).a
268         $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
269         $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
270         
271 endif # PORTNAME == aix
272
273 else # PORTNAME == cygwin
274
275 # Cygwin case
276 $(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
277         $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
278         $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(DLLINIT) $(SHLIB_LINK)
279         $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
280
281 $(DLLINIT): $(DLLINIT:%.o=%.c)
282         $(MAKE) -C $(@D) $(@F)
283
284 endif # PORTNAME == cygwin
285
286 else # PORTNAME == beos
287
288 # BEOS case
289 $(shlib): $(OBJS)
290         ln -fs $(top_srcdir)/src/backend/postgres _APP_
291         $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
292
293 endif # PORTNAME == beos
294
295 endif # enable_shared
296
297
298 ##
299 ## INSTALL
300 ##
301
302 .PHONY: install-lib install-lib-static install-lib-shared
303 install-lib: install-lib-static install-lib-shared
304
305 install-lib-static: lib$(NAME).a
306         $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
307 ifeq ($(PORTNAME), darwin)
308         cd $(DESTDIR)$(libdir) && \
309         ranlib lib$(NAME).a
310 endif
311
312 ifeq ($(enable_shared), yes)
313 install-lib-shared: $(shlib)
314         $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
315 ifneq ($(PORTNAME), cygwin)
316 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
317         cd $(DESTDIR)$(libdir) && \
318         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
319         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
320 endif
321 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
322         cd $(DESTDIR)$(libdir) && \
323         rm -f lib$(NAME)$(DLSUFFIX) && \
324         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
325 endif
326
327 endif # not cygwin
328 endif # enable_shared
329
330
331 ##
332 ## UNINSTALL
333 ##
334
335 .PHONY: uninstall-lib
336 uninstall-lib:
337         rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
338 ifeq ($(enable_shared), yes)
339         rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
340           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
341           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
342 endif # enable_shared
343
344
345 ##
346 ## CLEAN
347 ##
348
349 .PHONY: clean-lib
350 clean-lib:
351         rm -f lib$(NAME).a
352 ifeq ($(enable_shared), yes)
353         rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
354 ifdef EXPSUFF
355         rm -f lib$(NAME)$(EXPSUFF)
356 endif
357 endif
358 ifeq ($(PORTNAME), cygwin)
359         rm -f $(NAME).dll $(NAME).def
360 endif