

SOURCES = Test.cpp

BUILD_DIR = build
CXXFLAGS = -std=c++14


UNAME := $(shell uname)


# LINUX version
ifeq ($(UNAME), Linux)
TARGETS := $(BUILD_DIR)/hello-linux-64 $(BUILD_DIR)/hello-win64.exe $(BUILD_DIR)/hello-macosx.bin
endif

# WINDOWS version
ifeq ($(UNAME), MINGW64_NT-10.0)
TARGETS := $(BUILD_DIR)/hello-win64.exe
endif

all: $(TARGETS)
	@echo "all..."
	@echo $(UNAME)

.PRECIOUS: $(BUILD_DIR)/ $(BUILD_DIR)%/

$(BUILD_DIR)/:
	@echo "dir1..."
	@mkdir -p $@

$(BUILD_DIR)%/:
	@echo "dir2..."
	@mkdir -p $@

.SECONDEXPANSION:

$(BUILD_DIR)/hello-linux-64: Test.cpp $$(@D)/
	@echo "Building Linux binary..."
	@x86_64-linux-gnu-g++      $< -o $@

$(BUILD_DIR)/hello-win64.exe: Test.cpp $$(@D)/
	@echo "Building Windows binary..."
	@x86_64-w64-mingw32-g++    $< -o $@

$(BUILD_DIR)/hello-macosx.bin: Test.cpp $$(@D)/
	@echo "Building MacOSX binary..."
	@x86_64-apple-darwin19-c++ $< -o $@

tidy: $(BUILD_DIR)/tidy.xml

$(BUILD_DIR)/tidy.xml: $$(@D)/
	@chmod u+x ./clang-tidy-to-junit.py
	@clang-tidy -checks='c*,l*,m*' $(SOURCES) -- $(CXXFLAGS) | ./clang-tidy-to-junit.py $(PWD)/ > $@

test:  $(BUILD_DIR)/tests.xml

$(BUILD_DIR)/tests.xml: $$(@D)/
	@echo '<?xml version="1.0" encoding="UTF-8" ?>' > $@
	@echo '<testsuites id="1" name="Clang-Tidy" tests="1" errors="0" failures="0" time="0">' >> $@
	@echo '</testsuites>' >> $@

publish:
	@echo "Publish..."

.PHONY: test $(BUILD_DIR)/tests.xml

