2019-04-01 11:21:00 +00:00
|
|
|
DEFAULT_HOST:=i686-elf
|
2019-04-01 01:18:48 +00:00
|
|
|
HOST?=DEFAULT_HOST
|
2019-04-01 11:21:00 +00:00
|
|
|
HOSTARCH:=i386
|
2019-04-01 01:18:48 +00:00
|
|
|
|
|
|
|
CFLAGS?= -O2 -g
|
|
|
|
CPPFLAGS?=
|
|
|
|
LDFLAGS?=
|
|
|
|
LIBS?=
|
|
|
|
|
|
|
|
DESTDIR?=
|
|
|
|
PREFIX?=/usr/local
|
|
|
|
EXEC_PREFIX?=$(PREFIX)
|
|
|
|
BOOTDIR?=$(EXEC_PREFIX)/boot
|
|
|
|
INCLUDEDIR?=$(PREFIX)/include
|
|
|
|
|
|
|
|
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra
|
|
|
|
CPPFLAGS:=$(CPPFLAGS) -D__is_kernel -Iinclude
|
|
|
|
LDFLAGS:=$(LDFLAGS)
|
2019-04-01 11:21:00 +00:00
|
|
|
LIBS:=$(LIBS) -nostdlib -lgcc
|
2019-04-01 01:18:48 +00: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)
|
|
|
|
|
2019-04-01 11:21:00 +00:00
|
|
|
KERNEL_OBJS= \
|
|
|
|
$(KERNEL_ARCH_OBJS) \
|
|
|
|
kernel/utils.o \
|
2019-04-07 14:34:15 +00:00
|
|
|
kernel/serial.o \
|
2019-04-06 19:00:11 +00:00
|
|
|
kernel/gdt.o \
|
2019-04-07 12:16:53 +00:00
|
|
|
kernel/idt.o \
|
2019-04-01 11:21:00 +00:00
|
|
|
kernel/kernel.o
|
2019-04-01 01:18:48 +00: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
|
|
|
|
.SUFFIXES: .o .c .s
|
|
|
|
|
|
|
|
all: red.kernel
|
|
|
|
|
|
|
|
red.kernel: $(OBJS) $(ARCHDIR)/linker.ld
|
|
|
|
$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST)
|
|
|
|
|
|
|
|
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
|
|
|
|
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@
|
2019-04-07 15:36:51 +00:00
|
|
|
|
|
|
|
$(ARCHDIR)/gdt.o:
|
|
|
|
nasm -f elf $(ARCHDIR)/gdt.s
|
2019-04-01 01:18:48 +00:00
|
|
|
|
|
|
|
.c.o:
|
2019-04-01 11:21:00 +00:00
|
|
|
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS)
|
2019-04-01 01:18:48 +00:00
|
|
|
.s.o:
|
|
|
|
$(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f red.kernel
|
2019-04-01 11:21:00 +00:00
|
|
|
rm -f $(OBJS) *.o */*.o */*/*.o
|
2019-04-01 01:18:48 +00:00
|
|
|
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:
|
2019-04-01 11:46:40 +00:00
|
|
|
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 \
|
2019-04-01 01:18:48 +00:00
|
|
|
iso
|
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|
2019-04-06 19:00:11 +00:00
|
|
|
|