This repository has been archived on 2024-06-25. You can view files and clone it, but cannot push or open issues or pull requests.
rockOS/kernel/Makefile

90 lines
2.0 KiB
Makefile
Raw Normal View History

2022-07-20 16:42:13 +03:00
DEFAULT_HOST=$(shell ../default-host.sh)
2022-07-18 09:59:04 +03:00
HOST?=DEFAULT_HOST
2022-07-20 16:42:13 +03:00
HOSTARCH=$(shell ../target-triplet-to-arch.sh $(HOST))
2022-07-18 09:59:04 +03:00
CFLAGS?=-O3 -g
CPPFLAGS?=
LDFLAGS?=
LIBS?=
DESTDIR?=
PREFIX?=/usr/local
EXEC_PREFIX?=$(PREFIX)
BOOTDIR?=$(EXEC_PREFIX)/boot
INCLUDEDIR?=$(PREFIX)/include
CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra -Wformat -Wpedantic -fstack-protector-strong -mgeneral-regs-only -mno-red-zone
2022-07-18 09:59:04 +03: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_FLAGS)
CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS)
LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
KERNEL_OBJS=\
$(KERNEL_ARCH_OBJS) \
2022-07-20 02:23:23 +03:00
rockos/kernel.o \
rockos/data_struct/sorted_array.o \
rockos/kheap.o \
2022-07-20 02:23:23 +03:00
rockos/paging.o \
2022-07-21 12:20:35 +03:00
rockos/keyboard.o \
rockos/timer.o \
2022-07-27 05:49:06 +03:00
rockos/vfs.o \
2022-07-18 09:59:04 +03:00
OBJS=\
2022-07-18 18:14:20 +03:00
$(ARCHDIR)/boot/crti.o \
2022-07-18 09:59:04 +03:00
$(ARCHDIR)/crtbegin.o \
$(KERNEL_OBJS) \
$(ARCHDIR)/crtend.o \
2022-07-18 18:14:20 +03:00
$(ARCHDIR)/boot/crtn.o \
2022-07-18 09:59:04 +03:00
LINK_LIST=\
$(LDFLAGS) \
2022-07-18 18:14:20 +03:00
$(ARCHDIR)/boot/crti.o \
2022-07-18 09:59:04 +03:00
$(ARCHDIR)/crtbegin.o \
$(KERNEL_OBJS) \
$(LIBS) \
$(ARCHDIR)/crtend.o \
2022-07-18 18:14:20 +03:00
$(ARCHDIR)/boot/crtn.o \
2022-07-18 09:59:04 +03:00
.PHONY: all clean install install-headers install-kernel
.SUFFIXES: .o .c .S
all: rockos.kernel
rockos.kernel: $(OBJS) $(ARCHDIR)/linker.ld
$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST)
2022-07-20 16:42:13 +03:00
$(GRUB_FILE) --is-x86-multiboot rockos.kernel
2022-07-18 09:59:04 +03:00
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $@
.c.o:
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS)
.S.o:
$(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
clean:
rm -f rockos.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)
2022-07-20 16:42:13 +03:00
cp -Rp include/. $(DESTDIR)$(INCLUDEDIR)/.
2022-07-18 09:59:04 +03:00
install-kernel: rockos.kernel
mkdir -p $(DESTDIR)$(BOOTDIR)
cp rockos.kernel $(DESTDIR)$(BOOTDIR)
-include $(OBJS:.o=.d)