+#------------------------------------------------------------------------
+# Create a TAGS database for emacs
+#------------------------------------------------------------------------
+
+ifeq ($(LEVEL), .)
+tags:
+ etags -l c++ `find include lib tools -name '*.cpp' -o -name '*.h'`
+all:: tags
+endif
+
+#------------------------------------------------------------------------
+# Handle the TOOLNAME option - used when building tool executables...
+#------------------------------------------------------------------------
+#
+# The TOOLNAME option should be used with a USEDLIBS variable that tells the
+# libraries (and the order of the libs) that should be linked to the
+# tool. USEDLIBS should contain a list of library names (some with .a extension)
+# that are automatically linked in as .o files unless the .a suffix is added.
+#
+ifdef TOOLNAME
+
+# TOOLEXENAME* - These compute the output filenames to generate...
+TOOLEXENAME_G := $(BUILD_ROOT_TOP)/tools/Debug/$(TOOLNAME)
+TOOLEXENAME_O := $(BUILD_ROOT_TOP)/tools/Release/$(TOOLNAME)
+TOOLEXENAME_P := $(BUILD_ROOT_TOP)/tools/Profile/$(TOOLNAME)
+TOOLEXENAMES := $(BUILD_ROOT_TOP)/tools/$(CONFIGURATION)/$(TOOLNAME)
+
+# USED_LIBS_OPTIONS - Compute the options line that add -llib1 -llib2, etc.
+USED_LIBS_OPTIONS := $(patsubst %.a.o, -l%, $(addsuffix .o, $(USEDLIBS)))
+USED_LIBS_OPTIONS_G := $(patsubst %.o, $(LIBDEBUG)/%.o, $(USED_LIBS_OPTIONS))
+USED_LIBS_OPTIONS_O := $(patsubst %.o, $(LIBRELEASE)/%.o,$(USED_LIBS_OPTIONS))
+USED_LIBS_OPTIONS_P := $(patsubst %.o, $(LIBPROFILE)/%.o,$(USED_LIBS_OPTIONS))
+
+
+# USED_LIB_PATHS - Compute the path of the libraries used so that tools are
+# rebuilt if libraries change. This has to make sure to handle .a/.so and .o
+# files seperately.
+#
+STATICUSEDLIBS := $(patsubst %.a.o, lib%.a, $(addsuffix .o, $(USEDLIBS)))
+USED_LIB_PATHS_G := $(addprefix $(LIBDEBUG)/, $(STATICUSEDLIBS))
+USED_LIB_PATHS_O := $(addprefix $(LIBRELEASE)/, $(STATICUSEDLIBS))
+USED_LIB_PATHS_P := $(addprefix $(LIBPROFILE)/, $(STATICUSEDLIBS))
+LINK_OPTS := $(TOOLLINKOPTS) $(PLATFORMLINKOPTS)
+
+
+# Tell make that we need to rebuild subdirectories before we can link the tool.
+# This affects things like LLI which has library subdirectories.
+$(USED_LIB_PATHS_G) $(USED_LIB_PATHS_O) $(USED_LIB_PATHS_P): \
+ $(addsuffix /.makeall, $(PARALLEL_DIRS))
+
+all:: $(TOOLEXENAMES)
+clean::
+ $(VERB) rm -f $(TOOLEXENAMES)
+
+$(TOOLEXENAME_G): $(ObjectsG) $(USED_LIB_PATHS_G) $(TOOLDEBUG)/.dir
+ @echo ======= Linking $(TOOLNAME) debug executable $(STRIP_WARN_MSG) =======
+ $(VERB) $(LinkG) -o $@ $(ObjectsG) $(USED_LIBS_OPTIONS_G) $(LINK_OPTS)
+
+$(TOOLEXENAME_O): $(ObjectsO) $(USED_LIB_PATHS_O) $(TOOLRELEASE)/.dir
+ @echo ======= Linking $(TOOLNAME) release executable =======
+ $(VERB) $(LinkO) -o $@ $(ObjectsO) $(USED_LIBS_OPTIONS_O) $(LINK_OPTS)
+
+$(TOOLEXENAME_P): $(ObjectsP) $(USED_LIB_PATHS_P) $(TOOLPROFILE)/.dir
+ @echo ======= Linking $(TOOLNAME) profile executable =======
+ $(VERB) $(LinkP) -o $@ $(ObjectsP) $(USED_LIBS_OPTIONS_P) $(LINK_OPTS)
+
+endif
+
+