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
|
|
|
|
|
2022-11-16 19:47:19 +02:00
|
|
|
CFLAGS:=$(CFLAGS) -fstack-protector -ffreestanding -Wall -Wextra -Wno-unused-function
|
2022-11-12 21:04:47 +02:00
|
|
|
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
|
|
|
LDFLAGS:=$(LDFLAGS)
|
|
|
|
LIBS:=$(LIBS) -nostdlib -lk -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/kernel.o \
|
2022-11-16 19:48:36 +02:00
|
|
|
kernel/kmalloc.o \
|
2022-11-15 21:42:14 +02:00
|
|
|
kernel/SSP.o \
|
2022-11-12 21:04:47 +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 \
|
|
|
|
|
|
|
|
.PHONY: all clean install install-headers install-kernel
|
2022-11-14 00:27:11 +02:00
|
|
|
.SUFFIXES: .o .cpp .S
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
all: banan-os.kernel
|
|
|
|
|
|
|
|
banan-os.kernel: $(OBJS) $(ARCHDIR)/linker.ld
|
2022-11-14 00:27:11 +02:00
|
|
|
$(CXX) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(CPPFLAGS) $(LINK_LIST)
|
2022-11-12 21:04:47 +02:00
|
|
|
grub-file --is-x86-multiboot banan-os.kernel
|
|
|
|
|
|
|
|
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
|
2022-11-15 21:42:14 +02:00
|
|
|
OBJ=`$(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2022-11-12 21:30:26 +02:00
|
|
|
.cpp.o:
|
|
|
|
$(CXX) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
|
|
|
|
2022-11-12 21:04:47 +02:00
|
|
|
.S.o:
|
2022-11-14 00:27:11 +02:00
|
|
|
$(CXX) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f banan-os.kernel
|
|
|
|
rm -f $(OBJS) *.o */*.o */*/*.o
|
|
|
|
rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d
|
|
|
|
|
|
|
|
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)
|
|
|
|
cp banan-os.kernel $(DESTDIR)$(BOOTDIR)
|
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|