commit d5ebfbdac2fd0471b76ce67e5651e998f53c4e15
parent 6d7ea95206f370df80d8774856f81579dc5600cb
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date: Fri, 3 Jul 2026 16:09:38 +0200
Small reorg
Diffstat:
6 files changed, 74 insertions(+), 60 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,8 +1,7 @@
-busybox
*.o
.deps
test/
*.inc.h
*.inc.s
stabbish
-features.h
+bbox/features.h
diff --git a/Makefile b/Makefile
@@ -2,86 +2,80 @@
CFLAGS=-static
BB_VER=1.38.0
-CC=$(PWD)/.deps/x86_64-linux-musl-native/bin/gcc
-export PATH:=$(PWD)/.deps/x86_64-linux-musl-native/bin:$(PATH)
+CC=gcc
+DEP_DIR=$(PWD)/.deps
-stabbish: main.o busybox.inc.o | $(CC)
- $(info LD $@)
+BBOX_MKFLAGS=HOSTCFLAGS+="-static" HOSTLDFLAGS+="-static" EXTRA_LDFLAGS="-static"
+
+DEP_MUSL=$(DEP_DIR)/x86_64-linux-musl-native
+DEP_BBOX=$(DEP_DIR)/busybox-$(BB_VER)
+
+BBOX=$(DEP_BBOX)/busybox
+MUSL_CC=$(DEP_MUSL)/bin/gcc
+
+export PATH:=$(DEP_MUSL)/bin:$(PATH)
+
+stabbish: main.o bbox/busybox.inc.o | $(MUSL_CC)
+ $(info $() LD $@)
@$(CC) $(CFLAGS) $^ -o $@
-main.o: main.c busybox.inc.h features.h | $(CC)
- $(info CC $@)
+main.o: main.c bbox/busybox.inc.h bbox/features.h | $(MUSL_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}' >$@
+bbox/features.h: $(BBOX)
+ $(info $() GEN $@)
+ @$^ --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,%,$<)[];" >$@
- @echo "extern const int _inc_$(patsubst %.inc.o,%,$<)_size;" >>$@
+%.inc.h: tmplt/inc.h
+ $(info $() GEN $@)
+ @sed 's@NAME@$(patsubst %.inc.h,%,$(@F))@g' $< > $@
-%.inc.o: %.inc.s | $(CC)
- $(info ASM $@)
- @$(CC) $(CFLAGS) -c $< -o $@
+%.inc.s: tmplt/inc.s
+ $(info $() GEN $@)
+ @sed 's@NAME@$(patsubst %.inc.s,%,$(@F))@g' $< > $@
-%.inc.s: %
- $(info GEN $@)
- @echo ' .section ".rodata"' >$@
- @echo ' .globl _inc_$<' >>$@
- @echo ' .type _inc_$<, STT_OBJECT' >>$@
- @echo ' .globl _inc_$<_size' >>$@
- @echo ' .type _inc_$<_size, STT_OBJECT' >>$@
- @echo '_inc_$<:' >>$@
- @echo ' .incbin "$<"' >>$@
- @echo ' .byte 0' >>$@
- @echo ' .size _inc_$<, .-_inc_$<' >>$@
- @echo '_inc_$<_size:' >>$@
- @echo ' .int (. - _inc_$<)' >>$@
-
-$(CC):
- $(info DWNL $@)
+bbox/busybox.inc.o: bbox/busybox.inc.s $(BBOX) | $(MUSL_CC)
+ $(info $() ASM $@)
+ @cd $(dir $(word 2,$^)) && $(CC) $(CFLAGS) -c $(PWD)/$< -o $(PWD)/$@
+
+$(MUSL_CC):
+ $(info $() DWNL $@)
@mkdir -p .deps
@cd .deps && curl -fSL 'https://musl.cc/x86_64-linux-musl-native.tgz' | tar xz
-.deps/busybox-$(BB_VER)/Config.in:
- $(info DWNL $@)
+$(DEP_BBOX)/Config.in:
+ $(info $() DWNL $@)
@mkdir -p .deps
@cd .deps && curl -fSL https://busybox.net/downloads/busybox-$(BB_VER).tar.bz2 | tar xj
-.deps/busybox-$(BB_VER)/.config: .deps/busybox-$(BB_VER)/Config.in $(CC)
- $(info MK $@)
- @cp config $@
- @yes "" | make -C .deps/busybox-$(BB_VER) oldconfig HOSTCFLAGS+="-static" HOSTLDFLAGS+="-static" EXTRA_LDFLAGS="-static"
-
-.deps/busybox-$(BB_VER)/busybox: .deps/busybox-$(BB_VER)/.config $(CC)
- $(info MK $@)
- @make -j$$(nproc) -C .deps/busybox-$(BB_VER) HOSTCFLAGS+="-static" HOSTLDFLAGS+="-static" EXTRA_LDFLAGS="-static"
+$(DEP_BBOX)/.config: bbox/config $(DEP_BBOX)/Config.in | $(MUSL_CC)
+ $(info $() MK $@)
+ @cp $< $@
+ @yes "" | make -C $(DEP_BBOX) oldconfig $(BBOX_MKFLAGS)
-busybox: .deps/busybox-$(BB_VER)/busybox
- $(info LN $@)
- @ln -sf $< $@
+$(BBOX): $(DEP_BBOX)/.config | $(MUSL_CC)
+ $(info $() MK $@)
+ @make -j$$(nproc) -C $(DEP_BBOX) $(BBOX_MKFLAGS)
test/test.sh:
- $(info GEN $@)
+ $(info $() GEN $@)
@mkdir -p test
@echo "type ls" >$@
test/stabbish_plain: stabbish test/test.sh
- $(info CAT $@)
+ $(info $() CAT $@)
@cat $^ > $@
@chmod +x $@
test/stabbish_%: stabbish test/test.sh
- $(info CAT $@)
+ $(info $() CAT $@)
@$(patsubst test/stabbish_%,%,$@) -c test/test.sh | cat $< - >$@
@chmod +x $@
-.PHONY:
test: test/stabbish_plain test/stabbish_bzip2 test/stabbish_gzip test/stabbish_xz
@for test in $^; do \
- printf "Test $$test..."; \
+ printf " TST $$test"; \
if [ "$$(./$$test)" = "ls is ls" ]; then \
echo " [OK]"; \
else \
@@ -89,13 +83,21 @@ test: test/stabbish_plain test/stabbish_bzip2 test/stabbish_gzip test/stabbish_x
fi \
done
-.PHONY:
-clean:
- $(info CLEAN .)
- @rm -rf *.inc.* main.o stabbish test features.h
+clean_bbox:
+ $(info $() CLEAN bbox)
+ @rm -r bbox/*.inc.* bbox/features.h
+
+clean_test:
+ $(info $() CLEAN test)
+ @rm -rf test
+
+clean: clean_bbox clean_test
+ $(info $() CLEAN .)
+ @rm -rf main.o stabbish
-.PHONY:
cleanall: clean
- $(info CLEAN .deps/busybox-$(BB_VER))
+ $(info $() CLEAN $(DEP_BBOX))
@make -C .deps/busybox-$(BB_VER) clean
@rm -f .deps/busybox-$(BB_VER)/.config
+
+.PHONY: test clean_test clean cleanall
diff --git a/config b/bbox/config
diff --git a/main.c b/main.c
@@ -10,8 +10,8 @@
#include <sys/mman.h>
#include <unistd.h>
-#include "busybox.inc.h"
-#include "features.h"
+#include "bbox/busybox.inc.h"
+#include "bbox/features.h"
#if defined(__LP64__)
#define ElfW(type) Elf64_##type
diff --git a/tmplt/inc.h b/tmplt/inc.h
@@ -0,0 +1,2 @@
+extern const char _inc_NAME[];
+extern const int _inc_NAME_size;
diff --git a/tmplt/inc.s b/tmplt/inc.s
@@ -0,0 +1,11 @@
+ .section ".rodata"
+ .globl _inc_NAME
+ .type _inc_NAME, STT_OBJECT
+ .globl _inc_NAME_size
+ .type _inc_NAME_size, STT_OBJECT
+_inc_NAME:
+ .incbin "NAME"
+ .byte 0
+ .size _inc_NAME, .-_inc_NAME
+_inc_NAME_size:
+ .int (. - _inc_NAME)