BuildSystem: We are now using cmake instead of plain make

I have been annoyed for a while since I had to build everything
when running the os since the buildsystem was really bad.

I wanted to rewrite the whole build system and changed to using cmake

:)
This commit is contained in:
Bananymous 2023-04-02 04:07:27 +03:00
parent c5b83074ac
commit e49d3c7bfe
28 changed files with 260 additions and 499 deletions

6
.gitignore vendored
View File

@ -1,7 +1,3 @@
*.img
isodir
sysroot
.vscode/
.idea/
bochsrc
bx_enh_dbg.ini
build/

8
BAN/CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.26)
project(BAN CXX)
add_custom_target(ban-install
COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/include/* ${BANAN_INCLUDE}
DEPENDS sysroot
)

View File

@ -1,90 +0,0 @@
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)
INCLUDEDIR?=$(PREFIX)/include
LIBDIR?=$(EXEC_PREFIX)/lib
CFLAGS:=$(CFLAGS) -Iinclude -ffreestanding -Wall -Wextra -Werror=return-type
CPPFLAGS:=$(CPPFLAGS)
LIBBANK_CFLAGS:=$(CFLAGS) -D__is_kernel -Iinclude -ffreestanding -Wall -Wextra
LIBBANK_CPPFLAGS:=$(CPPFLAGS) -fno-rtti -fno-exceptions
ARCHDIR=arch/$(HOSTARCH)
include $(ARCHDIR)/make.config
CFLAGS:=$(CFLAGS) $(ARCH_CFLAGS)
CPPFLAGS:=$(CPPFLAGS) $(ARCH_CPPFLAGS)
LIBBANK_CFLAGS:=$(LIBBANK_CFLAGS) $(KERNEL_ARCH_CFLAGS)
LIBBANK_CPPFLAGS:=$(LIBBANK_CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
BUILDDIR=$(abspath build)
FREEOBJS= \
$(ARCH_FREEOBJS) \
BAN/Memory.o \
BAN/String.o \
BAN/StringView.o \
BAN/Time.o \
HOSTEDOBJS=\
$(ARCH_HOSTEDOBJS) \
OBJS=\
$(FREEOBJS) \
$(HOSTEDOBJS) \
LIBBANK_OBJS=$(FREEOBJS:.o=.bank.o)
BINARIES=libbank.a
.PHONY: all always clean install install-headers install-libs
.SUFFIXES: .o .bank.o .cpp .S
all: $(BINARIES)
libban.a: always $(OBJS)
cd $(BUILDDIR) && $(AR) rcs $@ $(OBJS)
libbank.a: always $(LIBBANK_OBJS)
cd $(BUILDDIR) && $(AR) rcs $@ $(LIBBANK_OBJS)
.cpp.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
.S.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
.cpp.bank.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBBANK_CFLAGS) $(LIBBANK_CPPFLAGS)
.S.bank.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBBANK_CFLAGS) $(LIBBANK_CPPFLAGS)
clean:
rm -rf $(BUILDDIR)
always:
mkdir -p $(BUILDDIR)/BAN
install: install-headers install-libs
install-headers:
mkdir -p $(DESTDIR)$(INCLUDEDIR)
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/.
install-libs: $(BINARIES)
mkdir -p $(DESTDIR)$(LIBDIR)
cp $(BUILDDIR)/$(BINARIES) $(DESTDIR)$(LIBDIR)
-include $(OBJS:.o=.d)
-include $(LIBBANK_OBJS:.o=.d)

View File

@ -1,8 +0,0 @@
ARCH_CFLAGS=
ARCH_CPPFLAGS=
KERNEL_ARCH_CFLAGS=
KERNEL_ARCH_CPPFLAGS=
ARCH_FREEOBJS=\
ARCH_HOSTEDOBJS=\

View File

@ -1,8 +0,0 @@
ARCH_CFLAGS=
ARCH_CPPFLAGS=
KERNEL_ARCH_CFLAGS=
KERNEL_ARCH_CPPFLAGS=
ARCH_FREEOBJS=\
ARCH_HOSTEDOBJS=\

View File

@ -1,5 +1,6 @@
#pragma once
#include <BAN/Errors.h>
#include <BAN/ForwardList.h>
#include <BAN/Formatter.h>
#include <BAN/Hash.h>
@ -87,7 +88,7 @@ namespace BAN
String String::formatted(const char* format, const Args&... args)
{
String result;
BAN::Formatter::print([&](char c){ result.push_back(c); }, format, args...);
BAN::Formatter::print([&](char c){ MUST(result.push_back(c)); }, format, args...);
return result;
}

49
CMakeLists.txt Normal file
View File

@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.26)
project(banan-os CXX ASM)
set(BANAN_ARCH x86_64)
set(BANAN_SYSROOT ${CMAKE_BINARY_DIR}/sysroot)
set(BANAN_INCLUDE ${BANAN_SYSROOT}/usr/include)
set(BANAN_BOOT ${BANAN_SYSROOT}/boot)
set(DISK_IMAGE_PATH ${CMAKE_BINARY_DIR}/banan-os.img)
add_subdirectory(kernel)
add_subdirectory(BAN)
add_subdirectory(libc)
add_custom_target(sysroot
COMMAND mkdir -p ${BANAN_SYSROOT}
COMMAND mkdir -p ${BANAN_BOOT}
COMMAND mkdir -p ${BANAN_INCLUDE}
COMMAND cp -r ${CMAKE_SOURCE_DIR}/base/* ${BANAN_SYSROOT}/
)
add_custom_target(image
COMMAND ${CMAKE_COMMAND} -E env SYSROOT="${BANAN_SYSROOT}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/image.sh
DEPENDS kernel-install
DEPENDS ban-install
DEPENDS libc-install
USES_TERMINAL
)
add_custom_target(image-full
COMMAND ${CMAKE_COMMAND} -E env SYSROOT="${BANAN_SYSROOT}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/image-full.sh
DEPENDS kernel-install
DEPENDS ban-install
DEPENDS libc-install
USES_TERMINAL
)
add_custom_target(qemu
COMMAND ${CMAKE_COMMAND} -E env BANAN_ARCH="${BANAN_ARCH}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/qemu.sh
DEPENDS image
USES_TERMINAL
)
add_custom_target(bochs
COMMAND ${CMAKE_COMMAND} -E env DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/bochs.sh
DEPENDS image
USES_TERMINAL
)

15
base/boot/grub/grub.cfg Normal file
View File

@ -0,0 +1,15 @@
menuentry "banan-os" {
multiboot /boot/banan-os.kernel root=/dev/hda1
}
menuentry "banan-os (no serial)" {
multiboot /boot/banan-os.kernel root=/dev/hda1 noserial
}
menuentry "banan-os (no apic)" {
multiboot /boot/banan-os.kernel root=/dev/hda1 noapic
}
menuentry "banan-os (no apic, no serial)" {
multiboot /boot/banan-os.kernel root=/dev/hda1 noapic noserial
}

View File

@ -1,6 +1,5 @@
#!/bin/sh
set -e
. ./disk.sh
BOCHS_CONFIG_FILE=bochsrc
COM1_TERMINAL=kitty
@ -15,7 +14,7 @@ COM1_DEVICE=$(cat $COM1_DEVICE_FILE)
rm $COM1_DEVICE_FILE
cat > $BOCHS_CONFIG_FILE << EOF
ata0-master: type=disk, path=banan-os.img, status=inserted
ata0-master: type=disk, path=$DISK_IMAGE_PATH, status=inserted
boot: disk
clock: sync=realtime, time0=local
display_library: x, options="gui_debug"

View File

@ -1,7 +0,0 @@
#!/bin/sh
set -e
. ./headers.sh
for PROJECT in $PROJECTS; do
(cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install)
done

View File

@ -1,11 +0,0 @@
#!/bin/sh
set -e
. ./config.sh
for PROJECT in $PROJECTS; do
(cd $PROJECT && $MAKE clean)
done
rm -rf sysroot
rm -rf isodir
rm -rf banan-os.img

View File

@ -1,33 +0,0 @@
SYSTEM_HEADER_PROJECTS="libc BAN kernel"
PROJECTS="libc BAN kernel"
export MAKE=${MAKE:-make}
export HOST=${HOST:-$(./default-host.sh)}
export AR=${HOST}-ar
export AS=${HOST}-as
export CC=${HOST}-gcc
export CXX=${HOST}-g++
export PREFIX=/usr
export EXEC_PREFIX=$PREFIX
export BOOTDIR=/boot
export LIBDIR=$EXEC_PREFIX/lib
export INCLUDEDIR=$PREFIX/include
export CFLAGS='-O2 -g'
export CPPFLAGS='--std=c++20 -Wno-literal-suffix'
export UBSAN=0
# Configure the cross-compiler to use the desired system root.
export SYSROOT="$(pwd)/sysroot"
export CC="$CC --sysroot=$SYSROOT"
export CXX="$CXX --sysroot=$SYSROOT"
# Work around that the -elf gcc targets doesn't have a system include directory
# because it was configured with --without-headers rather than --with-sysroot.
if echo "$HOST" | grep -Eq -- '-elf($|-)'; then
export CC="$CC -isystem=$INCLUDEDIR"
export CXX="$CXX -isystem=$INCLUDEDIR"
fi

View File

@ -1,2 +0,0 @@
#!/bin/sh
echo x86_64-elf

View File

@ -1,9 +0,0 @@
#!/bin/sh
set -e
. ./config.sh
mkdir -p "$SYSROOT"
for PROJECT in $SYSTEM_HEADER_PROJECTS; do
(cd $PROJECT && DESTDIR="$SYSROOT" $MAKE install-headers)
done

View File

@ -1,16 +1,12 @@
#!/bin/sh
set -e
. ./build.sh
cp -r base/* $SYSROOT
DISK_NAME=banan-os.img
DISK_SIZE=$[50 * 1024 * 1024]
MOUNT_DIR=/mnt
dd if=/dev/zero of=$DISK_NAME bs=512 count=$[$DISK_SIZE / 512]
dd if=/dev/zero of=$DISK_IMAGE_PATH bs=512 count=$[$DISK_SIZE / 512] > /dev/null
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk $DISK_NAME
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk $DISK_IMAGE_PATH > /dev/null
g # gpt
n # new partition
1 # partition number 1
@ -36,40 +32,25 @@ sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk $DISK_NAME
w # write changes
EOF
LOOP_DEV=$(sudo losetup -f --show $DISK_NAME)
LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH)
sudo partprobe $LOOP_DEV
PARTITION1=${LOOP_DEV}p1
PARTITION2=${LOOP_DEV}p2
PARTITION3=${LOOP_DEV}p3
sudo mkfs.ext2 $PARTITION3
sudo mkfs.ext2 $PARTITION3 > /dev/null
sudo mount $PARTITION3 $MOUNT_DIR
echo 'hello' | sudo tee ${MOUNT_DIR}/hello.txt
echo 'hello' | sudo tee ${MOUNT_DIR}/hello.txt > /dev/null
sudo umount $MOUNT_DIR
sudo mkfs.ext2 $PARTITION2
sudo mkfs.ext2 $PARTITION2 > /dev/null
sudo mount $PARTITION2 $MOUNT_DIR
sudo cp -r ${SYSROOT}/* ${MOUNT_DIR}/
sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory=${MOUNT_DIR}/boot $LOOP_DEV
echo -e '
menuentry "banan-os" {
multiboot /boot/banan-os.kernel root=/dev/hda1
}
menuentry "banan-os (no serial)" {
multiboot /boot/banan-os.kernel root=/dev/hda1 noserial
}
menuentry "banan-os (no apic)" {
multiboot /boot/banan-os.kernel root=/dev/hda1 noapic
}
menuentry "banan-os (no apic, no serial)" {
multiboot /boot/banan-os.kernel root=/dev/hda1 noapic noserial
}
' | sudo tee ${MOUNT_DIR}/boot/grub/grub.cfg
sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory=${MOUNT_DIR}/boot $LOOP_DEV > /dev/null
sudo umount $MOUNT_DIR

22
image.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
set -e
if [ ! -f $DISK_IMAGE_PATH ]; then
$(dirname "$0")/image-full.sh
exit 0
fi
MOUNT_DIR=/mnt
LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH)
sudo partprobe $LOOP_DEV
ROOT_PARTITON=${LOOP_DEV}p2
sudo mount $ROOT_PARTITON $MOUNT_DIR
sudo cp -r ${SYSROOT}/* ${MOUNT_DIR}/
sudo umount $MOUNT_DIR
sudo losetup -d $LOOP_DEV

3
kernel/.gitignore vendored
View File

@ -1,3 +0,0 @@
*.d
*.kernel
*.o

141
kernel/CMakeLists.txt Normal file
View File

@ -0,0 +1,141 @@
cmake_minimum_required(VERSION 3.26)
project(kernel CXX ASM)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_COMPILER ${BANAN_ARCH}-elf-g++)
set(CMAKE_CXX_COMPILER_WORKS True)
set(KERNEL_SOURCES
font/prefs.psf.o
kernel/ACPI.cpp
kernel/APIC.cpp
kernel/build_libc.cpp
kernel/CPUID.cpp
kernel/Debug.cpp
kernel/Device.cpp
kernel/DeviceManager.cpp
kernel/ELF.cpp
kernel/Font.cpp
kernel/FS/Ext2.cpp
kernel/FS/VirtualFileSystem.cpp
kernel/Input/PS2Controller.cpp
kernel/Input/PS2Keyboard.cpp
kernel/Input/PS2Keymap.cpp
kernel/InterruptController.cpp
kernel/kernel.cpp
kernel/kmalloc.cpp
kernel/PCI.cpp
kernel/PIC.cpp
kernel/PIT.cpp
kernel/Process.cpp
kernel/RTC.cpp
kernel/Scheduler.cpp
kernel/Semaphore.cpp
kernel/Serial.cpp
kernel/Shell.cpp
kernel/SpinLock.cpp
kernel/SSP.cpp
kernel/Storage/ATAController.cpp
kernel/Storage/StorageDevice.cpp
kernel/Syscall.cpp
kernel/Thread.cpp
kernel/TTY.cpp
kernel/VesaTerminalDriver.cpp
userspace/userspace.cpp
icxxabi.cpp
)
if(ENABLE_KERNEL_UBSAN)
set(KERNEL_SOURCES ${KERNEL_SOURCES} ubsan.cpp)
endif()
if("${BANAN_ARCH}" STREQUAL "x86_64")
set(KERNEL_SOURCES
${KERNEL_SOURCES}
arch/x86_64/boot.S
arch/x86_64/GDT.cpp
arch/x86_64/IDT.cpp
arch/x86_64/interrupts.S
arch/x86_64/MMU.cpp
arch/x86_64/SpinLock.S
arch/x86_64/Thread.S
)
elseif("${BANAN_ARCH}" EQUAL "i386")
set(KERNEL_SOURCES
${KERNEL_SOURCES}
arch/i386/boot.S
arch/i386/GDT.cpp
arch/i386/IDT.cpp
arch/i386/MMU.cpp
arch/i386/SpinLock.S
arch/i386/Thread.S
)
else()
message(FATAL_ERROR "unsupported architecure")
endif()
set(BAN_SOURCES
../BAN/BAN/Memory.cpp
../BAN/BAN/String.cpp
../BAN/BAN/StringView.cpp
../BAN/BAN/Time.cpp
)
set(LIBC_SOURCES
../libc/ctype.cpp
../libc/string.cpp
)
set(KERNEL_SOURCES
${KERNEL_SOURCES}
${BAN_SOURCES}
${LIBC_SOURCES}
)
add_executable(kernel ${KERNEL_SOURCES})
target_include_directories(kernel PUBLIC include ../BAN/include ../libc/include)
target_compile_definitions(kernel PUBLIC __is_kernel)
target_compile_definitions(kernel PUBLIC __arch=x86_64)
target_compile_options(kernel PUBLIC -O2 -g)
target_compile_options(kernel PUBLIC -Wno-literal-suffix)
target_compile_options(kernel PUBLIC -fno-rtti -fno-exceptions)
target_compile_options(kernel PUBLIC -fstack-protector -ffreestanding -Wall -Wextra -Werror=return-type -fno-omit-frame-pointer -mno-sse -mno-sse2)
if(ENABLE_KERNEL_UBSAN)
target_compile_options(kernel PUBLIC -fsanitize=undefined)
endif()
if("${BANAN_ARCH}" STREQUAL "x86_64")
target_compile_options(kernel PUBLIC -mcmodel=large -mno-red-zone -mno-mmx)
target_link_options(kernel PUBLIC LINKER:-z,max-page-size=4096)
target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/x86_64/linker.ld)
elseif("${BANAN_ARCH}" STREQUAL "i386")
target_link_options(kernel PUBLIC LINKER:-T,${CMAKE_CURRENT_SOURCE_DIR}/arch/i386/linker.ld)
endif()
target_link_options(kernel PUBLIC -ffreestanding -nostdlib -O2)
add_custom_target(kernel-install
COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/include/* ${BANAN_INCLUDE}/
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/kernel ${BANAN_BOOT}/banan-os.kernel
DEPENDS sysroot
DEPENDS kernel
)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=crtbegin.o OUTPUT_VARIABLE CRTBEGIN OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=crtend.o OUTPUT_VARIABLE CRTEND OUTPUT_STRIP_TRAILING_WHITESPACE)
add_custom_command(
TARGET kernel PRE_LINK
COMMAND ${CMAKE_CXX_COMPILER} -MD -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crti.S ${COMPILE_OPTIONS}
COMMAND ${CMAKE_CXX_COMPILER} -MD -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crtn.S ${COMPILE_OPTIONS}
COMMAND cp ${CRTBEGIN} .
COMMAND cp ${CRTEND} .
)
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_COMPILER} <CMAKE_CXX_LINK_FLAGS> <FLAGS> <LINK_FLAGS> -o <TARGET> ${CMAKE_CURRENT_BINARY_DIR}/crti.o ${CMAKE_CURRENT_BINARY_DIR}/crtbegin.o <OBJECTS> ${CMAKE_CURRENT_BINARY_DIR}/crtend.o ${CMAKE_CURRENT_BINARY_DIR}/crtn.o")

View File

@ -1,138 +0,0 @@
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
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
CPPFLAGS:=$(CPPFLAGS) -fno-rtti -fno-exceptions
LDFLAGS:=$(LDFLAGS)
LIBS:=$(LIBS) -nostdlib -lk -lbank -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)
ifeq ($(UBSAN), 1)
CFLAGS:=$(CFLAGS) -fsanitize=undefined
endif
BUILDDIR=$(abspath build)
KERNEL_OBJS= \
$(KERNEL_ARCH_OBJS) \
font/prefs.o \
kernel/ACPI.o \
kernel/APIC.o \
kernel/build_libc.o \
kernel/CPUID.o \
kernel/Debug.o \
kernel/Device.o \
kernel/DeviceManager.o \
kernel/Font.o \
kernel/FS/Ext2.o \
kernel/FS/VirtualFileSystem.o \
kernel/Input/PS2Controller.o \
kernel/Input/PS2Keyboard.o \
kernel/Input/PS2Keymap.o \
kernel/InterruptController.o \
kernel/kernel.o \
kernel/kmalloc.o \
kernel/PCI.o \
kernel/PIC.o \
kernel/PIT.o \
kernel/Process.o \
kernel/RTC.o \
kernel/Scheduler.o \
kernel/Semaphore.o \
kernel/Serial.o \
kernel/Shell.o \
kernel/SpinLock.o \
kernel/SSP.o \
kernel/Storage/ATAController.o \
kernel/Storage/StorageDevice.o \
kernel/Syscall.o \
kernel/Thread.o \
kernel/TTY.o \
kernel/VesaTerminalDriver.o \
userspace/userspace.o \
icxxabi.o \
ubsan.o \
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 always clean install install-headers install-kernel
.SUFFIXES: .o .c .cpp .S .psf
all: banan-os.kernel
banan-os.kernel: always $(OBJS) $(ARCHDIR)/linker.ld
cd $(BUILDDIR) && $(CXX) -T ../$(ARCHDIR)/linker.ld -o banan-os.kernel $(CFLAGS) $(CPPFLAGS) $(LINK_LIST)
cd $(BUILDDIR) && grub-file --is-x86-multiboot banan-os.kernel
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
OBJ=`$(CC) $(CFLAGS) $(LDFLAGS) -print-file-name=$(@F)` && cp "$$OBJ" $(BUILDDIR)/$@
.c.o:
$(CC) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS)
.cpp.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
.S.o:
$(CC) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS)
.psf.o:
objcopy -O $(ELF_FORMAT) -B i386 -I binary $< $(BUILDDIR)/$@
always:
mkdir -p $(BUILDDIR)/$(ARCHDIR)
mkdir -p $(BUILDDIR)/kernel
mkdir -p $(BUILDDIR)/kernel/FS
mkdir -p $(BUILDDIR)/kernel/Input
mkdir -p $(BUILDDIR)/kernel/Storage
mkdir -p $(BUILDDIR)/userspace
mkdir -p $(BUILDDIR)/font
clean:
rm -rf $(BUILDDIR)
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 $(BUILDDIR)/banan-os.kernel $(DESTDIR)$(BOOTDIR)
-include $(OBJS:.o=.d)

View File

@ -1,15 +0,0 @@
KERNEL_ARCH_CFLAGS=
KERNEL_ARCH_CPPFLAGS=
KERNEL_ARCH_LDFLAGS=
KERNEL_ARCH_LIBS=
ELF_FORMAT=elf32-i386
KERNEL_ARCH_OBJS= \
$(ARCHDIR)/boot.o \
$(ARCHDIR)/GDT.o \
$(ARCHDIR)/IDT.o \
$(ARCHDIR)/MMU.o \
$(ARCHDIR)/SpinLock.o \
$(ARCHDIR)/Thread.o \

View File

@ -1,16 +0,0 @@
KERNEL_ARCH_CFLAGS=-mcmodel=large -mno-red-zone -mno-mmx
KERNEL_ARCH_CPPFLAGS=
KERNEL_ARCH_LDFLAGS=-z max-page-size=4096
KERNEL_ARCH_LIBS=
ELF_FORMAT=elf64-x86-64
KERNEL_ARCH_OBJS= \
$(ARCHDIR)/boot.o \
$(ARCHDIR)/GDT.o \
$(ARCHDIR)/IDT.o \
$(ARCHDIR)/interrupts.o \
$(ARCHDIR)/MMU.o \
$(ARCHDIR)/SpinLock.o \
$(ARCHDIR)/Thread.o \

BIN
kernel/font/prefs.psf.o Normal file

Binary file not shown.

8
libc/CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.26)
project(libc CXX)
add_custom_target(libc-install
COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/include/* ${BANAN_INCLUDE}
DEPENDS sysroot
)

View File

@ -1,95 +0,0 @@
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)
INCLUDEDIR?=$(PREFIX)/include
LIBDIR?=$(EXEC_PREFIX)/lib
CFLAGS:=$(CFLAGS) -D__is_libc -Iinclude -ffreestanding -Wall -Wextra -Werror=return-type
CPPFLAGS:=$(CPPFLAGS)
LIBK_CFLAGS:=$(CFLAGS) -D__is_libk
LIBK_CPPFLAGS:=$(CPPFLAGS)
ARCHDIR=arch/$(HOSTARCH)
include $(ARCHDIR)/make.config
CFLAGS:=$(CFLAGS) $(ARCH_CFLAGS)
CPPFLAGS:=$(CPPFLAGS) $(ARCH_CPPFLAGS)
LIBK_CFLAGS:=$(LIBK_CFLAGS) $(KERNEL_ARCH_CFLAGS)
LIBK_CPPFLAGS:=$(LIBK_CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
BUILDDIR=$(abspath build)
FREEOBJS=\
$(ARCH_FREEOBJS) \
ctype.o \
stdio/printf.o \
stdio/putchar.o \
stdio/puts.o \
stdlib/abort.o \
string.o \
HOSTEDOBJS=\
$(ARCH_HOSTEDOBJS) \
OBJS=\
$(FREEOBJS) \
$(HOSTEDOBJS) \
LIBK_OBJS=$(FREEOBJS:.o=.libk.o)
#BINARIES=libc.a libk.a # Not ready for libc yet.
BINARIES=libk.a
.PHONY: all always clean install install-headers install-libs
.SUFFIXES: .o .libk.o .cpp .S
all: $(BINARIES)
libc.a: always $(OBJS)
cd $(BUILDDIR) && $(AR) rcs $@ $(OBJS)
libk.a: always $(LIBK_OBJS)
cd $(BUILDDIR) && $(AR) rcs $@ $(LIBK_OBJS)
.cpp.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
.S.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
.cpp.libk.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
.S.libk.o:
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
clean:
rm -rf $(BUILDDIR)
always:
mkdir -p $(BUILDDIR)/stdio
mkdir -p $(BUILDDIR)/stdlib
mkdir -p $(BUILDDIR)/string
install: install-headers install-libs
install-headers:
mkdir -p $(DESTDIR)$(INCLUDEDIR)
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/.
install-libs: $(BINARIES)
mkdir -p $(DESTDIR)$(LIBDIR)
cp $(BUILDDIR)/$(BINARIES) $(DESTDIR)$(LIBDIR)
-include $(OBJS:.o=.d)
-include $(LIBK_OBJS:.o=.d)

View File

@ -1,8 +0,0 @@
ARCH_CFLAGS=
ARCH_CPPFLAGS=
KERNEL_ARCH_CFLAGS=
KERNEL_ARCH_CPPFLAGS=
ARCH_FREEOBJS=\
ARCH_HOSTEDOBJS=\

View File

@ -1,8 +0,0 @@
ARCH_CFLAGS=
ARCH_CPPFLAGS=
KERNEL_ARCH_CFLAGS=
KERNEL_ARCH_CPPFLAGS=
ARCH_FREEOBJS=\
ARCH_HOSTEDOBJS=\

14
qemu.sh
View File

@ -1,11 +1,9 @@
#!/bin/sh
set -e
. ./disk.sh
qemu-system-$(./target-triplet-to-arch.sh $HOST) \
-m 128 \
-smp 2 \
-drive format=raw,media=disk,file=banan-os.img \
-serial stdio \
-accel kvm \
qemu-system-$BANAN_ARCH \
-m 128 \
-smp 2 \
-drive format=raw,media=disk,file=${DISK_IMAGE_PATH} \
-serial stdio \
-accel kvm \

View File

@ -1,6 +0,0 @@
#!/bin/sh
if echo "$1" | grep -Eq 'i[[:digit:]]86-'; then
echo i386
else
echo "$1" | grep -Eo '^[[:alnum:]_]*'
fi