]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
Clean up AIX build to avoid 'duplicate symbol' warnings, by moving use
[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 #    $PostgreSQL: pgsql/src/Makefile.shlib,v 1.98 2005/10/28 17:32:22 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 # Optional flags when building DLL's (only applicable to win32 and cygwin
30 # platforms).
31 # DLLTOOL_DEFFLAGS      Additional flags when creating the dll .def file
32 # DLLTOOL_LIBFLAGS      Additional flags when creating the lib<module>.a file
33 # DLLWRAP_FLAGS         Additional flags to dllwrap
34 # DLL_DEFFILE           Use pre-existing .def file instead of auto-generating
35 #                       one with all exports in it (win32 only).
36 #
37 # The module Makefile must also include
38 # $(top_builddir)/src/Makefile.global before including this file.
39 # (Makefile.global sets PORTNAME and other needed symbols.)
40 #
41 # This makefile provides the following (phony) targets:
42 #
43 # all-lib               build the static and shared (if applicable) libraries
44 # install-lib           install the libraries into $(libdir)
45 # uninstall-lib         remove the libraries from $(libdir)
46 # clean-lib             delete the static and shared libraries from the build dir
47 #
48 # Since `all-lib' is the first rule in this file you probably want to
49 # have the `all' target before including this file. In the most simple
50 # case it would look like this:
51 #
52 #     all: all-lib
53 #
54 # Similarly, the install rule might look like
55 #
56 #     install: install-lib
57 #
58 # plus any additional things you want to install. Et cetera.
59 #
60 # Got that?  Look at src/interfaces/libpq/Makefile for an example.
61 #
62 # While the linker allows creation of most shared libraries,
63 # -Bsymbolic requires resolution of all symbols, making the
64 # compiler a better choice for shared library creation on ELF platforms.
65 # With the linker, -Bsymbolic requires the crt1.o startup object file.
66 # bjm 2001-02-10
67
68
69 COMPILER = $(CC) $(CFLAGS)
70 LINK.static = $(AR) $(AROPT)
71
72
73
74 ifeq ($(enable_shared), yes)
75
76 # Insert -L from LDFLAGS after any -L already present in SHLIB_LINK
77 SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) $(filter -L%, $(LDFLAGS)) $(filter-out -L%, $(SHLIB_LINK))
78
79 # Default shlib naming convention used by the majority of platforms
80 shlib           = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
81 shlib_major     = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
82 shlib_bare      = lib$(NAME)$(DLSUFFIX)
83
84 # For each platform we support shared libraries on, set shlib to the
85 # name of the library (if default above is not right), set
86 # 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 override CFLAGS += $(CFLAGS_SL)
92
93 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
94
95 ifeq ($(PORTNAME), aix)
96   shlib                 = lib$(NAME)$(DLSUFFIX)
97 #   SHLIB_LINK          += -lc
98 endif
99
100 ifeq ($(PORTNAME), darwin)
101   ifneq ($(SO_MAJOR_VERSION), 0)
102     version_link        := -compatibility_version $(SO_MAJOR_VERSION) -current_version $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
103   endif
104   ifeq ($(DLTYPE), library)
105     # linkable library
106     DLSUFFIX            := .dylib
107     LINK.shared         = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) -multiply_defined suppress
108   else
109     # loadable module (default case)
110     DLSUFFIX            := .so
111     LINK.shared         = $(COMPILER) -bundle
112   endif
113   shlib                 = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
114   shlib_major           = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
115 endif
116
117 ifeq ($(PORTNAME), openbsd)
118   ifdef ELF_SYSTEM
119     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
120     SHLIB_LINK          += -lc
121   else
122     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
123   endif
124 endif
125
126 ifeq ($(PORTNAME), bsdi)
127   ifeq ($(DLSUFFIX), .so)
128     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
129     SHLIB_LINK          += -lc
130   endif
131   ifeq ($(DLSUFFIX), .o)
132     LINK.shared         = shlicc -O $(LDREL)
133   endif
134 endif
135
136 ifeq ($(PORTNAME), freebsd)
137   ifdef ELF_SYSTEM
138     shlib               = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
139     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
140   else
141     shlib               = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
142     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
143   endif
144 endif
145
146 ifeq ($(PORTNAME), netbsd)
147   ifdef ELF_SYSTEM
148     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
149   else
150     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
151   endif
152 endif
153
154 ifeq ($(PORTNAME), hpux)
155   shlib                 = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
156   ifeq ($(with_gnu_ld), yes)
157     LINK.shared         = $(CC) $(LDFLAGS) -shared -Wl,-h -Wl,$(soname)
158   else
159     # can't use the CC-syntax rpath pattern here
160     rpath =
161     ifeq ($(enable_rpath), yes)
162       LINK.shared       = $(LD) +h $(soname) -b +b $(rpathdir)
163     else
164       LINK.shared       = $(LD) +h $(soname) -b
165     endif
166     # On HPUX platforms, gcc is usually configured to search for libraries
167     # in /usr/local/lib, but ld won't do so.  Add an explicit -L switch so
168     # ld can find the same libraries gcc does.  Make sure it goes after any
169     # -L switches provided explicitly.
170     ifeq ($(GCC), yes)
171       SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) -L/usr/local/lib $(filter-out -L%, $(SHLIB_LINK))
172     endif
173   endif
174   # do this last so above filtering doesn't pull out -L switches in LDFLAGS
175   ifeq ($(GCC), yes)
176     SHLIB_LINK          += `$(CC) $(LDFLAGS) -print-libgcc-file-name`
177   endif
178 endif
179
180 ifeq ($(PORTNAME), irix)
181   shlib                 = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
182   LINK.shared           = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
183 endif
184
185 ifeq ($(PORTNAME), linux)
186   LINK.shared           = $(COMPILER) -shared -Wl,-soname,$(soname)
187 endif
188
189 ifeq ($(PORTNAME), solaris)
190   ifeq ($(GCC), yes)
191     LINK.shared         = $(CC) -shared
192   else
193     LINK.shared         = $(CC) -G
194   endif
195   ifeq ($(with_gnu_ld), yes)
196     LINK.shared         += -Wl,-soname,$(soname)
197   else
198     LINK.shared         += -h $(soname)
199   endif
200 endif
201
202 ifeq ($(PORTNAME), sunos4)
203   LINK.shared           = $(LD) -assert pure-text -Bdynamic
204 endif
205  
206 ifeq ($(PORTNAME), osf)
207   LINK.shared           = $(LD) -shared -expect_unresolved '*'
208 endif
209
210 ifeq ($(PORTNAME), sco)
211   ifeq ($(GCC), yes)
212     LINK.shared         = $(CC) -shared
213   else
214     LINK.shared         = $(CC) -G
215     endif
216   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
217 endif
218
219 ifeq ($(PORTNAME), svr4)
220   LINK.shared           = $(LD) -G
221 endif
222
223 ifeq ($(PORTNAME), univel)
224   LINK.shared           = $(LD) -G -z text
225 endif
226
227 ifeq ($(PORTNAME), unixware)
228   ifeq ($(GCC), yes)
229     LINK.shared         = $(CC) -shared
230   else
231     LINK.shared         = $(CC) -G
232   endif
233   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname) 
234 endif
235
236 ifeq ($(PORTNAME), cygwin)
237   shlib                 = cyg$(NAME)$(DLSUFFIX)
238   haslibarule   = yes
239 endif
240
241 ifeq ($(PORTNAME), win32)
242   shlib                 = lib$(NAME)$(DLSUFFIX)
243   haslibarule   = yes
244 endif
245
246 ifeq ($(PORTNAME), beos)
247   shlib                 = lib$(NAME)$(DLSUFFIX)
248   LINK.shared           = $(LD) -nostart
249   SHLIB_LINK            += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
250 endif
251
252 ifeq ($(enable_rpath), yes)
253 SHLIB_LINK += $(rpath)
254 endif
255
256 endif # enable_shared
257
258
259
260 ##
261 ## BUILD
262 ##
263
264 .PHONY: all-lib all-static-lib all-shared-lib
265
266 all-lib: all-static-lib all-shared-lib
267
268 all-static-lib: lib$(NAME).a
269
270 all-shared-lib: $(shlib)
271
272 ifndef LORDER
273 MK_NO_LORDER := true
274 endif
275
276 ifndef haslibarule
277 lib$(NAME).a: $(OBJS)
278 ifdef MK_NO_LORDER
279         $(LINK.static) $@ $^
280 else
281         $(LINK.static) $@ `$(LORDER) $^ | tsort`
282 endif
283         $(RANLIB) $@
284 endif #haslibarule
285
286 ifeq ($(enable_shared), yes)
287
288 ifneq ($(PORTNAME), win32)
289 ifneq ($(PORTNAME), cygwin)
290 ifneq ($(PORTNAME), beos)
291 ifneq ($(PORTNAME), aix)
292
293 # Normal case
294 $(shlib): $(OBJS)
295         $(LINK.shared) $(LDFLAGS_SL) $(OBJS) $(SHLIB_LINK) -o $@
296 # If we're using major and minor versions, then make a symlink to major-version-only.
297 ifneq ($(shlib), $(shlib_major))
298         rm -f $(shlib_major)
299         $(LN_S) $(shlib) $(shlib_major)
300 endif
301 # Make sure we have a link to a name without any version numbers
302 ifneq ($(shlib), $(shlib_bare))
303         rm -f $(shlib_bare)
304         $(LN_S) $(shlib) $(shlib_bare)
305 endif
306
307 else # PORTNAME == aix
308
309 # AIX case
310 $(shlib): lib$(NAME).a
311         $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
312         $(COMPILER) $(LDFLAGS) $(LDFLAGS_SL) -o $@ $< -Wl,-bE:lib$(NAME)$(EXPSUFF) $(SHLIB_LINK)
313         
314 endif # PORTNAME == aix
315
316 else # PORTNAME == beos
317
318 # BEOS case
319 $(shlib): $(OBJS)
320         ln -fs $(top_srcdir)/src/backend/postgres _APP_
321         $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
322
323 endif # PORTNAME == beos
324
325 else # PORTNAME == cygwin
326
327 # Cygwin case
328 $(shlib) lib$(NAME).a: $(OBJS)
329 ifndef DLL_DEFFILE
330         $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
331         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
332         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
333 else
334         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
335         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
336 endif
337
338 endif # PORTNAME == cygwin
339
340 else # PORTNAME == win32
341
342 # win32 case
343 $(shlib) lib$(NAME).a: $(OBJS)
344 ifndef DLL_DEFFILE
345         $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
346         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
347         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
348 else
349         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
350         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
351 endif
352
353 endif # PORTNAME == win32
354
355 endif # enable_shared
356
357
358 ##
359 ## INSTALL
360 ##
361
362 .PHONY: install-lib install-lib-static install-lib-shared
363 install-lib: install-lib-static install-lib-shared
364
365 install-lib-static: lib$(NAME).a
366         $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
367 ifeq ($(PORTNAME), darwin)
368         cd $(DESTDIR)$(libdir) && \
369         ranlib lib$(NAME).a
370 endif
371
372 ifeq ($(enable_shared), yes)
373 install-lib-shared: $(shlib)
374         $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
375 ifneq ($(PORTNAME), cygwin)
376 ifneq ($(PORTNAME), win32)
377 ifneq ($(shlib), $(shlib_major))
378         cd $(DESTDIR)$(libdir) && \
379         rm -f $(shlib_major) && \
380         $(LN_S) $(shlib) $(shlib_major)
381 endif
382 ifneq ($(shlib), $(shlib_bare))
383         cd $(DESTDIR)$(libdir) && \
384         rm -f $(shlib_bare) && \
385         $(LN_S) $(shlib) $(shlib_bare)
386 endif
387 endif # not win32
388 endif # not cygwin
389 endif # enable_shared
390
391
392 ##
393 ## UNINSTALL
394 ##
395
396 .PHONY: uninstall-lib
397 uninstall-lib:
398         rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
399 ifeq ($(enable_shared), yes)
400         rm -f $(DESTDIR)$(libdir)/$(shlib_bare) \
401           $(DESTDIR)$(libdir)/$(shlib_major) \
402           $(DESTDIR)$(libdir)/$(shlib)
403 endif # enable_shared
404
405
406 ##
407 ## CLEAN
408 ##
409
410 .PHONY: clean-lib
411 clean-lib:
412         rm -f lib$(NAME).a
413 ifeq ($(enable_shared), yes)
414         rm -f $(shlib_bare) $(shlib_major) $(shlib)
415 ifdef EXPSUFF
416         rm -f lib$(NAME)$(EXPSUFF)
417 endif
418 endif
419 ifeq ($(PORTNAME), cygwin)
420         rm -f $(NAME).dll $(NAME).def
421 endif
422
423 ifeq ($(PORTNAME), win32)
424         rm -f $(NAME).dll $(NAME).def
425 endif