feature (build system): setup a build system

This commit is contained in:
antifallobst 2023-04-20 23:16:17 +02:00
parent 4dc0bd6477
commit 0f52c02435
5 changed files with 98 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
cmake-build-debug
build

25
CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.00)
project(libc)
set(C 99)
set(CMAKE_NASM_COMPILE_OBJECT "nasm <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
add_library(libc)
add_library(libc_asm OBJECT)
target_include_directories(libc PRIVATE inc)
file(GLOB_RECURSE libc_src_c "src/**/*.c")
file(GLOB_RECURSE libc_inc "inc/**/*.h")
file(GLOB_RECURSE libc_src_asm "src/**/*.asm")
target_compile_options(libc PRIVATE "-g -fno-stack-protector -fno-stack-check -ffreestanding -m64 -march=x86-64 -mabi=sysv")
target_link_options(libc PRIVATE "-Bsymbolic -nostdlib -shared -fno-stack-protector")
enable_language(ASM_NASM)
set(CAN_USE_ASSEMBLER TRUE)
set_target_properties(libc PROPERTIES PREFIX "")
set_target_properties(libc PROPERTIES SUFFIX ".so")
target_sources(libc_asm PRIVATE ${libc_src_asm})
target_sources(libc PRIVATE ${libc_src_c} ${libc_inc} $<TARGET_OBJECTS:libc_asm>)

52
build.sh Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/bash
# This file is part of noxos and licensed under the MIT open source license
set -e
workspace_setup() {
echo " --> Setting up workspace"
mkdir -pv build
mkdir -pv build/cmake
echo ""
}
check_toolchain() {
echo " --> Checking Toolchain"
hash gcc
echo " |--> found gcc"
hash ld
echo " |--> found ld"
hash nasm
echo " |--> found nasm"
hash cmake
echo " |--> found cmake"
echo " --> All checks passed"
}
libc_build() {
echo " --> Building the noxos standard library"
cd build/cmake
cmake -S ../.. -B .
make
cd ../..
echo ""
}
echo "!=====[ NoxOS libc build script ]=====!"
case $1 in
"check")
check_toolchain
;;
*)
workspace_setup
libc_build
;;
esac
echo "!=====[ Finished ]=====!"

18
src/asm/syscall.asm Normal file
View File

@ -0,0 +1,18 @@
; This file is part of noxos and licensed under the MIT open source license
syscall_perform:
; set the interrupt ID
mov rax, rdi
; set the arguments
mov rdi, rsi
mov rsi, rdx
mov rdx, rcx
mov rcx, r8
int 0x80
; the return value is already set in RAX
ret
GLOBAL syscall_perform

1
src/libc.c Normal file
View File

@ -0,0 +1 @@
// This file is part of noxos and licensed under the MIT open source license