]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
Rename irix5 port to irix.
[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.76 2004/05/19 21:37:43 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 #
35 # The module Makefile must also include
36 # $(top_builddir)/src/Makefile.global before including this file.
37 # (Makefile.global sets PORTNAME and other needed symbols.)
38 #
39 # This makefile provides the following (phony) targets:
40 #
41 # all-lib               build the static and shared (if applicable) libraries
42 # install-lib           install the libraries into $(libdir)
43 # uninstall-lib         remove the libraries from $(libdir)
44 # clean-lib             delete the static and shared libraries from the build dir
45 #
46 # Since `all-lib' is the first rule in this file you probably want to
47 # have the `all' target before including this file. In the most simple
48 # case it would look like this:
49 #
50 #     all: all-lib
51 #
52 # Similarly, the install rule might look like
53 #
54 #     install: install-lib
55 #
56 # plus any additional things you want to install. Et cetera.
57 #
58 # Got that?  Look at src/interfaces/libpq/Makefile for an example.
59 #
60 # While the linker allows creation of most shared libraries,
61 # -Bsymbolic requires resolution of all symbols, making the
62 # compiler a better choice for shared library creation on ELF platforms.
63 # With the linker, -Bsymbolic requires the crt1.o startup object file.
64 # bjm 2001-02-10
65
66
67 COMPILER = $(CC) $(CFLAGS)
68 LINK.static = $(AR) $(AROPT)
69
70
71
72 ifeq ($(enable_shared), yes)
73
74 # For each platform we support shared libraries on, set shlib to the
75 # name of the library, LINK.shared to the command to link the library,
76 # and adjust SHLIB_LINK if necessary.
77
78 # Try to keep the sections in some kind of order, folks...
79
80 override CFLAGS += $(CFLAGS_SL)
81
82 soname = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
83
84 ifeq ($(PORTNAME), aix)
85   shlib                 := lib$(NAME)$(DLSUFFIX)
86 #   SHLIB_LINK          += -lc
87 endif
88
89 ifeq ($(PORTNAME), darwin)
90   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
91   LINK.shared           = $(COMPILER) -bundle
92 endif
93
94 ifeq ($(PORTNAME), openbsd)
95   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
96   ifdef ELF_SYSTEM
97     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
98     SHLIB_LINK          += -lc
99   else
100     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
101   endif
102 endif
103
104 ifeq ($(PORTNAME), bsdi)
105   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
106   ifeq ($(DLSUFFIX), .so)
107     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
108     SHLIB_LINK          += -lc
109   endif
110   ifeq ($(DLSUFFIX), .o)
111     LINK.shared         = shlicc -O $(LDREL)
112   endif
113 endif
114
115 ifeq ($(PORTNAME), freebsd)
116   ifdef ELF_SYSTEM
117     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
118     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
119   else
120     shlib               := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
121     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
122   endif
123 endif
124
125 ifeq ($(PORTNAME), netbsd)
126   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
127   ifdef ELF_SYSTEM
128     LINK.shared         = $(COMPILER) -shared -Wl,-x,-soname,$(soname)
129   else
130     LINK.shared         = $(LD) -x -Bshareable -Bforcearchive
131   endif
132 endif
133
134 ifeq ($(PORTNAME), hpux)
135   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
136   LINK.shared           = $(LD) +h $(soname) -b +b $(libdir)
137   ifeq ($(GCC), yes)
138     SHLIB_LINK          += `$(CC) -print-libgcc-file-name`
139   endif
140 endif
141
142 ifeq ($(PORTNAME), irix)
143   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
144   LINK.shared           = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
145 endif
146
147 ifeq ($(PORTNAME), linux)
148   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
149   LINK.shared           = $(COMPILER) -shared -Wl,-soname,$(soname)
150 endif
151
152 ifeq ($(PORTNAME), solaris)
153   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
154   ifeq ($(GCC), yes)
155     LINK.shared         = $(CC) -shared
156   else
157     LINK.shared         = $(CC) -G
158   endif
159   ifeq ($(with_gnu_ld), yes)
160     LINK.shared         += -Wl,-soname,$(soname)
161   else
162     LINK.shared         += -h $(soname)
163   endif
164 endif
165
166 ifeq ($(PORTNAME), sunos4)
167   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
168   LINK.shared           = $(LD) -assert pure-text -Bdynamic
169 endif
170  
171 ifeq ($(PORTNAME), osf)
172   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
173   LINK.shared           = $(LD) -shared -expect_unresolved '*'
174 endif
175
176 ifeq ($(PORTNAME), sco)
177   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
178   ifeq ($(GCC), yes)
179     LINK.shared         = $(CC) -shared
180   else
181     LINK.shared         = $(CC) -G
182     endif
183   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
184 endif
185
186 ifeq ($(PORTNAME), svr4)
187   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
188   LINK.shared           = $(LD) -G
189 endif
190
191 ifeq ($(PORTNAME), univel)
192   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
193   LINK.shared           = $(LD) -G -z text
194 endif
195
196 ifeq ($(PORTNAME), unixware)
197   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
198   ifeq ($(GCC), yes)
199     LINK.shared         = $(CC) -shared
200   else
201     LINK.shared         = $(CC) -G
202   endif
203   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname) 
204 endif
205
206 ifeq ($(PORTNAME), cygwin)
207   shlib                 := $(NAME)$(DLSUFFIX)
208 endif
209
210 ifeq ($(PORTNAME), win32)
211   shlib                 := lib$(NAME)$(DLSUFFIX)
212 endif
213
214 ifeq ($(PORTNAME), beos)
215   shlib                 := lib$(NAME)$(DLSUFFIX)
216   LINK.shared           = $(LD) -nostart
217   SHLIB_LINK            += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
218 endif
219
220 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
221 ifeq ($(enable_rpath), yes)
222 SHLIB_LINK += $(rpath)
223 endif
224
225 endif # enable_shared
226
227
228
229 ##
230 ## BUILD
231 ##
232
233 .PHONY: all-lib all-static-lib all-shared-lib
234
235 all-lib: all-static-lib all-shared-lib
236
237 all-static-lib: lib$(NAME).a
238
239 all-shared-lib: $(shlib)
240
241 ifneq ($(PORTNAME), cygwin)
242 ifneq ($(PORTNAME), win32)
243
244 ifndef LORDER
245 MK_NO_LORDER := true
246 endif
247
248 lib$(NAME).a: $(OBJS)
249 ifdef MK_NO_LORDER
250         $(LINK.static) $@ $^
251 else
252         $(LINK.static) $@ `$(LORDER) $^ | tsort`
253 endif
254         $(RANLIB) $@
255
256 endif # not win32
257 endif # not cygwin
258
259 ifeq ($(enable_shared), yes)
260
261 ifneq ($(PORTNAME), beos)
262 ifneq ($(PORTNAME), cygwin)
263 ifneq ($(PORTNAME), win32)
264 ifneq ($(PORTNAME), aix)
265
266 # Normal case
267 $(shlib): $(OBJS)
268         $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
269 # If we're using major and minor versions, then make a symlink to major-version-only.
270 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
271         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
272         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
273 endif
274 # Make sure we have a link to a name without any version numbers
275 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
276         rm -f lib$(NAME)$(DLSUFFIX)
277         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
278 endif
279
280 else # PORTNAME == aix
281
282 # AIX case
283 $(shlib): lib$(NAME).a
284         $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
285         $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
286         
287 endif # PORTNAME == aix
288
289 else # PORTNAME == win32
290
291 # win32 case
292 $(shlib) lib$(NAME).a: $(OBJS)
293         $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
294         $(DLLWRAP) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
295         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
296
297 endif # PORTNAME == win32
298
299 else # PORTNAME == cygwin
300
301 # Cygwin case
302 $(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
303         $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
304         $(DLLWRAP) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(DLLINIT) $(SHLIB_LINK)
305         $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
306
307 $(DLLINIT): $(DLLINIT:%.o=%.c)
308         $(MAKE) -C $(@D) $(@F)
309
310 endif # PORTNAME == cygwin
311
312 else # PORTNAME == beos
313
314 # BEOS case
315 $(shlib): $(OBJS)
316         ln -fs $(top_srcdir)/src/backend/postgres _APP_
317         $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
318
319 endif # PORTNAME == beos
320
321 endif # enable_shared
322
323
324 ##
325 ## INSTALL
326 ##
327
328 .PHONY: install-lib install-lib-static install-lib-shared
329 install-lib: install-lib-static install-lib-shared
330
331 install-lib-static: lib$(NAME).a
332         $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
333 ifeq ($(PORTNAME), darwin)
334         cd $(DESTDIR)$(libdir) && \
335         ranlib lib$(NAME).a
336 endif
337
338 ifeq ($(enable_shared), yes)
339 install-lib-shared: $(shlib)
340         $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
341 ifneq ($(PORTNAME), cygwin)
342 ifneq ($(PORTNAME), win32)
343 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
344         cd $(DESTDIR)$(libdir) && \
345         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
346         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
347 endif
348 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
349         cd $(DESTDIR)$(libdir) && \
350         rm -f lib$(NAME)$(DLSUFFIX) && \
351         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
352 endif
353
354 endif # not win32
355 endif # not cygwin
356 endif # enable_shared
357
358
359 ##
360 ## UNINSTALL
361 ##
362
363 .PHONY: uninstall-lib
364 uninstall-lib:
365         rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
366 ifeq ($(enable_shared), yes)
367         rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
368           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
369           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
370 endif # enable_shared
371
372
373 ##
374 ## CLEAN
375 ##
376
377 .PHONY: clean-lib
378 clean-lib:
379         rm -f lib$(NAME).a
380 ifeq ($(enable_shared), yes)
381         rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
382 ifdef EXPSUFF
383         rm -f lib$(NAME)$(EXPSUFF)
384 endif
385 endif
386 ifeq ($(PORTNAME), cygwin)
387         rm -f $(NAME).dll $(NAME).def
388 endif
389
390 ifeq ($(PORTNAME), win32)
391         rm -f $(NAME).dll $(NAME).def
392 endif