application.mk: fix multi MAINSRC match suffix in single Makefile

Change-Id: I998defe7208e4f3a9ae6aede33c54297ee27bd5f
Signed-off-by: dongjiuzhu <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu 2020-08-13 17:51:00 +08:00 committed by Xiang Xiao
parent 3c4089ef30
commit d635fcb2d8

View File

@ -78,17 +78,16 @@ AOBJS += $(CASRCS:.S=$(SUFFIX)$(OBJEXT))
COBJS = $(CSRCS:.c=$(SUFFIX)$(OBJEXT)) COBJS = $(CSRCS:.c=$(SUFFIX)$(OBJEXT))
CXXOBJS = $(CXXSRCS:$(CXXEXT)=$(SUFFIX)$(OBJEXT)) CXXOBJS = $(CXXSRCS:$(CXXEXT)=$(SUFFIX)$(OBJEXT))
ifeq ($(suffix $(MAINSRC)),$(CXXEXT)) MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
MAINOBJ = $(MAINSRC:$(CXXEXT)=$(SUFFIX)$(OBJEXT)) MAINCSRCS = $(filter %.c,$(MAINSRC))
else MAINCXXOBJ = $(MAINCXXSRCS:$(CXXEXT)=$(SUFFIX)$(OBJEXT))
MAINOBJ = $(MAINSRC:.c=$(SUFFIX)$(OBJEXT)) MAINCOBJ = $(MAINCSRCS:.c=$(SUFFIX)$(OBJEXT))
endif
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC) SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
ifneq ($(BUILD_MODULE),y) ifneq ($(BUILD_MODULE),y)
OBJS += $(MAINOBJ) OBJS += $(MAINCOBJ) $(MAINCXXOBJ)
endif endif
DEPPATH += --dep-path . DEPPATH += --dep-path .
@ -144,21 +143,19 @@ endif
ifeq ($(BUILD_MODULE),y) ifeq ($(BUILD_MODULE),y)
ifeq ($(suffix $(MAINSRC)),$(CXXEXT)) $(MAINCXXOBJ): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
$(MAINOBJ): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \ $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@)) $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
else
$(MAINOBJ): %$(SUFFIX)$(OBJEXT): %.c $(MAINCOBJ): %$(SUFFIX)$(OBJEXT): %.c
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@)) $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
endif
PROGLIST := $(wordlist 1,$(words $(MAINOBJ)),$(PROGNAME)) PROGLIST := $(wordlist 1,$(words $(MAINCOBJ) $(MAINCXXOBJ)),$(PROGNAME))
PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGLIST)) PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGLIST))
PROGOBJ := $(MAINOBJ) PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ)
$(PROGLIST): $(MAINOBJ) $(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ)
$(Q) mkdir -p $(BINDIR) $(Q) mkdir -p $(BINDIR)
ifeq ($(CONFIG_CYGWIN_WINTOOL),y) ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
$(call ELFLD,$(firstword $(PROGOBJ)),"${shell cygpath -w $(firstword $(PROGLIST))}") $(call ELFLD,$(firstword $(PROGOBJ)),"${shell cygpath -w $(firstword $(PROGLIST))}")
@ -178,21 +175,19 @@ else
MAINNAME := $(addsuffix _main,$(PROGNAME)) MAINNAME := $(addsuffix _main,$(PROGNAME))
ifeq ($(suffix $(MAINSRC)),$(CXXEXT)) $(MAINCXXOBJ): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
$(MAINOBJ): %$(SUFFIX)$(OBJEXT): %$(CXXEXT)
$(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))}) $(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))})
$(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))}) $(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(firstword $(MAINNAME))})
$(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME))) $(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME)))
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \ $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@)) $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
else
$(MAINOBJ): %$(SUFFIX)$(OBJEXT): %.c $(MAINCOBJ): %$(SUFFIX)$(OBJEXT): %.c
$(eval $<_CFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))}) $(eval $<_CFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))})
$(eval $<_CELFFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))}) $(eval $<_CELFFLAGS += ${shell $(DEFINE) "$(CC)" main=$(firstword $(MAINNAME))})
$(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME))) $(eval MAINNAME=$(filter-out $(firstword $(MAINNAME)),$(MAINNAME)))
$(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@)) $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
endif
install:: install::