2023-03-14 19:20:46 +03:00
|
|
|
include $(TOOLCHAIN_FILE)
|
2023-03-16 05:38:53 +03:00
|
|
|
export CC_FOR_TARGET
|
|
|
|
export LD_FOR_TARGET
|
|
|
|
export OBJDUMP_FOR_TARGET
|
|
|
|
export OBJCOPY_FOR_TARGET
|
|
|
|
export READELF_FOR_TARGET
|
2021-07-25 15:48:58 +03:00
|
|
|
|
2023-03-16 04:28:50 +03:00
|
|
|
override CC := $(CC_FOR_TARGET)
|
2022-09-05 03:17:53 +03:00
|
|
|
CFLAGS = -O2 -g -Wall -Wextra
|
|
|
|
LDFLAGS =
|
2023-03-16 04:28:50 +03:00
|
|
|
override LD := $(LD_FOR_TARGET)
|
2022-09-05 03:17:53 +03:00
|
|
|
override QEMU := qemu-system-x86_64
|
|
|
|
QEMUFLAGS = -m 1G -enable-kvm -cpu host
|
|
|
|
|
2023-09-12 01:02:57 +03:00
|
|
|
ifneq ($(findstring x86_64,$(shell $(CC_FOR_TARGET) -dumpmachine)),)
|
2023-08-04 17:54:24 +03:00
|
|
|
override LDFLAGS += \
|
|
|
|
-m elf_x86_64
|
|
|
|
endif
|
2023-09-12 01:02:57 +03:00
|
|
|
ifneq ($(findstring aarch64,$(shell $(CC_FOR_TARGET) -dumpmachine)),)
|
2023-08-04 17:54:24 +03:00
|
|
|
override LDFLAGS += \
|
|
|
|
-m aarch64elf
|
|
|
|
endif
|
2023-09-12 01:02:57 +03:00
|
|
|
ifneq ($(findstring riscv64,$(shell $(CC_FOR_TARGET) -dumpmachine)),)
|
2023-08-04 17:54:24 +03:00
|
|
|
override LDFLAGS += \
|
|
|
|
-m elf64lriscv
|
|
|
|
endif
|
|
|
|
|
|
|
|
override LDFLAGS += \
|
|
|
|
-Tlinker.ld \
|
|
|
|
-nostdlib \
|
|
|
|
-zmax-page-size=0x1000 \
|
|
|
|
-static \
|
|
|
|
-pie \
|
|
|
|
--no-dynamic-linker \
|
|
|
|
-ztext
|
|
|
|
|
|
|
|
override LDFLAGS_MB2 := \
|
|
|
|
-m elf_i386 \
|
|
|
|
-Tmultiboot2.ld \
|
|
|
|
-nostdlib \
|
|
|
|
-zmax-page-size=0x1000 \
|
|
|
|
-static
|
|
|
|
|
|
|
|
override LDFLAGS_MB1 := \
|
|
|
|
-m elf_i386 \
|
|
|
|
-Tmultiboot.ld \
|
|
|
|
-nostdlib \
|
|
|
|
-zmax-page-size=0x1000 \
|
|
|
|
-static
|
|
|
|
|
|
|
|
override CFLAGS += \
|
|
|
|
-std=c11 \
|
|
|
|
-nostdinc \
|
|
|
|
-ffreestanding \
|
|
|
|
-fno-stack-protector \
|
|
|
|
-fno-stack-check \
|
|
|
|
-fno-lto \
|
|
|
|
-fPIE \
|
|
|
|
-I../freestanding-headers \
|
|
|
|
-I. \
|
2023-08-04 15:56:07 +03:00
|
|
|
-D_LIMINE_PROTO
|
2022-09-05 03:17:53 +03:00
|
|
|
|
2023-09-12 01:02:57 +03:00
|
|
|
ifneq ($(findstring x86_64,$(shell $(CC_FOR_TARGET) -dumpmachine)),)
|
2023-08-04 17:54:24 +03:00
|
|
|
override CFLAGS += \
|
|
|
|
-m64 \
|
|
|
|
-march=x86-64 \
|
|
|
|
-mgeneral-regs-only \
|
|
|
|
-mno-red-zone
|
|
|
|
endif
|
|
|
|
|
2023-09-12 01:02:57 +03:00
|
|
|
ifneq ($(findstring aarch64,$(shell $(CC_FOR_TARGET) -dumpmachine)),)
|
2023-08-04 17:54:24 +03:00
|
|
|
override CFLAGS += \
|
|
|
|
-mgeneral-regs-only
|
2023-08-03 11:46:46 +03:00
|
|
|
endif
|
|
|
|
|
2023-09-12 01:02:57 +03:00
|
|
|
ifneq ($(findstring riscv64,$(shell $(CC_FOR_TARGET) -dumpmachine)),)
|
2023-08-04 17:54:24 +03:00
|
|
|
override CFLAGS += \
|
|
|
|
-march=rv64imac \
|
|
|
|
-mabi=lp64 \
|
|
|
|
-mno-relax
|
|
|
|
override LDFLAGS += \
|
|
|
|
--no-relax
|
|
|
|
endif
|
|
|
|
|
|
|
|
override CFLAGS_MB := \
|
|
|
|
-std=c11 \
|
|
|
|
-nostdinc \
|
|
|
|
-ffreestanding \
|
|
|
|
-fno-stack-protector \
|
|
|
|
-fno-stack-check \
|
|
|
|
-fno-lto \
|
|
|
|
-fno-PIE \
|
|
|
|
-fno-PIC \
|
|
|
|
-m32 \
|
|
|
|
-march=i686 \
|
|
|
|
-mgeneral-regs-only \
|
|
|
|
-I../freestanding-headers \
|
|
|
|
-I. \
|
|
|
|
-I../common/protos
|
2022-06-29 13:32:50 +03:00
|
|
|
|
2023-09-12 01:02:57 +03:00
|
|
|
ifneq ($(findstring 86,$(shell $(CC_FOR_TARGET) -dumpmachine)),)
|
2021-11-10 09:34:19 +03:00
|
|
|
all: test.elf multiboot2.elf multiboot.elf
|
2022-09-05 03:17:53 +03:00
|
|
|
else
|
|
|
|
all: test.elf
|
|
|
|
endif
|
2020-09-30 01:31:42 +03:00
|
|
|
|
2023-08-04 15:56:07 +03:00
|
|
|
flanterm:
|
|
|
|
mkdir -p flanterm
|
|
|
|
cp -rv ../common/flanterm/* ./flanterm/
|
|
|
|
|
2023-08-04 17:54:24 +03:00
|
|
|
limine.h:
|
|
|
|
cp -v ../limine.h ./
|
|
|
|
|
2023-08-04 15:56:07 +03:00
|
|
|
test.elf: limine.o e9print.o memory.o flanterm/flanterm.o flanterm/backends/fb.o
|
2023-08-04 17:54:24 +03:00
|
|
|
$(LD) $^ $(LDFLAGS) -o $@
|
2020-09-30 01:31:42 +03:00
|
|
|
|
2021-11-09 08:33:54 +03:00
|
|
|
multiboot2.elf: multiboot2_trampoline.o
|
2023-08-04 17:54:24 +03:00
|
|
|
$(CC) $(CFLAGS_MB) -c memory.c -o memory.o
|
|
|
|
$(CC) $(CFLAGS_MB) -c multiboot2.c -o multiboot2.o
|
|
|
|
$(CC) $(CFLAGS_MB) -c e9print.c -o e9print.o
|
|
|
|
$(LD) $^ memory.o multiboot2.o e9print.o $(LDFLAGS_MB2) -o $@
|
2021-11-10 09:34:19 +03:00
|
|
|
|
|
|
|
multiboot.elf: multiboot_trampoline.o
|
2023-08-04 17:54:24 +03:00
|
|
|
$(CC) $(CFLAGS_MB) -c memory.c -o memory.o
|
|
|
|
$(CC) $(CFLAGS_MB) -c multiboot.c -o multiboot.o
|
|
|
|
$(CC) $(CFLAGS_MB) -c e9print.c -o e9print.o
|
|
|
|
$(LD) $^ memory.o multiboot.o e9print.o $(LDFLAGS_MB1) -o $@
|
2021-11-09 08:33:54 +03:00
|
|
|
|
2023-08-04 17:54:24 +03:00
|
|
|
%.o: %.c flanterm limine.h
|
|
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
2020-09-30 01:31:42 +03:00
|
|
|
|
2021-11-09 08:33:54 +03:00
|
|
|
%.o: %.asm
|
2022-06-29 13:32:50 +03:00
|
|
|
nasm -felf32 -F dwarf -g $< -o $@
|
2021-11-09 08:33:54 +03:00
|
|
|
|
2020-09-30 01:31:42 +03:00
|
|
|
clean:
|
2022-06-14 04:56:30 +03:00
|
|
|
rm -rf test.elf limine.o e9print.o memory.o
|
2021-11-19 17:17:37 +03:00
|
|
|
rm -rf multiboot2.o multiboot2.elf multiboot2_trampoline.o
|
|
|
|
rm -rf multiboot.o multiboot_trampoline.o multiboot.elf
|
2023-08-04 17:54:24 +03:00
|
|
|
rm -rf flanterm limine.h
|