-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (86 loc) · 3.45 KB
/
Copy pathMakefile
File metadata and controls
100 lines (86 loc) · 3.45 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
.PHONY: all build core ffi windows windows-debug linux macos clean info
# ============================================================================
# Detect Operating System
# ============================================================================
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
# No -G hardcode: let CMake auto-detect the newest installed Visual
# Studio (VS2022, VS2026, whatever comes next). Hardcoding the
# generator name breaks the moment GitHub/local toolchain migrates
# to a newer VS (e.g. "Visual Studio 17 2022" -> "Visual Studio 18 2026").
CMAKE_GENERATOR_FLAG :=
MAKE_COMMAND := cmake --build build --config Release
LIB_PREFIX :=
LIB_SUFFIX := .dll
LIB_DIR := build/bin/Release
LIB_DIR_DEBUG := build/bin/Debug
else
DETECTED_OS := $(shell uname -s)
CMAKE_GENERATOR_FLAG := -G "Unix Makefiles"
LIB_PREFIX := lib
LIB_DIR := build
LIB_DIR_DEBUG := build
ifeq ($(DETECTED_OS),Darwin)
NPROC := $(shell sysctl -n hw.ncpu)
LIB_SUFFIX := .dylib
else
NPROC := $(shell nproc)
LIB_SUFFIX := .so
endif
MAKE_COMMAND := cd build && $(MAKE) -j$(NPROC)
endif
all: build
# ============================================================================
# General CMake Configuration (Release)
# ============================================================================
cmake-configure:
mkdir -p build
cd build && cmake $(CMAKE_GENERATOR_FLAG) -DCMAKE_BUILD_TYPE=Release ..
@echo "CMake configured for $(DETECTED_OS)"
build: cmake-configure
$(MAKE_COMMAND)
@echo "Build complete for $(DETECTED_OS)"
@echo "Library location: $(LIB_DIR)/$(LIB_PREFIX)bclibc_ffi$(LIB_SUFFIX)"
core: cmake-configure
cmake --build build --target bclibc_core --config Release
@echo "Core library built"
ffi: cmake-configure
cmake --build build --target bclibc_ffi --config Release
@echo "FFI library built"
# ============================================================================
# Windows Specific Targets
# ============================================================================
windows: cmake-configure
cmake --build build --config Release
@echo "Windows build complete"
@echo "DLL location: build/bin/Release/bclibc_ffi.dll"
@echo "LIB location: build/lib/Release/bclibc_ffi.lib"
windows-debug:
mkdir -p build
cd build && cmake $(CMAKE_GENERATOR_FLAG) -DCMAKE_BUILD_TYPE=Debug ..
cmake --build build --config Debug
@echo "Windows Debug build complete"
@echo "DLL location: build/bin/Debug/bclibc_ffi.dll"
# ============================================================================
# Linux Specific Targets
# ============================================================================
linux: cmake-configure
cd build && $(MAKE) -j$(NPROC)
@echo "Linux build complete"
# ============================================================================
# macOS Specific Targets
# ============================================================================
macos: cmake-configure
cd build && $(MAKE) -j$(NPROC)
@echo "macOS build complete"
clean:
rm -rf build
@echo "Cleaned build directory"
# ============================================================================
# Additional Target for Inspection / Debugging
# ============================================================================
info:
@echo "Detected OS: $(DETECTED_OS)"
@echo "CMake generator flag: $(CMAKE_GENERATOR_FLAG)"
@echo "Library prefix: $(LIB_PREFIX)"
@echo "Library suffix: $(LIB_SUFFIX)"