summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.editorconfig4
-rw-r--r--.gitignore5
-rw-r--r--3rd-party/linux-errno.txt2
-rw-r--r--CMakeLists.txt48
-rw-r--r--GNUmakefile (renamed from Makefile)73
-rwxr-xr-xbuild-aux/embed-sources.h.gen (renamed from cmd/srv9p/static.h.gen)2
-rwxr-xr-xbuild-aux/linux-errno.txt.gen (renamed from 3rd-party/linux-errno.txt.gen)13
-rwxr-xr-xbuild-aux/stack.c.gen9
-rw-r--r--build-aux/stack.py (renamed from stack.py)0
-rwxr-xr-xbuild-aux/stack.sh (renamed from stack.sh)0
-rw-r--r--cmd/sbc_harness/CMakeLists.txt16
-rw-r--r--cmd/srv9p/CMakeLists.txt38
-rw-r--r--lib9p/include/lib9p/linux-errno.h4
l---------pico_sdk_import.cmake1
14 files changed, 118 insertions, 97 deletions
diff --git a/.editorconfig b/.editorconfig
index b2ffbdd..e44781e 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -30,10 +30,10 @@ _mode = markdown
[*.9p{,.wip}]
_mode = 9p
-[{3rd-party/linux-errno.txt.gen,cmd/srv9p/static.h.gen}]
+[cmd/srv9p/static.h.gen]
_mode = sh
-[libusb/include/libusb/tusb_helpers.h.gen]
+[{build-aux/linux-errno.txt.gen,libusb/include/libusb/tusb_helpers.h.gen}]
_mode = bash
[{lib9p/idl.gen,lib9p/include/lib9p/linux-errno.h.gen,stack.py}]
diff --git a/.gitignore b/.gitignore
index 4e3ccaa..ee30cb2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,5 @@
*.tmp
.mypy_cache/
-build/
-
-/.sources.mk
+/build/
+/build-aux/sources.mk
diff --git a/3rd-party/linux-errno.txt b/3rd-party/linux-errno.txt
index d2f6585..839efc2 100644
--- a/3rd-party/linux-errno.txt
+++ b/3rd-party/linux-errno.txt
@@ -1,4 +1,4 @@
-# ./3rd-party/linux-errno.txt - Generated from linux.git v6.7. DO NOT EDIT!
+# 3rd-party/linux-errno.txt - Generated from build-aux/linux-errno.txt.gen and linux.git v6.7. DO NOT EDIT!
1 EPERM Operation not permitted
2 ENOENT No such file or directory
3 ESRCH No such process
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6655b0a..100214c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,11 +6,11 @@
cmake_minimum_required(VERSION 3.30)
if (NOT PICO_PLATFORM)
- message(FATAL_ERROR "PICO_PLATFORM must be specified")
+ message(FATAL_ERROR "PICO_PLATFORM must be specified; use the GNUmakefile to set this")
endif()
set(PICO_SDK_PATH "${CMAKE_SOURCE_DIR}/3rd-party/pico-sdk")
-include(pico_sdk_import.cmake)
+include("${PICO_SDK_PATH}/external/pico_sdk_import.cmake")
project(sbc_harness)
@@ -18,6 +18,50 @@ pico_sdk_init()
add_compile_options(-Wall -Wextra -Werror)
+function(target_embed_sources arg_target arg_hdrname)
+ set(embed_objs)
+ foreach(embed_src IN LISTS ARGN)
+ add_custom_command(
+ OUTPUT "${embed_src}.obj"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ COMMAND mkdir -p -- "$<PATH:GET_PARENT_PATH,${CMAKE_CURRENT_BINARY_DIR}/${embed_src}>" &&
+ ${CMAKE_LINKER} -r -b binary -o "${CMAKE_CURRENT_BINARY_DIR}/${embed_src}.obj" "${embed_src}"
+ DEPENDS "${embed_src}"
+ )
+ list(APPEND embed_objs "${embed_src}.obj")
+ endforeach()
+ set_source_files_properties("${embed_objs}" PROPERTIES
+ EXTERNAL_OBJECT true
+ GENERATED true
+ )
+
+ set_source_files_properties("${arg_hdrname}" PROPERTIES
+ GENERATED true
+ )
+ add_custom_command(
+ OUTPUT "${arg_hdrname}"
+ COMMAND "${CMAKE_SOURCE_DIR}/build-aux/embed-sources.h.gen" "${embed_objs}" >"${arg_hdrname}"
+ COMMAND_EXPAND_LISTS
+ DEPENDS "${embed_objs}" "${CMAKE_SOURCE_DIR}/build-aux/embed-sources.h.gen"
+ )
+
+ target_sources("${arg_target}" PRIVATE "${embed_objs}" "${arg_hdrname}")
+endfunction()
+
+function(add_stack_analysis arg_outfile arg_objlib_target)
+ target_compile_options("${arg_objlib_target}" PUBLIC "-fcallgraph-info=su,da")
+ set_source_files_properties("${arg_outfile}" PROPERTIES
+ GENERATED true
+ )
+ add_custom_command(
+ OUTPUT "${arg_outfile}"
+ COMMAND "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen" "$<TARGET_OBJECTS:${arg_objlib_target}>" >"${arg_outfile}"
+ COMMAND_EXPAND_LISTS
+ DEPENDS "$<TARGET_OBJECTS:${arg_objlib_target}>" "${CMAKE_SOURCE_DIR}/build-aux/stack.c.gen"
+ COMMENT "Calculating ${arg_objlib_target} required stack sizes"
+ )
+endfunction()
+
add_subdirectory(libcr)
add_subdirectory(libcr_ipc)
add_subdirectory(libmisc)
diff --git a/Makefile b/GNUmakefile
index 26ce8ba..28f287a 100644
--- a/Makefile
+++ b/GNUmakefile
@@ -1,37 +1,64 @@
-# Makefile - Main build script for sbc-harness project
+# GNUmakefile - Main build script for sbc-harness project
#
# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
+# Project configuration ########################################################
+
linux.git = $(HOME)/src/github.com/torvalds/linux
all: build
.PHONY: all
+# Configure GNU Make itself ####################################################
+
+ifeq ($(filter notintermediate,$(.FEATURES)),)
+$(error This $(firstword $(MAKEFILE_LIST)) requies GNU Make 4.4 or later for .NOTINTERMEDIATE)
+endif
+
.NOTINTERMEDIATE:
.DELETE_ON_ERROR:
-################################################################################
+.PHONY: FORCE
+
+# `generate` ###################################################################
generate/files =
generate/files += 3rd-party/linux-errno.txt
-3rd-party/linux-errno.txt: %: %.gen
- ./$< $(linux.git)
+3rd-party/linux-errno.txt: build-aux/linux-errno.txt.gen
+ $< $(linux.git) $@
generate/files += lib9p/include/lib9p/linux-errno.h
lib9p/include/lib9p/linux-errno.h: %: %.gen 3rd-party/linux-errno.txt
- ./$^ >$@
+ $^ >$@
generate/files += lib9p/9p.generated.c lib9p/include/lib9p/9p.generated.h
lib9p/9p.generated.c lib9p/include/lib9p/9p.generated.h &: lib9p/idl.gen lib9p/idl/*.9p
- ./$^
+ $^
generate/files += libusb/include/libusb/tusb_helpers.h 3rd-party/MS-LCID.pdf 3rd-party/MS-LCID.txt
libusb/include/libusb/tusb_helpers.h 3rd-party/MS-LCID.pdf 3rd-party/MS-LCID.txt &: libusb/include/libusb/tusb_helpers.h.gen
- ./$^
+ $^
-################################################################################
+generate/files += build-aux/sources.mk
+build-aux/sources.mk: $(if $(wildcard .git),FORCE)
+ git ls-files | grep -vFx $(foreach f,$(generate/files),-e $f) \
+ | sed 's,^,$(CURDIR)/,' | xargs editorconfig \
+ | sed -nE -e 's,\[$(CURDIR)/(.*)\],\1,p' -e 's/^_mode=//p' \
+ | sed -E '{N;s/(.*)\n(.*)/sources_\2 += \1/;}' \
+ | sort \
+ >$@.tmp
+ if ! cmp -s $@.tmp $@; then mv $@.tmp $@; fi
+
+generate: $(generate/files)
+.PHONY: generate
+
+generate-clean:
+ rm -f -- $(generate/files)
+.PHONY: generate-clean
+
+# `build` ######################################################################
platforms := $(shell sed -nE 's/if *\(PICO_PLATFORM STREQUAL "(.*)"\)/\1/p' cmd/*/CMakeLists.txt)
@@ -41,37 +68,17 @@ build: $(foreach p,$(platforms),build/$p/build)
$(foreach p,$(platforms),build/$p/Makefile): build/%/Makefile:
mkdir -p $(@D) && cd $(@D) && cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_PLATFORM=$* ../..
-$(foreach p,$(platforms),build/$p/build): build/%/build: build/%/Makefile
+$(foreach p,$(platforms),build/$p/build): build/%/build: build/%/Makefile generate
$(MAKE) -C $(<D)
.PHONY: $(foreach p,$(platforms),build/$p/build)
-generate: $(generate/files)
-.PHONY: generate
-
-generate-clean:
- rm -f -- $(generate/files)
-.PHONY: generate-clean
-
-################################################################################
-
-.PHONY: FORCE
-
-# List of sources, by type.
-.sources.mk: $(if $(wildcard .git),FORCE)
- git ls-files | grep -vFx $(foreach f,$(generate/files),-e $f) \
- | sed 's,^,$(CURDIR)/,' | xargs editorconfig \
- | sed -nE -e 's,\[$(CURDIR)/(.*)\],\1,p' -e 's/^_mode=//p' \
- | sed -E '{N;s/(.*)\n(.*)/sources_\2 += \1/;}' \
- | sort \
- >$@.tmp
- if ! cmp -s $@.tmp $@; then mv $@.tmp $@; fi
--include .sources.mk
-sources_all := $(foreach v,$(filter sources_%,$(.VARIABLES)),$($v))
+# `lint` and `format` ##########################################################
-# lint #############
+-include build-aux/sources.mk
get_dscname = sed -n '1,3{ /^\#!/d; /^<!--$$/d; /-\*- .* -\*-/d; s,[/*\# ]*,,; s/ - .*//;p; q; }'
+# `lint` ###########
lint:
$(MAKE) -k $(patsubst sources_%,lint/%,$(filter sources_%,$(.VARIABLES)))
lint/sh lint/bash: lint/%:
@@ -122,7 +129,7 @@ lint/all: lint/%:
done; exit $$r; }
.PHONY: lint lint/%
-# format ###########
+# `format` #########
format:
$(MAKE) -k $(patsubst sources_%,format/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES))))
format/python3: format/%:
diff --git a/cmd/srv9p/static.h.gen b/build-aux/embed-sources.h.gen
index a93419f..0ba6457 100755
--- a/cmd/srv9p/static.h.gen
+++ b/build-aux/embed-sources.h.gen
@@ -1,5 +1,5 @@
#!/bin/sh
-# srv9p/static.h.gen - Generate C definitions for GNU `ld -r -b binary` files
+# embed-sources.h.gen - Generate C definitions for GNU `ld -r -b binary` files
#
# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/3rd-party/linux-errno.txt.gen b/build-aux/linux-errno.txt.gen
index abfbe95..f94178f 100755
--- a/3rd-party/linux-errno.txt.gen
+++ b/build-aux/linux-errno.txt.gen
@@ -1,14 +1,17 @@
-#!/bin/sh
-# 3rd-party/linux-errno.txt.gen - Generate a listing of Linux kernel errnos
+#!/usr/bin/env bash
+# build-aux/linux-errno.txt.gen - Generate a listing of Linux kernel errnos
#
# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
set -e
+linux_git=${1:?}
+outfile=${2:?}
+
(
- cd "$1"
- echo "# ${0%.gen} - Generated from linux.git $(git describe). DO NOT EDIT!"
+ cd "${linux_git}"
+ echo "# ${outfile} - Generated from $0 and linux.git $(git describe). DO NOT EDIT!"
git ls-files include/uapi/ | grep errno |
xargs sed -nE 's,#\s*define\s+(E[A-Z0-9]+)\s+([0-9]+)\s+/\* (.*) \*/,\2 \1 \3,p' |
sort --numeric-sort
-) >"${0%.gen}"
+) >"${outfile}"
diff --git a/build-aux/stack.c.gen b/build-aux/stack.c.gen
new file mode 100755
index 0000000..9325791
--- /dev/null
+++ b/build-aux/stack.c.gen
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+# stack.c.gen - Analyze stack sizes for compiled objects
+#
+# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+for obj in "$@"; do
+ echo "// $obj"
+done
diff --git a/stack.py b/build-aux/stack.py
index c1e36d3..c1e36d3 100644
--- a/stack.py
+++ b/build-aux/stack.py
diff --git a/stack.sh b/build-aux/stack.sh
index 4a8a12e..4a8a12e 100755
--- a/stack.sh
+++ b/build-aux/stack.sh
diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt
index 85e61ab..2018cf7 100644
--- a/cmd/sbc_harness/CMakeLists.txt
+++ b/cmd/sbc_harness/CMakeLists.txt
@@ -5,7 +5,7 @@
if (PICO_PLATFORM STREQUAL "rp2040")
-# Main compilation #############################################################
+# Compile ######################################################################
add_library(sbc_harness_objs
main.c
@@ -27,19 +27,9 @@ pico_enable_stdio_uart(sbc_harness_objs 1)
pico_enable_stdio_semihosting(sbc_harness_objs 0)
pico_enable_stdio_rtt(sbc_harness_objs 0)
-# Stack analysis ###############################################################
+# Analyze the stack ############################################################
-target_compile_options(sbc_harness_objs PUBLIC "-fcallgraph-info=su,da")
-set_source_files_properties(sbc_harness_stack.c PROPERTIES
- GENERATED true
-)
-add_custom_command(
- OUTPUT sbc_harness_stack.c
- COMMAND set -o pipefail && cat -- "$<LIST:TRANSFORM,$<LIST:FILTER,$<TARGET_OBJECTS:sbc_harness_objs>,INCLUDE,\.c\.o(bj)?$>,REPLACE,\.o(bj)?$,.ci>" | sed 's,^,//,' >sbc_harness_stack.c
- COMMAND_EXPAND_LISTS
- DEPENDS $<TARGET_OBJECTS:sbc_harness_objs>
- COMMENT "Calculating sbc_harness required stack sizes"
-)
+add_stack_analysis(sbc_harness_stack.c sbc_harness_objs)
# Link #########################################################################
diff --git a/cmd/srv9p/CMakeLists.txt b/cmd/srv9p/CMakeLists.txt
index 4c170fb..b747882 100644
--- a/cmd/srv9p/CMakeLists.txt
+++ b/cmd/srv9p/CMakeLists.txt
@@ -5,15 +5,14 @@
if (PICO_PLATFORM STREQUAL "host")
-set(static_srcs
- static/README.md
- static/Documentation/x
-)
-
add_executable(srv9p
main.c
static9p.c
)
+target_embed_sources(srv9p static.h
+ static/README.md
+ static/Documentation/x
+)
target_include_directories(srv9p PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(srv9p PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config)
target_link_libraries(srv9p
@@ -23,33 +22,4 @@ target_link_libraries(srv9p
lib9p
)
-set(static_objs)
-foreach(static_src ${static_srcs})
- add_custom_command(
- OUTPUT "${static_src}.obj"
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- COMMAND dirname -- ${CMAKE_CURRENT_BINARY_DIR}/${static_src}.obj | xargs mkdir -p --
- COMMAND ${CMAKE_LINKER} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/${static_src}.obj ${static_src}
- DEPENDS "${static_src}"
- )
- list(APPEND static_objs "${static_src}.obj")
-endforeach()
-
-set_source_files_properties(${static_objs} PROPERTIES
- EXTERNAL_OBJECT true
- GENERATED true
-)
-
-set_source_files_properties(static.h PROPERTIES
- GENERATED true
-)
-
-add_custom_command(
- OUTPUT static.h
- DEPENDS ${static_objs} static.h.gen
- COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/static.h.gen ${static_objs} >static.h
-)
-
-target_sources(srv9p PRIVATE ${static_objs} static.h)
-
endif()
diff --git a/lib9p/include/lib9p/linux-errno.h b/lib9p/include/lib9p/linux-errno.h
index 160b88b..e7c74f5 100644
--- a/lib9p/include/lib9p/linux-errno.h
+++ b/lib9p/include/lib9p/linux-errno.h
@@ -1,5 +1,5 @@
-/* lib9p/linux-errno.h - Generated by `./lib9p/include/lib9p/linux-errno.h.gen 3rd-party/linux-errno.txt`. DO NOT EDIT! */
-/* ./3rd-party/linux-errno.txt - Generated from linux.git v6.7. DO NOT EDIT! */
+/* lib9p/linux-errno.h - Generated by `lib9p/include/lib9p/linux-errno.h.gen 3rd-party/linux-errno.txt`. DO NOT EDIT! */
+/* 3rd-party/linux-errno.txt - Generated from build-aux/linux-errno.txt.gen and linux.git v6.7. DO NOT EDIT! */
#ifndef _LIB9P_LINUX_ERRNO_H_
#define _LIB9P_LINUX_ERRNO_H_
diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake
deleted file mode 120000
index d34d145..0000000
--- a/pico_sdk_import.cmake
+++ /dev/null
@@ -1 +0,0 @@
-3rd-party/pico-sdk/external/pico_sdk_import.cmake \ No newline at end of file