Merge pull request #7771 from thewulf7/fix/makefile-windows-support

fix: Making Makefile compilable from powershell Windows
This commit is contained in:
Nghia Doan
2026-03-23 17:04:16 +07:00
committed by GitHub

View File

@@ -6,15 +6,28 @@ REPORT_PORTAL_PROJECT_NAME ?= ""
REPORT_PORTAL_LAUNCH_NAME ?= "Jan App"
REPORT_PORTAL_DESCRIPTION ?= "Jan App report"
# Detect OS
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
else
DETECTED_OS := $(shell uname -s)
endif
ifeq ($(OS),Windows_NT)
MKDIR = if not exist "$(1)" mkdir "$(1)"
else
MKDIR = mkdir -p $(1)
endif
# Default target, does nothing
all:
@echo "Specify a target to run"
# Installs yarn dependencies and builds core and extensions
install-and-build:
ifeq ($(OS),Windows_NT)
ifeq ($(DETECTED_OS),Windows)
echo "skip"
else ifeq ($(shell uname -s),Linux)
else ifeq ($(DETECTED_OS),Linux)
chmod +x src-tauri/build-utils/*
endif
yarn install
@@ -24,7 +37,7 @@ endif
# Install required Rust targets for macOS universal builds
install-rust-targets:
ifeq ($(shell uname -s),Darwin)
ifeq ($(DETECTED_OS),Darwin)
@echo "Detected macOS, installing universal build targets..."
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
@@ -88,7 +101,7 @@ dev-android: install-and-build install-android-rust-targets
dev-ios: install-and-build install-ios-rust-targets
@echo "Setting up iOS development environment..."
ifeq ($(shell uname -s),Darwin)
ifeq ($(DETECTED_OS),Darwin)
@if [ ! -d "src-tauri/gen/ios" ]; then \
echo "iOS app not initialized. Initializing..."; \
yarn tauri ios init; \
@@ -110,7 +123,7 @@ lint: install-and-build
# Testing
test: lint install-rust-targets
yarn download:bin
ifeq ($(OS),Windows_NT)
ifeq ($(DETECTED_OS),Windows)
endif
yarn test
yarn copy:assets:tauri
@@ -124,7 +137,7 @@ endif
# Build MLX server (macOS Apple Silicon only) - always builds
build-mlx-server:
ifeq ($(shell uname -s),Darwin)
ifeq ($(DETECTED_OS),Darwin)
@echo "Building MLX server for Apple Silicon..."
cd mlx-server && swift build -c release
@echo "Copying build products..."
@@ -162,7 +175,7 @@ endif
# Build MLX server only if not already present (for dev)
build-mlx-server-if-exists:
ifeq ($(shell uname -s),Darwin)
ifeq ($(DETECTED_OS),Darwin)
@if [ -f "src-tauri/resources/bin/mlx-server" ]; then \
echo "MLX server already exists at src-tauri/resources/bin/mlx-server, skipping build..."; \
else \
@@ -174,7 +187,7 @@ endif
# Build jan CLI (release, platform-aware) → src-tauri/resources/bin/jan[.exe]
build-cli:
ifeq ($(shell uname -s),Darwin)
ifeq ($(DETECTED_OS),Darwin)
cd src-tauri && cargo build --release --features cli --bin jan-cli --target aarch64-apple-darwin
cd src-tauri && cargo build --release --features cli --bin jan-cli --target x86_64-apple-darwin
lipo -create \
@@ -182,7 +195,7 @@ ifeq ($(shell uname -s),Darwin)
src-tauri/target/x86_64-apple-darwin/release/jan-cli \
-output src-tauri/resources/bin/jan-cli
chmod +x src-tauri/resources/bin/jan-cli
mkdir -p src-tauri/target/universal-apple-darwin/release
$(call MKDIR,'src-tauri/target/universal-apple-darwin/release')
echo "Checking for code signing identity..."; \
SIGNING_IDENTITY=$$(security find-identity -v -p codesigning | grep "Developer ID Application" | head -1 | sed 's/.*"\(.*\)".*/\1/'); \
@@ -195,7 +208,7 @@ ifeq ($(shell uname -s),Darwin)
fi
cp src-tauri/resources/bin/jan-cli src-tauri/target/universal-apple-darwin/release/jan-cli
else ifeq ($(OS),Windows_NT)
else ifeq ($(DETECTED_OS),Windows)
cd src-tauri && cargo build --release --features cli --bin jan-cli
cp src-tauri/target/release/jan-cli.exe src-tauri/resources/bin/jan-cli.exe
else
@@ -205,16 +218,20 @@ endif
# Debug build for local dev (faster, native arch only)
build-cli-dev:
mkdir -p src-tauri/resources/bin
$(call MKDIR,'src-tauri/resources/bin')
cd src-tauri && cargo build --features cli --bin jan-cli
ifeq ($(DETECTED_OS),Windows)
copy src-tauri\target\debug\jan-cli.exe src-tauri\resources\bin\jan-cli.exe
else
install -m755 src-tauri/target/debug/jan-cli src-tauri/resources/bin/jan-cli
endif
# Build
build: install-and-build install-rust-targets
yarn build
clean:
ifeq ($(OS),Windows_NT)
ifeq ($(DETECTED_OS),Windows)
-powershell -Command "Get-ChildItem -Path . -Include node_modules, .next, dist, build, out, .turbo, .yarn -Recurse -Directory | Remove-Item -Recurse -Force"
-powershell -Command "Get-ChildItem -Path . -Include package-lock.json, tsconfig.tsbuildinfo -Recurse -File | Remove-Item -Recurse -Force"
-powershell -Command "Remove-Item -Recurse -Force ./pre-install/*.tgz"
@@ -223,7 +240,7 @@ ifeq ($(OS),Windows_NT)
-powershell -Command "Remove-Item -Recurse -Force ./src-tauri/resources"
-powershell -Command "Remove-Item -Recurse -Force ./src-tauri/target"
-powershell -Command "if (Test-Path \"$($env:USERPROFILE)\jan\extensions\") { Remove-Item -Path \"$($env:USERPROFILE)\jan\extensions\" -Recurse -Force }"
else ifeq ($(shell uname -s),Linux)
else ifeq ($(DETECTED_OS),Linux)
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
find . -name ".next" -type d -exec rm -rf '{}' +
find . -name "dist" -type d -exec rm -rf '{}' +