]> granicus.if.org Git - postgresql/blob - src/Makefile.shlib
Win32 patch for Makefile.shlib
[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.74 2003/12/01 22:23:06 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 # 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) -bundle
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   ifeq ($(GCC), yes)
132     SHLIB_LINK          += `$(CC) -print-libgcc-file-name`
133   endif
134 endif
135
136 ifeq ($(PORTNAME), irix5)
137   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
138   LINK.shared           = $(COMPILER) -shared -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
139 endif
140
141 ifeq ($(PORTNAME), linux)
142   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
143   LINK.shared           = $(COMPILER) -shared -Wl,-soname,$(soname)
144 endif
145
146 ifeq ($(PORTNAME), solaris)
147   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
148   ifeq ($(GCC), yes)
149     LINK.shared         = $(CC) -shared
150   else
151     LINK.shared         = $(CC) -G
152   endif
153   ifeq ($(with_gnu_ld), yes)
154     LINK.shared         += -Wl,-soname,$(soname)
155   else
156     LINK.shared         += -h $(soname)
157   endif
158 endif
159
160 ifeq ($(PORTNAME), sunos4)
161   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
162   LINK.shared           = $(LD) -assert pure-text -Bdynamic
163 endif
164  
165 ifeq ($(PORTNAME), osf)
166   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
167   LINK.shared           = $(LD) -shared -expect_unresolved '*'
168 endif
169
170 ifeq ($(PORTNAME), sco)
171   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
172   ifeq ($(GCC), yes)
173     LINK.shared         = $(CC) -shared
174   else
175     LINK.shared         = $(CC) -G
176     endif
177   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname)
178 endif
179
180 ifeq ($(PORTNAME), svr4)
181   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
182   LINK.shared           = $(LD) -G
183 endif
184
185 ifeq ($(PORTNAME), univel)
186   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
187   LINK.shared           = $(LD) -G -z text
188 endif
189
190 ifeq ($(PORTNAME), unixware)
191   shlib                 := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
192   ifeq ($(GCC), yes)
193     LINK.shared         = $(CC) -shared
194   else
195     LINK.shared         = $(CC) -G
196   endif
197   LINK.shared           += -Wl,-z,text -Wl,-h,$(soname) 
198 endif
199
200 ifeq ($(PORTNAME), cygwin)
201   shlib                 := $(NAME)$(DLSUFFIX)
202 endif
203
204 ifeq ($(PORTNAME), win32)
205   shlib                 := lib$(NAME)$(DLSUFFIX)
206 endif
207
208 ifeq ($(PORTNAME), beos)
209   shlib                 := lib$(NAME)$(DLSUFFIX)
210   LINK.shared           = $(LD) -nostart
211   SHLIB_LINK            += -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
212 endif
213
214 SHLIB_LINK := $(filter -L%, $(LDFLAGS)) $(SHLIB_LINK)
215 ifeq ($(enable_rpath), yes)
216 SHLIB_LINK += $(rpath)
217 endif
218
219 endif # enable_shared
220
221
222
223 ##
224 ## BUILD
225 ##
226
227 .PHONY: all-lib all-static-lib all-shared-lib
228
229 all-lib: all-static-lib all-shared-lib
230
231 all-static-lib: lib$(NAME).a
232
233 all-shared-lib: $(shlib)
234
235 ifneq ($(PORTNAME), cygwin)
236 ifneq ($(PORTNAME), win32)
237
238 ifndef LORDER
239 MK_NO_LORDER := true
240 endif
241
242 lib$(NAME).a: $(OBJS)
243 ifdef MK_NO_LORDER
244         $(LINK.static) $@ $^
245 else
246         $(LINK.static) $@ `$(LORDER) $^ | tsort`
247 endif
248         $(RANLIB) $@
249
250 endif # not win32
251 endif # not cygwin
252
253 ifeq ($(enable_shared), yes)
254
255 ifneq ($(PORTNAME), beos)
256 ifneq ($(PORTNAME), cygwin)
257 ifneq ($(PORTNAME), win32)
258 ifneq ($(PORTNAME), aix)
259
260 # Normal case
261 $(shlib): $(OBJS)
262         $(LINK.shared) $(OBJS) $(SHLIB_LINK) -o $@
263 # If we're using major and minor versions, then make a symlink to major-version-only.
264 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
265         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
266         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
267 endif
268 # Make sure we have a link to a name without any version numbers
269 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
270         rm -f lib$(NAME)$(DLSUFFIX)
271         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
272 endif
273
274 else # PORTNAME == aix
275
276 # AIX case
277 $(shlib): lib$(NAME).a
278         $(MKLDEXPORT) lib$(NAME).a > lib$(NAME)$(EXPSUFF)
279         $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK) -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:lib$(NAME)$(EXPSUFF)
280         
281 endif # PORTNAME == aix
282
283 else # PORTNAME == win32
284
285 # win32 case
286 $(shlib) lib$(NAME).a: $(OBJS)
287         $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
288         $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
289         $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
290
291 endif # PORTNAME == win32
292
293 else # PORTNAME == cygwin
294
295 # Cygwin case
296 $(shlib) lib$(NAME).a: $(OBJS) $(DLLINIT)
297         $(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
298         $(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(DLLINIT) $(SHLIB_LINK)
299         $(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
300
301 $(DLLINIT): $(DLLINIT:%.o=%.c)
302         $(MAKE) -C $(@D) $(@F)
303
304 endif # PORTNAME == cygwin
305
306 else # PORTNAME == beos
307
308 # BEOS case
309 $(shlib): $(OBJS)
310         ln -fs $(top_srcdir)/src/backend/postgres _APP_
311         $(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
312
313 endif # PORTNAME == beos
314
315 endif # enable_shared
316
317
318 ##
319 ## INSTALL
320 ##
321
322 .PHONY: install-lib install-lib-static install-lib-shared
323 install-lib: install-lib-static install-lib-shared
324
325 install-lib-static: lib$(NAME).a
326         $(INSTALL_STLIB) $< $(DESTDIR)$(libdir)/lib$(NAME).a
327 ifeq ($(PORTNAME), darwin)
328         cd $(DESTDIR)$(libdir) && \
329         ranlib lib$(NAME).a
330 endif
331
332 ifeq ($(enable_shared), yes)
333 install-lib-shared: $(shlib)
334         $(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
335 ifneq ($(PORTNAME), cygwin)
336 ifneq ($(PORTNAME), win32)
337 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
338         cd $(DESTDIR)$(libdir) && \
339         rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) && \
340         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
341 endif
342 ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
343         cd $(DESTDIR)$(libdir) && \
344         rm -f lib$(NAME)$(DLSUFFIX) && \
345         $(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX)
346 endif
347
348 endif # not win32
349 endif # not cygwin
350 endif # enable_shared
351
352
353 ##
354 ## UNINSTALL
355 ##
356
357 .PHONY: uninstall-lib
358 uninstall-lib:
359         rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
360 ifeq ($(enable_shared), yes)
361         rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
362           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
363           $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
364 endif # enable_shared
365
366
367 ##
368 ## CLEAN
369 ##
370
371 .PHONY: clean-lib
372 clean-lib:
373         rm -f lib$(NAME).a
374 ifeq ($(enable_shared), yes)
375         rm -f lib$(NAME)$(DLSUFFIX) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
376 ifdef EXPSUFF
377         rm -f lib$(NAME)$(EXPSUFF)
378 endif
379 endif
380 ifeq ($(PORTNAME), cygwin)
381         rm -f $(NAME).dll $(NAME).def
382 endif
383
384 ifeq ($(PORTNAME), win32)
385         rm -f $(NAME).dll $(NAME).def
386 endif