#!/usr/bin/env bash
-# puts a tar file of the repo in the top level scratchdir
+# puts a tar file of the repo in the top level scratchdir, filename suffixed with UTC stamp from Z
set -euo pipefail
-# ensure we're in a git repo
+# 1) ensure we're in a git repo
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || {
echo "Error: not inside a git repository." >&2
exit 1
repo_top="$(git rev-parse --show-toplevel)"
repo_name="$(basename "$repo_top")"
ref_label="$(git describe --tags --always --dirty 2>/dev/null || git rev-parse --short HEAD)"
-out="${repo_top}/scratchpad/${repo_name}-${ref_label}.tar.gz"
-# create archive of HEAD (tracked files only; .gitignore’d stuff is omitted)
+# 2) ensure Z is available (prefer PATH; otherwise add repo-local RT-project-share path)
+if ! command -v Z >/dev/null 2>&1; then
+ z_guess="${repo_top}/tool_shared/third_party/RT-project-share/release/bash"
+ if [ -x "${z_guess}/Z" ]; then
+ PATH="${z_guess}:${PATH}"
+ else
+ echo "Error: required program 'Z' not found in PATH." >&2
+ echo "Hint: expected at '${z_guess}/Z' or ensure your env_* is sourced." >&2
+ exit 1
+ fi
+fi
+
+# 3) timestamp and output path
+stamp="$(Z)"
+# trim trailing newline just in case
+stamp="${stamp//$'\n'/}"
+
+mkdir -p "${repo_top}/scratchpad"
+out="${repo_top}/scratchpad/${repo_name}-${ref_label}-${stamp}.tar.gz"
+
+# 4) create archive of HEAD (tracked files only; .gitignore’d stuff omitted)
git -C "$repo_top" archive --format=tar --prefix="${repo_name}/" HEAD | gzip > "$out"
echo "Wrote ${out}"
KDIR := /lib/modules/$(shell uname -r)/build
# Use KBUILD_OUTPUT_DIR to direct Kbuild output to the scratchpad
-KBUILD_OUTPUT_DIR := $(TMPDIR)
+
+# PATH CORRECTION: Define REPO_ROOT (the Rabbit/ directory) relative to the shell's PWD.
+# Assuming PWD is the developer/ directory, REPO_ROOT is the parent directory.
+REPO_ROOT := $(dir $(PWD))
+
+# The scratchpad directory is relative to the REPO_ROOT, not the execution directory.
+KBUILD_OUTPUT_DIR := $(REPO_ROOT)/$(TMPDIR)
# Convert KBUILD_BASE_List (e.g. "no-op") into Kbuild-compatible object list (e.g. "no-op.o")
KERNEL_OBJS_M := $(addsuffix .o, $(KBUILD_BASE_List))
# Dependency: The temporary Kbuild source file (e.g. scratchpad/rabbit_module_no-op.c)
$(KBUILD_OUTPUT_DIR)/%.ko: $(KBUILD_OUTPUT_DIR)/%.c
@echo "--- Invoking Kbuild for Module: $* ---"
-
- # The Kbuild variables are passed on the command line:
- # M=$(PWD): tells Kbuild to use the project root as the source directory for relative paths.
- # O=$(KBUILD_OUTPUT_DIR): tells Kbuild where to place ALL output.
- # obj-m: specifies the single object file Kbuild must compile and link into a .ko
- $(MAKE) -C $(KDIR) M=$(PWD) O=$(KBUILD_OUTPUT_DIR) \
+ # M=$(REPO_ROOT): Tells Kbuild to look for source (cc/) relative to the project root,
+ # which is the directory containing the 'developer/' directory.
+ # O=$(KBUILD_OUTPUT_DIR): tells Kbuild where to place ALL output (scratchpad/).
+ $(MAKE) -C $(KDIR) M=$(REPO_ROOT) O=$(KBUILD_OUTPUT_DIR) \
obj-m=$*.o
# --- Rule to Create Kbuild-Compatible Source Link ---
# Kbuild expects a .c file, but our source is .mod.c and is read-only in cc/.
# Action: Copy the read-only source file to the scratchpad under the expected Kbuild name (.c).
-$(KBUILD_OUTPUT_DIR)/%.c: cc/%.mod.c
+$(KBUILD_OUTPUT_DIR)/%.c: $(REPO_ROOT)/cc/%.mod.c
@echo "--- Preparing Kbuild Source Link: $@ ---"
cp $< $@
# This target ensures that only the artifacts created by Kbuild are cleaned from the scratchpad.
clean_kernel:
@echo "--- Cleaning Kbuild Artifacts for Modules in $(KBUILD_OUTPUT_DIR) ---"
-
- # Kbuild is run from the project root (M=$(PWD)) but cleans files in the output directory (O=$(KBUILD_OUTPUT_DIR))
- # We pass obj-m to ensure Kbuild knows which modules to clean, thus only removing specific artifacts.
- $(MAKE) -C $(KDIR) M=$(PWD) O=$(KBUILD_OUTPUT_DIR) \
+ # M=$(REPO_ROOT): We use the correct project root again for Kbuild to find its context.
+ $(MAKE) -C $(KDIR) M=$(REPO_ROOT) O=$(KBUILD_OUTPUT_DIR) \
obj-m="$(KERNEL_OBJS_M)" clean