-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
86 lines (74 loc) · 2.82 KB
/
Copy pathMakefile
File metadata and controls
86 lines (74 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Makefile for Weather CLI (C++)
# Works on Windows (mingw32-make), macOS, and Linux.
#
# Usage:
# make build Build debug (default)
# make release Build release
# make test Run unit tests
# make run CITY=Paris Run the app (default city: London)
# make clean Remove build directory
# make help Show all targets
#
# Windows (MinGW): use mingw32-make instead of make
# mingw32-make build
# mingw32-make test
.PHONY: help build debug release test run clean
BUILD_DIR ?= build
CITY ?= London
# ---------------------------------------------------------------------------
# OS detection
# ---------------------------------------------------------------------------
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
CMAKE_GENERATOR := -G "Unix Makefiles" -DCMAKE_CXX_COMPILER=g++ -DCMAKE_MAKE_PROGRAM=mingw32-make
EXE_SUFFIX := .exe
RM_CMD := cmd /c "taskkill /f /im weather_cli.exe >nul 2>&1 & timeout /t 1 >nul 2>&1 & rmdir /s /q $(BUILD_DIR) >nul 2>&1 & exit /b 0"
NPROC := 4
else
DETECTED_OS := $(shell uname -s)
CMAKE_GENERATOR :=
EXE_SUFFIX :=
RM_CMD := rm -rf $(BUILD_DIR)
ifeq ($(DETECTED_OS),Darwin)
NPROC := $(shell sysctl -n hw.ncpu)
else
NPROC := $(shell nproc 2>/dev/null || echo 4)
endif
endif
# ---------------------------------------------------------------------------
# Targets
# ---------------------------------------------------------------------------
help:
@echo "Weather CLI (C++) - Build Targets"
@echo "=================================="
@echo ""
@echo " make build Build debug (default)"
@echo " make release Build optimized release"
@echo " make test Build and run all tests"
@echo " make run CITY=<name> Run the app (default: London)"
@echo " make clean Remove build directory"
@echo ""
@echo "Windows: replace make with mingw32-make"
@echo "Detected OS: $(DETECTED_OS)"
@echo ""
# Configure only if cache missing
$(BUILD_DIR)/CMakeCache.txt:
cmake -B $(BUILD_DIR) $(CMAKE_GENERATOR) -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
debug: $(BUILD_DIR)/CMakeCache.txt
cmake --build $(BUILD_DIR) -j$(NPROC)
@echo "Build complete: $(BUILD_DIR)/weather_cli$(EXE_SUFFIX)"
build: debug
release:
cmake -B $(BUILD_DIR) $(CMAKE_GENERATOR) -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON
cmake --build $(BUILD_DIR) -j$(NPROC)
@echo "Release build complete: $(BUILD_DIR)/weather_cli$(EXE_SUFFIX)"
test: $(BUILD_DIR)/CMakeCache.txt
cmake --build $(BUILD_DIR) -j$(NPROC)
ctest --test-dir $(BUILD_DIR) -C Debug --output-on-failure
@echo "All tests passed"
run: $(BUILD_DIR)/CMakeCache.txt
cmake --build $(BUILD_DIR) -j$(NPROC)
$(BUILD_DIR)/weather_cli$(EXE_SUFFIX) "$(CITY)"
clean:
$(RM_CMD)
@echo "Cleaned $(BUILD_DIR)"