Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 291a957

Browse files
committed
Split the LDFLAGS make variable into two parts: LDFLAGS is now used for
linking both executables and shared libraries, and we add on LDFLAGS_EX when linking executables or LDFLAGS_SL when linking shared libraries. This provides a significantly cleaner way of dealing with link-time switches than the former behavior. Also, make sure that the various platform-specific %.so: %.o rules incorporate LDFLAGS and LDFLAGS_SL; most of them missed that before. (I did not add these variables for the platforms that invoke $(LD) directly, however. It's not clear if we can do that safely, since for the most part we assume these variables use CC command-line syntax.) Per gripe from Aaron Swenson and subsequent investigation.
1 parent eb81b65 commit 291a957

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+183
-135
lines changed

configure

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ ld_R_works
704704
with_gnu_ld
705705
LD
706706
LDFLAGS_SL
707+
LDFLAGS_EX
707708
ELF_SYS
708709
EGREP
709710
GREP
@@ -856,6 +857,7 @@ LDFLAGS
856857
LIBS
857858
CPPFLAGS
858859
CPP
860+
LDFLAGS_EX
859861
LDFLAGS_SL
860862
DOCBOOKSTYLE'
861863

@@ -1551,7 +1553,8 @@ Some influential environment variables:
15511553
CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
15521554
you have headers in a nonstandard directory <include dir>
15531555
CPP C preprocessor
1554-
LDFLAGS_SL linker flags for shared library linking
1556+
LDFLAGS_EX extra linker flags for linking executables only
1557+
LDFLAGS_SL extra linker flags for linking shared libraries only
15551558
DOCBOOKSTYLE
15561559
location of DocBook stylesheets
15571560

@@ -5788,6 +5791,7 @@ LDFLAGS="$LDFLAGS $LIBDIRS"
57885791

57895792

57905793

5794+
57915795
# Check whether --with-gnu-ld was given.
57925796
if test "${with_gnu_ld+set}" = set; then
57935797
withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
@@ -28826,7 +28830,6 @@ fi
2882628830
# If compiler will take -Wl,--as-needed (or various platform-specific
2882728831
# spellings thereof) then add that to LDFLAGS. This is much easier than
2882828832
# trying to filter LIBS to the minimum for each executable.
28829-
# (Note that shared library links won't use this switch, though.)
2883028833
# On (at least) some Red-Hat-derived systems, this switch breaks linking to
2883128834
# libreadline; therefore we postpone testing it until we know what library
2883228835
# dependencies readline has. The test code will try to link with $LIBS.

configure.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.630 2010/06/04 07:28:30 scrappy Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.631 2010/07/05 18:54:37 tgl Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -785,7 +785,8 @@ AC_SUBST(ELF_SYS)
785785
CPPFLAGS="$CPPFLAGS $INCLUDES"
786786
LDFLAGS="$LDFLAGS $LIBDIRS"
787787

788-
AC_ARG_VAR(LDFLAGS_SL, [linker flags for shared library linking])
788+
AC_ARG_VAR(LDFLAGS_EX, [extra linker flags for linking executables only])
789+
AC_ARG_VAR(LDFLAGS_SL, [extra linker flags for linking shared libraries only])
789790

790791
PGAC_PROG_LD
791792
AC_SUBST(LD)
@@ -1770,7 +1771,6 @@ fi
17701771
# If compiler will take -Wl,--as-needed (or various platform-specific
17711772
# spellings thereof) then add that to LDFLAGS. This is much easier than
17721773
# trying to filter LIBS to the minimum for each executable.
1773-
# (Note that shared library links won't use this switch, though.)
17741774
# On (at least) some Red-Hat-derived systems, this switch breaks linking to
17751775
# libreadline; therefore we postpone testing it until we know what library
17761776
# dependencies readline has. The test code will try to link with $LIBS.

doc/src/sgml/installation.sgml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.347 2010/06/29 22:29:13 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/installation.sgml,v 1.348 2010/07/05 18:54:37 tgl Exp $ -->
22

33
<chapter id="installation">
44
<title><![%standalone-include[<productname>PostgreSQL</>]]>
@@ -1468,7 +1468,16 @@ su - postgres
14681468
<term><envar>LDFLAGS</envar></term>
14691469
<listitem>
14701470
<para>
1471-
options to pass to the link editor
1471+
options to use when linking either executables or shared libraries
1472+
</para>
1473+
</listitem>
1474+
</varlistentry>
1475+
1476+
<varlistentry>
1477+
<term><envar>LDFLAGS_EX</envar></term>
1478+
<listitem>
1479+
<para>
1480+
additional options for linking executables only
14721481
</para>
14731482
</listitem>
14741483
</varlistentry>
@@ -1477,7 +1486,7 @@ su - postgres
14771486
<term><envar>LDFLAGS_SL</envar></term>
14781487
<listitem>
14791488
<para>
1480-
linker options for shared library linking
1489+
additional options for linking shared libraries only
14811490
</para>
14821491
</listitem>
14831492
</varlistentry>

doc/src/sgml/ref/pg_config-ref.sgml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_config-ref.sgml,v 1.29 2010/04/03 07:23:01 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_config-ref.sgml,v 1.30 2010/07/05 18:54:37 tgl Exp $ -->
22

33
<refentry id="app-pgconfig">
44
<refmeta>
@@ -232,13 +232,24 @@
232232
</listitem>
233233
</varlistentry>
234234

235+
<varlistentry>
236+
<term><option>--ldflags_ex</option></>
237+
<listitem>
238+
<para>
239+
Print the value of the <varname>LDFLAGS_EX</varname> variable that was used for building
240+
<productname>PostgreSQL</>. This shows linker switches
241+
used for building executables only.
242+
</para>
243+
</listitem>
244+
</varlistentry>
245+
235246
<varlistentry>
236247
<term><option>--ldflags_sl</option></>
237248
<listitem>
238249
<para>
239250
Print the value of the <varname>LDFLAGS_SL</varname> variable that was used for building
240251
<productname>PostgreSQL</>. This shows linker switches
241-
used for building shared libraries.
252+
used for building shared libraries only.
242253
</para>
243254
</listitem>
244255
</varlistentry>
@@ -275,7 +286,7 @@
275286
<title>Notes</title>
276287

277288
<para>
278-
The option <option>--includedir-server</option> was new in
289+
The option <option>--includedir-server</option> was added in
279290
<productname>PostgreSQL</> 7.2. In prior releases, the server include files were
280291
installed in the same location as the client headers, which could
281292
be queried with the option <option>--includedir</option>. To make your
@@ -290,8 +301,9 @@
290301
<option>--cc</option>, <option>--cppflags</option>,
291302
<option>--cflags</option>, <option>--cflags_sl</option>,
292303
<option>--ldflags</option>, <option>--ldflags_sl</option>,
293-
and <option>--libs</option> are new in <productname>PostgreSQL</> 8.1.
294-
The option <option>--htmldir</option> is new in <productname>PostgreSQL</> 8.4.
304+
and <option>--libs</option> were added in <productname>PostgreSQL</> 8.1.
305+
The option <option>--htmldir</option> was added in <productname>PostgreSQL</> 8.4.
306+
The option <option>--ldflags_ex</option> was added in <productname>PostgreSQL</> 9.0.
295307
</para>
296308

297309
<para>

src/Makefile.global.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.262 2010/05/13 11:49:47 petere Exp $
2+
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.263 2010/07/05 18:54:37 tgl Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -236,6 +236,7 @@ LD = @LD@
236236
with_gnu_ld = @with_gnu_ld@
237237
ld_R_works = @ld_R_works@
238238
LDFLAGS = @LDFLAGS@
239+
LDFLAGS_EX = @LDFLAGS_EX@
239240
LDFLAGS_SL = @LDFLAGS_SL@
240241
LDREL = -r
241242
LDOUT = -o
@@ -455,9 +456,9 @@ LIBOBJS = @LIBOBJS@
455456
LIBS := -lpgport $(LIBS)
456457
# add location of libpgport.a to LDFLAGS
457458
ifdef PGXS
458-
override LDFLAGS := -L$(libdir) $(LDFLAGS)
459+
LDFLAGS += -L$(libdir)
459460
else
460-
override LDFLAGS := -L$(top_builddir)/src/port $(LDFLAGS)
461+
LDFLAGS += -L$(top_builddir)/src/port
461462
endif
462463

463464
# to make ws2_32.lib the last library, and always link with shfolder,

src/Makefile.shlib

Lines changed: 12 additions & 19 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-
# $PostgreSQL: pgsql/src/Makefile.shlib,v 1.123 2009/08/28 20:26:18 petere Exp $
9+
# $PostgreSQL: pgsql/src/Makefile.shlib,v 1.124 2010/07/05 18:54:37 tgl Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

@@ -78,11 +78,8 @@ LINK.static = $(AR) $(AROPT)
7878

7979

8080

81-
# Insert -L from LDFLAGS after any -L already present in SHLIB_LINK
82-
SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) $(filter -L%, $(LDFLAGS)) $(filter-out -L%, $(SHLIB_LINK))
83-
84-
# Need a -L-free version of LDFLAGS to use in combination with SHLIB_LINK
85-
LDFLAGS_NO_L = $(filter-out -L%, $(LDFLAGS))
81+
# Automatically append LDFLAGS and LDFLAGS_SL to SHLIB_LINK
82+
SHLIB_LINK += $(LDFLAGS) $(LDFLAGS_SL)
8683

8784
ifdef SO_MAJOR_VERSION
8885
# Default library naming convention used by the majority of platforms
@@ -104,7 +101,7 @@ stlib = lib$(NAME).a
104101

105102
ifndef soname
106103
# additional flags for backend modules
107-
SHLIB_LINK := $(BE_DLLLIBS) $(SHLIB_LINK)
104+
SHLIB_LINK += $(BE_DLLLIBS)
108105
endif
109106

110107
# For each platform we support shared libraries on, set shlib to the
@@ -208,17 +205,17 @@ ifeq ($(PORTNAME), hpux)
208205
shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
209206
endif
210207
ifeq ($(with_gnu_ld), yes)
211-
LINK.shared = $(CC) $(LDFLAGS_NO_L) -shared
208+
LINK.shared = $(CC) -shared
212209
ifdef soname
213210
LINK.shared += -Wl,-h -Wl,$(soname)
214211
endif
215212
else
216-
# can't use the CC-syntax rpath pattern here
217-
rpath =
218213
LINK.shared = $(LD) -b
219214
ifdef soname
220215
LINK.shared += +h $(soname)
221216
endif
217+
# can't use the CC-syntax rpath pattern here, so instead:
218+
rpath =
222219
ifeq ($(enable_rpath), yes)
223220
LINK.shared += +b '$(rpathdir)'
224221
endif
@@ -227,10 +224,10 @@ ifeq ($(PORTNAME), hpux)
227224
# ld can find the same libraries gcc does. Make sure it goes after any
228225
# -L switches provided explicitly.
229226
ifeq ($(GCC), yes)
230-
SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) -L/usr/local/lib $(filter-out -L%, $(SHLIB_LINK))
227+
SHLIB_LINK += -L/usr/local/lib
231228
endif
232229
endif
233-
# do this last so above filtering doesn't pull out -L switches in LDFLAGS
230+
# And we need to link with libgcc, too
234231
ifeq ($(GCC), yes)
235232
SHLIB_LINK += `$(CC) $(LDFLAGS) -print-libgcc-file-name`
236233
endif
@@ -327,10 +324,6 @@ ifeq ($(PORTNAME), win32)
327324
haslibarule = yes
328325
endif
329326

330-
ifeq ($(enable_rpath), yes)
331-
SHLIB_LINK += $(rpath)
332-
endif
333-
334327

335328

336329
##
@@ -362,7 +355,7 @@ ifneq ($(PORTNAME), aix)
362355

363356
# Normal case
364357
$(shlib): $(OBJS)
365-
$(LINK.shared) $(LDFLAGS_SL) $(OBJS) $(SHLIB_LINK) -o $@
358+
$(LINK.shared) -o $@ $(OBJS) $(SHLIB_LINK)
366359
ifdef shlib_major
367360
# If we're using major and minor versions, then make a symlink to major-version-only.
368361
ifneq ($(shlib), $(shlib_major))
@@ -396,7 +389,7 @@ $(shlib) $(stlib): $(OBJS)
396389
$(LINK.static) $(stlib) $^
397390
$(RANLIB) $(stlib)
398391
$(MKLDEXPORT) $(stlib) >$(exports_file)
399-
$(COMPILER) $(LDFLAGS_NO_L) $(LDFLAGS_SL) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(SHLIB_LINK)
392+
$(COMPILER) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(SHLIB_LINK)
400393
rm -f $(stlib)
401394
$(AR) $(AROPT) $(stlib) $(shlib)
402395

@@ -419,7 +412,7 @@ DLL_DEFFILE = lib$(NAME)dll.def
419412
endif
420413

421414
$(shlib): $(OBJS) $(DLL_DEFFILE)
422-
$(DLLWRAP) $(LDFLAGS_SL) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
415+
$(DLLWRAP) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
423416

424417
$(stlib): $(shlib) $(DLL_DEFFILE)
425418
$(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib $@

src/backend/Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/backend/Makefile,v 1.144 2010/05/12 23:48:36 momjian Exp $
8+
# $PostgreSQL: pgsql/src/backend/Makefile,v 1.145 2010/07/05 18:54:37 tgl Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -52,7 +52,7 @@ ifneq ($(PORTNAME), win32)
5252
ifneq ($(PORTNAME), aix)
5353

5454
postgres: $(OBJS)
55-
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
55+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
5656

5757
endif
5858
endif
@@ -62,9 +62,9 @@ ifeq ($(PORTNAME), cygwin)
6262

6363
postgres: $(OBJS) postgres.def libpostgres.a
6464
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
65-
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
65+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
6666
$(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
67-
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
67+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
6868
rm -f $@.exp $@.base
6969

7070
postgres.def: $(OBJS)
@@ -80,9 +80,9 @@ LIBS += -lsecur32
8080

8181
postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
8282
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
83-
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
83+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
8484
$(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
85-
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
85+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
8686
rm -f $@.exp $@.base
8787

8888
postgres.def: $(OBJS)
@@ -96,7 +96,7 @@ endif # win32
9696
ifeq ($(PORTNAME), aix)
9797

9898
postgres: $(POSTGRES_IMP)
99-
$(CC) $(CFLAGS) $(LDFLAGS) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
99+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
100100

101101
$(POSTGRES_IMP): $(OBJS)
102102
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
@@ -128,7 +128,7 @@ catalog/schemapg.h: submake-schemapg
128128
# The postgres.o target is needed by the rule in Makefile.global that
129129
# creates the exports file when MAKE_EXPORTS = true.
130130
postgres.o: $(OBJS)
131-
$(CC) $(LDREL) $(LDFLAGS) $(call expand_subsys,$^) $(LIBS) -o $@
131+
$(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@
132132

133133

134134
# The following targets are specified in make commands that appear in
@@ -306,4 +306,4 @@ maintainer-clean: distclean
306306
# are up to date. It saves the time of doing all the submakes.
307307
.PHONY: quick
308308
quick: $(OBJS)
309-
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres
309+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres

src/backend/port/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# be converted to Method 2.
1414
#
1515
# IDENTIFICATION
16-
# $PostgreSQL: pgsql/src/backend/port/Makefile,v 1.27 2008/10/29 16:06:46 petere Exp $
16+
# $PostgreSQL: pgsql/src/backend/port/Makefile,v 1.28 2010/07/05 18:54:37 tgl Exp $
1717
#
1818
#-------------------------------------------------------------------------
1919

@@ -44,7 +44,7 @@ endif
4444

4545
# IPC test program
4646
ipc_test: ipc_test.o pg_sema.o pg_shmem.o
47-
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@
47+
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $^ $(LIBS) -o $@
4848

4949
distclean clean:
5050
rm -f ipc_test ipc_test.o tas_cpp.s

src/bin/initdb/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.60 2010/05/12 11:33:09 momjian Exp $
8+
# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.61 2010/07/05 18:54:37 tgl Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -23,7 +23,7 @@ OBJS= initdb.o encnames.o pqsignal.o $(WIN32RES)
2323
all: submake-libpgport initdb
2424

2525
initdb: $(OBJS)
26-
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LIBS) -o $@$(X)
26+
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
2727

2828
# We used to pull in all of libpq to get encnames and pqsignal, but that
2929
# exposes us to risks of version skew if we link to a shared library.

0 commit comments

Comments
 (0)