summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2023-12-19 04:55:36 +0100
committerLizzy Fleckenstein <lizzy@vlhl.dev>2023-12-19 04:55:36 +0100
commit60b66c6454e7d05c47b3722d3c756540a7aee381 (patch)
tree9e366ce7a0aa13294f97994063fea26d5746f662
parent68b40f6327efeff0437d77c487f0175a9d53110a (diff)
downloadcuddles-60b66c6454e7d05c47b3722d3c756540a7aee381.tar.xz
uname command
-rw-r--r--.gitignore2
-rw-r--r--Makefile14
-rw-r--r--stage3/shell.c11
3 files changed, 25 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 1179c33..6f17dd4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@
bx_enh_dbg.ini
stage3/isr.asm
fs.tar
+stage3/version.c
+stage3/version.*.c
diff --git a/Makefile b/Makefile
index cf4bd3d..ba52724 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,8 @@ STAGE3 = \
stage3/yield.o \
stage3/ps2.o \
stage3/thread.o \
- stage3/shell.o
+ stage3/shell.o \
+ stage3/version.o
PAD_BOUNDARY = pad() { truncate -s $$(echo "($$(du -b $$1 | cut -f1)+$$2-1)/$$2*$$2" | bc) $$1; }; pad
@@ -58,6 +59,15 @@ stage3/%.o: stage3/%.asm
stage3/%.o: stage3/%.c
gcc $(CFLAGS) -c $< -o $@
+GIT_VERSION := $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
+
+stage3/version.c: stage3/version.$(GIT_VERSION).c
+ cp $< $@
+
+stage3/version.$(GIT_VERSION).c:
+ rm -f stage3/version.*.c
+ echo -e "#include \"def.h\"\nstr version = S(\"$(GIT_VERSION)\");" > $@
+
stage3/isr.asm: stage3/isr.lua
lua stage3/isr.lua > stage3/isr.asm
@@ -76,7 +86,7 @@ qemu: cuddles.img
run: qemu
clean:
- rm -rf stage3/*.o *.bin *.img *.map stage3/isr.asm fs.tar
+ rm -rf stage3/*.o *.bin *.img *.map stage3/{isr.asm,version.c,version.*.c} fs.tar
flash: cuddles.img
dd if=cuddles.img of=$(DEV)
diff --git a/stage3/shell.c b/stage3/shell.c
index 244a247..b0e1fce 100644
--- a/stage3/shell.c
+++ b/stage3/shell.c
@@ -158,6 +158,16 @@ static void cmd_love(str arg)
}
}
+extern str version;
+
+static void cmd_uname(str arg)
+{
+ (void) arg;
+ print(S("cuddles "));
+ print(version);
+ print(S("\n"));
+}
+
typedef struct {
str name;
void (*fn)(str arg);
@@ -174,6 +184,7 @@ static command registry[] = {
{ S("loadkeys"), &cmd_loadkeys },
{ S("clear"), &cmd_clear },
{ S("love"), &cmd_love },
+ { S("uname"), &cmd_uname },
};
void shell_run_cmd(str cmd)