1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

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.
This commit is contained in:
Tom Lane
2010-07-05 18:54:38 +00:00
parent eb81b6509f
commit 291a957745
49 changed files with 183 additions and 135 deletions

View File

@ -37,5 +37,6 @@ MKLDEXPORT=$(top_srcdir)/src/backend/port/aix/mkldexport.sh
%.exp: %.o
$(MKLDEXPORT) $^ >$@
# Rule for building a shared library from a single .o file
%$(DLSUFFIX): %.o %.exp
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -o $@ $*.o -Wl,-bE:$*.exp $(SHLIB_LINK)

View File

@ -20,5 +20,6 @@ else
CFLAGS_SL =
endif
# Rule for building a shared library from a single .o file
%.so: %.o
$(CC) $(CFLAGS) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<

View File

@ -1,4 +1,4 @@
# $PostgreSQL: pgsql/src/makefiles/Makefile.cygwin,v 1.13 2010/01/20 09:30:07 heikki Exp $
# $PostgreSQL: pgsql/src/makefiles/Makefile.cygwin,v 1.14 2010/07/05 18:54:38 tgl Exp $
DLLTOOL= dlltool
DLLWRAP= dllwrap
ifdef PGXS
@ -15,11 +15,6 @@ AROPT = crs
DLSUFFIX = .dll
CFLAGS_SL =
%.dll: %.o
$(DLLTOOL) --export-all --output-def $*.def $<
$(DLLWRAP) -o $@ --def $*.def $< $(SHLIB_LINK)
rm -f $*.def
ifneq (,$(findstring backend,$(subdir)))
ifeq (,$(findstring conversion_procs,$(subdir)))
ifeq (,$(findstring snowball,$(subdir)))
@ -42,3 +37,9 @@ endif
ifneq (,$(findstring src/pl/plpython,$(subdir)))
override CPPFLAGS+= -DUSE_DL_IMPORT
endif
# Rule for building a shared library from a single .o file
%.dll: %.o
$(DLLTOOL) --export-all --output-def $*.def $<
$(DLLWRAP) -o $@ --def $*.def $< $(SHLIB_LINK)
rm -f $*.def

View File

@ -1,16 +1,13 @@
AROPT = crs
AWK= awk
DLSUFFIX = .so
CFLAGS_SL =
ifdef PGXS
BE_DLLLIBS= -bundle_loader $(bindir)/postgres
BE_DLLLIBS = -bundle_loader $(bindir)/postgres
else
BE_DLLLIBS= -bundle_loader $(top_builddir)/src/backend/postgres
BE_DLLLIBS = -bundle_loader $(top_builddir)/src/backend/postgres
endif
# Rule for building shared libs (currently used only for regression test
# shlib ... should go away, since this is not really enough knowledge)
# Rule for building a shared library from a single .o file
%.so: %.o
$(CC) $(CFLAGS) -bundle -o $@ $< $(BE_DLLLIBS)
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -bundle -o $@ $< $(BE_DLLLIBS)

View File

@ -2,7 +2,8 @@ AROPT = crs
DLSUFFIX = .so
CFLAGS_SL = -fpic
# Rule for building a shared library from a single .o file
%.so: %.o
$(CC) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
sqlmansect = 5

View File

@ -14,9 +14,10 @@ allow_nonpic_in_shlib = yes
endif
# Rule for building a shared library from a single .o file
%.so: %.o
ifdef ELF_SYSTEM
$(CC) $(CFLAGS) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
else
$(LD) $(LDREL) $(LDOUT) $<.obj -x $<
@echo building shared object $@

View File

@ -22,7 +22,7 @@ endif
ifeq ($(with_gnu_ld), yes)
# XXX what to put here?
else
LDFLAGS += -Wl,-z
LDFLAGS_EX += -Wl,-z
endif
# set up appropriate options for shared library builds
@ -43,18 +43,17 @@ else
CFLAGS_SL = +Z
endif
# Rule for building shared libs (currently used only for regression test
# shlib ... should go away, since this is not really enough knowledge)
# Rule for building a shared library from a single .o file
%$(DLSUFFIX): %.o
ifeq ($(GCC), yes)
ifeq ($(with_gnu_ld), yes)
$(CC) $(LDFLAGS) -shared -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name`
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name`
else
$(LD) -b -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name`
endif
else
ifeq ($(with_gnu_ld), yes)
$(CC) $(LDFLAGS) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
else
$(LD) -b -o $@ $<
endif

View File

@ -5,14 +5,15 @@ DLSUFFIX = .so
# PIC is default
CFLAGS_SL =
%.so: %.o
$(CC) $(CFLAGS) -shared -o $@ $<
override CPPFLAGS += -U_NO_XOPEN4
ifneq ($(GCC), yes)
CFLAGS += -woff 1164,1171,1185,1195,1552
CFLAGS += -woff 1164,1171,1185,1195,1552
endif
LDFLAGS += -Wl,-woff,15 -Wl,-woff,84
# Rule for building a shared library from a single .o file
%.so: %.o
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
sqlmansect = 5sql

View File

@ -12,5 +12,6 @@ else
CFLAGS_SL = -fpic
endif
# Rule for building a shared library from a single .o file
%.so: %.o
$(CC) $(CFLAGS) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<

View File

@ -16,9 +16,10 @@ CFLAGS_SL = -fpic -DPIC
endif
# Rule for building a shared library from a single .o file
%.so: %.o
ifdef ELF_SYSTEM
$(CC) $(CFLAGS) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
else
$(LD) $(LDREL) $(LDOUT) $<.obj -x $<
@echo building shared object $@

View File

@ -14,9 +14,10 @@ CFLAGS_SL = -fpic -DPIC
endif
# Rule for building a shared library from a single .o file
%.so: %.o
ifdef ELF_SYSTEM
$(CC) $(CFLAGS) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
else
$(LD) $(LDREL) $(LDOUT) $<.obj -x $<
@echo building shared object $@

View File

@ -3,6 +3,7 @@ DLSUFFIX = .so
CFLAGS_SL =
rpath = -rpath '$(rpathdir)'
# Rule for building a shared library from a single .o file
%.so: %.o
$(LD) -shared -expect_unresolved '*' -o $@ $<

View File

@ -8,5 +8,6 @@ else
CFLAGS_SL = -K PIC
endif
# Rule for building a shared library from a single .o file
%.so: %.o
$(LD) -G -Bdynamic -o $@ $<

View File

@ -1,4 +1,4 @@
# $PostgreSQL: pgsql/src/makefiles/Makefile.solaris,v 1.14 2008/09/01 08:50:10 petere Exp $
# $PostgreSQL: pgsql/src/makefiles/Makefile.solaris,v 1.15 2010/07/05 18:54:38 tgl Exp $
AROPT = crs
@ -16,11 +16,12 @@ else
CFLAGS_SL = -KPIC
endif
# Rule for building a shared library from a single .o file
%.so: %.o
ifeq ($(GCC), yes)
$(CC) $(CFLAGS) -shared -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@ $<
else
$(CC) $(CFLAGS) -G -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -G -o $@ $<
endif
sqlmansect = 5sql

View File

@ -7,5 +7,6 @@ else
CFLAGS_SL = -PIC
endif
# Rule for building a shared library from a single .o file
%.so: %.o
$(LD) -assert pure-text -Bdynamic -o $@ $<

View File

@ -8,6 +8,7 @@ LDFLAGS += -LD-Blargedynsym
DLSUFFIX = .so
CFLAGS_SL =
# Rule for building a shared library from a single .o file
%.so: %.o
$(LD) -G -Bdynamic -o $@ $<

View File

@ -6,5 +6,6 @@ DLSUFFIX = .so
# "-G 0" works for both DEC cc and GNU cc.
CFLAGS_SL = -G 0
# Rule for building a shared library from a single .c file
%.so: %.c
$(CC) -c -G 0 $(CPPFLAGS) $(CFLAGS) -o $@ $<
$(CC) -c -G 0 $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) -o $@ $<

View File

@ -3,6 +3,7 @@ export_dynamic = -Wl,-Bexport
DLSUFFIX = .so
CFLAGS_SL = -K PIC
# Rule for building a shared library from a single .o file
%.so: %.o
$(LD) -G -Bdynamic -o $@ $<

View File

@ -13,6 +13,9 @@ else
endif
endif
# Unixware needs threads for everything that uses libpq
CFLAGS += $(PTHREAD_CFLAGS)
DLSUFFIX = .so
ifeq ($(GCC), yes)
CFLAGS_SL = -fpic
@ -25,10 +28,8 @@ else
SO_FLAGS = -G
endif
# Rule for building a shared library from a single .o file
%.so: %.o
$(CC) $(SO_FLAGS) -o $@ $<
$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) $(SO_FLAGS) -o $@ $<
sqlmansect = 5sql
# Unixware needs threads for everything that uses libpq
CFLAGS += $(PTHREAD_CFLAGS)

View File

@ -1,4 +1,4 @@
# $PostgreSQL: pgsql/src/makefiles/Makefile.win32,v 1.15 2010/01/20 09:30:07 heikki Exp $
# $PostgreSQL: pgsql/src/makefiles/Makefile.win32,v 1.16 2010/07/05 18:54:38 tgl Exp $
# Use replacement include files for those missing on Win32
override CPPFLAGS+="-I$(top_srcdir)/src/include/port/win32"
@ -13,11 +13,6 @@ AROPT = crs
DLSUFFIX = .dll
CFLAGS_SL =
%.dll: %.o
$(DLLTOOL) --export-all --output-def $*.def $<
$(DLLWRAP) -o $@ --def $*.def $< $(SHLIB_LINK)
rm -f $*.def
ifneq (,$(findstring backend,$(subdir)))
ifeq (,$(findstring conversion_procs,$(subdir)))
ifeq (,$(findstring snowball,$(subdir)))
@ -70,3 +65,9 @@ win32ver.rc: $(top_srcdir)/src/port/win32ver.rc
win32ver.o: win32ver.rc
$(WINDRES) -i $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(srcdir)
# Rule for building a shared library from a single .o file
%.dll: %.o
$(DLLTOOL) --export-all --output-def $*.def $<
$(DLLWRAP) -o $@ --def $*.def $< $(SHLIB_LINK)
rm -f $*.def

View File

@ -1,6 +1,6 @@
# PGXS: PostgreSQL extensions makefile
# $PostgreSQL: pgsql/src/makefiles/pgxs.mk,v 1.19 2010/01/05 03:56:52 tgl Exp $
# $PostgreSQL: pgsql/src/makefiles/pgxs.mk,v 1.20 2010/07/05 18:54:38 tgl Exp $
# This file contains generic rules to build many kinds of simple
# extension modules. You only need to set a few variables and include
@ -68,7 +68,6 @@ override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
ifdef MODULES
override CFLAGS += $(CFLAGS_SL)
SHLIB_LINK += $(BE_DLLLIBS)
endif
ifdef MODULEDIR
@ -287,5 +286,5 @@ endif
ifdef PROGRAM
$(PROGRAM): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LDFLAGS) $(LIBS) -o $@
$(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LIBS) $(LDFLAGS) $(LDFLAGS_EX) -o $@
endif