+CLEANFILES =
+clean::
+.PHONY: clean
+
+###--------------------------------------------------------------------------
+### Native C code.
+
+out/%.o: %.c
+ $(call v_tag,CC)mkdir -p $(OUTDIR)/ && \
+ $(CC) -c $(ALL_CFLAGS) -MMD -o$@ $<
+
+ALL_SOURCES =
+DISTFILES += $(ALL_SOURCES)
+
+objects = $(patsubst %.c,$(OUTDIR)/%$2,$1)
+CLEANFILES += $(OUTDIR)/*.o $(OUTDIR)/*.d
+
+###--------------------------------------------------------------------------
+### Java classes.
+
+## Java and Scala source files turn into multiple `.class' files with
+## unpredictable names. Rather than try to guess stable outputs for these
+## sources, we make artificial `timestamp' files and uses these in our
+## dependencies.
+CLASSDIR = $(OUTDIR)/cls
+stamps = $(patsubst %,$(OUTDIR)/%.$1-stamp,$2)
+
+clean::; rm -rf $(CLASSDIR)
+CLEANFILES += $(OUTDIR)/*.class-stamp
+
+## Compiling actual Java code. Note that this confuses the resident Scala
+## compiler, so we have to reset it here.
+CLSISH += java
+$(OUTDIR)/%.class-stamp: %.java
+ $(call v_tag,JAVAC)mkdir -p $(CLASSDIR)/ && \
+ $(JAVAC) -d $(CLASSDIR) -cp $(CLASSDIR) $(JAVAFLAGS) $< && \
+ echo built >$@
+ $(V_AT)$(SCALAC_RESET)
+
+## Compiling Scala code.
+CLSEXT += scala
+$(OUTDIR)/%.class-stamp: %.scala
+ $(call v_tag,SCALAC)mkdir -p $(CLASSDIR)/ && \
+ $(SCALAC) -d $(CLASSDIR) -cp $(CLASSDIR) $(SCALAFLAGS) $< && \
+ echo built >$@
+
+###--------------------------------------------------------------------------
+### Native-code libraries.
+
+SHLIBS += toy
+toy_SOURCES = jni.c
+
+shlibfile = $(patsubst %,$(OUTDIR)/lib%.so,$1)
+SHLIBFILES = $(call shlibfile,$(SHLIBS))
+TARGETS += $(SHLIBFILES)
+ALL_SOURCES += $(foreach l,$(SHLIBS),$($l_SOURCES))
+
+$(SHLIBFILES): $(OUTDIR)/lib%.so: $$(call objects,$$($$*_SOURCES),.o)
+ $(call v_tag,LD)$(LD) $(LDFLAGS.so) -o$@ $^ $(LIBS)
+
+###--------------------------------------------------------------------------
+### Java classes.
+
+## Writing things out longhand is tedious. `CLASSES' is a list of entries of
+## the form `SRC[:DEP,...]', saying that `SRC.ext', being a source file
+## capable of being built into `.class' files and setting `SRC.stamp', should
+## be so built, and that it depends on other similar sources named DEP having
+## been so built.
+CLASSES += util
+CLASSES += sys:util
+CLASSES += admin:sys,util
+CLASSES += tar:util
+CLASSES += progress:sys,util
+CLASSES += keys:progress,tar,sys,util
+CLASSES += terminal:progress,sys,util
+CLASSES += main:sys
+
+## Machinery for parsing the `CLASSES' list.
+COMMA = ,
+class-name = $(firstword $(subst :, ,$1))
+class-deps = $(subst $(COMMA), ,$(word 2,$(subst :, ,$1)))