Skip to content

Commit 7b021ce

Browse files
committed
Polish shared library build to reduce number of special hacks. In
particular, allow linking with arbitrary commands rather than only $(AR) or $(LD), and treat C++ without hacks. Add option to disable shared libraries. This takes the place of the BSD_SHLIB variable. The regression test driver ignores the plpgsql test if there are no shared libraries available.
1 parent bc083d3 commit 7b021ce

File tree

10 files changed

+513
-499
lines changed

10 files changed

+513
-499
lines changed

configure

Lines changed: 389 additions & 362 deletions
Large diffs are not rendered by default.

configure.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ AC_DEFINE_UNQUOTED([DEF_MAXBACKENDS], [$with_maxbackends],
227227
[The default soft limit on the number of concurrent connections, i.e., the default for the postmaster -N switch (--with-maxbackends)])
228228

229229

230+
#
231+
# Option to disable shared libraries
232+
#
233+
PGAC_ARG_BOOL(enable, shared, yes,
234+
[ --disable-shared do not build shared libraries])
235+
AC_SUBST(enable_shared)
236+
237+
230238
#
231239
# C compiler
232240
#

src/Makefile.global.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.103 2000/10/21 22:36:11 petere Exp $
2+
# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.104 2000/10/23 21:43:56 petere Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -114,6 +114,7 @@ with_tcl = @with_tcl@
114114
with_tk = @with_tk@
115115
enable_odbc = @enable_odbc@
116116
MULTIBYTE = @MULTIBYTE@
117+
enable_shared = @enable_shared@
117118

118119
python_extmakefile = @python_extmakefile@
119120
python_moduledir = @python_moduledir@
@@ -206,11 +207,6 @@ host_cpu = @host_cpu@
206207
HAVE_POSIX_SIGNALS= @HAVE_POSIX_SIGNALS@
207208
HPUXMATHLIB= @HPUXMATHLIB@
208209

209-
# Ignore BSD_SHLIB if you're not using one of the BSD ports. But if you
210-
# are, and it's one that doesn't have shared libraries (NetBSD/vax is an
211-
# example of this), set BSD_SHLIB to null in Makefile.custom.
212-
BSD_SHLIB= true
213-
214210
# This is mainly for use on FreeBSD, where we have both a.out and elf
215211
# systems now. May be applicable to other systems to?
216212
ELF_SYSTEM= @ELF_SYS@

src/Makefile.shlib

Lines changed: 98 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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

@@ -51,154 +51,157 @@
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+
68101
ifeq ($(PORTNAME), aix)
69102
shlib := lib$(NAME)$(DLSUFFIX)
70103
SHLIB_LINK += -lc
71104
endif
72105

73106
ifeq ($(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
83113
endif
84114

85115
ifeq ($(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
99123
endif
100124

101125
ifeq ($(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
112133
endif
113134

114135
ifeq ($(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
129146
endif
130147

131148
ifeq ($(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
136152
endif
137153

138154
ifeq ($(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)
142157
endif
143158

144159
ifeq ($(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)
150162
endif
151163

152164
ifeq ($(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)
157168
endif
158169

159170
ifeq ($(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 '*'
162173
endif
163174

164175
ifeq ($(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
168178
endif
169179

170180
ifeq ($(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
178183
endif
179184

180185
ifeq ($(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
188188
endif
189189

190190
ifeq ($(PORTNAME), win)
191191
shlib := $(NAME)$(DLSUFFIX)
192+
ifdef cplusplus
193+
SHLIB_LINK += --driver-name g++
194+
endif
192195
endif
193196

194197
ifeq ($(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
198201
endif
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
209212
all-lib: lib$(NAME).a $(shlib)
210213

211-
# Rules to build regular and shared libraries
212-
213214
ifneq ($(PORTNAME), win)
214215

215216
ifndef LORDER
@@ -218,22 +219,23 @@ endif
218219

219220
lib$(NAME).a: $(OBJS)
220221
ifdef MK_NO_LORDER
221-
$(AR) $(AROPT) $@ $^
222+
$(LINK.static) $@ $^
222223
else
223-
$(AR) $(AROPT) $@ `$(LORDER) $^ | tsort`
224+
$(LINK.static) $@ `$(LORDER) $^ | tsort`
224225
endif
225226
$(RANLIB) $@
226227

227228
endif # not win
228229

229-
ifdef shlib
230+
ifeq ($(enable_shared), yes)
231+
230232
ifneq ($(PORTNAME), beos)
231233
ifneq ($(PORTNAME), win)
232234
ifneq ($(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.
238240
ifneq ($(shlib), lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION))
239241
rm -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

277279
endif # 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
288291
install-lib-static: lib$(NAME).a
289292
$(INSTALL_DATA) $< $(DESTDIR)$(libdir)/lib$(NAME).a
290293

291-
ifdef shlib
294+
ifeq ($(enable_shared), yes)
292295
install-lib-shared: $(shlib)
293296
$(INSTALL_SHLIB) $< $(DESTDIR)$(libdir)/$(shlib)
294297
ifneq ($(PORTNAME), win)
@@ -304,7 +307,7 @@ ifneq ($(shlib), lib$(NAME)$(DLSUFFIX))
304307
endif
305308

306309
endif # not win
307-
endif # shlib
310+
endif # enable_shared
308311

309312

310313
##
@@ -314,11 +317,11 @@ endif # shlib
314317
.PHONY: uninstall-lib
315318
uninstall-lib:
316319
rm -f $(DESTDIR)$(libdir)/lib$(NAME).a
317-
ifdef shlib
320+
ifeq ($(enable_shared), yes)
318321
rm -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
329332
clean-lib:
330333
rm -f lib$(NAME).a
334+
ifeq ($(enable_shared), yes)
331335
rm -f $(shlib) lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION) lib$(NAME)$(DLSUFFIX)
336+
endif
332337
ifeq ($(PORTNAME), win)
333338
rm -rf $(NAME).def
334339
endif

0 commit comments

Comments
 (0)