misc: Disentangle Makefiles so it builds fine with -j

This commit is contained in:
mintsuki 2021-03-08 03:05:39 +01:00
parent a8626d6fdd
commit db20cc7580
3 changed files with 33 additions and 21 deletions

View File

@ -89,7 +89,7 @@ test.hdd:
parted -s test.hdd mklabel gpt
parted -s test.hdd mkpart primary 2048s 100%
echfs-test: | test-clean test.hdd bootloader all
echfs-test: | test-clean test.hdd limine-bios
$(MAKE) -C test
echfs-utils -g -p0 test.hdd quick-format 512 > part_guid
sed "s/@GUID@/`cat part_guid`/g" < test/limine.cfg > limine.cfg.tmp
@ -101,7 +101,7 @@ echfs-test: | test-clean test.hdd bootloader all
bin/limine-install test.hdd
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
ext2-test: | test-clean test.hdd bootloader all
ext2-test: | test-clean test.hdd limine-bios
$(MAKE) -C test
rm -rf test_image/
mkdir test_image
@ -118,7 +118,7 @@ ext2-test: | test-clean test.hdd bootloader all
bin/limine-install test.hdd
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
fat32-test: | test-clean test.hdd bootloader all
fat32-test: | test-clean test.hdd limine-bios
$(MAKE) -C test
rm -rf test_image/
mkdir test_image
@ -135,7 +135,7 @@ fat32-test: | test-clean test.hdd bootloader all
bin/limine-install test.hdd
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
iso9660-test: | test-clean test.hdd bootloader
iso9660-test: | test-clean test.hdd limine-bios
$(MAKE) -C test
rm -rf test_image/
mkdir -p test_image/boot
@ -143,7 +143,7 @@ iso9660-test: | test-clean test.hdd bootloader
genisoimage -no-emul-boot -b boot/limine-cd.bin -boot-load-size 4 -boot-info-table -o test.iso test_image/
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -cdrom test.iso -debugcon stdio
uefi-test: ovmf | test-clean test.hdd bootloader
uefi-test: ovmf | test-clean test.hdd limine-uefi
$(MAKE) -C test
rm -rf test_image/
mkdir test_image

View File

@ -1,7 +1,11 @@
CC = i386-elf-gcc
LD = i386-elf-gcc
OBJCOPY = i386-elf-objcopy
BUILDDIR = .
BUILDDIR =
ifeq ($(BUILDDIR), )
$(error BUILDDIR not specified)
endif
CFLAGS = -flto -Os -pipe -Wall -Wextra -Werror
@ -28,14 +32,16 @@ INTERNAL_LDFLAGS = \
-static \
-Tlinker.ld
.PHONY: all clean
.PHONY: all clean builddir
C_FILES := $(shell find -L ./ -type f -name '*.c' | sort)
ASM_FILES := $(shell find -L ./ -type f -name '*.asm' | sort)
OBJ := $(addprefix $(BUILDDIR)/, $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o))
HEADER_DEPS := $(addprefix $(BUILDDIR)/, $(C_FILES:.c=.d))
all: | builddir $(BUILDDIR)/decompressor.bin
all:
$(MAKE) builddir
$(MAKE) $(BUILDDIR)/decompressor.bin
builddir:
for i in $(OBJ); do mkdir -p `dirname $$i`; done
@ -46,10 +52,10 @@ $(BUILDDIR)/decompressor.bin: $(OBJ)
-include $(HEADER_DEPS)
$(addprefix $(BUILDDIR)/, %.o): %.c
$(BUILDDIR)/%.o: %.c
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
$(addprefix $(BUILDDIR)/, %.o): %.asm
$(BUILDDIR)/%.o: %.asm
nasm $< -f elf32 -o $@
clean:

View File

@ -1,5 +1,9 @@
TARGET = bios
BUILDDIR = .
TARGET =
BUILDDIR =
ifeq ($(BUILDDIR), )
$(error BUILDDIR not specified)
endif
ifeq ($(TARGET), bios)
TOOLCHAIN=i386-elf
@ -86,11 +90,13 @@ OBJ := $(addprefix $(BUILDDIR)/, $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o))
HEADER_DEPS := $(addprefix $(BUILDDIR)/, $(C_FILES:.c=.d))
ifeq ($(TARGET), bios)
all: | builddir everything
.PHONY: everything
everything: $(BUILDDIR)/limine_dbg.elf $(BUILDDIR)/limine.sys $(BUILDDIR)/stage2.bin $(BUILDDIR)/stage2.bin.gz
all:
$(MAKE) builddir
$(MAKE) $(BUILDDIR)/limine_dbg.elf $(BUILDDIR)/limine.sys $(BUILDDIR)/stage2.bin $(BUILDDIR)/stage2.bin.gz
else ifeq ($(TARGET), uefi)
all: | builddir $(BUILDDIR)/BOOTX64.EFI
all:
$(MAKE) builddir
$(MAKE) $(BUILDDIR)/BOOTX64.EFI
endif
builddir:
@ -154,27 +160,27 @@ endif
-include $(HEADER_DEPS)
$(addprefix $(BUILDDIR)/, %.o): %.c
$(BUILDDIR)/%.o: %.c
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
ifeq ($(TARGET), bios)
$(addprefix $(BUILDDIR)/, %.s2.o): %.s2.c
$(BUILDDIR)/%.s2.o: %.s2.c
$(CC) $(S2CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@
endif
ifeq ($(TARGET), uefi)
$(addprefix $(BUILDDIR)/, %.32.o): %.32.c
$(BUILDDIR)/%.32.o: %.32.c
$(CC32) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@.32
$(OBJCOPY) -I elf32-i386 -O elf64-x86-64 $@.32 $@
rm $@.32
endif
ifeq ($(TARGET), bios)
$(addprefix $(BUILDDIR)/, %.o): %.asm
$(BUILDDIR)/%.o: %.asm
nasm $< -F dwarf -g -f elf32 -o $@
endif
ifeq ($(TARGET), uefi)
$(addprefix $(BUILDDIR)/, %.o): %.asm
$(BUILDDIR)/%.o: %.asm
nasm $< -F dwarf -g -f elf64 -o $@
endif