2022-11-12 21:04:47 +02:00
|
|
|
DEFAULT_HOST!=../default-host.sh
|
|
|
|
HOST?=DEFAULT_HOST
|
|
|
|
HOSTARCH!=../target-triplet-to-arch.sh $(HOST)
|
|
|
|
|
|
|
|
CFLAGS?=-O2 -g
|
|
|
|
CPPFLAGS?=
|
|
|
|
LDFLAGS?=
|
|
|
|
LIBS?=
|
|
|
|
|
|
|
|
DESTDIR?=
|
|
|
|
PREFIX?=/usr/local
|
|
|
|
EXEC_PREFIX?=$(PREFIX)
|
|
|
|
BOOTDIR?=$(EXEC_PREFIX)/boot
|
|
|
|
INCLUDEDIR?=$(PREFIX)/include
|
|
|
|
|
2023-02-01 01:52:05 +02:00
|
|
|
CFLAGS:=$(CFLAGS) -D__is_kernel -D__arch=$(HOSTARCH) -Iinclude -fstack-protector -ffreestanding -Wall -Wextra -Werror=return-type -fno-omit-frame-pointer -mno-sse -mno-sse2
|
2022-12-07 02:41:18 +02:00
|
|
|
CPPFLAGS:=$(CPPFLAGS) -fno-rtti -fno-exceptions
|
2022-11-12 21:04:47 +02:00
|
|
|
LDFLAGS:=$(LDFLAGS)
|
2022-12-13 12:10:50 +02:00
|
|
|
LIBS:=$(LIBS) -nostdlib -lk -lbank -lgcc
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
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)
|
2022-12-03 18:15:10 +02:00
|
|
|
|
|
|
|
BUILDDIR=$(abspath build)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2023-01-23 20:13:57 +02:00
|
|
|
KERNEL_OBJS= \
|
|
|
|
$(KERNEL_ARCH_OBJS) \
|
2023-02-23 01:22:50 +02:00
|
|
|
font/prefs.o \
|
2023-01-23 20:13:57 +02:00
|
|
|
kernel/APIC.o \
|
2023-02-16 20:00:31 +02:00
|
|
|
kernel/ATA.o \
|
2023-01-23 20:13:57 +02:00
|
|
|
kernel/build_libc.o \
|
|
|
|
kernel/CPUID.o \
|
2023-01-25 21:39:03 +02:00
|
|
|
kernel/Debug.o \
|
2023-02-16 20:00:31 +02:00
|
|
|
kernel/DiskIO.o \
|
2023-02-22 22:29:31 +02:00
|
|
|
kernel/Font.o \
|
2023-02-20 01:46:00 +02:00
|
|
|
kernel/FS/Ext2.o \
|
|
|
|
kernel/FS/VirtualFileSystem.o \
|
2023-01-23 20:13:57 +02:00
|
|
|
kernel/Input.o \
|
|
|
|
kernel/InterruptController.o \
|
|
|
|
kernel/kernel.o \
|
|
|
|
kernel/kmalloc.o \
|
2023-02-26 02:56:53 +02:00
|
|
|
kernel/PCI.o \
|
2023-01-23 20:13:57 +02:00
|
|
|
kernel/PIC.o \
|
|
|
|
kernel/PIT.o \
|
|
|
|
kernel/RTC.o \
|
2023-02-01 01:53:35 +02:00
|
|
|
kernel/Scheduler.o \
|
2023-01-23 20:13:57 +02:00
|
|
|
kernel/Serial.o \
|
|
|
|
kernel/Shell.o \
|
2023-02-01 01:51:25 +02:00
|
|
|
kernel/SpinLock.o \
|
2023-01-23 20:13:57 +02:00
|
|
|
kernel/SSP.o \
|
2023-02-01 01:53:35 +02:00
|
|
|
kernel/Thread.o \
|
2023-01-23 20:13:57 +02:00
|
|
|
kernel/TTY.o \
|
|
|
|
kernel/VesaTerminalDriver.o \
|
|
|
|
icxxabi.o \
|
2022-12-13 00:59:53 +02:00
|
|
|
|
|
|
|
OBJS= \
|
|
|
|
$(ARCHDIR)/crti.o \
|
|
|
|
$(ARCHDIR)/crtbegin.o \
|
|
|
|
$(KERNEL_OBJS) \
|
|
|
|
$(ARCHDIR)/crtend.o \
|
|
|
|
$(ARCHDIR)/crtn.o \
|
|
|
|
|
|
|
|
LINK_LIST= \
|
|
|
|
$(LDFLAGS) \
|
|
|
|
$(ARCHDIR)/crti.o \
|
|
|
|
$(ARCHDIR)/crtbegin.o \
|
|
|
|
$(KERNEL_OBJS) \
|
|
|
|
$(LIBS) \
|
|
|
|
$(ARCHDIR)/crtend.o \
|
|
|
|
$(ARCHDIR)/crtn.o \
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2022-12-03 18:15:10 +02:00
|
|
|
.PHONY: all always clean install install-headers install-kernel
|
2023-02-23 01:22:50 +02:00
|
|
|
.SUFFIXES: .o .c .cpp .S .psf
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
all: banan-os.kernel
|
|
|
|
|
2022-12-03 18:15:10 +02:00
|
|
|
banan-os.kernel: always $(OBJS) $(ARCHDIR)/linker.ld
|
2022-12-07 02:41:18 +02:00
|
|
|
cd $(BUILDDIR) && $(CXX) -T ../$(ARCHDIR)/linker.ld -o banan-os.kernel $(CFLAGS) $(CPPFLAGS) $(LINK_LIST)
|
2022-12-03 18:15:10 +02:00
|
|
|
cd $(BUILDDIR) && grub-file --is-x86-multiboot banan-os.kernel
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
|
2022-12-03 18:15:10 +02:00
|
|
|
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $(BUILDDIR)/$@
|
2022-12-07 02:41:18 +02:00
|
|
|
|
2022-12-16 00:46:10 +02:00
|
|
|
.c.o:
|
|
|
|
$(CC) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS)
|
|
|
|
|
2022-11-12 21:30:26 +02:00
|
|
|
.cpp.o:
|
2022-12-03 18:15:10 +02:00
|
|
|
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
|
2022-11-12 21:30:26 +02:00
|
|
|
|
2022-11-12 21:04:47 +02:00
|
|
|
.S.o:
|
2022-12-03 18:15:10 +02:00
|
|
|
$(CC) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2023-02-23 01:22:50 +02:00
|
|
|
.psf.o:
|
2023-02-24 03:19:54 +02:00
|
|
|
objcopy -O $(ELF_FORMAT) -B i386 -I binary $< $(BUILDDIR)/$@
|
2023-02-23 01:22:50 +02:00
|
|
|
|
2022-12-03 18:15:10 +02:00
|
|
|
always:
|
2023-01-09 14:56:20 +02:00
|
|
|
mkdir -p $(BUILDDIR)/$(ARCHDIR)
|
2022-12-03 18:15:10 +02:00
|
|
|
mkdir -p $(BUILDDIR)/kernel
|
2023-02-20 01:46:00 +02:00
|
|
|
mkdir -p $(BUILDDIR)/kernel/FS
|
2023-02-23 01:22:50 +02:00
|
|
|
mkdir -p $(BUILDDIR)/font
|
2022-12-03 18:15:10 +02:00
|
|
|
|
2022-11-12 21:04:47 +02:00
|
|
|
clean:
|
2022-12-03 18:15:10 +02:00
|
|
|
rm -rf $(BUILDDIR)
|
|
|
|
|
2022-11-12 21:04:47 +02:00
|
|
|
install: install-headers install-kernel
|
|
|
|
|
|
|
|
install-headers:
|
|
|
|
mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
|
|
|
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/.
|
|
|
|
|
|
|
|
install-kernel: banan-os.kernel
|
|
|
|
mkdir -p $(DESTDIR)$(BOOTDIR)
|
2022-12-03 18:15:10 +02:00
|
|
|
cp $(BUILDDIR)/banan-os.kernel $(DESTDIR)$(BOOTDIR)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|