xiaoxiang781216 commented on code in PR #1979:
URL: https://github.com/apache/nuttx-apps/pull/1979#discussion_r1300514344


##########
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)))) \

Review Comment:
   change `$(word $(words $(PRIORITY)),$(PRIORITY))` to `$(lastword 
$(PRIORITY))`



##########
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), \

Review Comment:
   Change IDX to i, so we can simplify the variable reference to $i?



##########
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))) \

Review Comment:
   let's use the same variable prefix:
   PROGKEY_->PROGNAME_
   ELFPROGKEY_->PROGOBJ_
   REGAPPKEY_->PROGNAME_
   REGPRIORITYKEY_->PRIORITY_
   REGSTACKSIZEKEY_->STACKSIZE_
   REGUIDKEY_->UID_
   REGGIDKEY_->GID_
   REGMODEKEY_->MODE_



##########
Application.mk:
##########
@@ -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)))

Review Comment:
   let's apply the same change to:
   https://github.com/apache/nuttx-apps/blob/master/tools/Wasm.mk#L148
   and remove GETINDEX frrom Make.defs



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to