Skip to content

Commit

Permalink
Makefile: Treat LDFLAGS as passed to the compiler, not linker directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemoc committed Jan 6, 2018
1 parent 9c45845 commit 8a11fb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ endif
CC_PARAMS = $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)
CXX_PARAMS = $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH)

### Helpers
comma := ,

### Final flags
ifneq ($(origin CFLAGS),environment)
CFLAGS = $(OPTIONAL_FLAGS)
Expand All @@ -173,13 +170,6 @@ override CFLAGS += $(MUSTHAVE_FLAGS) $(MUSTHAVE_CFLAGS) \
$(if $(INCS_DIR),-I$(INCS_DIR),) -I$(SRCS_DIR)
override CXXFLAGS += $(MUSTHAVE_FLAGS) $(MUSTHAVE_CXXFLAGS) \
$(if $(INCS_DIR),-I$(INCS_DIR),) -I$(SRCS_DIR)
override LDFLAGS := $(subst -Wl$(comma),,$(LDFLAGS))
ifneq ($(origin CCLDFLAGS),environment)
CCLDFLAGS := $(addprefix -Wl$(comma),$(LDFLAGS))
endif
ifneq ($(origin CXXLDFLAGS),environment)
CXXLDFLAGS := $(addprefix -Wl$(comma),$(LDFLAGS))
endif

vpath %.h $(SRCS_DIR) $(INCS_DIR)
vpath %.c $(SRCS_DIR)
Expand Down Expand Up @@ -212,7 +202,7 @@ ifeq ($$($(1)_COMP),CC)
else
@echo " CXXLD $$@"
endif
$$(HIDE)$$($$($(1)_COMP)LD) $$($$($(1)_COMP)LDFLAGS) $$(TARGET_ARCH) \
$$(HIDE)$$($$($(1)_COMP)LD) $$(LDFLAGS) $$(TARGET_ARCH) \
-o $$@ $$(filter %.o,$$^) \
-Wl,-Bstatic $$($(1)_SLIBS) -Wl,-Bdynamic $$($(1)_DLIBS)

Expand Down Expand Up @@ -256,7 +246,7 @@ ifeq ($$($(1)_COMP),CC)
else
@echo " CXXLD $$@"
endif
$$(HIDE)$$($$($(1)_COMP)LD) $$($$($(1)_COMP)LDFLAGS) $$(TARGET_ARCH) \
$$(HIDE)$$($$($(1)_COMP)LD) $$(LDFLAGS) $$(TARGET_ARCH) \
-shared -Wl,-soname,$$($(1)_SONAME) \
-o $$@ $$(filter %.o,$$^) \
-Wl,-Bstatic $$($(1)_SLIBS) -Wl,-Bdynamic $$($(1)_DLIBS)
Expand Down
13 changes: 13 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Latest stuff
* Support building on systems with undefined PATH_MAX, e.g. GNU Hurd.
Simple, but not ideal solution yet - PATH_MAX is assumed to be 4096.

* Stop assuming that LDFLAGS has flags only for the linker (LD).
It used to be true long time ago, when these flags were passed
directly to ld. Nowadays (for quite many years already) it happens
differently and ld is almost never called directly during build,
because it's the compiler that is used for performing linking stage
(so called CCLD, practically almost always the same as CC).

The build process was already using CCLD (defaulting to CC's value),
but was prefixing all unprefixed flags in LDFLAGS with -Wl, prefix,
making it impossible to pass non-linker flags via LDFLAGS to CCLD.
No more! Now it's assumed that LDFLAGS are meant to be passed to
the compiler, so linker flags require explicit -Wl, prefix.


v1.1.1a (2018-01-02)
------------------------------------------------------------------------
Expand Down

0 comments on commit 8a11fb9

Please sign in to comment.