+ifneq ($(findstring modules,$(MAKECMDGOALS)),modules)
+
+#############################################################
+#
+# Include the modules
+-include $(patsubst %,%/module.mk,$(MODULES))
+
+#
+#
+#############################################################
+
+#############################################################
+#
+# include dependencies if not making them!
+ifneq ($(MAKECMDGOALS),depend )
+# Don't include if cleaning of any sort
+ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
+#$(warning INCLUDEFILES=$(INCLUDEFILES))
+-include $(INCLUDEFILES)
+endif
+endif
+#############################################################
+
+endif
+endif
+# **************************************************************************
+
+#############################################################
+#
+# include dummy dependency file
+# *MUST* be last includefile
+include build/dummy.d
+#############################################################
+
+
+# targets
+
+.PHONY: alilibs aliroot makedistr clean htmldoc profile
+
+modules: $(patsubst %,%/module.mk,$(MODULES))
+
+
+aliroot: $(BINPATH) $(ALLEXECS) alilibs bin
+
+ifeq ($(ALIPROFILE),YES)
+alilibs: $(LIBPATH) $(ALLLIBS) $(ALLALIBS) lib modules
+else
+alilibs: $(LIBPATH) $(ALLLIBS) lib modules
+endif
+
+# Single Makefile "distribution": Makefile + modules + mkdepend scripts
+makedistr: $(MODULES)
+ tar -cvf MakeDistr.tar $(patsubst %,%/*.pkg,$(MODULES)) \
+ Makefile create build/*
+
+all: aliroot
+
+
+depend: $(INCLUDEFILES)
+
+debug:
+ifndef ALIQUIET
+ @echo "***** Entering DEBUG mode. *****"
+endif
+ @(export ALIDEBUG=YES && $(MAKE))
+profile:
+ifndef ALIQUIET
+ @echo "***** Entering PROFILE mode. *****"
+endif
+ @(export ALIPROFILE=YES && $(MAKE))
+lib:
+ @mkdir lib
+ @mkdir lib/tgt_$(ALICE_TARGET)
+
+bin:
+ @mkdir bin
+ @mkdir bin/tgt_$(ALICE_TARGET)
+
+$(MODULES):
+ifndef ALIQUIET
+ @echo "***** Making $@ *****"
+endif
+ @mkdir -p $@
+
+$(BINPATH):
+ifndef ALIQUIET
+ @echo "***** Making $@ *****"
+endif
+ @mkdir -p $@
+
+$(LIBPATH):
+ifndef ALIQUIET
+ @echo "***** Making $@ *****"
+endif
+ @mkdir -p $@
+
+build/dummy.d: $(EXPORTFILES)
+ @(if [ ! -f $@ ] ; then \
+ touch $@; \
+ fi)
+
+clean:
+ @echo "***** No targen clean, use one of these *****"
+ @echo " clean-aliroot : Clean up all aliroot libraries"
+ @echo " clean-MODULENAME : Clean everything from module MODULENAME"
+ @echo " clean-all : Cleans up everything, including cern libraires"
+ @echo " clean-modules : Clean all module.mk file in all modules"
+ @echo " clean-libs : Clean all libraries (not object files)"
+ @echo "********************************************"
+
+clean-all: clean-modules clean-libs clean-bins
+ifndef ALIQUIET
+ @echo "***** Cleaning up everything ****"
+endif
+ $(MUTE)rm -rf $(patsubst %,%/tgt_$(ALICE_TARGET),$(MODULES))
+ $(MUTE)rm -rf $(EXPORTDIR)
+
+#This cleans only libraries that are not CERN-libraries
+
+clean-aliroot: $(patsubst %,%/module.mk,$(ALIROOTMODULES)) $(patsubst %,clean-%,$(ALIROOTMODULES))
+
+CHECKMODULES := $(ALIROOTMODULES)
+CHECKMODULES := $(filter-out HBTP,$(CHECKMODULES))
+CHECKMODULES := $(filter-out MEVSIM,$(CHECKMODULES))
+CHECKMODULES := $(filter-out EPEMGEN,$(CHECKMODULES))
+CHECKMODULES := $(filter-out TPHIC,$(CHECKMODULES))
+
+check-all: $(patsubst %,%/module.mk,$(CHECKMODULES)) $(patsubst %,check-%,$(CHECKMODULES))
+
+reveng-all: $(patsubst %,%/module.mk,$(CHECKMODULES)) $(patsubst %,reveng-%,$(CHECKMODULES))
+
+revdisp-all: $(patsubst %,%/module.mk,$(CHECKMODULES)) $(patsubst %,revdisp-%,$(CHECKMODULES))
+
+clean-dicts:
+ifndef ALIQUIET
+ @echo "***** Cleaning up G__ files *****"
+endif
+ $(MUTE)rm -rf */tgt_$(ALICE_TARGET)/G__*
+
+clean-modules:
+ifndef ALIQUIET
+ @echo "***** Cleaning up module.mk files *****"
+endif
+ $(MUTE)rm -rf $(patsubst %,%/module.mk,$(MODULES))
+
+clean-depend:
+ifndef ALIQUIET
+ @echo "***** Cleaning up dependencies *****"
+endif
+ $(MUTE)echo rm `find . -name "*.d"`
+
+clean-objects:
+ifndef ALIQUIET
+ @echo "***** Cleaning up .o files *****"
+endif
+ $(MUTE)echo rm `find . -name "*.o"`
+
+clean-libs:
+ifndef ALIQUIET
+ @echo "***** Cleaning up library files *****"
+endif
+ $(MUTE)rm -rf lib/tgt_$(ALICE_TARGET)/*
+
+clean-bins:
+ifndef ALIQUIET
+ @echo "***** Cleaning up binary files *****"
+endif
+ $(MUTE)rm -rf bin/tgt_$(ALICE_TARGET)
+
+clean-check-all: $(patsubst %,%/module.mk,$(CHECKMODULES)) $(patsubst %,clean-check-%,$(CHECKMODULES))
+
+clean-reveng-all: $(patsubst %,%/module.mk,$(CHECKMODULES)) $(patsubst %,clean-reveng-%,$(CHECKMODULES))
+
+htmldoc:
+ @rm -rf html/roothtml
+ @rm -f html/picts
+ @rm -f /tmp/macros
+ @cd html ;\
+ aliroot -q -b "mkhtml.C(0,1)" ;\
+ ls ../macros/*.C > /tmp/macros ;\
+ for i in $(ALIROOTMODULES) ; do \
+ ls ../$$i/*.C 2>/dev/null >> /tmp/macros ;\
+ done ;\
+ for i in `cat /tmp/macros` ; do \
+ echo $$i ; \
+ aliroot -b -q "mkhtml.C(\"$$i\")" > /dev/null ;\
+ done ;\
+ ./makeExampleList ;
+ @ln -s ../picts html/picts
+ @ln -s ../../picts html/roothtml/picts
+ @ln -s ../../../picts html/roothtml/src/picts
+ @ln -s ../../../picts html/roothtml/examples/picts