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) "
0 commit comments