use shebang recipes for conditional dependencies instead of inline templating
This commit is contained in:
125
justfile
125
justfile
@ -157,9 +157,41 @@ LINUX_BAREMETAL_INCLUDES := f"\
|
|||||||
|
|
||||||
# TODO: Grave mistake to template the commands depending on the target... Should've used shebang recipes instead
|
# TODO: Grave mistake to template the commands depending on the target... Should've used shebang recipes instead
|
||||||
|
|
||||||
|
[private]
|
||||||
|
build-wasm-host-fail module:
|
||||||
|
{{ CROSS_CC }} {{ CROSS_CFLAGS }} {{ CROSS_INCLUDES }} \
|
||||||
|
-c {{ BUILD_DIR }}-{{ module }}/module_host.c \
|
||||||
|
-o {{ BUILD_DIR }}-{{ module }}/system.o
|
||||||
|
|
||||||
|
[private]
|
||||||
|
build-wasm-host-linux module:
|
||||||
|
{{ LINUX_CC }} {{ LINUX_CFLAGS }} {{ LINUX_INCLUDES }} \
|
||||||
|
-c {{ BUILD_DIR }}-{{ module }}/module_host.c \
|
||||||
|
-o {{ BUILD_DIR }}-{{ module }}/system.o
|
||||||
|
|
||||||
|
[private]
|
||||||
|
build-wasm-host-linux-baremetal module:
|
||||||
|
{{ CROSS_CC }} {{ LINUX_BAREMETAL_CFLAGS }} {{ LINUX_BAREMETAL_INCLUDES }} \
|
||||||
|
-c {{ BUILD_DIR }}-{{ module }}/module_host.c \
|
||||||
|
-o {{ BUILD_DIR }}-{{ module }}/system.o
|
||||||
|
|
||||||
|
[private]
|
||||||
|
build-wasm-host-dispatch module target="fail":
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
if [ "{{ target }}" = "fail" ]; then
|
||||||
|
just build-wasm-host-fail "{{ module }}"
|
||||||
|
elif [ "{{ target }}" = "linux" ]; then
|
||||||
|
just build-wasm-host-linux "{{ module }}"
|
||||||
|
elif [ "{{ target }}" = "linux-baremetal" ]; then
|
||||||
|
just build-wasm-host-linux-baremetal "{{ module }}"
|
||||||
|
else
|
||||||
|
echo "unknown target: {{ target }}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
[doc("Compile C-Host: The host uses WAMR to load the AOT module")]
|
[doc("Compile C-Host: The host uses WAMR to load the AOT module")]
|
||||||
[group("build-host")]
|
[group("build-host")]
|
||||||
build-wasm-host module target="fail": (build-wasm-aot-array module)
|
build-wasm-host module target="fail": (build-wasm-aot-array module) && (build-wasm-host-dispatch module target)
|
||||||
cp targets/wasm-host/{{ target }}.c {{ BUILD_DIR }}-{{ module }}/module_host.c
|
cp targets/wasm-host/{{ target }}.c {{ BUILD_DIR }}-{{ module }}/module_host.c
|
||||||
sed -i \
|
sed -i \
|
||||||
-e "s/__WASM_ARRAY_FILE__/wasm_module_array.c/g" \
|
-e "s/__WASM_ARRAY_FILE__/wasm_module_array.c/g" \
|
||||||
@ -167,37 +199,79 @@ build-wasm-host module target="fail": (build-wasm-aot-array module)
|
|||||||
-e "s/__WASM_ARRAY_LEN__/build_{{ module }}_wasm_module_aot_len/g" \
|
-e "s/__WASM_ARRAY_LEN__/build_{{ module }}_wasm_module_aot_len/g" \
|
||||||
{{ BUILD_DIR }}-{{ module }}/module_host.c
|
{{ BUILD_DIR }}-{{ module }}/module_host.c
|
||||||
|
|
||||||
# Build depending on the target platform
|
[private]
|
||||||
{{ if target == "fail" { CROSS_CC + " " + CROSS_CFLAGS + " " + CROSS_INCLUDES } else if target == "linux" { LINUX_CC + " " + LINUX_CFLAGS + " " + LINUX_INCLUDES } else if target == "linux-baremetal" { CROSS_CC + " " + LINUX_BAREMETAL_CFLAGS + " " + LINUX_BAREMETAL_INCLUDES } else { error("invalid target") } }} \
|
build-system-startup-fail module:
|
||||||
-c {{ BUILD_DIR }}-{{ module }}/module_host.c \
|
{{ CROSS_CC }} targets/startup.s {{ CROSS_CFLAGS }} -c -o {{ BUILD_DIR }}-{{ module }}/startup.o
|
||||||
-o {{ BUILD_DIR }}-{{ module }}/system.o
|
|
||||||
|
|
||||||
[doc("Compile bootloader")]
|
[doc("Compile bootloader")]
|
||||||
[group("build-host")]
|
[group("build-host")]
|
||||||
build-system-startup module target="fail":
|
build-system-startup module target="fail":
|
||||||
{{ if target == "fail" { CROSS_CC } else if target == "linux" { LINUX_CC } else if target == "linux-baremetal" { CROSS_CC } else { error("invalid target") } }} \
|
#!/usr/bin/env sh
|
||||||
targets/startup.s \
|
if [ "{{ target }}" = "fail" ]; then
|
||||||
{{ if target == "fail" { CROSS_CFLAGS } else if target == "linux" { LINUX_CFLAGS } else if target == "linux-baremetal" { LINUX_BAREMETAL_CFLAGS } else { error("invalid target") } }} \
|
just build-system-startup-fail "{{ module }}"
|
||||||
-c -o {{ BUILD_DIR }}-{{ module }}/startup.o
|
else
|
||||||
|
echo "{{ target }} doesn't need bootloader"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[private]
|
||||||
|
build-system-syscalls-fail module:
|
||||||
|
{{ CROSS_CC }} targets/syscalls.c {{ CROSS_CFLAGS }} -c -o {{ BUILD_DIR }}-{{ module }}/syscalls.o
|
||||||
|
|
||||||
|
[private]
|
||||||
|
build-system-syscalls-linux-baremetal module:
|
||||||
|
{{ CROSS_CC }} targets/syscalls.c {{ LINUX_BAREMETAL_CFLAGS }} -c -o {{ BUILD_DIR }}-{{ module }}/syscalls.o
|
||||||
|
|
||||||
[doc("Compile newlib syscall stubs")]
|
[doc("Compile newlib syscall stubs")]
|
||||||
[group("build-host")]
|
[group("build-host")]
|
||||||
build-system-syscalls module target="fail":
|
build-system-syscalls module target="fail":
|
||||||
{{ if target == "fail" { CROSS_CC } else if target == "linux" { LINUX_CC } else if target == "linux-baremetal" { CROSS_CC } else { error("invalid target") } }} \
|
#!/usr/bin/env sh
|
||||||
targets/syscalls.c \
|
if [ "{{ target }}" = "fail" ]; then
|
||||||
{{ if target == "fail" { CROSS_CFLAGS } else if target == "linux" { LINUX_CFLAGS } else if target == "linux-baremetal" { LINUX_BAREMETAL_CFLAGS } else { error("invalid target") } }} \
|
just build-system-syscalls-fail "{{ module }}"
|
||||||
-c -o {{ BUILD_DIR }}-{{ module }}/syscalls.o
|
elif [ "{{ target }}" = "linux-baremetal" ]; then
|
||||||
|
just build-system-syscalls-linux-baremetal "{{ module }}"
|
||||||
|
else
|
||||||
|
echo "{{ target }} doesn't require syscall stubs"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[private]
|
||||||
|
link-system-fail module:
|
||||||
|
{{ CROSS_CC }} \
|
||||||
|
-Wl,-T targets/linker.ld \
|
||||||
|
{{ BUILD_DIR }}-{{ module }}/system.o \
|
||||||
|
{{ BUILD_DIR }}-{{ module }}/startup.o \
|
||||||
|
{{ BUILD_DIR }}-{{ module }}/syscalls.o \
|
||||||
|
{{ CROSS_LDFLAGS }} \
|
||||||
|
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||||
|
|
||||||
|
[private]
|
||||||
|
link-system-linux module:
|
||||||
|
{{ LINUX_CC }} \
|
||||||
|
{{ BUILD_DIR }}-{{ module }}/system.o \
|
||||||
|
{{ LINUX_LDFLAGS }} \
|
||||||
|
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||||
|
|
||||||
|
[private]
|
||||||
|
link-system-linux-baremetal module:
|
||||||
|
{{ CROSS_CC }} \
|
||||||
|
{{ BUILD_DIR }}-{{ module }}/system.o \
|
||||||
|
{{ BUILD_DIR }}-{{ module }}/syscalls.o \
|
||||||
|
{{ LINUX_BAREMETAL_LDFLAGS }} \
|
||||||
|
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||||
|
|
||||||
[doc("Link C-Host, syscall stubs and bootloader")]
|
[doc("Link C-Host, syscall stubs and bootloader")]
|
||||||
[group("build-host")]
|
[group("build-host")]
|
||||||
link-system module target="fail": (build-wasm-host module target) (build-system-syscalls module target) (build-system-startup module target)
|
link-system module target="fail": (build-wasm-host module target) (build-system-syscalls module target) (build-system-startup module target)
|
||||||
{{ if target == "fail" { CROSS_CC } else if target == "linux" { LINUX_CC } else if target == "linux-baremetal" { CROSS_CC } else { error("invalid target") } }} \
|
#!/usr/bin/env sh
|
||||||
{{ if target == "fail" { "-Wl,-T targets/linker.ld" } else { "" } }} \
|
if [ "{{ target }}" = "fail" ]; then
|
||||||
{{ BUILD_DIR }}-{{ module }}/system.o \
|
just link-system-fail "{{ module }}"
|
||||||
{{ if target == "fail" { f"{{BUILD_DIR}}-{{module}}/syscalls.o" + " " + f"{{BUILD_DIR}}-{{module}}/startup.o" } else { "" } }} \
|
elif [ "{{ target }}" = "linux" ]; then
|
||||||
{{ if target == "linux-baremetal" { f"{{BUILD_DIR}}-{{module}}/syscalls.o" } else { "" } }} \
|
just link-system-linux "{{ module }}"
|
||||||
{{ if target == "fail" { CROSS_LDFLAGS } else if target == "linux" { LINUX_LDFLAGS } else if target == "linux-baremetal" { LINUX_BAREMETAL_LDFLAGS } else { error("invalid target") } }} \
|
elif [ "{{ target }}" = "linux-baremetal" ]; then
|
||||||
-o {{ BUILD_DIR }}-{{ module }}/system.elf
|
just link-system-linux-baremetal "{{ module }}"
|
||||||
|
else
|
||||||
|
echo "unknown target: {{ target }}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
[doc("Create bootdisk")]
|
[doc("Create bootdisk")]
|
||||||
[group("build-host")]
|
[group("build-host")]
|
||||||
@ -363,12 +437,17 @@ resultbrowser:
|
|||||||
# Debugging recipes
|
# Debugging recipes
|
||||||
# =================================================================================================================== #
|
# =================================================================================================================== #
|
||||||
|
|
||||||
[doc("Launch radare2 at os_main")]
|
[doc("Run binary")]
|
||||||
[group("debug")]
|
[group("debug")]
|
||||||
radare module:
|
run module:
|
||||||
radare2 -AA -c "s dbg.os_main; pdf" {{ BUILD_DIR }}-{{ module }}/system.elf
|
{{ BUILD_DIR }}-{{ module }}/system.elf
|
||||||
|
|
||||||
[doc("Launch gdb")]
|
[doc("Launch gdb")]
|
||||||
[group("debug")]
|
[group("debug")]
|
||||||
gdb module:
|
gdb module:
|
||||||
gdb --tui {{ BUILD_DIR }}-{{ module }}/system.elf
|
gdb --tui {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||||
|
|
||||||
|
[doc("Launch radare2 at os_main")]
|
||||||
|
[group("debug")]
|
||||||
|
radare module:
|
||||||
|
radare2 -AA -c "s dbg.os_main; pdf" {{ BUILD_DIR }}-{{ module }}/system.elf
|
||||||
|
|||||||
Reference in New Issue
Block a user