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