|
| 1 | +# Makefile for BitSwing |
| 2 | + |
| 3 | +# Project directories |
| 4 | +BPF_DIR := bpf |
| 5 | +USER_DIR := user |
| 6 | + |
| 7 | +# BPF build output (assuming a release build) |
| 8 | +BPF_TARGET := $(BPF_DIR)/target/bpfel-unknown-none/release/bitswing-bpf |
| 9 | + |
| 10 | +# User-space binary (release build) |
| 11 | +USER_TARGET := $(USER_DIR)/target/release/bitswing-user |
| 12 | + |
| 13 | +# If you need a special Docker image to cross-compile eBPF, set it here: |
| 14 | +AYA_BUILDER_IMAGE := ghcr.io/aya-rs/aya-builder-x86_64-unknown-linux-gnu:latest |
| 15 | + |
| 16 | +# Phony targets don't correspond to actual files |
| 17 | +.PHONY: all bpf user clean run install |
| 18 | + |
| 19 | +## Default target: build everything |
| 20 | +all: bpf user |
| 21 | + |
| 22 | +## Build the BPF crate |
| 23 | +bpf: |
| 24 | + # Option 1: Native build (requires rustup target add bpfel-unknown-none) |
| 25 | + # cd $(BPF_DIR) && cargo build --release --target bpfel-unknown-none |
| 26 | + # |
| 27 | + # Option 2: Use Docker-based builder (uncomment if you use aya-builder) |
| 28 | + # docker run --rm -v $(shell pwd):/workdir -w /workdir/$(BPF_DIR) \ |
| 29 | + # $(AYA_BUILDER_IMAGE) cargo build --release --target bpfel-unknown-none |
| 30 | + # |
| 31 | + # For now, we'll assume local native build: |
| 32 | + cd $(BPF_DIR) && cargo build --release --target bpfel-unknown-none |
| 33 | + |
| 34 | +## Build the user-space crate |
| 35 | +user: |
| 36 | + cd $(USER_DIR) && cargo build --release |
| 37 | + |
| 38 | +## Clean all build artifacts |
| 39 | +clean: |
| 40 | + cd $(BPF_DIR) && cargo clean |
| 41 | + cd $(USER_DIR) && cargo clean |
| 42 | + |
| 43 | +## Run the user-space binary (requires sudo if attaching XDP) |
| 44 | +run: all |
| 45 | + @echo "Running BitSwing user-space daemon..." |
| 46 | + sudo $(USER_TARGET) |
| 47 | + |
| 48 | +## Optional: Install the user binary (and optionally the BPF bytecode) to /usr/local/bin |
| 49 | +install: all |
| 50 | + @echo "Installing user binary to /usr/local/bin..." |
| 51 | + sudo cp $(USER_TARGET) /usr/local/bin/bitswing |
| 52 | + @echo "Installing BPF bytecode to /usr/local/lib/bitswing/..." |
| 53 | + sudo mkdir -p /usr/local/lib/bitswing |
| 54 | + sudo cp $(BPF_TARGET) /usr/local/lib/bitswing/bitswing-bpf |
| 55 | + @echo "Install complete." |
0 commit comments