summaryrefslogtreecommitdiff
path: root/GNUmakefile
diff options
context:
space:
mode:
Diffstat (limited to 'GNUmakefile')
-rw-r--r--GNUmakefile207
1 files changed, 122 insertions, 85 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 28f287a..272306a 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,6 +1,6 @@
# GNUmakefile - Main build script for sbc-harness project
#
-# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
# Project configuration ########################################################
@@ -25,122 +25,159 @@ endif
generate/files =
+generate/files += COPYING.txt
+COPYING.txt:
+ wget --no-use-server-timestamps -O $@ https://www.gnu.org/licenses/agpl-3.0.txt
+
+generate/files += 3rd-party/COPYING.newlib.txt
+3rd-party/COPYING.newlib.txt: /usr/share/licenses/arm-none-eabi-newlib/COPYING.NEWLIB
+ cp $< $@
+
+generate/files += libmisc/tests/test_obj_autobox.c
+libmisc/tests/test_obj_autobox.c: %: %.gen libmisc/tests/test_obj_nest.c
+ $^ $@
+
generate/files += 3rd-party/linux-errno.txt
-3rd-party/linux-errno.txt: build-aux/linux-errno.txt.gen
+3rd-party/linux-errno.txt: lib9p/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 += libmisc/error_generated.c
+libmisc/error_generated.c: %: %.gen libmisc/include/libmisc/error.h
+ $^ $@
+
+generate/files += lib9p/idl/2010-9P2000.L.9p
+lib9p/idl/2010-9P2000.L.9p: %: %.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 += lib9p/core_generated.c lib9p/core_include/lib9p/_core_generated.h
+lib9p/core_generated.c lib9p/core_include/lib9p/_core_generated.h &: lib9p/core.gen lib9p/idl/__init__.py lib9p/core_gen lib9p/core_gen/*.py lib9p/idl lib9p/idl/2010-9P2000.L.9p lib9p/idl/*.9p
+ $< $(sort $(filter %.9p,$^))
+
+generate/files += lib9p/srv_generated.c
+lib9p/srv_generated.c: %: %.gen libmisc/include/libmisc/error.h
+ $^ $@
+
+generate/files += lib9p/tests/test_compile.c
+lib9p/tests/test_compile.c: %: %.gen lib9p/core_include/lib9p/_core_generated.h
+ $^ $@
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
+ifeq ($(INNER),)
+nonsource/files = $(generate/files)
+nonsource/files += 3rd-party/COPYING.wiznet-dhcp.txt
+# 100644 blob/regular file
+# 100755 blob/executable file
+# 120000 blob/symlink
+# 160000 commit (submodule)
+# 040000 tree (directory)
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 \
+ git ls-files --format='%(objectmode) %(path)' \
+ | sed -n 's/^100... //p' \
+ | grep -vFx $(foreach f,$(nonsource/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
+ @echo '################################################################################'
+endif
+generate:
+ifeq ($(INNER),)
generate: $(generate/files)
+endif
.PHONY: generate
generate-clean:
rm -f -- $(generate/files)
.PHONY: generate-clean
-# `build` ######################################################################
+# `build` and `check` ##########################################################
+
+# define the matrix
-platforms := $(shell sed -nE 's/if *\(PICO_PLATFORM STREQUAL "(.*)"\)/\1/p' cmd/*/CMakeLists.txt)
+platforms_build = rp2040
+platforms_check = host
+platforms = $(platforms_build) $(platforms_check)
+build_types = Debug Release RelWithDebInfo MinSizeRel
-build: $(foreach p,$(platforms),build/$p/build)
+# span the matrix
+
+build: $(foreach t,$(build_types),$(foreach p,$(platforms_build),build/$p-$t/build))
.PHONY: build
-$(foreach p,$(platforms),build/$p/Makefile): build/%/Makefile:
- mkdir -p $(@D) && cd $(@D) && cmake -DCMAKE_BUILD_TYPE=Debug -DPICO_PLATFORM=$* ../..
+build-check: $(foreach t,$(build_types),$(foreach p,$(platforms_check),build/$p-$t/build))
+.PHONY: build-check
+
+check: generate
+ $(MAKE) -k INNER=t $(foreach t,$(build_types),$(foreach p,$(platforms_check),build/$p-$t/check))
+.PHONY: check
+
+# define the cells
-$(foreach p,$(platforms),build/$p/build): build/%/build: build/%/Makefile generate
+# build/{matrix}/Makefile
+$(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/Makefile)): build/%/Makefile:
+ mkdir -p $(@D) && cd $(@D) && cmake -DPICO_PLATFORM=$(firstword $(subst -, ,$*)) -DCMAKE_BUILD_TYPE=$(lastword $(subst -, ,$*)) ../..
+
+# build/{matrix}/build
+$(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/build)): build/%/build: build/%/Makefile generate
$(MAKE) -C $(<D)
-.PHONY: $(foreach p,$(platforms),build/$p/build)
+.PHONY: $(foreach t,$(build_types),$(foreach p,$(platforms),build/$p-$t/build))
+
+# build/{matrix}/check
+#
+# `gcc` writes .gcno
+# Running the program writes .gcda (updates existing files, concurrent-safe)
+# GCC `gcov` post-processes .gcno+.gcda to .gcov
+# `gcovr` is a Python script that calls `gcov` and merges and post-processes the .gcov files to other formats
+gcovr_flags = --txt=$(@D)/coverage.txt
+gcovr_flags += --html=$(@D)/coverage.html --html-details --html-single-page=js-enabled
+gcovr_flags += --sort uncovered-number --sort-reverse
+$(foreach t,$(build_types),$(foreach p,$(platforms_check),build/$p-$t/check)): build/%/check: build/%/build
+ ./build-aux/gcov-prune $(@D)
+ +cd $(@D) && ctest --output-on-failure $(if $(filter --jobserver-auth=%,$(MAKEFLAGS)),--parallel)
+ gcovr $(gcovr_flags) -- $(@D)
+.PHONY: $(foreach t,$(build_types),$(foreach p,$(platforms_check),build/$p-$t/check))
# `lint` and `format` ##########################################################
-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/%:
- shellcheck $(sources_$*)
-lint/python3: lint/%:
- mypy --strict --scripts-are-modules $(sources_$*)
- black --check $(sources_$*)
- isort --check $(sources_$*)
-lint/c: lint/%:
- @for filename in $(filter %.h,$(sources_$*)); do \
- dscname=$$($(get_dscname) $$filename); \
- guard=$${dscname//'/'/'_'}; \
- guard=$${guard//'.'/'_'}; \
- guard="_$${guard^^}_"; \
- if ! { grep -Fxq "#ifndef $${guard}" "$$filename" && \
- grep -Fxq "#define $${guard}" "$$filename" && \
- grep -Fxq "#endif /* $${guard} */" "$$filename"; }; then \
- echo "$$filename does not have $${guard} guard"; r=1; \
- fi; \
- done
-lint/make lint/cmake lint/gitignore lint/ini lint/9p lint/markdown: lint/%:
- @:
-lint/unknown: lint/%:
- @printf "%s: cannot lint unknown file type\n" $(sources_$*) >&2
-lint/all: lint/%:
- $(eval export sources_$*)
- @find $$(printf '%s\n' $${sources_$*} | grep -vE '^cmd/[^/]+/static/') \
- -maxdepth 0 -type f | \
- { r=0; while read -r filename; do \
- if ! grep -q 'Copyright (C) 2024 Luke T. Shumaker' $$filename; then \
- echo "$$filename is missing a copyright statement"; r=1; \
- fi; \
- if ! grep -q ' SPDX-License-Identifier[:] ' $$filename; then \
- echo "$$filename is missing an SPDX-License-Identifier"; r=1; \
- fi; \
- dscname_act=$$($(get_dscname) $$filename); \
- dscname_exp=$$(echo "$$filename" | sed \
- -e 's,.*/config/,,' \
- -e 's,.*include/,,' \
- -e 's,^lib9p/idl/,,' \
- -e 's/\.wip$$//'); \
- if [ "$$dscname_act" != "$$dscname_exp" ] && [ "cmd/$$dscname_act" != "$$dscname_exp" ]; then \
- echo "$$filename self-identifies as $$dscname_act (expected $$dscname_exp)"; r=1; \
- fi; \
- if grep -n --color=auto "$$(printf '\\S\t')" $$filename; then \
- echo "$$filename uses tabs for alignment"; r=1; \
- fi; \
- done; exit $$r; }
+sources_all := $(foreach v,$(filter sources_%,$(.VARIABLES)),$($v))
+
+build-aux/venv: build-aux/requirements.txt
+ python3 -m venv $@
+ $@/bin/pip install -r $<
+ touch --no-create $@
+
+flashimgs = $(patsubst flashimg/%/CMakeLists.txt,%,$(filter flashimg/%/CMakeLists.txt,$(sources_cmake)))
+
+# `lint` ###############################
+lint: lint/src .WAIT lint/bin
+lint/src:
+ $(MAKE) -k INNER=t $(patsubst sources_%,lint/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES))))
+lint/bin: build build-aux/lint-bin
+ ./build-aux/lint-bin $(foreach i,$(flashimgs),$(foreach t,$(build_types),$(foreach p,$(platforms_build),build/$p-$t/flashimg/$i/$i.elf)))
+$(patsubst sources_%,lint/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES)))): build-aux/lint-src
+ ./build-aux/lint-src $(@F) $(sources_$(@F))
+lint/python3: build-aux/venv
.PHONY: lint lint/%
-# `format` #########
-format:
- $(MAKE) -k $(patsubst sources_%,format/%,$(filter-out sources_all,$(filter sources_%,$(.VARIABLES))))
-format/python3: format/%:
- black $(sources_$*)
- isort $(sources_$*)
-format/sh format/bash: format/%
- @:
-format/c: format/%:
- @: TODO
-format/make format/cmake format/gitignore format/ini format/9p format/markdown: format/%:
- @:
-format/unknown: format/%:
- @:
+# `format` #############################
+# generic ##########
+format: $(patsubst sources_%,format/%,$(filter-out sources_all sources_unknown,$(filter sources_%,$(.VARIABLES))))
.PHONY: format format/%
+# specific #########
+format/c: format/%:
+ @: TODO: Adopt a C code-formatter
+format/sh format/bash: format/%:
+ shfmt --write --case-indent --simplify $(sources_$(@F))
+format/python3: ./build-aux/venv
+ ./build-aux/venv/bin/black $(sources_$(@F))
+ ./build-aux/venv/bin/isort $(sources_$(@F))
+format/make format/cmake format/gitignore format/ini format/9p-idl format/9p-log format/markdown format/pip format/man-cat:
+ @: TODO: Write/adopt formatters for these file types