commit e462dbfb83041c01a8061d43e81819487a3e5da4
parent dcfcec80926b674ea9afea8e7e7f9a39f04e0a50
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date: Thu, 2 Jul 2026 23:22:56 +0200
Detect applest
Diffstat:
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -5,3 +5,4 @@ test/
*.inc.h
*.inc.s
stabbish
+features.h
diff --git a/Makefile b/Makefile
@@ -9,10 +9,14 @@ stabbish: main.o busybox.inc.o | $(CC)
$(info LD $@)
@$(CC) $(CFLAGS) $^ -o $@
-main.o: main.c busybox.inc.h | $(CC)
+main.o: main.c busybox.inc.h features.h | $(CC)
$(info CC $@)
@$(CC) $(CFLAGS) -c $< -o $@
+features.h: busybox
+ $(info GEN $@)
+ @./busybox --list | sed 's/[-\[\.]/_/g' | awk '{printf "#define BB_HAVE_%s \n", $$1}' >$@
+
%.inc.h: %.inc.o
$(info GEN $@)
@echo "extern const char _inc_$(patsubst %.inc.o,%,$<)[];" >$@
@@ -76,7 +80,7 @@ test/stabbish_%: stabbish test/test.sh
@chmod +x $@
.PHONY:
-test: test/stabbish_plain test/stabbish_bzip2 test/stabbish_gzip test/stabbish_xz test/stabbish_zstd
+test: test/stabbish_plain test/stabbish_bzip2 test/stabbish_gzip test/stabbish_xz
@for test in $^; do \
printf "Test $$test..."; \
if [ "$$(./$$test)" = "ls is ls" ]; then \
@@ -88,7 +92,7 @@ test: test/stabbish_plain test/stabbish_bzip2 test/stabbish_gzip test/stabbish_x
.PHONY:
clean:
- rm -rf *.inc.* main.o stabbish test
+ rm -rf *.inc.* main.o stabbish test features.h
.PHONY:
cleanall: clean
diff --git a/main.c b/main.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include "busybox.inc.h"
+#include "features.h"
#if defined(__LP64__)
#define ElfW(type) Elf64_##type
@@ -24,13 +25,20 @@ struct magic {
};
const struct magic MAGICS[] = {
+#ifdef BB_HAVE_xzcat
{.length = 6,
.byte = {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
.tool = "xzcat"},
+#endif
+#ifdef BB_HAVE_zcat
{.length = 2, .byte = {0x1F, 0x8B}, .tool = "zcat"},
+#endif
+#ifdef BB_HAVE_bzcat
{.length = 3, .byte = {0x42, 0x5A, 0x68}, .tool = "bzcat"},
+#endif
+#ifdef BB_HAVE_zstdcat
{.length = 4, .byte = {0x28, 0xB5, 0x2F, 0xFD}, .tool = "zstdcat"},
-
+#endif
};
const size_t MAGICS_size = sizeof(MAGICS) / sizeof(MAGICS[0]);