bhcli

A TUI for chatting on LE PHP Chats
git clone https://git.dasho.dev/bhcli.git
Log | Files | Refs | README

Makefile (9772B)


      1 # BHCLI Makefile - Modern Cargo-based build system
      2 # Works with both rustup and system-installed Rust (Homebrew, apt, etc.)
      3 
      4 .PHONY: help build release install clean test check fmt clippy \
      5        build-linux build-macos build-windows build-all \
      6        setup-targets install-rust-targets
      7 
      8 # Default target
      9 help:
     10 @echo "BHCLI Build System"
     11 @echo "=================="
     12 @echo ""
     13 @echo "Development:"
     14 @echo "  make build          - Debug build for current platform"
     15 @echo "  make release        - Optimized release build"
     16 @echo "  make install        - Install to ~/.cargo/bin"
     17 @echo "  make test           - Run all tests"
     18 @echo "  make check          - Check code without building"
     19 @echo "  make fmt            - Format code with rustfmt"
     20 @echo "  make clippy         - Run clippy linter"
     21 @echo "  make clean          - Clean build artifacts"
     22 @echo ""
     23 @echo "Building:"
     24 @echo "  make build-local         - Optimized build for current platform (with audio)"
     25 @echo "  make build-linux-musl    - Static Linux binary (no audio, portable)"
     26 @echo "  make build-windows       - Windows binary (no audio, portable)"
     27 @echo "  make build-all           - Build for all available platforms"
     28 @echo ""
     29 @echo "Features:"
     30 @echo "  make build-no-audio      - Build current platform without audio"
     31 @echo "  make build-linux-audio   - Linux build with audio (native only)"
     32 @echo ""
     33 @echo "Setup (if using rustup):"
     34 @echo "  make setup-targets       - Install cross-compile targets"
     35 @echo "  make show-targets        - Show installed targets"
     36 @echo ""
     37 
     38 # Detect if rustup is available
     39 RUSTUP_EXISTS := $(shell command -v rustup 2> /dev/null)
     40 
     41 # Development builds
     42 build:
     43 cargo build
     44 
     45 release:
     46 cargo build --release
     47 
     48 # Install to system
     49 install:
     50 cargo install --path .
     51 
     52 # Testing and verification
     53 test:
     54 cargo test --all-features
     55 
     56 check:
     57 cargo check --all-features
     58 
     59 fmt:
     60 cargo fmt --all
     61 
     62 clippy:
     63 cargo clippy --all-features -- -D warnings
     64 
     65 clean:
     66 cargo clean
     67 rm -rf dist/
     68 
     69 # Feature variants
     70 build-no-audio:
     71 cargo build --release --no-default-features
     72 
     73 # Setup cross-compilation targets (only works with rustup)
     74 setup-targets:
     75 ifdef RUSTUP_EXISTS
     76 @echo "Installing Rust cross-compilation targets..."
     77 @echo ""
     78 rustup target add x86_64-unknown-linux-musl || true
     79 rustup target add x86_64-pc-windows-gnu || true
     80 @echo ""
     81 @echo "✓ Targets installed"
     82 @echo ""
     83 @echo "Note: For full cross-compilation you may also need:"
     84 @echo "  - musl-tools (Linux): apt install musl-tools"
     85 @echo "  - mingw-w64 (Windows): apt install mingw-w64"
     86 @echo ""
     87 else
     88 @echo "Rustup not found. You have a system Rust installation."
     89 @echo ""
     90 @echo "Cross-compilation targets are typically not needed with system Rust."
     91 @echo "Just use 'make release' to build for your current platform."
     92 @echo ""
     93 @echo "If you need cross-compilation, consider using rustup:"
     94 @echo "  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
     95 @echo ""
     96 endif
     97 
     98 install-rust-targets: setup-targets
     99 
    100 # Build for current platform (works with any Rust installation)
    101 build-local:
    102 @echo "Building optimized binary for current platform..."
    103 @echo "(With audio support)"
    104 @mkdir -p dist
    105 cargo build --release
    106 @cp target/release/bhcli dist/bhcli-local 2>/dev/null || \
    107 	cp target/release/bhcli.exe dist/bhcli-local.exe 2>/dev/null || \
    108 	echo "Warning: Could not copy binary to dist/"
    109 @echo "✓ Binary created in dist/ (with audio support)"
    110 @ls -lh dist/bhcli-* 2>/dev/null || ls -lh target/release/bhcli* 2>/dev/null
    111 
    112 # Check if a specific target is available
    113 check-target-musl:
    114 ifdef RUSTUP_EXISTS
    115 @rustup target list | grep -q "x86_64-unknown-linux-musl (installed)" || \
    116 	(echo "Target not installed. Run: make setup-targets" && exit 1)
    117 else
    118 @echo "Attempting build without rustup target checking..."
    119 endif
    120 
    121 check-target-windows:
    122 ifdef RUSTUP_EXISTS
    123 @rustup target list | grep -q "x86_64-pc-windows-gnu (installed)" || \
    124 	(echo "Target not installed. Run: make setup-targets" && exit 1)
    125 else
    126 @echo "Attempting build without rustup target checking..."
    127 endif
    128 
    129 # Cross-platform builds
    130 build-linux-musl:
    131 @echo "Building static Linux binary (x86_64-musl)..."
    132 @echo "(Building without audio for portability)"
    133 @mkdir -p dist
    134 @if cargo build --release --target x86_64-unknown-linux-musl --no-default-features 2>/dev/null; then \
    135 	cp target/x86_64-unknown-linux-musl/release/bhcli dist/bhcli-linux-x86_64 && \
    136 	echo "✓ Linux binary created: dist/bhcli-linux-x86_64" && \
    137 	echo "  Note: Audio disabled for maximum compatibility"; \
    138 else \
    139 	echo ""; \
    140 	echo "Cross-compilation to x86_64-unknown-linux-musl failed."; \
    141 	echo ""; \
    142 	if [ -n "$(RUSTUP_EXISTS)" ]; then \
    143 		echo "You may need:"; \
    144 		echo "  1. rustup target add x86_64-unknown-linux-musl"; \
    145 		echo "  2. apt install musl-tools (on Linux)"; \
    146 	else \
    147 		echo "Your system Rust may not support this target."; \
    148 		echo "Consider using rustup for cross-compilation."; \
    149 	fi; \
    150 	echo ""; \
    151 	exit 1; \
    152 fi
    153 
    154 # Linux build with audio (for native compilation)
    155 build-linux-audio:
    156 @echo "Building Linux binary with audio support..."
    157 @mkdir -p dist
    158 cargo build --release
    159 @cp target/release/bhcli dist/bhcli-linux-audio
    160 @echo "✓ Linux binary with audio: dist/bhcli-linux-audio"
    161 
    162 build-macos:
    163 @echo "Building macOS binary..."
    164 @mkdir -p dist
    165 @if cargo build --release 2>/dev/null; then \
    166 	cp target/release/bhcli dist/bhcli-macos && \
    167 	echo "✓ macOS binary created: dist/bhcli-macos"; \
    168 else \
    169 	echo "Build failed"; \
    170 	exit 1; \
    171 fi
    172 
    173 build-windows:
    174 @echo "Building Windows binary..."
    175 @echo "(Building without audio for portability)"
    176 @mkdir -p dist
    177 @if cargo build --release --target x86_64-pc-windows-gnu --no-default-features 2>/dev/null; then \
    178 	cp target/x86_64-pc-windows-gnu/release/bhcli.exe dist/bhcli-windows-x86_64.exe && \
    179 	echo "✓ Windows binary created: dist/bhcli-windows-x86_64.exe" && \
    180 	echo "  Note: Audio disabled for maximum compatibility"; \
    181 else \
    182 	echo ""; \
    183 	echo "Cross-compilation to Windows failed."; \
    184 	echo ""; \
    185 	if [ -n "$(RUSTUP_EXISTS)" ]; then \
    186 		echo "You may need:"; \
    187 		echo "  1. rustup target add x86_64-pc-windows-gnu"; \
    188 		echo "  2. apt install mingw-w64 (on Linux)"; \
    189 	else \
    190 		echo "Your system Rust may not support this target."; \
    191 		echo "Consider using rustup for cross-compilation."; \
    192 	fi; \
    193 	echo ""; \
    194 	exit 1; \
    195 fi
    196 
    197 # Build for all supported platforms
    198 build-all:
    199 @echo "Building for all available platforms..."
    200 @echo ""
    201 @mkdir -p dist
    202 @BUILD_SUCCESS=0; \
    203 echo "Attempting Linux static build..."; \
    204 if $(MAKE) build-linux-musl 2>/dev/null; then \
    205 	BUILD_SUCCESS=1; \
    206 else \
    207 	echo "⚠ Linux build skipped (target not available)"; \
    208 fi; \
    209 echo ""; \
    210 echo "Attempting Windows build..."; \
    211 if $(MAKE) build-windows 2>/dev/null; then \
    212 	BUILD_SUCCESS=1; \
    213 else \
    214 	echo "⚠ Windows build skipped (target not available)"; \
    215 fi; \
    216 echo ""; \
    217 echo "Building for current platform..."; \
    218 $(MAKE) build-local; \
    219 BUILD_SUCCESS=1; \
    220 echo ""; \
    221 echo "========================================="; \
    222 echo "Build complete!"; \
    223 echo "========================================="; \
    224 ls -lh dist/ 2>/dev/null || echo "Binaries in target/release/"
    225 
    226 # Distribution packages
    227 dist:
    228 @echo "Creating distribution packages..."
    229 @mkdir -p dist
    230 @$(MAKE) build-all
    231 @if [ -f dist/bhcli-linux-x86_64 ]; then \
    232 	cd dist && tar -czf bhcli-linux-x86_64.tar.gz bhcli-linux-x86_64 && \
    233 	echo "✓ Created bhcli-linux-x86_64.tar.gz"; \
    234 fi
    235 @if [ -f dist/bhcli-windows-x86_64.exe ]; then \
    236 	cd dist && zip -q bhcli-windows-x86_64.zip bhcli-windows-x86_64.exe && \
    237 	echo "✓ Created bhcli-windows-x86_64.zip"; \
    238 fi
    239 @if [ -f dist/bhcli-local ]; then \
    240 	cd dist && tar -czf bhcli-local.tar.gz bhcli-local && \
    241 	echo "✓ Created bhcli-local.tar.gz"; \
    242 fi
    243 @echo ""
    244 @echo "Distribution packages:"
    245 @ls -lh dist/*.tar.gz dist/*.zip 2>/dev/null || echo "No packages created"
    246 
    247 # Verify release build
    248 verify-release:
    249 @echo "Verifying release build..."
    250 @cargo build --release
    251 @echo "✓ Release build successful"
    252 @echo ""
    253 @echo "Binary location:"
    254 @ls -lh target/release/bhcli* 2>/dev/null || echo "Check target/release/"
    255 
    256 # Development helpers
    257 watch:
    258 @command -v cargo-watch >/dev/null 2>&1 || \
    259 	(echo "cargo-watch not installed. Install with: cargo install cargo-watch" && exit 1)
    260 cargo watch -x 'check --all-features' -x 'test --all-features'
    261 
    262 run:
    263 cargo run --release
    264 
    265 # Cargo commands wrapped for convenience
    266 update:
    267 cargo update
    268 
    269 doc:
    270 cargo doc --no-deps --open
    271 
    272 # Show installed targets (if using rustup)
    273 show-targets:
    274 ifdef RUSTUP_EXISTS
    275 @echo "Installed Rust targets:"
    276 @rustup target list | grep installed
    277 else
    278 @echo "Rustup not found. You have a system Rust installation."
    279 @echo ""
    280 @echo "Your Rust compiler:"
    281 @rustc --version
    282 @echo ""
    283 @echo "Your Cargo version:"
    284 @cargo --version
    285 @echo ""
    286 @echo "System Rust typically supports your native platform only."
    287 @echo "For cross-compilation, consider using rustup."
    288 endif
    289 
    290 # Show Rust installation info
    291 rust-info:
    292 @echo "Rust Installation Information"
    293 @echo "=============================="
    294 @echo ""
    295 @echo "Rustc version:"
    296 @rustc --version
    297 @echo ""
    298 @echo "Cargo version:"
    299 @cargo --version
    300 @echo ""
    301 ifdef RUSTUP_EXISTS
    302 @echo "Rustup version:"
    303 @rustup --version
    304 @echo ""
    305 @echo "Active toolchain:"
    306 @rustup show active-toolchain
    307 @echo ""
    308 @echo "Installed targets:"
    309 @rustup target list | grep installed
    310 else
    311 @echo "Installation type: System Rust (Homebrew, apt, or other)"
    312 @echo ""
    313 @echo "Note: System Rust installations typically support your"
    314 @echo "      native platform only. For cross-compilation, consider"
    315 @echo "      using rustup."
    316 endif
    317 @echo ""
    318 @echo "To check if cross-compilation works, try:"
    319 @echo "  make build-all"