Build: Added CMake support
Signed-off-by: Max Logaev <maxlogaev@proton.me>
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -31,6 +31,8 @@
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# Build dirs
|
||||
toolchain/binutils/build
|
||||
toolchain/gcc/build
|
||||
# CMake build dir
|
||||
build
|
||||
|
||||
# SDK dir
|
||||
sdk
|
||||
|
28
CMakeLists.txt
Normal file
28
CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
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)
|
10
activate-env
Executable file
10
activate-env
Executable 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"
|
@@ -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
|
5
example/CMakeLists.txt
Normal file
5
example/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.31)
|
||||
|
||||
project(hello)
|
||||
add_executable(hello hello.c)
|
||||
install(TARGETS hello DESTINATION bin)
|
21
libraries/CMakeLists.txt
Normal file
21
libraries/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
# 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}
|
||||
DEPENDS copy-kos-app-lds
|
||||
)
|
8
libraries/kos-crt-stub/CMakeLists.txt
Normal file
8
libraries/kos-crt-stub/CMakeLists.txt
Normal 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)
|
@@ -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
|
@@ -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
|
@@ -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
|
||||
}
|
59
toolchain/CMakeLists.txt
Normal file
59
toolchain/CMakeLists.txt
Normal 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)
|
Reference in New Issue
Block a user