Compare commits

...

4 Commits

Author SHA1 Message Date
f8a4bed8d9 Docs: Added minimal build instruction
Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
2025-03-23 18:16:13 +03:00
b16bb3c49e Build: Added run-kos.sh script
Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
2025-03-23 18:16:07 +03:00
4c92c11668 Tests: Added hello (prints a message to the debug board)
Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
2025-03-23 18:14:41 +03:00
9449b64b05 Build: Added CMake support
Signed-off-by: Max Logaev <maxlogaev@proton.me>
2025-03-23 17:15:53 +03:00
16 changed files with 194 additions and 117 deletions

12
.gitignore vendored
View File

@@ -31,6 +31,12 @@
*.out
*.app
# Build dirs
toolchain/binutils/build
toolchain/gcc/build
# CMake build dir
build
# SDK dir
sdk
# Downloaded KolibriOS artifacts
kolibrios-img.7z
kolibri.img

29
CMakeLists.txt Normal file
View File

@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.31)
project(kolibrios-ports)
include(ExternalProject)
# Number of threads for build
set(JOBS 6)
# Installation directory for GCC and Binutils"
if(NOT DEFINED ENV{SDK_TOOLCHAIN_DIR})
message(FATAL_ERROR "The environment variable SDK_TOOLCHAIN_DIR is not set!")
endif()
set(SDK_TOOLCHAIN_DIR $ENV{SDK_TOOLCHAIN_DIR})
message(STATUS "SDK_TOOLCHAIN_DIR=${SDK_TOOLCHAIN_DIR}")
# Directory for installing ports"
if(NOT DEFINED ENV{SDK_SYSROOT_DIR})
message(FATAL_ERROR "The environment variable SDK_SYSROOT_DIR is not set!")
endif()
set(SDK_SYSROOT_DIR $ENV{SDK_SYSROOT_DIR})
message(STATUS "SDK_SYSROOT_DIR=${SDK_SYSROOT_DIR}")
add_subdirectory(toolchain)
add_subdirectory(libraries)
add_subdirectory(tests)

View File

@@ -1,2 +1,16 @@
# kolibrios-sdk
This is a C/C++ SDK for porting software to KolibriOS
## Build
At the project root:
```sh
source activate-env
cmake -B build
cmake --build build
```
## Testing
Launch KolibriOS with the mounted `SDK_TOOLCHAIN_DIR` directory:
```sh
./run-kos.sh
```

10
activate-env Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
# Installation directory for GCC and Binutils"
export SDK_TOOLCHAIN_DIR="$(pwd)/sdk/toolchain"
# Directory for installing ports"
export SDK_SYSROOT_DIR="$(pwd)/sdk/sysroot"
# Add i586-kolibrios toolchain to PATH
export PATH=$PATH:"$SDK_TOOLCHAIN_DIR/bin"

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Copyright (C) KolibriOS-NG team 2024. All rights reserved
# Distributed under terms of the GNU General Public License
source scripts/start-recipe
ROOT_DIR="$PWD"
PATH=$PATH:"$SDK_TOOLCHAIN_DIR/bin"
declare -a DIRS=(
"toolchain/binutils"
"toolchain/gcc"
"libraries/kos-crt-stub"
)
BUILD()
{
for dir in "${DIRS[@]}" ; do
cd "$ROOT_DIR/$dir"
./kos-recipe.sh
done
}
INSTALL()
{
:;
# "For root recipes, installation is performed in BUILD"
}
CLEAN()
{
for dir in "${DIRS[@]}" ; do
cd "$ROOT_DIR/$dir"
./kos-recipe.sh --clean
done
}
source scripts/end-recipe

20
libraries/CMakeLists.txt Normal file
View File

@@ -0,0 +1,20 @@
# Rules for building libraries
# Copy NewLib headers to sysroot dir
add_custom_target(copy-newlib-headers
COMMAND
${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/newlib/libc/include"
"${SDK_SYSROOT_DIR}/include"
COMMENT "Copying all Newlib headers to ${SDK_SYSROOT_DIR}/include"
)
# Pseudo libc (kos-crt-stub)
ExternalProject_Add(
kos-crt-stub
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/kos-crt-stub
CMAKE_ARGS
-DCMAKE_C_COMPILER=i586-kolibrios-gcc
-DCMAKE_C_COMPILER_WORKS=1
-DCMAKE_INSTALL_PREFIX=${SDK_SYSROOT_DIR}
)

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.31)
project(crt-stub)
# Pseudo libc
add_library(c crt-stub.c)
install(TARGETS c DESTINATION lib)

View File

@@ -1,26 +0,0 @@
#!/bin/bash
# Copyright (C) KolibriOS-NG team 2024. All rights reserved
# Distributed under terms of the GNU General Public License
source ../../scripts/start-recipe
BUILD()
{
i586-kolibrios-gcc -c crt-stub.c -o crt-stub.o
i586-kolibrios-ar crs libc.a crt-stub.o
}
INSTALL()
{
mkdir -p "$SDK_SYSROOT_DIR/lib"
cp -f kos-app.lds "$SDK_SYSROOT_DIR/lib/"
cp -f libc.a "$SDK_SYSROOT_DIR/lib"
}
CLEAN()
{
rm -f crt-stub.o libc.a
}
source ../../scripts/end-recipe

15
run-kos.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
set -eu
download_kolibrios()
{
wget -O "kolibrios-img.7z" https://builds.kolibrios.org/en_US/latest-img.7z
7z e kolibrios-img.7z kolibri.img
}
if [ ! -f "kolibri.img" ]; then
download_kolibrios
fi
qemu-system-i386 -boot a -fda kolibri.img -m 512 -drive file=fat:rw:"$SDK_SYSROOT_DIR" -usbdevice tablet

View File

@@ -1,32 +0,0 @@
# Copyright (C) KolibriOS-NG team 2024. All rights reserved
# Distributed under terms of the GNU General Public License
show_help()
{
cat << EOF
usage: $0 [OPTION]
Options:
--build run recipe build
--install run recipe install (stub for root scripts)
--clean remove build artifacts
--help show this help
Running without parameters is equivalent to running:
'--build' and '--install'
Warning: Run the script only from the directory where it is located!
EOF
}
if [[ $# -eq 0 ]]; then
BUILD
INSTALL
else
case $1 in
"--build" ) BUILD ;;
"--install" ) INSTALL ;;
"--clean" ) CLEAN ;;
"--help" ) show_help ;;
*) fatal "Unknown argument!"
esac
fi

View File

@@ -1,17 +0,0 @@
set -eu
TARGET=i586-kolibrios
SDK_TOOLCHAIN_DIR=/opt/kolibrios-sdk/toolchain
SDK_SYSROOT_DIR=/opt/kolibrios-sdk/sysroot
NUM_JOBS=8
msg()
{
echo -e "\e[32m$1\e[0m"
}
fatal()
{
echo -e "\e[31m$1\e[0m"
exit 1
}

12
tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,12 @@
# Rules for building tests
# Pseudo libc (kos-crt-stub)
ExternalProject_Add(
test-hello
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hello
CMAKE_ARGS
-DCMAKE_C_COMPILER=i586-kolibrios-gcc
-DCMAKE_C_COMPILER_WORKS=1
-DCMAKE_INSTALL_PREFIX=${SDK_SYSROOT_DIR}
BUILD_ALWAYS TRUE
)

View File

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.31)
project(hello)
add_executable(hello hello.c)
install(TARGETS hello DESTINATION bin)

13
tests/hello/hello.c Normal file
View File

@@ -0,0 +1,13 @@
/*
* SPDX-License-Identifier: GPL-2.0
* Copyright (C) 2025 KolibriOS team
*/
int main()
{
char *hello = "I: Hello KolibriOS from GCC!\n";
while(*hello) {
__asm__ __inline__("int $0x40" ::"a"(63), "b"(1), "c"(*hello));
hello++;
}
}

59
toolchain/CMakeLists.txt Normal file
View File

@@ -0,0 +1,59 @@
# Rules for building the i586-kolibrios-gcc toolchain
# Binutils
set(BINUTILS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/binutils)
ExternalProject_Add(
binutils
SOURCE_DIR ${BINUTILS_SRC_DIR}
CONFIGURE_COMMAND
${BINUTILS_SRC_DIR}/configure
--target=i586-kolibrios
--prefix=${SDK_TOOLCHAIN_DIR}
--with-sysroot=${SDK_SYSROOT_DIR}
--disable-werror
--disable-nls
--disable-intl
--disable-sim
--disable-gdb
--enable-shared
BUILD_COMMAND make -j${JOBS}
INSTALL_COMMAND make install-strip
)
# GCC
set(GCC_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gcc)
ExternalProject_Add(
gcc
SOURCE_DIR ${GCC_SRC_DIR}
CONFIGURE_COMMAND
${GCC_SRC_DIR}/configure
--target=i586-kolibrios
--with-sysroot=${SDK_SYSROOT_DIR}
--prefix=${SDK_TOOLCHAIN_DIR}
--disable-multilib
--disable-nls
--enable-shared
--enable-languages=c
BUILD_COMMAND
make -j${JOBS} all-gcc all-target-libgcc
INSTALL_COMMAND
make install-strip-gcc install-target-libgcc
DEPENDS
binutils
)
add_dependencies(gcc copy-newlib-headers)
# Copy kos-app.lds
add_custom_target(copy-kos-app-lds
COMMAND
${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/kos-app.lds"
"${SDK_TOOLCHAIN_DIR}/i586-kolibrios/lib/"
)
# Toolchain
add_custom_target(toolchain)
add_dependencies(toolchain gcc copy-kos-app-lds kos-crt-stub)