#
# Description:
#
#  This top-level Makefile is responsible for compiling all files in src/
#  and creating the binaries in bin/, documents in doc/, etc.
#
#  Here are the targets:
#
#    make           # Build the binaries.
#    make clean     # Remove all generated files.
#    make tests     # Run all of the tests.
#    make logs      # Run all tests but generate logs instead of checking them.
#    make pdfs      # Build the pdfs.
#    make <file>    # Re-build the named file (bin/prog, etc).
#

# Must be set first
TOP := .

# The default rule
.PHONY: default
default: build

# Settings
include $(TOP)/mk/settings.mk.inc

# Rules for this directory
.PHONY: clean
clean:
	$(Q)rm -rf $(BIN_DIR) $(TEMP_DIR) $(DOC_DIR)

.PHONY: tests
tests: build
	$(Q)export TOP=$(TOP);                                         \
            for X in $(TEST_DIR)/syntactic/*.pip; do                   \
              echo "   T $$X";                                         \
              $(TESTIT) $$X.log $(BIN_DIR)/pip --print-ast $$X &&      \
                $(TESTIT) $$X.log $(BIN_DIR)/pip --print-ast $$X.log;  \
            done;                                                      \
            for X in $(TEST_DIR)/semantic/*.pip; do                    \
              echo "   T $$X";                                         \
              $(TESTIT) $$X.log $(BIN_DIR)/pip --analyze $$X;          \
            done;                                                      \
            for X in $(TEST_DIR)/full/*.pip; do                        \
              echo "   T $$X";                                         \
              $(TESTIT) $$X.log $(BIN_DIR)/pip --analyze $$X;          \
            done

.PHONY: logs
logs: build
	$(Q)export TOP=$(TOP);                                         \
            for X in $(TEST_DIR)/syntactic/*.pip; do                   \
              echo "   G $$X";                                         \
              $(BIN_DIR)/pip --print-ast $$X > $$X.log 2>&1;           \
            done;                                                      \
            for X in $(TEST_DIR)/semantic/*.pip; do                    \
              echo "   G $$X";                                         \
              $(BIN_DIR)/pip --analyze $$X > $$X.log 2>&1;             \
            done;                                                      \
            for X in $(TEST_DIR)/full/*.pip; do                        \
              echo "   G $$X";                                         \
              $(BIN_DIR)/pip --analyze $$X > $$X.log 2>&1;             \
            done

# Load all TOP/src/**/Make*.inc
MF := $(shell find $(TOP)/src -name 'Make*.inc')
include $(MF)

# The standard rules
include mk/rules.mk.inc
