66# Copyright (c) 1998, Regents of the University of California
77#
88# IDENTIFICATION
9- # $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.26 2000/10/20 21:03:38 petere Exp $
9+ # $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.27 2000/10/23 21:43:56 petere Exp $
1010#
1111#-------------------------------------------------------------------------
1212
5151#
5252# Got that? Look at src/interfaces/libpq/Makefile for an example.
5353
54+ ifndef cplusplus
55+ COMPILER = $(CC)
56+ else
57+ COMPILER = $(CXX)
58+ endif
59+
60+
61+ # First, a few hacks for building *static* libraries.
62+
63+ LINK.static = $(AR) $(AROPT)
64+
65+ ifdef cplusplus
5466
55- # shlib is empty by default. If we know how to build a shared library
56- # it will contain the name of the file, otherwise it will remain
57- # empty. Thus `ifdef shlib' could be used in the containing make file
58- # to test whether shared libraries are available.
59- shlib :=
67+ ifeq ($(PORTNAME), irix5)
68+ ifneq ($(GXX), yes)
69+ LINK.static = $(CXX) -ar -o
70+ endif
71+ endif
6072
61- # For each platform we support shared libraries on, set shlib and
62- # update flags as needed to build a shared lib. Note we depend on
63- # Makefile.global (or really Makefile.port) to supply DLSUFFIX and
64- # other symbols.
73+ ifeq ($(PORTNAME), solaris)
74+ ifneq ($(GXX), yes)
75+ LINK.static = $(CXX) -xar -o
76+ endif
77+ endif
78+
79+ endif # cplusplus
80+
81+
82+
83+ ifeq ($(enable_shared), yes)
84+
85+ # For each platform we support shared libraries on, set shlib to the
86+ # name of the library, LINK.shared to the command to link the library,
87+ # and adjust SHLIB_LINK if necessary.
6588
6689# Try to keep the sections in some kind of order, folks...
6790
91+ # XXX fix Makefile.aix
92+ ifneq ($(PORTNAME), aix)
93+ ifndef cplusplus
94+ override CFLAGS+= $(CFLAGS_SL)
95+ else
96+ override CXXFLAGS+= $(CFLAGS_SL)
97+ endif
98+ endif
99+
100+
68101ifeq ($(PORTNAME), aix)
69102 shlib:= lib$(NAME)$(DLSUFFIX)
70103 SHLIB_LINK+= -lc
71104endif
72105
73106ifeq ($(PORTNAME), openbsd)
74- ifdef BSD_SHLIB
75- shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
76- ifdef ELF_SYSTEM
77- LDFLAGS_SL:= -x -Bshareable -soname $(shlib)
78- else
79- LDFLAGS_SL:= -x -Bshareable -Bforcearchive
80- endif
81- override CFLAGS+= $(CFLAGS_SL)
107+ shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
108+ ifdef ELF_SYSTEM
109+ LINK.shared= $(LD) -x -Bshareable -soname $(shlib)
110+ else
111+ LINK.shared= $(LD) -x -Bshareable -Bforcearchive
82112 endif
83113endif
84114
85115ifeq ($(PORTNAME), bsdi)
86- ifdef BSD_SHLIB
87- ifeq ($(DLSUFFIX), .so)
88- shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
89- LDFLAGS_SL += -shared -soname $(shlib)
90- override CFLAGS+= $(CFLAGS_SL)
91- endif
92- ifeq ($(DLSUFFIX), .o)
93- shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
94- LD:= shlicc
95- LDFLAGS_SL += -O $(LDREL)
96- override CFLAGS+= $(CFLAGS_SL)
97- endif
116+ shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
117+ ifeq ($(DLSUFFIX), .so)
118+ LINK.shared= $(LD) -shared -soname $(shlib)
119+ endif
120+ ifeq ($(DLSUFFIX), .o)
121+ LINK.shared= shlicc -O $(LDREL)
98122 endif
99123endif
100124
101125ifeq ($(PORTNAME), freebsd)
102- ifdef BSD_SHLIB
103- ifdef ELF_SYSTEM
104- shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
105- LDFLAGS_SL:= -x -shared -soname $(shlib)
106- else
107- shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
108- LDFLAGS_SL:= -x -Bshareable -Bforcearchive
109- endif
110- override CFLAGS+= $(CFLAGS_SL)
126+ ifdef ELF_SYSTEM
127+ shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
128+ LINK.shared= $(LD) -x -shared -soname $(shlib)
129+ else
130+ shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
131+ LINK.shared= $(LD) -x -Bshareable -Bforcearchive
111132 endif
112133endif
113134
114135ifeq ($(PORTNAME), netbsd)
115- ifdef BSD_SHLIB
116- soname:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
117- shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
118- ifdef ELF_SYSTEM
119- LD:= $(CC)
120- LDFLAGS_SL:= -shared -Wl,-soname -Wl,$(soname)
121- ifneq ($(SHLIB_LINK),)
122- LDFLAGS_SL+= -Wl,-R$(libdir)
123- endif
124- else
125- LDFLAGS_SL:= -x -Bshareable -Bforcearchive
136+ soname:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
137+ shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
138+ ifdef ELF_SYSTEM
139+ LINK.shared= $(COMPILER) -shared -Wl,-soname -Wl,$(soname)
140+ ifneq ($(SHLIB_LINK),)
141+ LINK.shared+= -Wl,-R$(libdir)
126142 endif
127- override CFLAGS+= $(CFLAGS_SL)
143+ else
144+ LINK.shared= $(LD) -x -Bshareable -Bforcearchive
128145 endif
129146endif
130147
131148ifeq ($(PORTNAME), hpux)
132149# HPUX doesn't believe in version numbers for shlibs
133150 shlib:= lib$(NAME)$(DLSUFFIX)
134- LDFLAGS_SL:= -b
135- override CFLAGS+= $(CFLAGS_SL)
151+ LINK.shared= $(LD) -b
136152endif
137153
138154ifeq ($(PORTNAME), irix5)
139- shlib := lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
140- LDFLAGS_SL := -shared -rpath $(libdir) -set_version sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
141- override CFLAGS += $(CFLAGS_SL)
155+ shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
156+ LINK.shared:= $(COMPILER) -shared -rpath $(libdir) -set_version sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
142157endif
143158
144159ifeq ($(PORTNAME), linux)
145160 shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
146- LD:= $(CC)
147- LDFLAGS_SL:= -shared -Wl,-soname,$(shlib)
148- LDFLAGS_ODBC:= -lm
149- override CFLAGS+= $(CFLAGS_SL)
161+ LINK.shared= $(COMPILER) -shared -Wl,-soname,$(shlib)
150162endif
151163
152164ifeq ($(PORTNAME), solaris)
153165 shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
154- LDFLAGS_SL:= -G
166+ LINK.shared= $(COMPILER) -G
155167 SHLIB_LINK+= -ldl -lsocket -lresolv -lnsl -lm -lc
156- override CFLAGS+= $(CFLAGS_SL)
157168endif
158169
159170ifeq ($(PORTNAME), osf)
160171 shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
161- LDFLAGS_SL+= -shared -expect_unresolved '*'
172+ LINK.shared= $(LD) -shared -expect_unresolved '*'
162173endif
163174
164175ifeq ($(PORTNAME), svr4)
165176 shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
166- LDFLAGS_SL:= -G
167- override CFLAGS+= $(CFLAGS_SL)
177+ LINK.shared= $(LD) -G
168178endif
169179
170180ifeq ($(PORTNAME), univel)
171181 shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
172- LDFLAGS_SL:= -G -z text
173- override CFLAGS+= $(CFLAGS_SL)
174- ifeq ($(CXX), CC)
175- override CXXFLAGS += -Xw
176- COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
177- endif
182+ LINK.shared= $(LD) -G -z text
178183endif
179184
180185ifeq ($(PORTNAME), unixware)
181186 shlib:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
182- LDFLAGS_SL:= -G -z text
183- override CFLAGS+= $(CFLAGS_SL)
184- ifeq ($(CXX), CC)
185- override CXXFLAGS += -Xw
186- COMPILE.cc = $(CXX) $(CXXFLAGS:ll,alloca=ll) $(CPPFLAGS) $(TARGET_ARCH) -c
187- endif
187+ LINK.shared= $(LD) -G -z text
188188endif
189189
190190ifeq ($(PORTNAME), win)
191191 shlib:= $(NAME)$(DLSUFFIX)
192+ ifdef cplusplus
193+ SHLIB_LINK+= --driver-name g++
194+ endif
192195endif
193196
194197ifeq ($(PORTNAME), beos)
195- install- shlib-dep :=install-shlib
196- shlib:= lib$(NAME)$(DLSUFFIX)
197- LDFLAGS_SL: = -nostart - ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
198+ shlib :=lib$(NAME)$(DLSUFFIX)
199+ LINK.shared= $(LD) -nostart
200+ SHLIB_LINK+ = -ltermcap -lstdc++.r4 -lbind -lsocket -L/boot/develop/lib/x86
198201endif
199202
200- # Note that in what follows, shlib is empty when not building a shared
201- # library.
203+ endif # enable_shared
204+
202205
203206
204207##
@@ -208,8 +211,6 @@ endif
208211.PHONY: all-lib
209212all-lib: lib$(NAME).a $(shlib)
210213
211- # Rules to build regular and shared libraries
212-
213214ifneq ($(PORTNAME), win)
214215
215216ifndef LORDER
@@ -218,22 +219,23 @@ endif
218219
219220lib$(NAME).a: $(OBJS)
220221ifdef MK_NO_LORDER
221- $(AR) $(AROPT ) $@ $^
222+ $(LINK.static ) $@ $^
222223else
223- $(AR) $(AROPT ) $@ `$(LORDER) $^ | tsort`
224+ $(LINK.static ) $@ `$(LORDER) $^ | tsort`
224225endif
225226$(RANLIB) $@
226227
227228endif # not win
228229
229- ifdef shlib
230+ ifeq ($(enable_shared), yes)
231+
230232ifneq ($(PORTNAME), beos)
231233ifneq ($(PORTNAME), win)
232234ifneq ($(PORTNAME), aix)
233235
234236# Normal case
235237$(shlib): $(OBJS)
236- $(LD) $(LDFLAGS_SL ) -o $@ $(OBJS) $(SHLIB_LINK)
238+ $(LINK.shared ) -o $@ $(OBJS) $(SHLIB_LINK)
237239# If we're using major and minor versions, then make a symlink to major-version-only.
238240ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
239241rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
@@ -275,7 +277,8 @@ $(shlib): $(OBJS)
275277$(CC) -Xlinker -soname=$@ $(LDFLAGS_SL) -o $@ _APP_ $(OBJS) $(SHLIB_LINK)
276278
277279endif # PORTNAME == beos
278- endif # shlib
280+
281+ endif # enable_shared
279282
280283
281284##
@@ -288,7 +291,7 @@ install-lib: install-lib-static install-lib-shared
288291install-lib-static: lib$(NAME).a
289292$(INSTALL_DATA) $< $(DESTDIR)$(libdir)/lib$(NAME).a
290293
291- ifdef shlib
294+ ifeq ($(enable_shared), yes)
292295install-lib-shared: $(shlib)
293296$(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
294297ifneq ($(PORTNAME), win)
@@ -304,7 +307,7 @@ ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
304307endif
305308
306309endif # not win
307- endif #shlib
310+ endif #enable_shared
308311
309312
310313##
@@ -314,11 +317,11 @@ endif # shlib
314317.PHONY: uninstall-lib
315318uninstall-lib:
316319rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
317- ifdef shlib
320+ ifeq ($(enable_shared), yes)
318321rm -f $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX) \
319322 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) \
320323 $(DESTDIR)$(libdir)/lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
321- endif #shlib
324+ endif #enable_shared
322325
323326
324327##
@@ -328,7 +331,9 @@ endif # shlib
328331.PHONY: clean-lib
329332clean-lib:
330333rm -f lib$(NAME).a
334+ ifeq ($(enable_shared), yes)
331335rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
336+ endif
332337ifeq ($(PORTNAME), win)
333338rm -rf $(NAME).def
334339endif