+DIRS = Legacy-2 Base-2 LambdaDelta-2
+
+SILENTMAKE = $(H)$(MAKE) $(S) --no-print-directory H=$(H) S=$(S)
+
+MAS = $(shell find $(DIRS) -mindepth 2 -name "*.ma")
+
+all: depends
+ $(H)$(RM) $(LOG)
+ $(SILENTMAKE) build
+
+opt all.opt: depends
+ $(H)$(RM) $(LOG)
+ $(SILENTMAKE) build.opt
+
+%.build.opt:
+ $(SILENTMAKE) $(patsubst %.mma, %.ma, $(shell find $* -name "*.mma"))
+ $(H)echo $*/theory.ma `$(BIN)matitadep.opt -stdout $*/theory.ma` >> depends
+
+build: $(DIRS:%=%.build.opt)
+ $(H)$(BIN)matitac $(MATITAOPTIONS) 2>> $(LOG)
+ $(H)$(RM) depends
+
+build.opt: $(DIRS:%=%.build.opt)
+ $(H)$(BIN)matitac.opt $(MATITAOPTIONS) 2>> $(LOG)
+ $(H)$(RM) depends
+
+clean:
+ $(H)$(BIN)matitaclean $(MATITAOPTIONS)
+ $(H)rm -f $(MAS) depends
+
+clean.opt:
+ $(H)$(BIN)matitaclean.opt $(MATITAOPTIONS)
+ $(H)rm -f $(MAS) depends
+
+clean.ma:
+ $(H)$(BIN)matitaclean.opt $(MATITAOPTIONS) $(MAS)
+ $(H)$(RM) $(MAS) depends
+
+clean.mma:
+# $(H)for FILE in */*.mma ; do if [ -e ../LambdaDelta-1/$${FILE/.mma/.ma} ] ; then true ; else rm $$FILE ; fi done
+
+depend:
+ @echo matitadep
+ $(H)$(BIN)matitadep $(foreach DIR, $(DIRS), -exclude $(DIR)/theory.ma)
+ $(H)cat $(DIRS:%=%/depends) >> depends
+
+depend.opt:
+ @echo matitadep.opt
+ $(H)$(BIN)matitadep.opt $(foreach DIR, $(DIRS), -exclude $(DIR)/theory.ma)
+ $(H)cat $(DIRS:%=%/depends) >> depends
+
+depends: depend.opt
+
+%.ma: %.mma
+ $(H)$(BIN)matitac.opt $(MATITAOPTIONS) $(word 3,$(shell grep -h $< */depends)) `$(BIN)matitadep.opt -stdout $<` 2>> $(LOG)
+ $(H)$(BIN)matitac.opt $(MATITAOPTIONS) -dump $@ $< 2>> $(LOG)
+ $(H)echo $@ `$(BIN)matitadep.opt -stdout $@` >> depends
+
+$(foreach DIR, $(DIRS), $(eval include $(DIR)/.depend))