|
| 1 | +ifeq ($(OS),Windows_NT) |
| 2 | + DETECTED_OS := Windows |
| 3 | +else |
| 4 | + UNAME_S := $(shell uname -s) |
| 5 | + ifeq ($(UNAME_S),Linux) |
| 6 | + DETECTED_OS := Linux |
| 7 | + endif |
| 8 | + ifeq ($(UNAME_S),Darwin) |
| 9 | + DETECTED_OS := macOS |
| 10 | + endif |
| 11 | +endif |
| 12 | + |
| 13 | +BUILD_DIR := build |
| 14 | +INSTALL_DIR := install |
| 15 | +NATIVE_DIR := native |
| 16 | + |
| 17 | +.PHONY: build clean install-deps install-dir |
| 18 | + |
| 19 | +build: install-deps |
| 20 | +ifeq ($(DETECTED_OS),macOS) |
| 21 | + @echo "Building for macOS..." |
| 22 | + @echo "Configuring CMake..." |
| 23 | + cmake -B $(BUILD_DIR) \ |
| 24 | + -DCMAKE_CXX_COMPILER=clang++ \ |
| 25 | + -DCMAKE_C_COMPILER=clang \ |
| 26 | + -DCMAKE_BUILD_TYPE=Release \ |
| 27 | + -DCMAKE_OSX_DEPLOYMENT_TARGET=13.3 \ |
| 28 | + -DCMAKE_MACOSX_RPATH=ON \ |
| 29 | + -DCMAKE_INSTALL_RPATH='@executable_path/../lib' \ |
| 30 | + -DGGML_NATIVE=OFF \ |
| 31 | + -DGGML_OPENMP=OFF \ |
| 32 | + -DLLAMA_CURL=OFF \ |
| 33 | + -GNinja \ |
| 34 | + -S $(NATIVE_DIR) |
| 35 | + @echo "Building..." |
| 36 | + cmake --build $(BUILD_DIR) --config Release |
| 37 | + @echo "Installing..." |
| 38 | + cmake --install $(BUILD_DIR) \ |
| 39 | + --config Release \ |
| 40 | + --prefix $(INSTALL_DIR) |
| 41 | + @echo "Cleaning install directory..." |
| 42 | + rm -rf $(INSTALL_DIR)/lib/cmake |
| 43 | + rm -rf $(INSTALL_DIR)/lib/pkgconfig |
| 44 | + rm -rf $(INSTALL_DIR)/include |
| 45 | + @echo "Build complete! Binaries are in $(INSTALL_DIR)" |
| 46 | +else ifeq ($(DETECTED_OS),Linux) |
| 47 | + @echo "Linux build not implemented yet" |
| 48 | + @exit 1 |
| 49 | +else ifeq ($(DETECTED_OS),Windows) |
| 50 | + @echo "Windows build not implemented yet" |
| 51 | + @exit 1 |
| 52 | +else |
| 53 | + @echo "Unsupported OS: $(DETECTED_OS)" |
| 54 | + @exit 1 |
| 55 | +endif |
| 56 | + |
| 57 | +install-deps: |
| 58 | +ifeq ($(DETECTED_OS),macOS) |
| 59 | + @echo "Installing build dependencies for macOS..." |
| 60 | + @if ! command -v ninja >/dev/null 2>&1; then \ |
| 61 | + echo "Installing Ninja..."; \ |
| 62 | + brew install ninja; \ |
| 63 | + else \ |
| 64 | + echo "Ninja already installed"; \ |
| 65 | + fi |
| 66 | +else ifeq ($(DETECTED_OS),Linux) |
| 67 | + @echo "Linux dependency installation not implemented yet" |
| 68 | + @exit 1 |
| 69 | +else ifeq ($(DETECTED_OS),Windows) |
| 70 | + @echo "Windows dependency installation not implemented yet" |
| 71 | + @exit 1 |
| 72 | +else |
| 73 | + @echo "Unsupported OS: $(DETECTED_OS)" |
| 74 | + @exit 1 |
| 75 | +endif |
| 76 | + |
| 77 | +clean: |
| 78 | + rm -rf $(BUILD_DIR) |
| 79 | + rm -rf $(INSTALL_DIR) |
| 80 | + |
| 81 | +install-dir: |
| 82 | + @echo "$(INSTALL_DIR)" |
| 83 | + |
| 84 | +help: |
| 85 | + @echo "Available targets:" |
| 86 | + @echo " build - Build llama.cpp (macOS only for now)" |
| 87 | + @echo " install-deps - Install build dependencies" |
| 88 | + @echo " install-dir - Print install directory path" |
| 89 | + @echo " clean - Clean build artifacts" |
| 90 | + @echo " help - Show this help" |
0 commit comments