Skip to content

Commit 286e731

Browse files
authored
add Makefile for Windows, Linux, MacOS build (#16)
* Add makefile * Add makefile * Add windows makefile * Add windows makefile * remove unc build
1 parent 0d6c30e commit 286e731

4 files changed

Lines changed: 78 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "phosphor"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55
description = "Phosphor — a SID player for USBSID-Pico"
66

Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
SHELL := /bin/bash
2+
3+
APP_NAME := Phosphor
4+
BIN_NAME := phosphor
5+
DIST_DIR := dist
6+
7+
# Extract version from Cargo.toml
8+
VERSION := $(shell sed -n 's/^version[[:space:]]*=[[:space:]]*"\(.*\)"/\1/p' Cargo.toml | head -n 1)
9+
10+
UNAME_S := $(shell uname -s)
11+
12+
MAC_OUT := $(DIST_DIR)/$(APP_NAME)-$(VERSION)-macOS.pkg
13+
LIN_OUT := $(DIST_DIR)/$(APP_NAME)-$(VERSION)-linux-amd64.deb
14+
15+
.PHONY: help clean dist linux_deb macos_pkg
16+
17+
help:
18+
@echo "Targets:"
19+
@echo " make linux_deb - build .deb via cargo deb"
20+
@echo " make macos_pkg - rename/copy macOS pkg"
21+
@echo " make dist - build for current OS"
22+
@echo " make clean"
23+
@echo ""
24+
@echo "Detected OS=$(UNAME_S) VERSION=$(VERSION)"
25+
26+
clean:
27+
rm -rf $(DIST_DIR)
28+
29+
dist:
30+
@mkdir -p $(DIST_DIR)
31+
@if [[ "$(UNAME_S)" == "Linux" ]]; then \
32+
$(MAKE) linux_deb; \
33+
elif [[ "$(UNAME_S)" == "Darwin" ]]; then \
34+
$(MAKE) macos_pkg; \
35+
else \
36+
echo "Unsupported OS for this Makefile"; exit 1; \
37+
fi
38+
39+
# -----------------------
40+
# Linux
41+
# -----------------------
42+
linux_deb:
43+
@if [[ "$(UNAME_S)" != "Linux" ]]; then echo "Run this on Linux"; exit 1; fi
44+
@mkdir -p $(DIST_DIR)
45+
cargo deb
46+
@DEB_PATH=$$(ls -1 target/debian/*.deb | head -n 1); \
47+
cp "$$DEB_PATH" "$(LIN_OUT)"; \
48+
echo "Built: $(LIN_OUT)"
49+
50+
# -----------------------
51+
# macOS
52+
# -----------------------
53+
macos_pkg:
54+
@if [[ "$(UNAME_S)" != "Darwin" ]]; then echo "Run this on macOS"; exit 1; fi
55+
@mkdir -p $(DIST_DIR)
56+
@if [[ -z "$${PKG_IN:-}" ]]; then \
57+
echo "Usage:"; \
58+
echo "make macos_pkg PKG_IN=path/to/pkg"; \
59+
exit 1; \
60+
fi
61+
cp "$$PKG_IN" "$(MAC_OUT)"
62+
@echo "Built: $(MAC_OUT)"

Makefile.windows

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
APP_NAME = Phosphor
2+
BIN_NAME = phosphor
3+
DIST_DIR = dist
4+
5+
SHELL := powershell.exe
6+
.SHELLFLAGS := -NoProfile -ExecutionPolicy Bypass -Command
7+
8+
.PHONY: windows clean
9+
10+
windows:
11+
$$ErrorActionPreference='Stop'; $$toml=Get-Content 'Cargo.toml' -Raw; $$m=[regex]::Match($$toml,'(?m)^version\s*=\s*"([^"]+)"'); $$ver=$$m.Groups[1].Value; New-Item -ItemType Directory -Force -Path '$(DIST_DIR)' | Out-Null; cargo build --release; $$out=Join-Path '$(DIST_DIR)' ('$(APP_NAME)-'+$$ver+'-windows-x86_64.exe'); Copy-Item 'target\release\$(BIN_NAME).exe' $$out -Force; Write-Host ('Built: '+$$out)
12+
13+
clean:
14+
if (Test-Path "$(DIST_DIR)") { Remove-Item -Recurse -Force "$(DIST_DIR)" }

0 commit comments

Comments
 (0)