# This top-level makefile is exported into the Pin kit and is referenced by
# several external scripts.  Be careful when changing the names of the makefile
# targets so as not to break anything that depends on them.

# All directories which contain tests should be placed here.
# Please maintain alphabetical order.

ALL_TEST_DIRS := AVX AVX2 AlignChk AndroidTests AttachDetach Buffer CacheClient ChildProcess Cpp11Tests CrossIa32Intel64 \
                 Debugger DebugInfo DebugTrace GracefulExit I18N IArg ImageTests InlinedFuncsOpt Insmix InstLibExamples \
                 InstructionTests InstrumentationOrderAndVersion JitProfilingApiTests MacTests ManualExamples           \
                 MaskVector Memory MemTrace MemTranslate Mix Mmx MyPinTool Probes Regvalue Replay RtnTests SegTrace     \
                 SegmentsVirtualization SignalTests SimpleExamples SyncTests SyscallsEmulation Tests ToolUnitTests Tsx  \
                 XyzzyKnobs

# Some of these targets are referenced in the User Guide and/or are commonly used by Pin users.
# Others are used by the nightly system and/or remote-builder.py.

all: build

utils:
	$(MAKE) -C Utils
	$(MAKE) -C InstLib

build: utils
	-$(MAKE) -k $(ALL_TEST_DIRS:%=%.build)

install: Utils.install
	-$(MAKE) -k $(ALL_TEST_DIRS:%=%.install)

test: $(ALL_TEST_DIRS:%=%.test)
	Utils/testsummary

sanity: $(ALL_TEST_DIRS:%=%.sanity)
	Utils/testsummary

clean: $(ALL_TEST_DIRS:%=%.clean)
	-$(MAKE) -k -C Utils clean

# These are directory-specific template targets.

$(ALL_TEST_DIRS:%=%.build):
	-$(MAKE) -k -C $(@:%.build=%)

$(ALL_TEST_DIRS:%=%.install):
	-$(MAKE) -k -C $(@:%.install=%) install

# The InstLib directory only needs to be built, not installed.
Utils.install:
	$(MAKE) -C $(@:%.install=%) install
	$(MAKE) -C InstLib

$(ALL_TEST_DIRS:%=%.test):
	-$(MAKE) -k -C $(@:%.test=%) test

$(ALL_TEST_DIRS:%=%.sanity):
	-$(MAKE) -k -C $(@:%.sanity=%) install
	-$(MAKE) -k -C $(@:%.sanity=%) sanity
	-$(MAKE) -k -C $(@:%.sanity=%) clean-remote

$(ALL_TEST_DIRS:%=%.clean):
	-$(MAKE) -k -C $(@:%.clean=%) clean

.PHONY: all utils build install test sanity clean
.PHONY: $(ALL_TEST_DIRS:%=%.build) $(ALL_TEST_DIRS:%=%.install) $(ALL_TEST_DIRS:%=%.test)
.PHONY: $(ALL_TEST_DIRS:%=%.sanity) $(ALL_TEST_DIRS:%=%.clean)
