Newer
Older
Code / Makefile
@John Ryland John Ryland on 3 Jul 2023 1 KB fix


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
LINUX_CXX  := x86_64-linux-gnu-g++
WIN32_CXX  := x86_64-w64-mingw32-g++
MACOSX_CXX := x86_64-apple-darwin19-clang++
endif

# WINDOWS version
ifeq ($(UNAME), MINGW64_NT-10.0)
TARGETS := $(BUILD_DIR)/hello-win64.exe
WIN32_CXX  := x86_64-w64-mingw32-g++
endif

# MACOSX version
ifeq ($(UNAME), Darwin)
TARGETS := $(BUILD_DIR)/hello-macosx.bin
MACOSX_CXX := x86_64-apple-darwin22-c++-13
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..."
	@$(LINUX_CXX) $< -o $@

$(BUILD_DIR)/hello-win64.exe: Test.cpp $$(@D)/
	@echo "Building Windows binary..."
	@$(WIN32_CXX) $< -o $@

$(BUILD_DIR)/hello-macosx.bin: Test.cpp $$(@D)/
	@echo "Building MacOSX binary..."
	ls -la /usr/lib/llvm-10/lib || true
	$(MACOSX_CXX) $< -o $@ -v -Wl,-lto_library,/usr/lib/llvm-10/lib/libLTO.so || true
	$(MACOSX_CXX) $< -o $@ -v -Wl,lto_library,/usr/lib/llvm-10/lib/libLTO.so || true
	$(MACOSX_CXX) $< -o $@ -v -O0 || true
	$(MACOSX_CXX) $< -o $@ -v -fno-lto -L/usr/lib/llvm-13/lib

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