osdev5/Makefile

138 lines
2.8 KiB
Makefile
Raw Normal View History

2021-09-29 10:50:37 +03:00
ARCH?=aarch64
ifeq ($(ARCH),aarch64)
MACH?=qemu
endif
GDB?=gdb-multiarch
LLVM_BASE=$(shell llvm-config --bindir)
2021-10-18 19:15:42 +03:00
CLANG=clang-14
LDLLD=ld.lld-12
2021-09-29 10:50:37 +03:00
OBJCOPY=$(LLVM_BASE)/llvm-objcopy
2021-10-01 18:37:47 +03:00
MKIMAGE?=mkimage
2021-09-29 10:50:37 +03:00
PROFILE?=debug
O=target/$(ARCH)-$(MACH)/$(PROFILE)
2021-10-26 14:09:47 +03:00
CARGO_COMMON_OPTS=
ifeq ($(PROFILE),release)
CARGO_COMMON_OPTS+=--release
endif
CARGO_BUILD_OPTS=$(CARGO_COMMON_OPTS) \
--target=../etc/$(ARCH)-$(MACH).json
ifeq ($(VERBOSE),1)
CARGO_BUILD_OPTS+=--features verbose
endif
2021-09-29 10:50:37 +03:00
ifneq ($(MACH),)
CARGO_BUILD_OPTS+=--features mach_$(MACH)
endif
2021-11-09 16:35:31 +02:00
QEMU_OPTS=-s
2021-09-29 10:50:37 +03:00
ifeq ($(ARCH),x86_64)
$(error TODO)
else
ifeq ($(MACH),qemu)
2021-10-14 19:20:51 +03:00
QEMU_OPTS+=-kernel $(O)/kernel.bin \
2021-10-18 19:15:42 +03:00
-initrd $(O)/initrd.img \
2021-10-11 18:54:36 +03:00
-M virt,virtualization=on \
2021-09-29 10:50:37 +03:00
-cpu cortex-a72 \
-m 512 \
2021-11-09 16:35:31 +02:00
-serial mon:stdio \
2021-10-14 19:20:51 +03:00
-device qemu-xhci \
2021-10-21 21:00:51 +03:00
-display none \
2021-10-14 19:20:51 +03:00
-net none
2021-09-29 10:50:37 +03:00
endif
ifeq ($(MACH),rpi3)
QEMU_OPTS+=-kernel $(O)/kernel.bin \
-initrd $(O)/initrd.img \
-M raspi3b \
2021-11-09 16:35:31 +02:00
-serial mon:stdio \
-display none \
-net none
endif
2021-09-29 10:50:37 +03:00
endif
2021-10-28 00:40:40 +03:00
ifneq ($(QEMU_SDCARD),)
QEMU_OPTS+=-drive if=sd,file=$(QEMU_SDCARD)
endif
2021-10-10 21:24:22 +03:00
ifeq ($(QEMU_DINT),1)
QEMU_OPTS+=-d int
endif
ifeq ($(QEMU_PAUSE),1)
QEMU_OPTS+=-S
endif
2021-09-29 10:50:37 +03:00
.PHONY: address error etc kernel src
2021-10-26 00:59:43 +03:00
all: kernel initrd
2021-09-29 10:50:37 +03:00
kernel:
cd kernel && cargo build $(CARGO_BUILD_OPTS)
2021-10-14 19:20:51 +03:00
ifeq ($(ARCH),aarch64)
$(LLVM_BASE)/llvm-strip -o $(O)/kernel.strip $(O)/kernel
$(LLVM_BASE)/llvm-size $(O)/kernel.strip
$(OBJCOPY) -O binary $(O)/kernel.strip $(O)/kernel.bin
2021-10-14 19:20:51 +03:00
endif
ifeq ($(MACH),orangepi3)
$(MKIMAGE) \
-A arm64 \
-O linux \
-T kernel \
-C none \
-a 0x48000000 \
-e 0x48000000 \
-n kernel \
-d $(O)/kernel.bin \
$(O)/uImage
2021-10-01 18:37:47 +03:00
endif
2021-09-29 10:50:37 +03:00
2021-10-26 00:59:43 +03:00
initrd:
2021-11-05 15:24:10 +02:00
cd user && cargo build \
2021-10-26 14:09:47 +03:00
--target=../etc/$(ARCH)-osdev5.json \
-Z build-std=core,alloc,compiler_builtins \
$(CARGO_COMMON_OPTS)
2021-11-05 15:24:10 +02:00
mkdir -p $(O)/rootfs/bin
cp target/$(ARCH)-osdev5/$(PROFILE)/init $(O)/rootfs/init
cp target/$(ARCH)-osdev5/$(PROFILE)/shell $(O)/rootfs/bin
2021-11-20 13:54:06 +02:00
cp target/$(ARCH)-osdev5/$(PROFILE)/fuzzy $(O)/rootfs/bin
2021-11-23 17:55:58 +02:00
cp target/$(ARCH)-osdev5/$(PROFILE)/ls $(O)/rootfs/bin
2021-11-05 15:24:10 +02:00
cd $(O)/rootfs && tar cf ../initrd.img `find -type f -printf "%P\n"`
2021-10-26 14:09:47 +03:00
ifeq ($(MACH),orangepi3)
$(MKIMAGE) \
-A arm64 \
-O linux \
-T ramdisk \
-C none \
-a 0x80000000 \
-n initrd \
-d $(O)/initrd.img \
$(O)/uRamdisk
endif
2021-10-26 00:59:43 +03:00
test:
cd fs/vfs && cargo test
cd fs/memfs && cargo test
cd fs/fat32 && cargo test
2021-09-29 10:50:37 +03:00
clean:
cargo clean
2021-10-18 15:06:08 +03:00
doc:
cd kernel && cargo doc --all-features --target=../etc/$(ARCH)-$(MACH).json
doc-open:
cd kernel && cargo doc --open --all-features --target=../etc/$(ARCH)-$(MACH).json
2021-10-07 14:43:14 +03:00
clippy:
cd kernel && cargo clippy $(CARGO_BUILD_OPTS)
2021-11-11 22:46:01 +02:00
cd user && cargo clippy \
2021-11-05 13:50:00 +02:00
--target=../etc/$(ARCH)-osdev5.json \
-Zbuild-std=core,alloc,compiler_builtins $(CARGO_COMMON_OPTS)
2021-10-07 14:43:14 +03:00
2021-09-29 18:56:52 +03:00
qemu: all
2021-10-07 13:56:17 +03:00
$(QEMU_PREFIX)qemu-system-$(ARCH) $(QEMU_OPTS)
2021-09-29 10:50:37 +03:00
2021-09-29 18:56:52 +03:00
gdb: all
2021-09-29 10:50:37 +03:00
$(GDB) -x etc/gdbrc $(O)/kernel