diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-24 09:38:56 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-24 09:38:56 -0700 |
| commit | ac525dc59de1ae195c40f8e21b09485d0e5d9330 (patch) | |
| tree | d1af8c53dbcdf64526d0d5b5d49c8fdc53489af1 /chapter-modules/Makefile | |
| parent | 2a7ed6bda01f028cf13f803d89b10908d7ea7937 (diff) | |
| download | Simple-ac525dc59de1ae195c40f8e21b09485d0e5d9330.tar.gz Simple-ac525dc59de1ae195c40f8e21b09485d0e5d9330.zip | |
module split
Diffstat (limited to 'chapter-modules/Makefile')
| -rw-r--r-- | chapter-modules/Makefile | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/chapter-modules/Makefile b/chapter-modules/Makefile new file mode 100644 index 00000000..e89e1bd7 --- /dev/null +++ b/chapter-modules/Makefile @@ -0,0 +1,201 @@ +# +# Makefile expects to run at the project root, and not nested inside anywhere +# +# cd $DESK/Simple/chapterXX; make +# +# +# first time only - this is the only thing that hits the Interwebs +# +# make lib +# +# any time you want to nuke everything from space: +# +# make clean tags +# +# run the tests +# +# make tests + +####################################################### +# +# Boilerplate because make syntax isn't the best +# + +# Use bash for recipes +SHELL := /bin/bash + +# Remove target on error (no broken leftover files) +.DELETE_ON_ERROR: + +# Keep partial builds but not partial recipes; keeping them speeds up the next `make` +.NOTINTERMEDIATE: + +# for printing variable values +# usage: make print-VARIABLE +# > VARIABLE = value_of_variable +print-% : ; @echo $* = $($*) + +# literal space +space := $() $() + +# Decide OS-specific questions +# jar-file seperator +ifeq ($(OS),Windows_NT) + SEP = ; +else + SEP = : +endif +# Find a reasonable ctags. +CTAGS = $(shell which ctags) +# Hack for MacOS: /usr/bin/ctags is unfriendly, so look for ctags from brew +ifeq ($(UNAME),Darwin) + CTAGS = $(shell brew list ctags 2> /dev/null | grep bin/ctags) +endif + +# Fun Args to javac. Mostly limit to java8 source definitions, and fairly +# aggressive lint warnings. +JAVAC_ARGS = -g + +# Source code +SIMPLE := com/seaofnodes/simple +SRC := src/main/java +TST := src/test/java +CLZDIR:= build/classes +main_javas := $(wildcard $(SRC)/$(SIMPLE)/*java $(SRC)/$(SIMPLE)/*/*java $(SRC)/$(SIMPLE)/node/cpus/*/*java) +test_javas := $(wildcard $(TST)/$(SIMPLE)/*java $(TST)/$(SIMPLE)/*/*java) +main_classes := $(patsubst $(SRC)/%java,$(CLZDIR)/main/%class,$(main_javas)) +include $(firstword $(wildcard ../graph/graph.mk graph/graph.mk)) +include $(firstword $(wildcard ../print/print.mk print/print.mk)) +include $(firstword $(wildcard ../isa/isa.mk isa/isa.mk)) +test_classes := $(patsubst $(TST)/%java,$(CLZDIR)/test/%class,$(test_javas)) +test_cp := $(patsubst $(TST)/$(SIMPLE)/%.java,com.seaofnodes.simple.%,$(wildcard $(TST)/$(SIMPLE)/*Test.java)) +classes = $(main_classes) $(test_classes) +# All the libraries +libs = $(wildcard lib/*jar) +jars = $(subst $(space),$(SEP),$(libs)) + + +default_targets := $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag +# Optionally add ctags to the default target if a reasonable one was found. +ifneq ($(CTAGS),) +default_targets += tags +endif + +default: $(default_targets) + +####################################################### +# Compile the chapter and shared viewer sources together + +$(CLZDIR)/main/.mtag: $(main_javas) Makefile + @[ -d $(CLZDIR)/main ] || mkdir -p $(CLZDIR)/main + @# This crap is really just "javac", but with a beautiful error message. + @# The very very long list of java files is suppressed and counted. + @# The required output "Note: blah blah deprecated blah" is suppressed. + $(file >.argsM.txt,$(main_javas)) + @if [ ! -z "$(main_javas)" ] ; then \ + echo "compiling main because " $< " and " `wc -w < .argsM.txt` " more files" ; \ + if ! javac $(JAVAC_ARGS) -cp "$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(SRC) -d $(CLZDIR)/main $(main_javas) >& .out.txt ; then \ + cat .out.txt ; \ + exit 1; \ + fi ; \ + rm -rf .out.txt ; \ + fi + @touch $(CLZDIR)/main/.mtag + @rm -f .argsM.txt + +$(main_classes): $(CLZDIR)/main/.mtag + + + +####################################################### + +OODT := $(isa_test_javas) +$(CLZDIR)/test/.ttag: $(test_classes) $(test_javas) $(isa_test_javas) $(CLZDIR)/main/.mtag + @[ -d $(CLZDIR)/test ] || mkdir -p $(CLZDIR)/test + $(file >.argsT.txt,$(OODT)) + @if [ ! -z "$(OODT)" ] ; then \ + echo "compiling test because " $< " and " `wc -w < .argsT.txt` " more files" ; \ + if ! javac $(JAVAC_ARGS) -cp "$(CLZDIR)/test$(SEP)$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(TST) -d $(CLZDIR)/test $(OODT) >& .out.txt ; then \ + cat .out.txt ; \ + exit 1; \ + fi ; \ + rm -rf .out.txt ; \ + fi + @touch $(CLZDIR)/test/.ttag + @rm -f .argsT.txt + +# Collect just the out-of-date files +$(test_classes): $(CLZDIR)/test/%class: $(TST)/%java + $(eval OODT += $$<) + +####################################################### +# Base launch line for JVM tests +JVM=nice java -ea -cp "$(CLZDIR)/main${SEP}${jars}${SEP}$(CLZDIR)/test" + + +tests: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag + @echo "testing " $(test_cp) + @[ -d build/objs ] || mkdir -p build/objs + @$(JVM) org.junit.runner.JUnitCore $(test_cp) + @$(JVM) org.junit.runner.JUnitCore com.seaofnodes.simple.FuzzerWrap + +fuzzer: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag + @echo "fuzzing " $(test_cp) + @$(JVM) org.junit.runner.JUnitCore com.seaofnodes.simple.FuzzerWrap + +# Build a Simple jar +release: build/release/simple.jar + +# Build a Simple jar +build/release/simple.jar: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag + @echo "jarring " $@ " because " $? + @[ -d $(dir $@) ] || mkdir -p $(dir $@) + @jar cf build/release/simple.jar -C $(CLZDIR)/main . -C $(CLZDIR)/test . -C $(SRC)/$(SIMPLE) . -C $(TST)/$(SIMPLE) . + + +.PHONY: clean +clean: + rm -rf build + rm -f TAGS + (find . -name "*~" -exec rm {} \; 2>/dev/null; exit 0) + +# Download libs from maven +lib: lib/junit-4.12.jar lib/hamcrest-core-1.3.jar + +# Jars +lib/junit-4.12.jar: + @[ -d lib ] || mkdir -p lib + @(cd lib; wget https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar) + +lib/hamcrest-core-1.3.jar: + @[ -d lib ] || mkdir -p lib + @(cd lib; wget https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar) + +# Build emacs tags (part of a tasty emacs ide experience) +tags: $(main_javas) $(test_javas) + @rm -f TAGS + @$(CTAGS) -e --recurse=yes --extra=+q --fields=+fksaiS $(SRC) $(TST) + +spill-stats: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag + @[ -d build/objs ] || mkdir -p build/objs + @$(JVM) com.seaofnodes.simple.SpillStats + +.PHONY: spill-stats + +.PHONY: build +build: $(CLZDIR)/main/.mtag + +# The ABI shim gives standalone native tests the same entry contract as clients. +CPU_PORT := x86_64_v2 +ifeq ($(OS),Windows_NT) +CALL_CONV := win64 +NATIVE_ABI := ms_abi +else +CALL_CONV := SystemV +NATIVE_ABI := sysv_abi +endif +runtime_obj := build/release/$(CPU_PORT)_$(CALL_CONV)/simple_crt.o +$(runtime_obj): src/main/c/simple_crt.c Makefile + @mkdir -p $(dir $@) + gcc -c -O2 -DCALL_CONV=$(NATIVE_ABI) $< -o $@ +tests: $(runtime_obj) |
