2015-09-05 13:37:38 -04:00
|
|
|
############################################################################
|
|
|
|
|
# apps/Application.mk
|
|
|
|
|
#
|
2024-12-29 12:20:13 +01:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
#
|
2022-03-08 08:55:07 +00:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
# this work for additional information regarding copyright ownership. The
|
|
|
|
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
# "License"); you may not use this file except in compliance with the
|
|
|
|
|
# License. You may obtain a copy of the License at
|
2015-09-05 13:37:38 -04:00
|
|
|
#
|
2022-03-08 08:55:07 +00:00
|
|
|
# http:#www.apache.org/licenses/LICENSE-2.0
|
2015-09-05 13:37:38 -04:00
|
|
|
#
|
2022-03-08 08:55:07 +00:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
|
# under the License.
|
2015-09-05 13:37:38 -04:00
|
|
|
#
|
|
|
|
|
############################################################################
|
|
|
|
|
|
2018-08-23 11:06:15 -06:00
|
|
|
# If this is an executable program (with MAINSRC), we must build it as a
|
|
|
|
|
# loadable module for the KERNEL build (always) or if the tristate module
|
|
|
|
|
# has the value "m"
|
|
|
|
|
|
|
|
|
|
ifneq ($(MAINSRC),)
|
2024-03-22 15:59:24 +08:00
|
|
|
ifeq ($(DYNLIB),y)
|
2019-10-06 06:14:39 -06:00
|
|
|
BUILD_MODULE = y
|
2024-03-22 15:59:24 +08:00
|
|
|
MODAELFFLAGS = $(CMODULELFFLAGS)
|
|
|
|
|
MODCFLAGS = $(CMODULEFLAGS)
|
|
|
|
|
MODCXXFLAGS = $(CXXMODULEFLAGS)
|
|
|
|
|
MODLDFLAGS = $(LDMODULEFLAGS)
|
|
|
|
|
else ifneq ($(or $(filter y,$(CONFIG_BUILD_KERNEL)), $(filter m,$(MODULE))),)
|
|
|
|
|
BUILD_MODULE = y
|
|
|
|
|
MODAELFFLAGS = $(AELFFLAGS)
|
|
|
|
|
MODCFLAGS = $(CELFFLAGS)
|
|
|
|
|
MODCXXFLAGS = $(CXXELFFLAGS)
|
|
|
|
|
MODLDFLAGS = $(LDELFFLAGS)
|
2019-10-06 06:14:39 -06:00
|
|
|
endif
|
2018-08-23 11:06:15 -06:00
|
|
|
endif
|
|
|
|
|
|
2020-01-17 16:44:46 -06:00
|
|
|
# The GNU make CURDIR will always be a POSIX-like path with forward slashes
|
|
|
|
|
# as path segment separators. If we know that this is a native build, then
|
|
|
|
|
# we need to fix up the path so the DELIM will match the actual delimiter.
|
|
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
2023-03-12 21:09:44 +08:00
|
|
|
CWD = $(strip ${shell echo %CD% | cut -d: -f2})
|
2020-01-17 16:44:46 -06:00
|
|
|
else
|
2023-03-12 21:09:44 +08:00
|
|
|
CWD = $(CURDIR)
|
2020-01-17 16:44:46 -06:00
|
|
|
endif
|
|
|
|
|
|
2024-03-22 15:59:24 +08:00
|
|
|
SUFFIX ?= $(subst $(DELIM),.,$(CWD))
|
|
|
|
|
|
|
|
|
|
PROGNAME := $(subst ",,$(PROGNAME))
|
|
|
|
|
|
2022-10-14 10:01:50 +03:00
|
|
|
# Add the static application library to the linked libraries.
|
|
|
|
|
|
|
|
|
|
LDLIBS += $(call CONVERT_PATH,$(BIN))
|
2020-05-20 12:35:03 +08:00
|
|
|
|
2022-01-27 18:25:09 +09:00
|
|
|
# When building a module, link with the compiler runtime.
|
|
|
|
|
# This should be linked after libapps. Consider that mbedtls in libapps
|
|
|
|
|
# uses __udivdi3.
|
|
|
|
|
ifeq ($(BUILD_MODULE),y)
|
|
|
|
|
# Revisit: This only works for gcc and clang.
|
|
|
|
|
# Do other compilers have similar?
|
|
|
|
|
COMPILER_RT_LIB = $(shell $(CC) $(ARCHCPUFLAGS) --print-libgcc-file-name)
|
2022-04-15 13:46:45 +08:00
|
|
|
ifeq ($(wildcard $(COMPILER_RT_LIB)),)
|
|
|
|
|
# if "--print-libgcc-file-name" unable to find the correct libgcc PATH
|
|
|
|
|
# then go ahead and try "--print-file-name"
|
|
|
|
|
COMPILER_RT_LIB := $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name $(notdir $(COMPILER_RT_LIB))))
|
2022-01-27 18:25:09 +09:00
|
|
|
endif
|
2022-04-15 13:46:45 +08:00
|
|
|
LDLIBS += $(COMPILER_RT_LIB)
|
2022-01-27 18:25:09 +09:00
|
|
|
endif
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
# Apps compilation can achieve out-of-tree intermediate products
|
|
|
|
|
# by specifying "PREFIX" to a directory in its own Makefile.
|
|
|
|
|
# Default value is NULL,
|
|
|
|
|
# Make sure the out-of-tree directory exists and ends with $(DELIM) when setting it.
|
|
|
|
|
|
|
|
|
|
PREFIX ?=
|
|
|
|
|
|
2018-08-23 11:06:15 -06:00
|
|
|
# Object files
|
|
|
|
|
|
2020-09-08 19:23:33 +08:00
|
|
|
RASRCS = $(filter %.s,$(ASRCS))
|
|
|
|
|
CASRCS = $(filter %.S,$(ASRCS))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
RAOBJS = $(RASRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
CAOBJS = $(CASRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
COBJS = $(CSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
CXXOBJS = $(CXXSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
RUSTOBJS = $(RUSTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
ZIGOBJS = $(ZIGSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
DOBJS = $(DSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
SWIFTOBJS = $(SWIFTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2020-08-13 17:51:00 +08:00
|
|
|
MAINCXXSRCS = $(filter %$(CXXEXT),$(MAINSRC))
|
|
|
|
|
MAINCSRCS = $(filter %.c,$(MAINSRC))
|
2022-02-18 17:19:12 +01:00
|
|
|
MAINRUSTSRCS = $(filter %$(RUSTEXT),$(MAINSRC))
|
2022-03-16 11:38:09 -03:00
|
|
|
MAINZIGSRCS = $(filter %$(ZIGEXT),$(MAINSRC))
|
2024-06-05 14:15:15 -03:00
|
|
|
MAINDSRCS = $(filter %$(DEXT),$(MAINSRC))
|
2024-08-22 14:15:29 -03:00
|
|
|
MAINSWIFTSRCS = $(filter %$(SWIFTEXT),$(MAINSRC))
|
2024-05-28 17:53:56 +08:00
|
|
|
MAINCXXOBJ = $(MAINCXXSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
MAINCOBJ = $(MAINCSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
MAINRUSTOBJ = $(MAINRUSTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
MAINZIGOBJ = $(MAINZIGSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
MAINDOBJ = $(MAINDSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
|
|
|
|
MAINSWIFTOBJ = $(MAINSWIFTSRCS:%=$(PREFIX)%$(SUFFIX)$(OBJEXT))
|
2015-09-30 12:06:28 -04:00
|
|
|
|
|
|
|
|
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
|
2024-08-22 14:15:29 -03:00
|
|
|
OBJS = $(RAOBJS) $(CAOBJS) $(COBJS) $(CXXOBJS) $(RUSTOBJS) $(ZIGOBJS) $(DOBJS) $(SWIFTOBJS) $(EXTOBJS)
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2018-08-23 11:06:15 -06:00
|
|
|
ifneq ($(BUILD_MODULE),y)
|
2024-08-22 14:15:29 -03:00
|
|
|
OBJS += $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ)
|
2015-09-05 13:37:38 -04:00
|
|
|
endif
|
|
|
|
|
|
2023-08-25 16:21:18 +09:00
|
|
|
ifneq ($(strip $(PROGNAME)),)
|
2024-08-22 14:15:29 -03:00
|
|
|
PROGOBJ := $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ)
|
2023-07-25 16:53:44 +08:00
|
|
|
PROGLIST := $(addprefix $(BINDIR)$(DELIM),$(PROGNAME))
|
|
|
|
|
REGLIST := $(addprefix $(BUILTIN_REGISTRY)$(DELIM),$(addsuffix .bdat,$(PROGNAME)))
|
|
|
|
|
|
|
|
|
|
NLIST := $(shell seq 1 $(words $(PROGNAME)))
|
|
|
|
|
$(foreach i, $(NLIST), \
|
|
|
|
|
$(eval PROGNAME_$(word $i,$(PROGOBJ)) := $(word $i,$(PROGNAME))) \
|
apps: Sanitize PROGNAME for _main symbol generation
Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.
Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.
The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.
Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
fire on either current .zig source (generated _tmp.zig is
byte-identical to the source)
Fixes #19447
Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-16 20:17:06 +00:00
|
|
|
$(eval PROGSYM_$(word $i,$(PROGOBJ)) := $(subst -,_,$(word $i,$(PROGNAME)))) \
|
2023-07-25 16:53:44 +08:00
|
|
|
$(eval PROGOBJ_$(word $i,$(PROGLIST)) := $(word $i,$(PROGOBJ))) \
|
|
|
|
|
$(eval PRIORITY_$(word $i,$(REGLIST)) := \
|
|
|
|
|
$(if $(word $i,$(PRIORITY)),$(word $i,$(PRIORITY)),$(lastword $(PRIORITY)))) \
|
|
|
|
|
$(eval STACKSIZE_$(word $i,$(REGLIST)) := \
|
|
|
|
|
$(if $(word $i,$(STACKSIZE)),$(word $i,$(STACKSIZE)),$(lastword $(STACKSIZE)))) \
|
|
|
|
|
$(eval UID_$(word $i,$(REGLIST)) := \
|
|
|
|
|
$(if $(word $i,$(UID)),$(word $i,$(UID)),$(lastword $(UID)))) \
|
|
|
|
|
$(eval GID_$(word $i,$(REGLIST)) := \
|
|
|
|
|
$(if $(word $i,$(GID)),$(word $i,$(GID)),$(lastword $(GID)))) \
|
|
|
|
|
$(eval MODE_$(word $i,$(REGLIST)) := \
|
|
|
|
|
$(if $(word $i,$(MODE)),$(word $i,$(MODE)),$(lastword $(MODE)))) \
|
2026-07-15 16:11:18 +08:00
|
|
|
$(eval STACKSIZE_$(word $i,$(PROGLIST)) := $(STACKSIZE_$(word $i,$(REGLIST)))) \
|
|
|
|
|
$(eval PRIORITY_$(word $i,$(PROGLIST)) := $(PRIORITY_$(word $i,$(REGLIST)))) \
|
|
|
|
|
$(eval UID_$(word $i,$(PROGLIST)) := $(UID_$(word $i,$(REGLIST)))) \
|
|
|
|
|
$(eval GID_$(word $i,$(PROGLIST)) := $(GID_$(word $i,$(REGLIST)))) \
|
|
|
|
|
$(eval MODE_$(word $i,$(PROGLIST)) := $(MODE_$(word $i,$(REGLIST)))) \
|
2023-07-25 16:53:44 +08:00
|
|
|
)
|
2026-07-15 16:11:18 +08:00
|
|
|
|
|
|
|
|
# Emit the application's configured attributes as absolute ELF symbols
|
|
|
|
|
# (nx_stacksize, nx_priority, and nx_uid/nx_gid/nx_mode under
|
|
|
|
|
# CONFIG_SCHED_USER_IDENTITY) so the binary loader can recover them.
|
|
|
|
|
# Per-target so each PROGLIST entry picks up its own STACKSIZE_/PRIORITY_.
|
|
|
|
|
|
|
|
|
|
$(PROGLIST): MODLDFLAGS += \
|
|
|
|
|
$(if $(STACKSIZE_$@),--defsym nx_stacksize=$(STACKSIZE_$@)) \
|
2026-07-26 17:00:11 +02:00
|
|
|
$(if $(filter-out SCHED_PRIORITY_DEFAULT,$(PRIORITY_$@)),--defsym nx_priority=$(PRIORITY_$@))
|
2026-07-15 16:11:18 +08:00
|
|
|
ifeq ($(CONFIG_SCHED_USER_IDENTITY),y)
|
|
|
|
|
$(PROGLIST): MODLDFLAGS += \
|
|
|
|
|
$(if $(UID_$@),--defsym nx_uid=$(UID_$@)) \
|
|
|
|
|
$(if $(GID_$@),--defsym nx_gid=$(GID_$@)) \
|
|
|
|
|
$(if $(MODE_$@),--defsym nx_mode=$(MODE_$@))
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
# Keep the attribute symbols through --strip-unneeded so the binary loader
|
|
|
|
|
# can still read them from the stripped runtime image in bin/.
|
2026-07-26 17:00:11 +02:00
|
|
|
$(PROGLIST): NX_KEEP = $(if $(STACKSIZE_$@),-K nx_stacksize) $(if $(filter-out SCHED_PRIORITY_DEFAULT,$(PRIORITY_$@)),-K nx_priority) $(if $(UID_$@),-K nx_uid) $(if $(GID_$@),-K nx_gid) $(if $(MODE_$@),-K nx_mode)
|
2023-07-25 16:53:44 +08:00
|
|
|
endif
|
|
|
|
|
|
2023-07-13 15:44:41 +08:00
|
|
|
# Condition flags
|
|
|
|
|
|
2023-07-17 12:06:13 +08:00
|
|
|
DO_REGISTRATION ?= y
|
2023-07-13 15:44:41 +08:00
|
|
|
|
|
|
|
|
ifeq ($(PROGNAME),)
|
|
|
|
|
DO_REGISTRATION = n
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
ifeq ($(WASM_BUILD),y)
|
|
|
|
|
DO_REGISTRATION = n
|
|
|
|
|
endif
|
|
|
|
|
|
2026-07-15 16:11:18 +08:00
|
|
|
ifeq ($(BUILD_MODULE),y)
|
2024-03-22 15:59:24 +08:00
|
|
|
DO_REGISTRATION = n
|
|
|
|
|
endif
|
|
|
|
|
|
2023-03-31 10:25:13 +08:00
|
|
|
# Compile flags, notice the default flags only suitable for flat build
|
2023-01-31 15:09:21 +08:00
|
|
|
|
|
|
|
|
ZIGELFFLAGS ?= $(ZIGFLAGS)
|
2023-03-31 10:25:13 +08:00
|
|
|
RUSTELFFLAGS ?= $(RUSTFLAGS)
|
2024-06-05 14:15:15 -03:00
|
|
|
DELFFLAGS ?= $(DFLAGS)
|
2024-08-22 14:15:29 -03:00
|
|
|
SWIFTELFFLAGS ?= $(SWIFTFLAGS)
|
2023-01-31 15:09:21 +08:00
|
|
|
|
2021-03-24 17:50:17 -03:00
|
|
|
DEPPATH += --dep-path .
|
|
|
|
|
DEPPATH += --obj-path .
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2021-03-24 17:50:17 -03:00
|
|
|
VPATH += :.
|
|
|
|
|
|
2018-08-23 11:06:15 -06:00
|
|
|
# Targets follow
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
all:: $(PREFIX).built
|
2023-05-19 11:42:48 +10:00
|
|
|
@:
|
2020-07-24 23:18:37 +01:00
|
|
|
.PHONY: clean depend distclean
|
2019-10-03 14:07:17 -06:00
|
|
|
.PRECIOUS: $(BIN)
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2018-09-03 09:29:56 -06:00
|
|
|
define ELFASSEMBLE
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_BEGIN)"AS: $1 "
|
2024-03-22 15:59:24 +08:00
|
|
|
$(Q) $(MODULECC) -c $(MODAELFFLAGS) $($(strip $1)_AELFFLAGS) $1 -o $2
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_END)
|
2018-09-03 09:29:56 -06:00
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
define ELFCOMPILE
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_BEGIN)"CC: $1 "
|
2024-03-22 15:59:24 +08:00
|
|
|
$(Q) $(MODULECC) -c $(MODCFLAGS) $($(strip $1)_CELFFLAGS) $1 -o $2
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_END)
|
2018-09-03 09:29:56 -06:00
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
define ELFCOMPILEXX
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_BEGIN)"CXX: $1 "
|
2024-03-22 15:59:24 +08:00
|
|
|
$(Q) $(CXX) -c $(MODCXXFLAGS) $($(strip $1)_CXXELFFLAGS) $1 -o $2
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_END)
|
2018-09-03 09:29:56 -06:00
|
|
|
endef
|
|
|
|
|
|
2022-02-18 17:19:12 +01:00
|
|
|
define ELFCOMPILERUST
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_BEGIN)"RUSTC: $1 "
|
2022-02-18 17:19:12 +01:00
|
|
|
$(Q) $(RUSTC) --emit obj $(RUSTELFFLAGS) $($(strip $1)_RUSTELFFLAGS) $1 -o $2
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_END)
|
2022-02-18 17:19:12 +01:00
|
|
|
endef
|
|
|
|
|
|
2024-01-20 16:27:03 +08:00
|
|
|
# Remove target suffix here since zig compiler add .o automatically
|
2022-02-27 15:23:33 -03:00
|
|
|
define ELFCOMPILEZIG
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_BEGIN)"ZIG: $1 "
|
2023-02-26 02:12:10 +08:00
|
|
|
$(Q) $(ZIG) build-obj $(ZIGELFFLAGS) $($(strip $1)_ZIGELFFLAGS) --name $(basename $2) $1
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_END)
|
2022-02-27 15:23:33 -03:00
|
|
|
endef
|
|
|
|
|
|
2024-06-05 14:15:15 -03:00
|
|
|
define ELFCOMPILED
|
|
|
|
|
$(ECHO_BEGIN)"DC: $1 "
|
|
|
|
|
$(Q) $(DC) -c $(DELFFLAGS) $($(strip $1)_DELFFLAGS) $1 -of $2
|
|
|
|
|
$(ECHO_END)
|
|
|
|
|
endef
|
|
|
|
|
|
2024-08-22 14:15:29 -03:00
|
|
|
define ELFCOMPILESWIFT
|
|
|
|
|
$(ECHO_BEGIN)"SWIFTC: $1 "
|
|
|
|
|
$(Q) $(SWIFTC) -c $(SWIFTELFFLAGS) $($(strip $1)_SWIFTELFFLAGS) $1 -o $2
|
|
|
|
|
$(ECHO_END)
|
|
|
|
|
endef
|
|
|
|
|
|
2019-10-06 06:14:39 -06:00
|
|
|
define ELFLD
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_BEGIN)"LD: $2 "
|
2024-03-22 15:59:24 +08:00
|
|
|
$(Q) $(MODULELD) $(MODLDFLAGS) $(LDMAP) $(LDLIBPATH) $(ARCHCRT0OBJ) $1 $(LDSTARTGROUP) $(LDLIBS) $(LDENDGROUP) -o $2
|
2023-02-02 17:54:29 +08:00
|
|
|
$(ECHO_END)
|
2019-10-06 06:14:39 -06:00
|
|
|
endef
|
|
|
|
|
|
2024-01-20 16:27:03 +08:00
|
|
|
# rename "main()" in $1 to "xxx_main()" and save to $2
|
|
|
|
|
define RENAMEMAIN
|
|
|
|
|
$(ECHO_BEGIN)"Rename main() in $1 and save to $2"
|
apps: Sanitize PROGNAME for _main symbol generation
Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.
Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.
The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.
Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
fire on either current .zig source (generated _tmp.zig is
byte-identical to the source)
Fixes #19447
Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-16 20:17:06 +00:00
|
|
|
$(Q) ${shell cat $1 | sed -e "s/fn[ ]\+main/fn $(addsuffix _main,$(PROGSYM_$@))/" > $2}
|
2024-01-20 16:27:03 +08:00
|
|
|
$(ECHO_END)
|
|
|
|
|
endef
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(RAOBJS): $(PREFIX)%.s$(SUFFIX)$(OBJEXT): %.s
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODAELFFLAGS)), \
|
2020-09-18 18:23:39 +08:00
|
|
|
$(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(CAOBJS): $(PREFIX)%.S$(SUFFIX)$(OBJEXT): %.S
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODAELFFLAGS)), \
|
2019-10-06 06:14:39 -06:00
|
|
|
$(call ELFASSEMBLE, $<, $@), $(call ASSEMBLE, $<, $@))
|
2018-09-03 09:29:56 -06:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(COBJS): $(PREFIX)%.c$(SUFFIX)$(OBJEXT): %.c
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODCFLAGS)), \
|
2019-10-06 06:14:39 -06:00
|
|
|
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
|
2018-09-03 09:29:56 -06:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(CXXOBJS): $(PREFIX)%$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT)
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODCXXFLAGS)), \
|
2019-10-06 06:14:39 -06:00
|
|
|
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
|
2018-09-03 09:29:56 -06:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(RUSTOBJS): $(PREFIX)%$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2022-02-18 17:19:12 +01:00
|
|
|
$(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(ZIGOBJS): $(PREFIX)%$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES), $(CELFFLAGS)), \
|
2022-02-27 15:23:33 -03:00
|
|
|
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(DOBJS): $(PREFIX)%$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES), $(CELFFLAGS)), \
|
2024-06-05 14:15:15 -03:00
|
|
|
$(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(SWIFTOBJS): $(PREFIX)%$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES), $(CELFFLAGS)), \
|
2024-08-22 14:15:29 -03:00
|
|
|
$(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@))
|
|
|
|
|
|
2023-10-17 21:07:46 +08:00
|
|
|
AROBJS :=
|
2023-10-11 12:15:21 +08:00
|
|
|
ifneq ($(OBJS),)
|
2023-10-17 21:07:46 +08:00
|
|
|
SORTOBJS := $(sort $(OBJS))
|
|
|
|
|
$(eval $(call SPLITVARIABLE,OBJS_SPILT,$(SORTOBJS),100))
|
2023-10-11 12:15:21 +08:00
|
|
|
$(foreach BATCH, $(OBJS_SPILT_TOTAL), \
|
|
|
|
|
$(foreach obj, $(OBJS_SPILT_$(BATCH)), \
|
|
|
|
|
$(eval substitute := $(patsubst %$(OBJEXT),%_$(BATCH)$(OBJEXT),$(obj))) \
|
|
|
|
|
$(eval AROBJS += $(substitute)) \
|
|
|
|
|
$(eval $(call AROBJSRULES, $(substitute),$(obj))) \
|
|
|
|
|
) \
|
|
|
|
|
)
|
|
|
|
|
endif
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(PREFIX).built: $(AROBJS)
|
2023-10-11 12:15:21 +08:00
|
|
|
$(call SPLITVARIABLE,ALL_OBJS,$(AROBJS),100)
|
2023-08-30 19:57:16 +08:00
|
|
|
$(foreach BATCH, $(ALL_OBJS_TOTAL), \
|
2024-10-28 17:37:19 +08:00
|
|
|
$(if $(strip $(ALL_OBJS_$(BATCH))), \
|
|
|
|
|
$(shell $(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $(ALL_OBJS_$(BATCH)))) \
|
|
|
|
|
) \
|
2023-08-30 19:57:16 +08:00
|
|
|
)
|
2023-09-11 11:54:19 +08:00
|
|
|
$(Q) touch $@
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2019-10-06 06:14:39 -06:00
|
|
|
ifeq ($(BUILD_MODULE),y)
|
2018-09-04 09:38:26 -06:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINCXXOBJ): $(PREFIX)%$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT)
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODCXXFLAGS)), \
|
2019-10-06 06:14:39 -06:00
|
|
|
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
|
2020-08-13 17:51:00 +08:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINCOBJ): $(PREFIX)%.c$(SUFFIX)$(OBJEXT): %.c
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODCFLAGS)), \
|
2019-10-06 06:14:39 -06:00
|
|
|
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
|
2018-09-04 09:38:26 -06:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINZIGOBJ): $(PREFIX)%$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2024-01-20 16:27:03 +08:00
|
|
|
$(call ELFCOMPILEZIG, $<, $@), $(call COMPILEZIG, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINDOBJ): $(PREFIX)%$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2024-06-05 14:15:15 -03:00
|
|
|
$(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINSWIFTOBJ): $(PREFIX)%$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2024-08-22 14:15:29 -03:00
|
|
|
$(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@))
|
|
|
|
|
|
|
|
|
|
$(PROGLIST): $(MAINCOBJ) $(MAINCXXOBJ) $(MAINRUSTOBJ) $(MAINZIGOBJ) $(MAINDOBJ) $(MAINSWIFTOBJ)
|
2020-03-16 17:12:16 +08:00
|
|
|
$(Q) mkdir -p $(BINDIR)
|
2024-01-20 16:27:03 +08:00
|
|
|
$(call ELFLD, $(PROGOBJ_$@), $(call CONVERT_PATH,$@))
|
2023-07-25 16:53:44 +08:00
|
|
|
$(Q) chmod +x $@
|
2024-11-20 20:01:40 +08:00
|
|
|
ifneq ($(CONFIG_DEBUG_SYMBOLS),)
|
|
|
|
|
$(Q) mkdir -p $(BINDIR_DEBUG)
|
|
|
|
|
$(Q) cp $@ $(BINDIR_DEBUG)
|
2026-07-15 16:11:18 +08:00
|
|
|
$(Q) $(MODULESTRIP) $(NX_KEEP) $@
|
2019-10-07 02:55:44 -06:00
|
|
|
endif
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2018-09-12 06:09:20 -06:00
|
|
|
install:: $(PROGLIST)
|
2023-05-19 11:42:48 +10:00
|
|
|
@:
|
2018-09-04 09:38:26 -06:00
|
|
|
|
2015-09-05 13:37:38 -04:00
|
|
|
else
|
2019-10-06 06:14:39 -06:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINCXXOBJ): $(PREFIX)%$(CXXEXT)$(SUFFIX)$(OBJEXT): %$(CXXEXT)
|
apps: Sanitize PROGNAME for _main symbol generation
Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.
Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.
The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.
Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
fire on either current .zig source (generated _tmp.zig is
byte-identical to the source)
Fixes #19447
Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-16 20:17:06 +00:00
|
|
|
$(eval $<_CXXFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(addsuffix _main,$(PROGSYM_$@))})
|
|
|
|
|
$(eval $<_CXXELFFLAGS += ${shell $(DEFINE) "$(CXX)" main=$(addsuffix _main,$(PROGSYM_$@))})
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODCXXFLAGS)), \
|
2019-10-06 06:14:39 -06:00
|
|
|
$(call ELFCOMPILEXX, $<, $@), $(call COMPILEXX, $<, $@))
|
2020-08-13 17:51:00 +08:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINCOBJ): $(PREFIX)%.c$(SUFFIX)$(OBJEXT): %.c
|
apps: Sanitize PROGNAME for _main symbol generation
Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.
Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.
The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.
Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
fire on either current .zig source (generated _tmp.zig is
byte-identical to the source)
Fixes #19447
Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-16 20:17:06 +00:00
|
|
|
$(eval $<_CFLAGS += ${DEFINE_PREFIX}main=$(addsuffix _main,$(PROGSYM_$@)))
|
|
|
|
|
$(eval $<_CELFFLAGS += ${DEFINE_PREFIX}main=$(addsuffix _main,$(PROGSYM_$@)))
|
2024-03-22 15:59:24 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(MODCFLAGS)), \
|
2019-10-06 06:14:39 -06:00
|
|
|
$(call ELFCOMPILE, $<, $@), $(call COMPILE, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINRUSTOBJ): $(PREFIX)%$(RUSTEXT)$(SUFFIX)$(OBJEXT): %$(RUSTEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2022-02-18 17:19:12 +01:00
|
|
|
$(call ELFCOMPILERUST, $<, $@), $(call COMPILERUST, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINZIGOBJ): $(PREFIX)%$(ZIGEXT)$(SUFFIX)$(OBJEXT): %$(ZIGEXT)
|
2024-01-20 16:27:03 +08:00
|
|
|
$(Q) $(call RENAMEMAIN, $<, $(basename $<)_tmp.zig)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2024-01-20 16:27:03 +08:00
|
|
|
$(call ELFCOMPILEZIG, $(basename $<)_tmp.zig, $@), $(call COMPILEZIG, $(basename $<)_tmp.zig, $@))
|
|
|
|
|
$(Q) rm -f $(basename $<)_tmp.zig
|
2022-02-27 15:23:33 -03:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINDOBJ): $(PREFIX)%$(DEXT)$(SUFFIX)$(OBJEXT): %$(DEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2024-06-05 14:15:15 -03:00
|
|
|
$(call ELFCOMPILED, $<, $@), $(call COMPILED, $<, $@))
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(MAINSWIFTOBJ): $(PREFIX)%$(SWIFTEXT)$(SUFFIX)$(OBJEXT): %$(SWIFTEXT)
|
2024-03-19 17:37:09 +08:00
|
|
|
$(if $(and $(CONFIG_MODULES),$(CELFFLAGS)), \
|
2024-08-22 14:15:29 -03:00
|
|
|
$(call ELFCOMPILESWIFT, $<, $@), $(call COMPILESWIFT, $<, $@))
|
|
|
|
|
|
2018-09-03 09:29:56 -06:00
|
|
|
install::
|
2023-05-19 11:42:48 +10:00
|
|
|
@:
|
2018-09-04 09:38:26 -06:00
|
|
|
|
|
|
|
|
endif # BUILD_MODULE
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2024-03-22 16:00:19 +08:00
|
|
|
postinstall::
|
2023-05-19 11:42:48 +10:00
|
|
|
@:
|
2020-07-16 20:29:35 +08:00
|
|
|
|
2024-03-22 16:00:19 +08:00
|
|
|
context::
|
|
|
|
|
|
2023-07-13 15:44:41 +08:00
|
|
|
ifeq ($(DO_REGISTRATION),y)
|
2019-10-06 06:14:39 -06:00
|
|
|
|
2018-09-03 09:29:56 -06:00
|
|
|
$(REGLIST): $(DEPCONFIG) Makefile
|
2023-07-25 16:53:44 +08:00
|
|
|
$(eval PROGNAME_$@ := $(basename $(notdir $@)))
|
apps: Sanitize PROGNAME for _main symbol generation
Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.
Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.
The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.
Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
fire on either current .zig source (generated _tmp.zig is
byte-identical to the source)
Fixes #19447
Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-16 20:17:06 +00:00
|
|
|
$(eval PROGSYM_$@ := $(subst -,_,$(PROGNAME_$@)))
|
2023-04-15 15:01:04 +08:00
|
|
|
ifeq ($(CONFIG_SCHED_USER_IDENTITY),y)
|
apps: Sanitize PROGNAME for _main symbol generation
Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.
Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.
The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.
Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
fire on either current .zig source (generated _tmp.zig is
byte-identical to the source)
Fixes #19447
Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-16 20:17:06 +00:00
|
|
|
$(call REGISTER,$(PROGNAME_$@),$(PRIORITY_$@),$(STACKSIZE_$@),$(if $(BUILD_MODULE),,$(PROGSYM_$@)_main),$(UID_$@),$(GID_$@),$(MODE_$@))
|
2023-04-15 15:01:04 +08:00
|
|
|
else
|
apps: Sanitize PROGNAME for _main symbol generation
Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.
Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.
The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.
Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
fire on either current .zig source (generated _tmp.zig is
byte-identical to the source)
Fixes #19447
Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-16 20:17:06 +00:00
|
|
|
$(call REGISTER,$(PROGNAME_$@),$(PRIORITY_$@),$(STACKSIZE_$@),$(if $(BUILD_MODULE),,$(PROGSYM_$@)_main))
|
2023-04-15 15:01:04 +08:00
|
|
|
endif
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2020-07-16 20:29:35 +08:00
|
|
|
register:: $(REGLIST)
|
2023-05-19 11:42:48 +10:00
|
|
|
@:
|
2015-09-05 13:37:38 -04:00
|
|
|
else
|
2020-07-16 20:29:35 +08:00
|
|
|
register::
|
2023-05-19 11:42:48 +10:00
|
|
|
@:
|
2015-09-05 13:37:38 -04:00
|
|
|
endif
|
|
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
$(PREFIX).depend: Makefile $(wildcard $(foreach SRC, $(SRCS), $(addsuffix /$(SRC), $(subst :, ,$(VPATH))))) $(DEPCONFIG)
|
2024-10-17 11:49:59 +08:00
|
|
|
$(shell echo "# Gen Make.dep automatically" >$(PREFIX)Make.dep)
|
2023-07-24 21:50:54 +08:00
|
|
|
$(call SPLITVARIABLE,ALL_DEP_OBJS,$^,100)
|
|
|
|
|
$(foreach BATCH, $(ALL_DEP_OBJS_TOTAL), \
|
2024-05-28 17:53:56 +08:00
|
|
|
$(shell $(MKDEP) $(DEPPATH) --obj-suffix .c$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.c,$(ALL_DEP_OBJS_$(BATCH))) >>$(PREFIX)Make.dep) \
|
|
|
|
|
$(shell $(MKDEP) $(DEPPATH) --obj-suffix .S$(SUFFIX)$(OBJEXT) "$(CC)" -- $(CFLAGS) -- $(filter %.S,$(ALL_DEP_OBJS_$(BATCH))) >>$(PREFIX)Make.dep) \
|
|
|
|
|
$(shell $(MKDEP) $(DEPPATH) --obj-suffix $(CXXEXT)$(SUFFIX)$(OBJEXT) "$(CXX)" -- $(CXXFLAGS) -- $(filter %$(CXXEXT),$(ALL_DEP_OBJS_$(BATCH))) >>$(PREFIX)Make.dep) \
|
2023-10-17 21:07:46 +08:00
|
|
|
)
|
2020-03-23 11:33:08 +08:00
|
|
|
$(Q) touch $@
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
depend:: $(PREFIX).depend
|
2023-05-19 11:42:48 +10:00
|
|
|
@:
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2018-09-03 09:29:56 -06:00
|
|
|
clean::
|
2023-09-11 11:54:19 +08:00
|
|
|
$(call DELFILE, .built)
|
2023-10-17 21:07:46 +08:00
|
|
|
$(call CLEANAROBJS)
|
2015-09-05 13:37:38 -04:00
|
|
|
$(call CLEAN)
|
2018-09-03 09:29:56 -06:00
|
|
|
distclean:: clean
|
2026-07-06 10:11:19 +08:00
|
|
|
$(call DELFILE, .kconfig)
|
2015-09-05 13:37:38 -04:00
|
|
|
$(call DELFILE, Make.dep)
|
2020-03-23 11:33:08 +08:00
|
|
|
$(call DELFILE, .depend)
|
2015-09-05 13:37:38 -04:00
|
|
|
|
2024-05-28 17:53:56 +08:00
|
|
|
-include $(PREFIX)Make.dep
|
2023-07-18 18:17:33 +08:00
|
|
|
|
|
|
|
|
# Include Wasm specific definitions
|
|
|
|
|
include $(APPDIR)/tools/Wasm.mk
|