Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion examples/sotest/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@
#
############################################################################

include $(wildcard $(APPDIR)/examples/sotest/*/Make.defs)
ifeq ($(CONFIG_EXAMPLES_SOTEST),y)
include $(APPDIR)/examples/sotest/main/Make.defs
endif

ifneq ($(CONFIG_EXAMPLES_SOTEST),n)
include $(APPDIR)/examples/sotest/modprint/Make.defs
include $(APPDIR)/examples/sotest/sotest/Make.defs
endif
108 changes: 91 additions & 17 deletions examples/sotest/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,101 @@
# ##############################################################################

if(CONFIG_EXAMPLES_SOTEST)
set(SOTEST_SYMTAB ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c)
set(SOTEST_ROMFS_IMG ${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.img)
set(SOTEST_ROMFS_SRC ${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.c)
set(SOTEST_MODPRINT_ELF ${CMAKE_BINARY_DIR}/bin/modprint)
set(SOTEST_SHARED_ELF ${CMAKE_BINARY_DIR}/bin/sotest)

# Dynamic applications are wrapped in ELF_* helper targets when the build uses
# the non-ELF-capable compiler path.
if(CMAKE_C_ELF_COMPILER)
set(SOTEST_MODPRINT_TARGET modprint)
set(SOTEST_SHARED_TARGET sotest)
else()
set(SOTEST_MODPRINT_TARGET ELF_modprint)
set(SOTEST_SHARED_TARGET ELF_sotest)
endif()

# FIXME: fix all empty a after the kernel build is implemented
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c
COMMAND
${NUTTX_APPS_DIR}/tools/mksymtab.sh ${CMAKE_CURRENT_BINARY_DIR}/empty
g_sot > ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c)
OUTPUT ${SOTEST_SYMTAB}
COMMAND ${NUTTX_APPS_DIR}/tools/mksymtab.sh ${SOTEST_MODPRINT_ELF}
${SOTEST_SHARED_ELF} g_sot > ${SOTEST_SYMTAB}
DEPENDS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET})

add_custom_target(
sotest_romfs
COMMAND genromfs -f sotest_romfs.img -d empty
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_source_files_properties(${SOTEST_SYMTAB} PROPERTIES GENERATED TRUE)

add_custom_command(
OUTPUT sotest_romfs.c
COMMAND xxd -i sotest_romfs.img > sotest_romfs.c
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS sotest_romfs)
set(SOTEST_GENERATED_OUTPUTS ${SOTEST_SYMTAB})
set(SOTEST_SRCS sotest_main.c ${SOTEST_SYMTAB})

if(CONFIG_EXAMPLES_SOTEST_BUILTINFS)
set(SOTEST_ROMFS_DEPS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET})

if(CONFIG_SYSTEM_NXPKG)
set(SOTEST_SHARED_INDEX ${CMAKE_BINARY_DIR}/bin/shared-index.json)
set(SOTEST_SHARED_SCRIPT ${CMAKE_BINARY_DIR}/bin/pkgsotest.nsh)
set(SOTEST_FIXTURE_HOST_DIR ${CMAKE_CURRENT_BINARY_DIR}/host)
set(SOTEST_FIXTURE_HOST_SRC
${CMAKE_CURRENT_SOURCE_DIR}/host/CMakeLists.txt)
set(SOTEST_FIXTURE_TOOL
${SOTEST_FIXTURE_HOST_DIR}/mk_pkg_fixture_shared${CMAKE_EXECUTABLE_SUFFIX}
)

add_custom_command(
OUTPUT ${SOTEST_FIXTURE_TOOL}
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/host -B
${SOTEST_FIXTURE_HOST_DIR}
COMMAND ${CMAKE_COMMAND} --build ${SOTEST_FIXTURE_HOST_DIR} --target
mk_pkg_fixture_shared
DEPENDS ${SOTEST_FIXTURE_HOST_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/mk_pkg_fixture_shared.c
VERBATIM)

add_custom_command(
OUTPUT ${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT}
COMMAND
${SOTEST_FIXTURE_TOOL} ${SOTEST_MODPRINT_ELF} ${SOTEST_SHARED_ELF}
${SOTEST_SHARED_INDEX} ${SOTEST_SHARED_SCRIPT} ${CONFIG_ARCH}
${CONFIG_ARCH_BOARD}
DEPENDS ${SOTEST_MODPRINT_TARGET} ${SOTEST_SHARED_TARGET}
${SOTEST_FIXTURE_TOOL}
VERBATIM)

list(APPEND SOTEST_ROMFS_DEPS ${SOTEST_SHARED_INDEX}
${SOTEST_SHARED_SCRIPT})
endif()

add_custom_command(
OUTPUT ${SOTEST_ROMFS_IMG}
COMMAND genromfs -f ${SOTEST_ROMFS_IMG} -d ${CMAKE_BINARY_DIR}/bin
DEPENDS ${SOTEST_ROMFS_DEPS}
VERBATIM)

get_filename_component(SOTEST_ROMFS_IMG_NAME ${SOTEST_ROMFS_IMG} NAME)

# xxd -i derives the generated array/length symbol names from the exact path
# it is given - sotest_main.c declares them as plain
# "sotest_romfs_img"/"sotest_romfs_img_len", so xxd must be run against just
# the bare filename (via WORKING_DIRECTORY) rather than the absolute
# ${SOTEST_ROMFS_IMG} path, or every non- alphanumeric character in that
# path (e.g. every "/" in the build directory) gets folded into the symbol
# name instead, leaving the names sotest_main.c expects undefined at link
# time.

add_custom_command(
OUTPUT ${SOTEST_ROMFS_SRC}
COMMAND xxd -i ${SOTEST_ROMFS_IMG_NAME} > ${SOTEST_ROMFS_SRC}
DEPENDS ${SOTEST_ROMFS_IMG}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

set_source_files_properties(${SOTEST_ROMFS_SRC} PROPERTIES GENERATED TRUE)

list(APPEND SOTEST_GENERATED_OUTPUTS ${SOTEST_ROMFS_SRC})
list(APPEND SOTEST_SRCS ${SOTEST_ROMFS_SRC})
endif()

nuttx_add_application(
NAME sotest SRCS sotest_main.c ${CMAKE_CURRENT_BINARY_DIR}/sotest_symtab.c
${CMAKE_CURRENT_BINARY_DIR}/sotest_romfs.c)
add_custom_target(sotest_artifacts DEPENDS ${SOTEST_GENERATED_OUTPUTS})

nuttx_add_application(NAME sotest SRCS ${SOTEST_SRCS} DEPENDS
sotest_artifacts)
endif()
25 changes: 23 additions & 2 deletions examples/sotest/main/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,29 @@ ifeq ($(CONFIG_EXAMPLES_SOTEST_BUILTINFS),y)
ROMFSIMG = sotest_romfs.img
ROMFSSRC = sotest_romfs.c
ROMFSOBJ = $(ROMFSSRC:.c=$(OBJEXT))
ifdef CONFIG_SYSTEM_NXPKG
HOSTOBJSEXT ?= hobj
PKGSHAREDINDEX = $(BINDIR)/shared-index.json
PKGSHAREDTEST = $(BINDIR)/pkgsotest.nsh
PKG_FIXTURE_GEN = mk_pkg_fixture_shared$(HOSTEXEEXT)
PKG_FIXTURE_SRCS = mk_pkg_fixture_shared.c
PKG_FIXTURE_OBJS = $(PKG_FIXTURE_SRCS:.c=.$(HOSTOBJSEXT))
PKG_FIXTURE_OUTPUTS = $(PKGSHAREDINDEX) $(PKGSHAREDTEST)

$(PKG_FIXTURE_OBJS): %.$(HOSTOBJSEXT): %.c
@echo "CC: $<"
$(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@

$(PKG_FIXTURE_GEN): $(PKG_FIXTURE_OBJS)
$(Q) $(HOSTCC) $(HOSTLDFLAGS) $(PKG_FIXTURE_OBJS) -o $@

$(PKG_FIXTURE_OUTPUTS) &: $(BINDIR)/modprint $(BINDIR)/sotest $(PKG_FIXTURE_GEN)
$(Q) ./$(PKG_FIXTURE_GEN) $(BINDIR)/modprint $(BINDIR)/sotest \
$(PKGSHAREDINDEX) $(PKGSHAREDTEST) $(CONFIG_ARCH) \
$(CONFIG_ARCH_BOARD)
endif

$(ROMFSIMG):
$(ROMFSIMG): $(PKG_FIXTURE_OUTPUTS)
$(Q) genromfs -d $(BINDIR) -f $@

$(ROMFSSRC): $(ROMFSIMG)
Expand All @@ -67,6 +88,6 @@ postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ)
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)

distclean::
$(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ))
$(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) $(ROMFSOBJ) $(PKG_FIXTURE_GEN) $(PKG_FIXTURE_OBJS))

include $(APPDIR)/Application.mk
26 changes: 26 additions & 0 deletions examples/sotest/main/host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ##############################################################################
# apps/examples/sotest/main/host/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#
# ##############################################################################

cmake_minimum_required(VERSION 3.16)
project(sotest_fixture_host LANGUAGES C)

add_executable(mk_pkg_fixture_shared ../mk_pkg_fixture_shared.c)
Loading
Loading