Skip to contentSkip to conversation

HOST_{CFLAGS,LDFLAGS} definition

RFC Petr Vorel 2 participants 2 messages Jan 27, 2022

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

Hi,

not sure what I do wrong, but due evaluation in include/mk/config.mk.in:

ifeq ($(strip $(HOST_CFLAGS)),)
HOST_CFLAGS := $(CFLAGS)
endif

ifeq ($(strip $(HOST_LDFLAGS)),)
HOST_LDFLAGS := $(LDFLAGS)
endif

HOST_CFLAGS and HOST_LDFLAGS must be defined for make (not for configure). Of course exporting variables works.

Also whole point of previous code was to have a default, but that's wrong. On some embedded platforms it fails as without properly defined HOST_CFLAGS it can inherit flags which aren't usable for host (e.g. -mlongcalls -mauto-litpools) and whole compilation fails.

IMHO we should change it to (i.e. not inherit anything):

HOST_CFLAGS := $(HOST_CFLAGS)
HOST_LDFLAGS := $(HOST_LDFLAGS)

HOST_CFLAGS += $(WLDFLAGS)
HOST_LDFLAGS += $(DEBUG_CFLAGS) $(OPT_CFLAGS) $(WCFLAGS)

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Petr,
sorry for the resend, forgot the mailing list

Am 1/27/2022 um 11:57 AM schrieb Petr Vorel:

Quoted 12 lines

Hi,

not sure what I do wrong, but due evaluation in include/mk/config.mk.in:

ifeq ($(strip $(HOST_CFLAGS)),)
HOST_CFLAGS := $(CFLAGS)
endif

ifeq ($(strip $(HOST_LDFLAGS)),)
HOST_LDFLAGS := $(LDFLAGS)
endif

Quoted 7 lines

HOST_CFLAGS and HOST_LDFLAGS must be defined for make (not for configure). Of course exporting variables works.

Also whole point of previous code was to have a default, but that's wrong. On some embedded platforms it fails as without properly defined HOST_CFLAGS it can inherit flags which aren't usable for host (e.g. -mlongcalls -mauto-litpools) and whole compilation fails.

Having the default is required for native builds.
The only problem I see with this is that empty HOST_CFLAGS passed through the environment is not possible using the current implementation. It is however possible passing en empte HOST_CFLAGS as make parameter:

Makefile:
CFLAGS := cflags

ifeq ($(strip $(HOST_CFLAGS)),)
HOST_CFLAGS := $(CFLAGS)
endif

all:

	@echo "Value of HOST_CFLAGS: '${HOST_CFLAGS}'"
$ make
Value of HOST_CFLAGS: 'cflags'
$ make HOST_CFLAGS=host
Value of HOST_CFLAGS: 'host'
$ make HOST_CFLAGS=
Value of HOST_CFLAGS: ''
Quoted 8 lines

IMHO we should change it to (i.e. not inherit anything):

HOST_CFLAGS := $(HOST_CFLAGS)
HOST_LDFLAGS := $(HOST_LDFLAGS)

HOST_CFLAGS += $(WLDFLAGS)
HOST_LDFLAGS += $(DEBUG_CFLAGS) $(OPT_CFLAGS) $(WCFLAGS)

This wouldn't have any effect if HOST_CFLAGS is passed as parameter to make and would be even worse than the current solution, if HOST_CFLAGS is passed on the shell. You do not want any default switches, that are not absolutely necessary, otherwise you can have the same problem as
before: Incompatibility with the host compiler.

Maybe we should learn from the kernel here. It doesn't have a HOST_CFLAGS, just a HOSTCC. If you want to add CFLAGS for the host, you just append it to the HOSTCC.

Joerg

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp