diff --git a/Application.mk b/Application.mk index 0c27c8facb3..ce2d6c2301f 100644 --- a/Application.mk +++ b/Application.mk @@ -93,6 +93,35 @@ ifneq ($(BUILD_MODULE),y) OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) endif +ifneq ($(PROGNAME),) + PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) + ifneq ($(words $(PROGOBJ)), $(words $(PROGNAME))) + $(warning "program names $(PROGNAME) does not match mainsrcs $(PROGOBJ)") + endif + PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGNAME)) + REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME))) + + NLIST := $(shell seq 1 $(words $(PROGNAME))) + $(foreach IDX, $(NLIST), \ + $(eval PROGKEY_$(word $(IDX),$(PROGOBJ)) := $(word $(IDX),$(PROGNAME))) \ + $(eval ELFPROGKEY_$(word $(IDX),$(PROGLIST)) := $(word $(IDX),$(PROGOBJ))) \ + $(eval REGAPPKEY_$(word $(IDX),$(REGLIST)) := $(word $(IDX),$(PROGNAME))) \ + $(eval REGPRIORITYKEY_$(word $(IDX),$(REGLIST)) := \ + $(if $(word $(IDX),$(PRIORITY)),$(word $(IDX),$(PRIORITY)),$(word $(words $(PRIORITY)),$(PRIORITY)))) \ + $(eval REGSTACKSIZEKEY_$(word $(IDX),$(REGLIST)) := \ + $(if $(word $(IDX),$(STACKSIZE)),$(word $(IDX),$(STACKSIZE)),$(word $(words $(STACKSIZE)),$(STACKSIZE)))) \ + $(eval REGUIDKEY_$(word $(IDX),$(REGLIST)) := \ + $(if $(word $(IDX),$(UID)),$(word $(IDX),$(UID)), \ + $(if $(UID),$(word $(words $(UID)),$(UID)),))) \ + $(eval REGGIDKEY_$(word $(IDX),$(REGLIST)) := \ + $(if $(word $(IDX),$(GID)),$(word $(IDX),$(GID)), \ + $(if $(GID),$(word $(words $(GID)),$(GID)),))) \ + $(eval REGMODEKEY_$(word $(IDX),$(REGLIST)) := \ + $(if $(word $(IDX),$(MODE)),$(word $(IDX),$(MODE)), \ + $(if $(MODE),$(word $(words $(MODE)),$(MODE)),))) \ + ) +endif + # Condition flags DO_REGISTRATION ?= y @@ -196,38 +225,28 @@ $(MAINCOBJ): %.c$(SUFFIX)$(OBJEXT): %.c $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@)) -PROGLIST := $(wordlist 1,$(words $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ)),$(PROGNAME)) -PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGLIST)) -PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) - $(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(Q) mkdir -p $(BINDIR) - $(call ELFLD,$(firstword $(PROGOBJ)),$(call CONVERT_PATH,$(firstword $(PROGLIST)))) - $(Q) chmod +x $(firstword $(PROGLIST)) + $(call ELFLD,$(ELFPROGKEY_$@),$(call CONVERT_PATH,$@)) + $(Q) chmod +x $@ ifneq ($(CONFIG_DEBUG_SYMBOLS),y) - $(Q) $(STRIP) $(firstword $(PROGLIST)) + $(Q) $(STRIP) $@ endif - $(eval PROGLIST=$(filter-out $(firstword $(PROGLIST)),$(PROGLIST))) - $(eval PROGOBJ=$(filter-out $(firstword $(PROGOBJ)),$(PROGOBJ))) install:: $(PROGLIST) @: else -MAINNAME := $(addsuffix _main,$(PROGNAME)) - $(MAINCXXOBJ): %$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT) - $(eval MAIN=$(word $(call GETINDEX,$<,$(MAINCXXSRCS)),$(MAINNAME))) - $(eval $<_CXXFLAGS += ${DEFINE_PREFIX}main=$(MAIN)) - $(eval $<_CXXELFFLAGS += ${DEFINE_PREFIX}main=$(MAIN)) + $(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(addsuffix _main, $(strip $(PROGKEY_$@)))}) + $(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(addsuffix _main, $(strip $(PROGKEY_$@)))}) $(if $(and $(CONFIG_BUILD_LOADABLE),$(CXXELFFLAGS)), \ $(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@)) $(MAINCOBJ): %.c$(SUFFIX)$(OBJEXT): %.c - $(eval MAIN=$(word $(call GETINDEX,$<,$(MAINCSRCS)),$(MAINNAME))) - $(eval $<_CFLAGS += ${DEFINE_PREFIX}main=$(MAIN)) - $(eval $<_CELFFLAGS += ${DEFINE_PREFIX}main=$(MAIN)) + $(eval $<_CFLAGS += ${DEFINE_PREFIX}main=$(addsuffix _main, $(strip $(PROGKEY_$@)))) + $(eval $<_CELFFLAGS += ${DEFINE_PREFIX}main=$(addsuffix _main, $(strip $(PROGKEY_$@)))) $(if $(and $(CONFIG_BUILD_LOADABLE),$(CELFFLAGS)), \ $(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@)) @@ -249,22 +268,11 @@ context:: ifeq ($(DO_REGISTRATION),y) -REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME))) -APPLIST := $(PROGNAME) - $(REGLIST): $(DEPCONFIG) Makefile ifeq ($(CONFIG_SCHED_USER_IDENTITY),y) - $(call REGISTER,$(firstword $(APPLIST)),$(firstword $(PRIORITY)),$(firstword $(STACKSIZE)),$(if $(BUILD_MODULE),,$(firstword $(APPLIST))_main),$(firstword $(UID)),$(firstword $(GID)),$(firstword $(MODE))) + $(call REGISTER,$(REGAPPKEY_$@),$(REGPRIORITYKEY_$@),$(REGSTACKSIZEKEY_$@),$(if $(BUILD_MODULE),,$(REGAPPKEY_$@)_main),$(REGUIDKEY_$@),$(REGGIDKEY_$@),$(REGMODEKEY_$@)) else - $(call REGISTER,$(firstword $(APPLIST)),$(firstword $(PRIORITY)),$(firstword $(STACKSIZE)),$(if $(BUILD_MODULE),,$(firstword $(APPLIST))_main)) -endif - $(eval APPLIST=$(filter-out $(firstword $(APPLIST)),$(APPLIST))) - $(if $(filter-out $(firstword $(PRIORITY)),$(PRIORITY)),$(eval PRIORITY=$(filter-out $(firstword $(PRIORITY)),$(PRIORITY)))) - $(if $(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE)),$(eval STACKSIZE=$(filter-out $(firstword $(STACKSIZE)),$(STACKSIZE)))) -ifeq ($(CONFIG_SCHED_USER_IDENTITY),y) - $(if $(filter-out $(firstword $(UID)),$(UID)),$(eval UID=$(filter-out $(firstword $(UID)),$(UID)))) - $(if $(filter-out $(firstword $(GID)),$(GID)),$(eval GID=$(filter-out $(firstword $(GID)),$(GID)))) - $(if $(filter-out $(firstword $(MODE)),$(MODE)),$(eval MODE=$(filter-out $(firstword $(MODE)),$(MODE)))) + $(call REGISTER,$(REGAPPKEY_$@),$(REGPRIORITYKEY_$@),$(REGSTACKSIZEKEY_$@),$(if $(BUILD_MODULE),,$(REGAPPKEY_$@)_main)) endif register:: $(REGLIST)