summaryrefslogtreecommitdiff
path: root/build-support
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-12 13:16:00 -0800
committerCliff Click <cliffc@acm.org>2026-11-12 13:52:46 -0800
commit467338ee01565234762db8077c067df42c3b40a8 (patch)
tree42c44a77da87c4811b1eb7611d0952dc2c55e022 /build-support
parent0720fd8ed0aa92248622a9f3c3ebd522b002fd91 (diff)
downloadSimple-467338ee01565234762db8077c067df42c3b40a8.tar.gz
Simple-467338ee01565234762db8077c067df42c3b40a8.zip
Add audio, overhaul makefiles
Adds simple audio support to Simple Overhaul makefiles; remove common boilerplate; make them more uniform
Diffstat (limited to 'build-support')
-rw-r--r--build-support/early-chapter.mk53
-rw-r--r--build-support/java.mk85
-rw-r--r--build-support/libraries.mk26
3 files changed, 113 insertions, 51 deletions
diff --git a/build-support/early-chapter.mk b/build-support/early-chapter.mk
index d0135b74..462aca1c 100644
--- a/build-support/early-chapter.mk
+++ b/build-support/early-chapter.mk
@@ -1,51 +1,2 @@
-# Chapters 1-3 and 5 previously only had Maven builds.
-# Included with the chapter as the working directory.
-SHELL := /bin/bash
-.DEFAULT_GOAL := tests
-.DELETE_ON_ERROR:
-SIMPLE := com/seaofnodes/simple
-SRC := src/main/java
-TST := src/test/java
-CLZDIR := build/classes
-SEP := $(if $(filter Windows_NT,$(OS)),;,:)
-CTAGS ?= ctags
-JAVAC_ARGS ?= -g
-main_javas := $(wildcard $(SRC)/$(SIMPLE)/*.java $(SRC)/$(SIMPLE)/*/*.java)
-test_javas := $(wildcard $(TST)/$(SIMPLE)/*.java $(TST)/$(SIMPLE)/*/*.java)
-test_cp := $(patsubst $(TST)/$(SIMPLE)/%.java,com.seaofnodes.simple.%,$(wildcard $(TST)/$(SIMPLE)/*Test.java))
-jars := lib/junit-4.12.jar$(SEP)lib/hamcrest-core-1.3.jar
-main_classes := $(CLZDIR)/main/.mtag
-test_classes := $(CLZDIR)/test/.ttag
-
-include $(firstword $(wildcard ../graph/graph.mk graph/graph.mk))
-include $(firstword $(wildcard ../print/print.mk print/print.mk))
-
-.PHONY: build
-build: $(main_classes)
-
-$(main_classes): $(main_javas)
- @mkdir -p $(CLZDIR)/main
- javac $(JAVAC_ARGS) -d $(CLZDIR)/main $(main_javas)
- @touch $@
-
-$(test_classes): $(test_javas) $(main_classes) lib/junit-4.12.jar lib/hamcrest-core-1.3.jar
- @mkdir -p $(CLZDIR)/test
- javac $(JAVAC_ARGS) -cp "$(CLZDIR)/main$(SEP)$(jars)" -d $(CLZDIR)/test $(test_javas)
- @touch $@
-
-.PHONY: tests tags lib
-tests: $(test_classes)
- java -ea -cp "$(CLZDIR)/main$(SEP)$(CLZDIR)/test$(SEP)$(jars)" org.junit.runner.JUnitCore $(test_cp)
-
-tags:
- $(CTAGS) -e --recurse=yes --fields=+fksaiS $(SRC) $(TST)
-
-lib: lib/junit-4.12.jar lib/hamcrest-core-1.3.jar
-lib/junit-4.12.jar:
- @mkdir -p lib
- wget -O $@ https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar
-lib/hamcrest-core-1.3.jar:
- @mkdir -p lib
- wget -O $@ https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
-
-include $(firstword $(wildcard ../build-support/chapter-release.mk build-support/chapter-release.mk))
+# Compatibility for older/linearized Makefiles; all chapters use the same rules.
+include $(dir $(lastword $(MAKEFILE_LIST)))java.mk
diff --git a/build-support/java.mk b/build-support/java.mk
new file mode 100644
index 00000000..6e91ea92
--- /dev/null
+++ b/build-support/java.mk
@@ -0,0 +1,85 @@
+# Common chapter build mechanics. Chapter Makefiles add only their own features.
+SHELL := /bin/bash
+.DEFAULT_GOAL := default
+.DELETE_ON_ERROR:
+.NOTINTERMEDIATE:
+
+java_rules := $(lastword $(MAKEFILE_LIST))
+BUILD_SUPPORT := $(patsubst %/,%,$(dir $(java_rules)))
+SIMPLE := com/seaofnodes/simple
+SRC := src/main/java
+TST := src/test/java
+CLZDIR ?= build/classes
+JAVAC_ARGS ?= -g
+SEP := $(if $(filter Windows_NT,$(OS)),;,:)
+CTAGS := $(shell command -v ctags 2>/dev/null)
+
+include $(BUILD_SUPPORT)/libraries.mk
+library_rules := $(lastword $(MAKEFILE_LIST))
+
+# Explicit paths/prerequisites: a missing JAR must not disappear from the classpath.
+space := $() $()
+libs := $(required_jars)
+jars := $(subst $(space),$(SEP),$(libs))
+main_javas := $(wildcard $(SRC)/$(SIMPLE)/*.java $(SRC)/$(SIMPLE)/*/*.java $(SRC)/$(SIMPLE)/node/cpus/*/*.java)
+test_javas := $(wildcard $(TST)/$(SIMPLE)/*.java $(TST)/$(SIMPLE)/*/*.java)
+include $(firstword $(wildcard ../graph/graph.mk graph/graph.mk))
+include $(firstword $(wildcard ../print/print.mk print/print.mk))
+ifeq ($(USE_ISA),1)
+include $(firstword $(wildcard ../isa/isa.mk isa/isa.mk))
+endif
+
+main_classes := $(CLZDIR)/main/.mtag
+test_classes := $(CLZDIR)/test/.ttag
+simple_driver := $(TST)/$(SIMPLE)/Simple.java
+test_cp = $(patsubst $(TST)/$(SIMPLE)/%.java,com.seaofnodes.simple.%,$(wildcard $(TST)/$(SIMPLE)/*Test.java)) $(EXTRA_TESTS)
+JVM = nice java -ea -cp "$(CLZDIR)/main$(SEP)$(jars)$(SEP)$(CLZDIR)/test"
+
+.PHONY: default build tests fuzzer tags clean release
+DEFAULT_TARGETS ?= tests
+default: $(DEFAULT_TARGETS) $(if $(CTAGS),tags)
+build: $(main_classes)
+print-%: ; @echo $* = $($*)
+
+# Compile a complete source set once, including shared sources. Per-class rules
+# and collecting only changed files left stale dependents in several chapters.
+$(CLZDIR)/main $(CLZDIR)/test:
+ @mkdir -p $@
+
+$(main_classes): $(main_javas) $(required_jars) Makefile $(java_rules) $(library_rules) | $(CLZDIR)/main
+ $(file >$(CLZDIR)/main.sources,$(main_javas))
+ @echo "compiling main " $(words $(main_javas)) " files"
+ @if ! javac $(JAVAC_ARGS) -cp "$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(SRC) -d $(CLZDIR)/main @$(CLZDIR)/main.sources >$(CLZDIR)/main.javac.log 2>&1; then cat $(CLZDIR)/main.javac.log; exit 1; fi
+ @touch $@
+
+$(test_classes): $(test_javas) $(isa_test_javas) $(main_classes) $(required_jars) Makefile $(java_rules) $(library_rules) | $(CLZDIR)/test
+ $(file >$(CLZDIR)/test.sources,$(test_javas) $(isa_test_javas))
+ @echo "compiling test " $(words $(test_javas) $(isa_test_javas)) " files"
+ @if ! javac $(JAVAC_ARGS) -cp "$(CLZDIR)/test$(SEP)$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(TST) -d $(CLZDIR)/test @$(CLZDIR)/test.sources >$(CLZDIR)/test.javac.log 2>&1; then cat $(CLZDIR)/test.javac.log; exit 1; fi
+ @touch $@
+
+ifneq ($(CUSTOM_TESTS),1)
+tests: $(test_classes)
+ @mkdir -p build/objs
+ @$(JVM) org.junit.runner.JUnitCore $(test_cp)
+ifneq ($(wildcard $(TST)/$(SIMPLE)/FuzzerWrap.java),)
+tests: fuzzer
+endif
+endif
+
+ifneq ($(wildcard $(TST)/$(SIMPLE)/FuzzerWrap.java),)
+fuzzer: $(test_classes)
+ @$(JVM) org.junit.runner.JUnitCore com.seaofnodes.simple.FuzzerWrap
+endif
+
+ifneq ($(CUSTOM_RELEASE),1)
+include $(BUILD_SUPPORT)/chapter-release.mk
+endif
+
+tags: TAGS
+TAGS: $(main_javas) $(test_javas)
+ @$(CTAGS) -e --recurse=yes --fields=+fksaiS $(SRC) $(TST)
+
+clean:
+ rm -rf build
+ rm -f TAGS
diff --git a/build-support/libraries.mk b/build-support/libraries.mk
new file mode 100644
index 00000000..e45f1d08
--- /dev/null
+++ b/build-support/libraries.mk
@@ -0,0 +1,26 @@
+# Dependency downloads are permitted only by an explicit setup goal.
+# Keep this cache outside build/ so make clean does not erase it.
+.PHONY: lib libs init
+required_jars := lib/junit-4.12.jar lib/hamcrest-core-1.3.jar
+lib libs init: $(required_jars)
+
+# Chapters are self-contained, but identical JARs need not be downloaded again.
+# Copy an existing repository/sibling cache even for an ordinary offline build.
+cached-library = $(firstword $(filter-out $(abspath $@),$(abspath $(wildcard ../lib/$(notdir $@) ../chapter*/lib/$(notdir $@)))))
+
+# The legacy `lib` name remains an explicit setup alias.
+ifneq ($(filter lib libs init,$(MAKECMDGOALS)),)
+define download-library
+mkdir -p $(dir $@) && curl -fsSL $(1) -o $@.tmp && mv $@.tmp $@
+endef
+else
+define download-library
+echo "Missing cached dependency: $@. Run make libs (or make init) while online." >&2; exit 1
+endef
+endif
+
+lib/junit-4.12.jar:
+ @$(if $(cached-library),mkdir -p lib && cp "$(cached-library)" $@,$(call download-library,https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar))
+
+lib/hamcrest-core-1.3.jar:
+ @$(if $(cached-library),mkdir -p lib && cp "$(cached-library)" $@,$(call download-library,https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar))