]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
Some code review for xml.c:
[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.109 2007/02/20 22:45:57 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 # 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 # Need a -L-free version of LDFLAGS to use in combination with SHLIB_LINK
80 LDFLAGS_NO_L = $(filter-out -L%, $(LDFLAGS))
81
82 # Default shlib naming convention used by the majority of platforms
83 shlib           = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
84 shlib_major     = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
85 shlib_bare      = lib$(NAME)$(DLSUFFIX)
86
87 # For each platform we support shared libraries on, set shlib to the
88 # name of the library (if default above is not right), set
89 # LINK.shared to the command to link the library,
90 # and adjust SHLIB_LINK if necessary.
91
92 # Try to keep the sections in some kind of order, folks...
93
94 override CFLAGS += $(CFLAGS_SL)
95
96 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
97
98 ifeq ($(PORTNAME), aix)
99   shlib                 = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
100   haslibarule   = yes
101 endif
102
103 ifeq ($(PORTNAME), darwin)
104   ifneq ($(SO_MAJOR_VERSION), 0)
105     version_link        = -compatibility_version $(SO_MAJOR_VERSION) -current_version $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
106   endif
107   ifeq ($(DLTYPE), library)
108     # linkable library
109     DLSUFFIX            = .dylib
110     LINK.shared         = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) $(exported_symbols_list) -multiply_defined suppress
111   else
112     # loadable module (default case)
113     DLSUFFIX            = .so
114     LINK.shared         = $(COMPILER) -bundle -multiply_defined suppress
115   endif
116   shlib                 = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
117   shlib_major           = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
118 endif
119
120 ifeq ($(PORTNAME), openbsd)
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   ifeq ($(DLSUFFIX), .so)
131     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
132     SHLIB_LINK          += -lc
133   endif
134   ifeq ($(DLSUFFIX), .o)
135     LINK.shared         = shlicc -O $(LDREL)
136   endif
137 endif
138
139 ifeq ($(PORTNAME), freebsd)
140   ifdef ELF_SYSTEM
141     shlib               = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
142     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
143   else
144     shlib               = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
145     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
146   endif
147 endif
148
149 ifeq ($(PORTNAME), netbsd)
150   ifdef ELF_SYSTEM
151     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
152   else
153     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
154   endif
155 endif
156
157 ifeq ($(PORTNAME), hpux)
158   shlib                 = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
159   ifeq ($(with_gnu_ld), yes)
160     LINK.shared         = $(CC) $(LDFLAGS_NO_L) -shared -Wl,-h -Wl,$(soname)
161   else
162     # can't use the CC-syntax rpath pattern here
163     rpath =
164     ifeq ($(enable_rpath), yes)
165       LINK.shared       = $(LD) +h $(soname) -b +b '$(rpathdir)'
166     else
167       LINK.shared       = $(LD) +h $(soname) -b
168     endif
169     # On HPUX platforms, gcc is usually configured to search for libraries
170     # in /usr/local/lib, but ld won't do so.  Add an explicit -L switch so
171     # ld can find the same libraries gcc does.  Make sure it goes after any
172     # -L switches provided explicitly.
173     ifeq ($(GCC), yes)
174       SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) -L/usr/local/lib $(filter-out -L%, $(SHLIB_LINK))
175     endif
176   endif
177   # do this last so above filtering doesn't pull out -L switches in LDFLAGS
178   ifeq ($(GCC), yes)
179     SHLIB_LINK          += `$(CC) $(LDFLAGS) -print-libgcc-file-name`
180   endif
181 endif
182
183 ifeq ($(PORTNAME), irix)
184   shlib                 = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
185   LINK.shared           = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
186 endif
187
188 ifeq ($(PORTNAME), linux)
189   LINK.shared           = $(COMPILER) -shared -Wl,-soname,$(soname) $(exported_symbols_list)
190 endif
191
192 ifeq ($(PORTNAME), solaris)
193   ifeq ($(GCC), yes)
194     LINK.shared         = $(COMPILER) -shared # $(COMPILER) needed for -m64
195   else
196 # CFLAGS added for X86_64
197     LINK.shared         = $(CC) -G $(CFLAGS)
198   endif
199   ifeq ($(with_gnu_ld), yes)
200     LINK.shared         += -Wl,-soname,$(soname)
201   else
202     LINK.shared         += -h $(soname)
203   endif
204 endif
205
206 ifeq ($(PORTNAME), sunos4)
207   LINK.shared           = $(LD) -assert pure-text -Bdynamic
208 endif
209  
210 ifeq ($(PORTNAME), osf)
211   LINK.shared           = $(LD) -shared -expect_unresolved '*'
212 endif
213
214 ifeq ($(PORTNAME), sco)
215   ifeq ($(GCC), yes)
216     LINK.shared         = $(CC) -shared
217   else
218     LINK.shared         = $(CC) -G
219     endif
220   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
221 endif
222
223 ifeq ($(PORTNAME), svr4)
224   LINK.shared           = $(LD) -G
225 endif
226
227 ifeq ($(PORTNAME), univel)
228   LINK.shared           = $(LD) -G -z text
229 endif
230
231 ifeq ($(PORTNAME), unixware)
232   ifeq ($(GCC), yes)
233     LINK.shared         = $(CC) -shared
234   else
235     LINK.shared         = $(CC) -G
236   endif
237   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname) 
238 endif
239
240 ifeq ($(PORTNAME), cygwin)
241   shlib                 = cyg$(NAME)$(DLSUFFIX)
242   haslibarule   = yes
243 endif
244
245 ifeq ($(PORTNAME), win32)
246   shlib                 = lib$(NAME)$(DLSUFFIX)
247   haslibarule   = yes
248 endif
249
250 ifeq ($(enable_rpath), yes)
251 SHLIB_LINK += $(rpath)
252 endif
253
254 endif # enable_shared
255
256
257
258 ##
259 ## BUILD
260 ##
261
262 .PHONY: all-lib all-static-lib all-shared-lib
263
264 all-lib: all-static-lib all-shared-lib
265
266 all-static-lib: lib$(NAME).a
267
268 all-shared-lib: $(shlib)
269
270 ifndef haslibarule
271 lib$(NAME).a: $(OBJS)
272         $(LINK.static) $@ $^
273         $(RANLIB) $@
274 endif #haslibarule
275
276 ifeq ($(enable_shared), yes)
277
278 ifneq ($(PORTNAME), win32)
279 ifneq ($(PORTNAME), cygwin)
280 ifneq ($(PORTNAME), aix)
281
282 # Normal case
283 $(shlib): $(OBJS)
284         $(LINK.shared) $(LDFLAGS_SL) $(OBJS) $(SHLIB_LINK) -o $@
285 # If we're using major and minor versions, then make a symlink to major-version-only.
286 ifneq ($(shlib), $(shlib_major))
287         rm -f $(shlib_major)
288         $(LN_S) $(shlib) $(shlib_major)
289 endif
290 # Make sure we have a link to a name without any version numbers
291 ifneq ($(shlib), $(shlib_bare))
292         rm -f $(shlib_bare)
293         $(LN_S) $(shlib) $(shlib_bare)
294 endif
295
296 else # PORTNAME == aix
297
298 # AIX case
299 $(shlib) lib$(NAME).a: $(OBJS)
300         $(LINK.static) lib$(NAME).a $^
301         $(RANLIB) lib$(NAME).a
302         $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
303         $(COMPILER) $(LDFLAGS_NO_L) $(LDFLAGS_SL) -o $(shlib) lib$(NAME).a -Wl,-bE:lib$(NAME)$(EXPSUFF) $(SHLIB_LINK)
304         rm -f lib$(NAME).a
305         $(AR) $(AROPT) lib$(NAME).a $(shlib)
306         
307 endif # PORTNAME == aix
308
309 else # PORTNAME == cygwin
310
311 # Cygwin case
312 $(shlib) lib$(NAME).a: $(OBJS)
313 ifndef DLL_DEFFILE
314         $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
315         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
316         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
317 else
318         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
319         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
320 endif
321
322 endif # PORTNAME == cygwin
323
324 else # PORTNAME == win32
325
326 # win32 case
327 $(shlib) lib$(NAME).a: $(OBJS)
328 ifndef DLL_DEFFILE
329         $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
330         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
331         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
332 else
333         $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
334         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
335 endif
336
337 endif # PORTNAME == win32
338
339 endif # enable_shared
340
341
342 ##
343 ## INSTALL
344 ##
345
346 .PHONY: install-lib install-lib-static install-lib-shared
347 install-lib: install-lib-static install-lib-shared
348
349 install-lib-static: lib$(NAME).a
350         $(INSTALL_STLIB) $< '$(DESTDIR)$(libdir)/lib$(NAME).a'
351 ifeq ($(PORTNAME), darwin)
352         cd '$(DESTDIR)$(libdir)' && \
353         ranlib lib$(NAME).a
354 endif
355
356 ifeq ($(enable_shared), yes)
357 install-lib-shared: $(shlib)
358 # we don't install $(shlib) on AIX
359 ifneq ($(PORTNAME), aix)
360         $(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
361 ifneq ($(PORTNAME), cygwin)
362 ifneq ($(PORTNAME), win32)
363 ifneq ($(shlib), $(shlib_major))
364         cd '$(DESTDIR)$(libdir)' && \
365         rm -f $(shlib_major) && \
366         $(LN_S) $(shlib) $(shlib_major)
367 endif
368 ifneq ($(shlib), $(shlib_bare))
369         cd '$(DESTDIR)$(libdir)' && \
370         rm -f $(shlib_bare) && \
371         $(LN_S) $(shlib) $(shlib_bare)
372 endif
373 endif # not win32
374 endif # not cygwin
375 endif # not aix
376 endif # enable_shared
377
378
379 ##
380 ## UNINSTALL
381 ##
382
383 .PHONY: uninstall-lib
384 uninstall-lib:
385         rm -f '$(DESTDIR)$(libdir)/lib$(NAME).a'
386 ifeq ($(enable_shared), yes)
387         rm -f '$(DESTDIR)$(libdir)/$(shlib_bare)' \
388           '$(DESTDIR)$(libdir)/$(shlib_major)' \
389           '$(DESTDIR)$(libdir)/$(shlib)'
390 endif # enable_shared
391
392
393 ##
394 ## CLEAN
395 ##
396
397 .PHONY: clean-lib
398 clean-lib:
399         rm -f lib$(NAME).a
400 ifeq ($(enable_shared), yes)
401         rm -f $(shlib_bare) $(shlib_major) $(shlib)
402 ifdef EXPSUFF
403         rm -f lib$(NAME)$(EXPSUFF)
404 endif
405 endif
406 ifeq ($(PORTNAME), cygwin)
407         rm -f $(NAME).dll $(NAME).def
408 endif
409
410 ifeq ($(PORTNAME), win32)
411         rm -f $(NAME).dll $(NAME).def
412 endif