spo/ass2/simulator_SIC_XE/Makefile
2025-12-07 11:33:03 +01:00

68 lines
2 KiB
Makefile

# Simple Makefile wrapper to configure, build and run the CMake project.
# Usage:
# make # configure + build with all cores
# make build # configure + build with all cores
# make all # clean + configure + build + run
# make run # just run the executable (no build)
# make clean # run CMake clean (or remove build files)
# make distclean # remove build dir and generated targets
CMAKE ?= cmake
BUILD_DIR := build
CMAKE_BUILD_TYPE ?= Release
TARGET := target/bin/simulator_exec
GUI_TARGET := target/bin/simulator_qt
NPROC := $(shell nproc)
.PHONY: all configure build run clean distclean
# Default target: just build
default: build
# make all: clean, build, then run
all: clean build run
configure:
@echo "Configuring (build dir: $(BUILD_DIR), type: $(CMAKE_BUILD_TYPE))"
$(CMAKE) -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE)
build: configure
@echo "Building with $(NPROC) cores..."
$(CMAKE) --build $(BUILD_DIR) -j$(NPROC)
# make run: just launch the executable (no build)
run:
@echo "Running primary target..."
# Prefer GUI if available, otherwise fall back to console executable
@if [ -x "$(GUI_TARGET)" ]; then \
echo "Launching GUI: $(GUI_TARGET)"; \
./$(GUI_TARGET); \
elif [ -x "$(TARGET)" ]; then \
./$(TARGET); \
else \
echo "No runnable target found (tried $(GUI_TARGET) and $(TARGET))."; exit 1; \
fi
.PHONY: run-gui
run-gui: build
@echo "Running GUI target ($(GUI_TARGET))"
@if [ -x "$(GUI_TARGET)" ]; then \
echo "Starting GUI..."; ./$(GUI_TARGET) -platform xcb; \
else \
echo "GUI executable not found: $(GUI_TARGET)"; exit 1; \
fi
.PHONY: build-gui
build-gui: configure
@echo "Building GUI (and core)..."
$(CMAKE) --build $(BUILD_DIR) -j$(shell nproc) --target simulator_qt || true
clean:
@echo "Cleaning build (CMake clean)..."
-$(CMAKE) --build $(BUILD_DIR) --target clean || true
@echo "Removing target directory..."
-rm -rf target/
distclean:
@echo "Removing build artifacts and generated files..."
-rm -rf $(BUILD_DIR) CMakeFiles CMakeCache.txt cmake_install.cmake target/