Skip to content

Commit

Permalink
WIP: Make subprojects automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Joppe committed Feb 22, 2024
1 parent 810b94c commit 103eca8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
45 changes: 11 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ _Makefile := $(lastword $(MAKEFILE_LIST))
# $/ is now the path prefix needed to reach here from `cwd`.
# It looks similar to `~/` on purpose, but it expands to nothing if already here.

## How to make a generic project (and its subprojects, if they have at least an .md file)
# `make`: All executables from all source code is executable.
# `make build/*.py.bringup`: *.py is executable with the venv/bin/python3 next to it.
# `make build/$(dir $(realpath .)).bringup`: A _start or main() found in *.c *.cpp *.s is executable.
# `make build/*.tested`: Executable * is verified.
# `make report`: Print a project self-test summary.
# `make gfm pdf html slides`: Print reports with all details of the project.
# `make old changes review audit`: Compare the project with last release.
# clean: Remove everything built by the project.
$(info -include $/project.mk)
-include $/project.mk

## How to make that generic project maker
ifneq (clean,$(findstring clean,$(MAKECMDGOALS)))
$/project.mk: $/generic.mk $/makemake.py
Expand All @@ -41,25 +29,14 @@ $/clean: $/clean_project
$/clean_project:
rm -f $/project.mk

## How to find subdirectories containing at least one .md file
$/SUBDIRS := $(foreach d,$(shell find $/. -mindepth 1 -maxdepth 1),$(notdir $d))
$/SUBPROJECTS := $(sort $(dir $(foreach d,$($/SUBDIRS),$(wildcard $/$d/*.md))))
$/ACTIVE_SUBPROJECTS := $(dir $(foreach d,$($/SUBPROJECTS),$(wildcard $/$d/Makefile)))

## How to make these as sub-projects before this project
$/all: | $($/ACTIVE_SUBPROJECTS:%=%all)
$/tested: | $($/ACTIVE_SUBPROJECTS:%=%tested)
$/build/report.txt: $($/ACTIVE_SUBPROJECTS:%=%build/report.txt)
$/gfm: | $($/ACTIVE_SUBPROJECTS:%=%gfm)
$/pdf: | $($/ACTIVE_SUBPROJECTS:%=%pdf)
$/html: | $($/ACTIVE_SUBPROJECTS:%=%html)
$/slides: | $($/ACTIVE_SUBPROJECTS:%=%slides)
$/old: | $($/ACTIVE_SUBPROJECTS:%=%old)
$/new: $($/ACTIVE_SUBPROJECTS:%=%new)
$/build/review.diff: $($/ACTIVE_SUBPROJECTS:%=%build/review.diff)
$/clean: | $($/ACTIVE_SUBPROJECTS:%=%clean)

## Finally attempt to include all sub-projects
# Note: Subprojects modify $/, this has to be the last command using it as a prefix to here.
$(info -include $($/SUBPROJECTS:%=%Makefile))
-include $($/SUBPROJECTS:%=%Makefile)
## How to make a generic project (and its subprojects, if they have at least an .md file)
# `make`: All executables from all source code is executable.
# `make build/*.py.bringup`: *.py is executable with the venv/bin/python3 next to it.
# `make build/$(dir $(realpath .)).bringup`: A _start or main() found in *.c *.cpp *.s is executable.
# `make build/*.tested`: Executable * is verified.
# `make report`: Print a project self-test summary.
# `make gfm pdf html slides`: Print reports with all details of the project.
# `make old changes review audit`: Compare the project with last release.
# clean: Remove everything built by the project.
$(info -include $/project.mk)
-include $/project.mk
23 changes: 22 additions & 1 deletion generic.mk
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,28 @@ $($/BUILD)report.diff: $($/OLD)report.gfm$/report.gfm
done ; \
rm xx**; ) >> $@

# Include the autogenerated dependencies
## Find subdirectories containing at least one .md file
$/SUBDIRS := $(foreach d,$(shell find $/. -mindepth 1 -maxdepth 1),$(notdir $d))
$/SUBPROJECTS := $(sort $(dir $(foreach d,$($/SUBDIRS),$(wildcard $/$d/*.md))))
$/ACTIVE_SUBPROJECTS := $(dir $(foreach d,$($/SUBPROJECTS),$(wildcard $/$d/Makefile)))

## Make these as sub-projects before this project
$/all: | $($/ACTIVE_SUBPROJECTS:%=%all)
$/tested: | $($/ACTIVE_SUBPROJECTS:%=%tested)
$/build/report.txt: $($/ACTIVE_SUBPROJECTS:%=%build/report.txt)
$/gfm: | $($/ACTIVE_SUBPROJECTS:%=%gfm)
$/pdf: | $($/ACTIVE_SUBPROJECTS:%=%pdf)
$/html: | $($/ACTIVE_SUBPROJECTS:%=%html)
$/slides: | $($/ACTIVE_SUBPROJECTS:%=%slides)
$/old: | $($/ACTIVE_SUBPROJECTS:%=%old)
$/new: $($/ACTIVE_SUBPROJECTS:%=%new)
$/build/review.diff: $($/ACTIVE_SUBPROJECTS:%=%build/review.diff)
$/clean: | $($/ACTIVE_SUBPROJECTS:%=%clean)

## Finally attempt to include all bringup files and sub-projects
# Note: Subprojects modify $/, so this has to be the last command using it as a prefix here.
$/DEPS += $($/SUBPROJECTS:%=%Makefile)
$(info -include $($/DEPS))
-include $($/DEPS)

endif # $/PROJECT

0 comments on commit 103eca8

Please sign in to comment.