#!/usr/bin/env bash
set -euo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"

build_dir=$(mktemp -d /tmp/ebpf-hello.XXXXXX)
clang -target bpf -O2 -g -Wall -I"/usr/include/$(clang -dumpmachine | sed 's/-pc-/-/')" \
    $(pkg-config --cflags libbpf) -c hello.bpf.c -o "$build_dir/hello.bpf.o"
bpftool gen skeleton "$build_dir/hello.bpf.o" > "$build_dir/hello.skel.h"
clang -O2 -Wall -I"$build_dir" hello.c -o "$build_dir/hello" \
    $(pkg-config --cflags --libs libbpf)
sudo "$build_dir/hello"
