usr.bin: add usr.bin

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-18 15:28:53 -04:00
commit f47a4bfa2c
8 changed files with 87 additions and 11 deletions

26
usr.bin/Makefile Normal file
View file

@ -0,0 +1,26 @@
ifneq ($(V),1)
Q := @
else
Q :=
endif
usr_dirs := utest
usr_bins := $(foreach d,$(usr_dirs),$d/$d)
.PHONY: all $(usr_dirs)
all: initramfs
$(usr_dirs):
$(Q)$(MAKE) --no-print-directory -C $@ DIR=usr.bin/$@
.PHONY: initramfs
initramfs: $(usr_dirs)
$(Q)mkdir -p ../initramfs/bin/
$(Q)cp $(usr_bins) ../initramfs/bin/
.PHONY: clean
clean:
$(Q)for dir in $(usr_dirs); do \
echo " CLEAN usr.bin/$$dir"; \
$(MAKE) --no-print-directory -C $$dir clean; \
done

30
usr.bin/Makefile.common Normal file
View file

@ -0,0 +1,30 @@
ifneq ($(V),1)
Q := @
else
Q :=
endif
USR_CFLAGS ?= -g3 -O0 -pipe -Wall -ffreestanding -nostdlib \
-fno-stack-protector -m64 -march=x86-64 -mabi=sysv \
-Iinclude -MMD
USR_LDFLAGS ?= -nostdlib -static -m elf_x86_64 -z max-page-size=0x1000
$(OUT): $(UOBJ)
$(Q)echo " LD [U] $(DIR)/$@"
$(Q)$(LD) $(USR_LDFLAGS) -o $@ $^
%.o: %.c
$(Q)echo " CC [U] $(DIR)/$@"
$(Q)$(CC) $(USR_CFLAGS) -c $< -o $@
%.o: %.S
$(Q)echo " CC [U] $(DIR)/$@"
$(Q)$(CC) $(USR_CFLAGS) -c $< -o $@
clean:
$(Q)rm -rf $(UOBJ) $(OUT)
print-%:
$(Q)echo $($(*))

4
usr.bin/utest/Makefile Normal file
View file

@ -0,0 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only
OUT := utest
UOBJ := utest.o
-include ../Makefile.common

BIN
usr.bin/utest/utest Executable file

Binary file not shown.

6
usr.bin/utest/utest.c Normal file
View file

@ -0,0 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
void _start()
{
while (1)
(void)0;
}