Syncboot/makefile
Curle 352db828e7 Modify existing Makefile to allow compilation of UEFI app.
Added targets for the main files - BOOTX64.EFI, data.c and entry.c
Also minor formatting changes, but whatever.
2019-07-17 15:45:24 +01:00

101 lines
2.7 KiB
Makefile
Executable File

DEFAULT_HOST:=i686-elf
HOST?=DEFAULT_HOST
HOSTARCH:=i386
CC:=$(PREFIX)/bin/$(DEFAULT_HOST)-gcc
CFLAGS?= -O0 -g -fno-pie -fno-stack-protector -Wl,--build-id=none
CPPFLAGS?=
LDFLAGS?=
LIBS?=
DESTDIR?=
PREFIX?=/usr/local
EXEC_PREFIX?=$(PREFIX)
BOOTDIR?=$(EXEC_PREFIX)/boot
INCLUDEDIR?=$(PREFIX)/include
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra -I"../include" -I"../../include"
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
LDFLAGS:=$(LDFLAGS)
LIBS:=$(LIBS) -nostdlib -lgcc
ARCHDIR=arch/$(HOSTARCH)
include $(ARCHDIR)/make.config
CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS)
CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS)
LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
KERNEL_OBJS= \
$(KERNEL_ARCH_OBJS) \
kernel/utils.o \
kernel/serial.o \
kernel/interrupts.o \
kernel/descriptor_tables.o \
kernel/kernel.o
OBJS=\
$(KERNEL_OBJS)
LINK_LIST=\
$(LDFLAGS) \
$(KERNEL_OBJS) \
$(LIBS) \
.PHONY: all clean install install-headers install-kernel
.SUFFIXES: .o .c .s
all: BOOTX64.EFI
red.kernel: $(OBJS) $(ARCHDIR)/linker.ld
$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST)
kernel/interrupts.o:
$(CC) -MD -c kernel/interrupts.c -o $@ -std=gnu11 $(CFLAGS) -mno-red-zone -mgeneral-regs-only $(CPPFLAGS)
.c.o:
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS)
.s.o:
nasm -f elf $< -o $@
clean:
rm -f red.kernel
rm -f $(OBJS) *.o */*.o */*/*.o
rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d
install: install-headers install-kernel gen-iso
install-headers:
mkdir -p $(DESTDIR)$(INCLUDEDIR)
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/.
install-kernel: red.kernel
mkdir -p $(DESTDIR)$(BOOTDIR)
cp red.kernel $(DESTDIR)$(BOOTDIR)
gen-iso:
rm -f red.iso
cp red.kernel iso/boot/kernel.elf
genisoimage -R \
-b boot/grub/stage2_eltorito \
-no-emul-boot \
-A ProjectRED \
-input-charset utf8 \
-quiet \
-boot-info-table \
-o red.iso \
iso
BOOTX64.EFI: arch/uefi/entry.o efi/lib/data.o
$(EFI-CC) -nostdlib -Wl,-dll -shared -Wl,--subsystem,10 -e efi_main -o BOOTX64.EFI arch/uefi/entry.o data.o -lgcc
arch/uefi/entry.o:
$(EFI-CC) -ffreestanding -Iinclude/efi/ -Iinclude/efi/x86_64 -Iinclude/efi/protocol -c -o arch/uefi/entry.o arch/uefi/entry.c
efi/lib/data.o:
$(EFI-CC) -ffreestanding -Iinclude/efi/ -Iinclude/efi/x86_64 -Iinclude/efi/protocol -c -o data.o efi/lib/data.c
-include $(OBJS:.o=.d)