summaryrefslogtreecommitdiff
path: root/mk/target.mk
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2024-02-12 16:18:03 -0600
committerAlejandro Soto <alejandro@34project.org>2024-02-20 11:11:18 -0600
commitbf5cece51a20eb4773d196ec650fb3af574afa17 (patch)
tree8abd33c815b38a3dee673ea345f106d4ddcae9ab /mk/target.mk
parent691a441bfeb90642840d2869cb04ec146e274a1e (diff)
mk: initial commit
This is a complete overhaul of the build system. This new implementations upports many new features and is very extensible.
Diffstat (limited to '')
-rw-r--r--mk/target.mk45
1 files changed, 45 insertions, 0 deletions
diff --git a/mk/target.mk b/mk/target.mk
new file mode 100644
index 0000000..d28c2e2
--- /dev/null
+++ b/mk/target.mk
@@ -0,0 +1,45 @@
+target_var = $(1)/$(rule_target)/$(rule_top)
+per_target = $($(call target_var,$(1)))
+
+rule_top_path = $(core_info/$(rule_top)/path)
+
+define target_entrypoint
+ $(1): rule_top := $$(rule_top)
+ $(1): rule_target := $$(rule_target)
+endef
+
+define check_target
+ ifneq ($$(target),$$(findstring $$(target),$$(targets)))
+ $$(error bad target '$$(target)')
+ endif
+endef
+
+define setup_submake_rules
+ .PHONY: $$(targets)
+
+ other_targets := $$(filter-out $$(target),$$(targets))
+
+ $$(foreach t,$$(targets),$$(eval $$(call top_rule,$$(t))))
+
+ ifeq (,$$(target))
+ $$(foreach other,$$(other_targets), \
+ $$(foreach core,$$(all_cores), \
+ $$(eval $$(call submake_rule,$$(other),$$(core)))))
+ else
+ $$(foreach core,$$(filter-out $$(top),$$(all_cores)), \
+ $$(eval $$(call submake_rule,$$(target),$$(core))))
+ endif
+endef
+
+define top_rule
+ $(1): $$(top_path)/$(1)
+endef
+
+define submake_rule
+ path := $$(core_info/$(2)/path)/$(1)
+
+ .PHONY: $$(path)
+
+ $$(path):
+ +$$(MAKE) --no-print-directory target=$(1) top=$(2) $$@
+endef