.PHONY: clean prepare cleanall iso hdd base kernel user test

ARCH ?= x86_64

kernel:
	make -C kernel ARCH=$(ARCH) ROOT=$(PWD) all

user:
	make -C user ARCH=$(ARCH) ROOT=$(PWD) all

ulib:
	make -C ulib ARCH=$(ARCH) ROOT=$(PWD) all

prepare:
	if [ ! -d limine ]; then \
		git clone https://github.com/limine-bootloader/limine.git --branch=v9.x-binary --depth=1; \
		cd limine; \
		make; \
	fi
	if [ ! -d toolchain/binutils-gdb ]; then \
		cd toolchain; \
		git clone git://sourceware.org/git/binutils-gdb.git --depth=1; \
		$(PWD)/scripts/build-binutils-gdb.sh; \
		cd ..; \
	fi
	if [ ! -d toolchain/gcc ]; then \
		cd toolchain; \
		git clone https://gcc.gnu.org/git/gcc.git --depth=1; \
		$(PWD)/scripts/build-gcc.sh; \
		cd ..; \
	fi

cleanall:
	make clean
	rm -rf limine

clean:
	make -C kernel ARCH=$(ARCH) ROOT=$(PWD) clean
	make -C user ARCH=$(ARCH) ROOT=$(PWD) clean
	make -C ulib ARCH=$(ARCH) ROOT=$(PWD) clean
	rm -f mop2.iso base.img disk.hdd

base:
	./scripts/mkbaseimg.sh

iso:
	./scripts/mkiso.sh

hdd:
	./scripts/mkhdd.sh
