diff --git a/.github/actions/prepare_env/action.yaml b/.github/actions/prepare_env/action.yaml index aee24f9ff..99965563c 100644 --- a/.github/actions/prepare_env/action.yaml +++ b/.github/actions/prepare_env/action.yaml @@ -13,20 +13,14 @@ runs: shell: bash run: sudo "$GITHUB_WORKSPACE/scripts/env/install_deps_ubuntu.bash" --install -v - - name: Configure environment - env: - ARCH: ${{ inputs.arch }} - shell: bash - run: sudo "$GITHUB_WORKSPACE/scripts/config/configure.bash" "$ARCH" debug -v -p test_mode - - name: Cache toolchain uses: actions/cache@v4 id: cache-build-tools with: - key: tools-${{ inputs.arch }}-${{ hashFiles('scripts/env/toolchain_versions.txt') }} + key: tools-${{ inputs.arch }}-${{ hashFiles('scripts/env/toolchain_versions.txt', 'scripts/env/build_cross_compile.bash') }} path: tools - - name: Build toolchain + - name: Build toolchain and Setup PATH env: TOOLCHAIN_PATH: ${{ github.workspace }}/tools BUILD_PATH: ${{ github.workspace }}/build @@ -35,16 +29,23 @@ runs: shell: bash run: | if [[ $BUILD_TOOLS_CACHE_HIT == 'true' ]]; then - echo "Toolchain is cached, skipping build" - if [[ $ARCH == 'x86_64' ]]; then - echo "Adding x86 toolchain paths to the PATH" - echo "$TOOLCHAIN_PATH/i386-elf/bin" >> $GITHUB_PATH - echo "$TOOLCHAIN_PATH/x86_64-elf/bin" >> $GITHUB_PATH - else - echo "Unsupported arch" - exit 1 - fi + echo "Toolchain is cached, skipping build" else echo "Building toolchain" sudo "$GITHUB_WORKSPACE/scripts/env/install_toolchain.bash" "$TOOLCHAIN_PATH" "$BUILD_PATH" "$ARCH" -v fi + + echo "Adding toolchain to PATH for subsequent steps" + if [[ $ARCH == 'x86_64' ]]; then + echo "$TOOLCHAIN_PATH/i386-elf/bin" >> $GITHUB_PATH + echo "$TOOLCHAIN_PATH/x86_64-elf/bin" >> $GITHUB_PATH + else + echo "Unsupported arch" + exit 1 + fi + + - name: Configure environment + env: + ARCH: ${{ inputs.arch }} + shell: bash + run: sudo "$GITHUB_WORKSPACE/scripts/config/configure.bash" "$ARCH" debug -v -p test_mode diff --git a/alkos/CMakeLists.txt b/alkos/CMakeLists.txt index d589aef29..cf77fd20a 100644 --- a/alkos/CMakeLists.txt +++ b/alkos/CMakeLists.txt @@ -88,9 +88,21 @@ add_subdirectory(libc) add_subdirectory(generated) add_subdirectory(kernel) +get_property(BOOTABLE_KERNEL_EXECUTABLE TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE) +get_property(KERNEL_MODULES TARGET alkos.kernel.config PROPERTY KERNEL_MODULES) +get_property(KERNEL_COMMANDS TARGET alkos.kernel.config PROPERTY KERNEL_COMMANDS) +get_property(ARCH_QEMU_COMMAND TARGET alkos.kernel.config PROPERTY ARCH_QEMU_COMMAND) +get_property(ARCH_QEMU_NORMAL_FLAGS TARGET alkos.kernel.config PROPERTY ARCH_QEMU_NORMAL_FLAGS) +get_property(ARCH_QEMU_TEST_FLAGS TARGET alkos.kernel.config PROPERTY ARCH_QEMU_TEST_FLAGS) + alkos_ensure_defined( - VARS BOOTABLE_KERNEL_EXECUTABLE - MESSAGE "No primary kernel executable defined by the end of the configuration." + VARS + BOOTABLE_KERNEL_EXECUTABLE + KERNEL_MODULES + KERNEL_COMMANDS + ARCH_QEMU_COMMAND + ARCH_QEMU_NORMAL_FLAGS + ARCH_QEMU_TEST_FLAGS ) ################################################################################ diff --git a/alkos/cmake/ValidationHelpers.cmake b/alkos/cmake/ValidationHelpers.cmake index c8dd7d590..594851a65 100644 --- a/alkos/cmake/ValidationHelpers.cmake +++ b/alkos/cmake/ValidationHelpers.cmake @@ -7,8 +7,8 @@ # alkos_ensure_defined #=============================================================================== # -# Checks if one or more variables are defined and halts with a fatal error, -# listing all undefined variables at once. +# Checks if one or more variables are defined (and nonempty) and halts with a +# fatal error, listing all undefined variables at once. # # Parameters: # VARS ... A list of variable names to check. @@ -42,7 +42,7 @@ function(alkos_ensure_defined) set(undefined_vars "") foreach(var_name ${ARG_VARS}) - if(NOT DEFINED ${var_name}) + if(NOT ${var_name}) list(APPEND undefined_vars "${var_name}") endif() endforeach() @@ -59,3 +59,63 @@ function(alkos_ensure_defined) message(FATAL_ERROR "${error_message}") endif() endfunction() + +#=============================================================================== +# alkos_ensure_property_defined +#=============================================================================== +# +# Checks if a property is defined for a target and halts with a fatal error, +# listing all undefined properties at once. +# +# Parameters: +# TARGET The target to check the properties for. +# PROPS ... A list of property names to check. +# MESSAGE (Optional) A supplementary message to append to the +# standard error output. This is useful for providing +# additional context or instructions to the user. +# +# Example: +# # Assume alkos.kernel.config is a target and BOOTABLE_KERNEL_EXECUTABLE +# # is not defined. +# alkos_ensure_property_defined( +# TARGET alkos.kernel.config +# PROPS BOOTABLE_KERNEL_EXECUTABLE KERNEL_MODULES +# MESSAGE "The BOOTABLE_KERNEL_EXECUTABLE property must be set for the KERNEL_MODULES target." +# ) +# +function(alkos_ensure_property_defined) + set(options) + set(oneValueArgs TARGET MESSAGE) + set(multiValueArgs PROPS) + + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT ARG_TARGET) + message(FATAL_ERROR "alkos_ensure_property_defined() called without a TARGET to check.") + endif() + + if(NOT ARG_PROPS) + message(FATAL_ERROR "alkos_ensure_property_defined() called without any PROPS to check.") + endif() + + set(undefined_props "") + foreach(prop_name ${ARG_PROPS}) + get_property(is_defined TARGET ${ARG_TARGET} PROPERTY ${prop_name} DEFINED) + if(NOT is_defined) + list(APPEND undefined_props "${prop_name}") + endif() + endforeach() + + if(undefined_props) + string(JOIN ", " undefined_props_str "${undefined_props}") + + set(error_message "The following required properties are not defined for target '${ARG_TARGET}': ${undefined_props_str}") + + if(ARG_MESSAGE) + string(APPEND error_message "\n${ARG_MESSAGE}") + endif() + + message(FATAL_ERROR "${error_message}") + endif() +endfunction() + diff --git a/alkos/kernel/CMakeLists.txt b/alkos/kernel/CMakeLists.txt index 80f380162..d87b80f55 100644 --- a/alkos/kernel/CMakeLists.txt +++ b/alkos/kernel/CMakeLists.txt @@ -1,5 +1,25 @@ message(STATUS "Configuring kernel...") +# This target acts as a central hub for configuration data (e.g., kernel modules) +# that needs to be communicated to the top-level CMakeLists.txt. +add_library(alkos.kernel.config INTERFACE) +add_library(alkos.kernel.headers INTERFACE) # Kernel headers for exporting +add_library(alkos.kernel.deps INTERFACE) # Target to link all dependencies to +#------------------------------------------------------------------------------# +# Notes: alkos.kernel.deps # +#------------------------------------------------------------------------------# +# Note: Caveat - linking objects to this target also requires +# using target_sources $ syntax because +# interface libraries are only carriers for headers and properties +# +#------------------------------------------------------------------------------# +# Note: This target is used to ensure proper linking order +# Idea was that this is the linking "api" of the kernel +# So that arch etc, doesn't have to care about the linking order +# This is current unused in the intended way, but may be useful in the future +# +#------------------------------------------------------------------------------# + ############################### Error Checking ############################### alkos_ensure_defined( @@ -11,19 +31,6 @@ alkos_ensure_defined( add_compile_definitions(__ALKOS_KERNEL__=1) add_compile_definitions(__ALKOS_LIBK__=1) # For LIBK headers -############################# Arch Dependent Vars ############################ - -# ---------------------------------------------------------------------------- -# Arch can optionally create other executables (for chainloading, etc) -# They need to place themselves in sysroot/boot -# This is the list of executables that will be loaded by the bootloader as -# modules -set(KERNEL_MODULES "") -# ---------------------------------------------------------------------------- -# This is the executable that the bootloader will give control to -set(BOOTABLE_KERNEL_EXECUTABLE alkos.kernel) -# ---------------------------------------------------------------------------- - ########################### Setting Sysroot Boot ############################# file(MAKE_DIRECTORY ${SYSROOT}/boot) @@ -49,91 +56,92 @@ if (CMAKE_FEATURE_FLAG_RUN_TEST_MODE) list(APPEND KERNEL_SOURCES ${KERNEL_TEST_SOURCES}) endif () + #################################### Exec #################################### -add_executable(alkos.kernel - ${KERNEL_SOURCES} -) +add_executable(alkos.kernel ${KERNEL_SOURCES}) ############################### Adding Headers ############################### -add_library(alkos.kernel.headers INTERFACE) target_include_directories(alkos.kernel.headers INTERFACE include test abi ) -target_link_libraries(alkos.kernel PRIVATE - alkos.kernel.headers -) - ########################## Configure for given Arch ########################## add_subdirectory(arch/${ARCH}) -############################### Error Checking ############################### - -alkos_ensure_defined( - VARS - BOOTABLE_KERNEL_EXECUTABLE - KERNEL_MODULES - KERNEL_COMMANDS - ARCH_QEMU_COMMAND - ARCH_QEMU_NORMAL_FLAGS - ARCH_QEMU_TEST_FLAGS - CRTI_OBJ - CRTN_OBJ -) - -message(STATUS "Bootable kernel executable: ${BOOTABLE_KERNEL_EXECUTABLE}") -message(STATUS "Kernel modules: ${KERNEL_MODULES}") -message(STATUS "Kernel commands: ${KERNEL_COMMANDS}") - -list(LENGTH KERNEL_MODULES KERNEL_MODULES_LENGTH) -list(LENGTH KERNEL_COMMANDS KERNEL_COMMANDS_LENGTH) - -# Check if the two lists are the same size -if(NOT KERNEL_MODULES_LENGTH EQUAL KERNEL_COMMANDS_LENGTH) - message(FATAL_ERROR "KERNEL_MODULES and KERNEL_COMMANDS have different sizes: ${KERNEL_MODULES_LENGTH} vs ${KERNEL_COMMANDS_LENGTH}") -endif() +# TODO: Immediately here, error checking should happen +# But the error checking itself fails!!! and for some reason +# alkos_ensure_property_defined() says the property is not defined ################################# ThirdParty ################################# -message(STATUS "Adding third-party libraries...") add_subdirectory(thirdparty) -################################## Linking ################################### +target_link_libraries(alkos.kernel.deps INTERFACE + alkos.kernel.thirdparty + libk + AutoGenLib +) -target_link_libraries(alkos.kernel PRIVATE libk gcc ${THIRD_PARTY_LIBRARIES} AutoGenLib) +################################ Linking Kernel ################################ + +target_link_libraries(alkos.kernel PRIVATE + target.properties + alkos.kernel.config + alkos.kernel.headers + alkos.kernel.deps +) ############## Linker Configuration for CXX Global Constructors ############## -# Set the linker to link objects in the correct order -# NOTE: ARCH cmake is expected to provide variables for global constructors -# according to the compiler needs # NOTE: This linking must be done at this level as global constructors # should be supported on each architecture -if (NOT DEFINED CRTI_OBJ OR NOT DEFINED CRTN_OBJ) - message(FATAL_ERROR "One of: crti.o, crtn.o is not defined. Those should be defined in the ARCH CMakeLists.txt file") -endif () -set(CMAKE_CXX_LINKER_LAUNCHER "/bin/bash -c") -set(CMAKE_CXX_LINK_EXECUTABLE -"/bin/bash -c \"${CMAKE_CXX_COMPILER} \ -${CRTI_OBJ} \ -\$\(${CMAKE_C_COMPILER} -print-file-name=crtbegin.o\) \ - \ -\$\(${CMAKE_C_COMPILER} -print-file-name=crtend.o\) \ -${CRTN_OBJ} \ --o \"" +# Retrieve our custom CRT object paths from the arch-specific configuration. +get_property(CRTI_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTI_OBJ) +get_property(CRTN_OBJ_PATH TARGET alkos.kernel.config PROPERTY CRTN_OBJ) +alkos_ensure_defined( + VARS CRTI_OBJ_PATH CRTN_OBJ_PATH + MESSAGE "CRTI_OBJ/CRTN_OBJ properties were not set by the architecture-specific CMake file." +) + +# Find the compiler's CRT object files at configure-time. +execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o + OUTPUT_VARIABLE CRTBEGIN_OBJ_PATH + ERROR_VARIABLE CRTBEGIN_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtend.o + OUTPUT_VARIABLE CRTEND_OBJ_PATH + ERROR_VARIABLE CRTEND_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +alkos_ensure_defined( + VARS CRTBEGIN_OBJ_PATH CRTEND_OBJ_PATH + MESSAGE "Could not find compiler's crtbegin.o/crtend.o files." ) -########################## Back-Propagate Variables ########################## +message(STATUS "Found CRT Objects:") +message(STATUS " crti: ${CRTI_OBJ_PATH}") +message(STATUS " crtbegin: ${CRTBEGIN_OBJ_PATH}") +message(STATUS " crtend: ${CRTEND_OBJ_PATH}") +message(STATUS " crtn: ${CRTN_OBJ_PATH}") + +# TODO: +# The below code could technically be replaced with target_link_libraries() +# it also should enforce the correct linking order. +# I have done so with success, but it introduced a bug where no tests were +# detected in the kernel and I was unable to reslove it so gave up for now. -set(BOOTABLE_KERNEL_EXECUTABLE ${BOOTABLE_KERNEL_EXECUTABLE} PARENT_SCOPE) -set(KERNEL_MODULES ${KERNEL_MODULES} PARENT_SCOPE) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} PARENT_SCOPE) +# Add all objects and libraries to the kernel target in the correct link order. +# The linker requires: crti, crtbegin,
, , crtend, crtn +set(CMAKE_CXX_LINK_EXECUTABLE + "${CMAKE_CXX_COMPILER} ${CRTI_OBJ_PATH} ${CRTBEGIN_OBJ_PATH} ${CRTEND_OBJ_PATH} ${CRTN_OBJ_PATH} -o " +) -set(ARCH_QEMU_COMMAND ${ARCH_QEMU_COMMAND} PARENT_SCOPE) -set(ARCH_QEMU_NORMAL_FLAGS ${ARCH_QEMU_NORMAL_FLAGS} PARENT_SCOPE) -set(ARCH_QEMU_TEST_FLAGS ${ARCH_QEMU_TEST_FLAGS} PARENT_SCOPE) diff --git a/alkos/kernel/arch/x86_64/CMakeLists.txt b/alkos/kernel/arch/x86_64/CMakeLists.txt index 573be933b..dda69e7b5 100644 --- a/alkos/kernel/arch/x86_64/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/CMakeLists.txt @@ -2,57 +2,31 @@ message(STATUS "Configuring for x86_64") ############################# Arch Dependent Vars ############################ -set(KERNEL_MODULES "") -set(KERNEL_COMMANDS "") # Kernel commands for the bootloader, has to be same size as KERNEL_MODULES -set(BOOTABLE_KERNEL_EXECUTABLE "") -set(ARCH_QEMU_COMMAND "qemu-system-x86_64") -set(ARCH_QEMU_NORMAL_FLAGS "-serial stdio -enable-kvm -cpu host -display default,show-cursor=on -m 4G -smp sockets=1,cores=4,threads=1") -set(ARCH_QEMU_TEST_FLAGS "-serial stdio -enable-kvm -cpu host -display none -m 4G -smp sockets=1,cores=4,threads=1") +set_property(TARGET alkos.kernel.config PROPERTY KERNEL_MODULES "") +set_property(TARGET alkos.kernel.config PROPERTY KERNEL_COMMANDS "") +set_property(TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE "") +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_COMMAND "qemu-system-x86_64") +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_NORMAL_FLAGS "-serial stdio -enable-kvm -cpu host -display default,show-cursor=on -m 4G -smp sockets=1,cores=4,threads=1") +set_property(TARGET alkos.kernel.config PROPERTY ARCH_QEMU_TEST_FLAGS "-serial stdio -enable-kvm -cpu host -display none -m 4G -smp sockets=1,cores=4,threads=1") ################################### Boot32 ################################### add_subdirectory(loader32) -# Retrieve the bootable kernel executable -set(BOOTABLE_KERNEL_EXECUTABLE alkos.loader32) +set_property(TARGET alkos.kernel.config PROPERTY BOOTABLE_KERNEL_EXECUTABLE alkos.loader32) ################################### Boot64 ################################### add_subdirectory(loader64) -set(KERNEL_MODULES ${KERNEL_MODULES} alkos.loader64) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} "loader64") +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_MODULES alkos.loader64) +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_COMMANDS "loader64") ################################### Kernel ################################### add_subdirectory(kernel) -set(KERNEL_MODULES ${KERNEL_MODULES} alkos.kernel) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} "kernel") +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_MODULES alkos.kernel) +set_property(TARGET alkos.kernel.config APPEND PROPERTY KERNEL_COMMANDS "kernel") ################################### Common ################################### add_subdirectory(common-loader-all) add_subdirectory(common-loader-64-kernel) - -############################### Error Checking ############################### - -alkos_ensure_defined( - VARS BOOTABLE_KERNEL_EXECUTABLE - MESSAGE "No primary kernel executable defined for x86_64 architecture." -) - -message(STATUS "Bootable kernel executable: ${BOOTABLE_KERNEL_EXECUTABLE}") -message(STATUS "Kernel modules: ${KERNEL_MODULES}") - -message(STATUS "CRTI_OBJ: ${CRTI_OBJ}, CRTN_OBJ: ${CRTN_OBJ}") - -########################## Back-Propagate Variables ########################## - -set(CRTI_OBJ "${CRTI_OBJ}" PARENT_SCOPE) -set(CRTN_OBJ "${CRTN_OBJ}" PARENT_SCOPE) - -set(BOOTABLE_KERNEL_EXECUTABLE ${BOOTABLE_KERNEL_EXECUTABLE} PARENT_SCOPE) -set(KERNEL_MODULES ${KERNEL_MODULES} PARENT_SCOPE) -set(KERNEL_COMMANDS ${KERNEL_COMMANDS} PARENT_SCOPE) - -set(ARCH_QEMU_COMMAND ${ARCH_QEMU_COMMAND} PARENT_SCOPE) -set(ARCH_QEMU_NORMAL_FLAGS ${ARCH_QEMU_NORMAL_FLAGS} PARENT_SCOPE) -set(ARCH_QEMU_TEST_FLAGS ${ARCH_QEMU_TEST_FLAGS} PARENT_SCOPE) diff --git a/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt index bb5b03041..114047242 100644 --- a/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/common-loader-64-kernel/CMakeLists.txt @@ -17,8 +17,10 @@ target_link_libraries(arch.common.kernel-loader.64 PRIVATE ############################# Linking libraries ############################## target_link_libraries(arch.common.kernel-loader.64 PRIVATE - libk arch.common.all.64 + alkos.kernel.headers + libk + AutoGenLib ) ############################### Adding Headers ############################### @@ -26,8 +28,3 @@ target_link_libraries(arch.common.kernel-loader.64 PRIVATE target_include_directories(alkos.kernel.headers INTERFACE . ) - -target_link_libraries(arch.common.kernel-loader.64 PRIVATE - alkos.kernel.headers - AutoGenLib -) diff --git a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt index 117aebe10..62cad3d61 100644 --- a/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/common-loader-all/CMakeLists.txt @@ -13,13 +13,17 @@ alkos_target_sources(arch.common.all.32) ############################# Linking libraries ############################## target_link_libraries(arch.common.all.64 PRIVATE - libk target.properties + libk + alkos.kernel.headers + AutoGenLib ) target_link_libraries(arch.common.all.32 PRIVATE - libk.32 target.properties.32 + libk.32 + alkos.kernel.headers + AutoGenLib ) ############################### Applying Flags ############################### @@ -31,13 +35,3 @@ set(CMAKE_ASM_NASM_COMPILE_OBJECT " target_include_directories(alkos.kernel.headers INTERFACE . ) - -target_link_libraries(arch.common.all.64 PRIVATE - alkos.kernel.headers - AutoGenLib -) - -target_link_libraries(arch.common.all.32 PRIVATE - alkos.kernel.headers - AutoGenLib -) diff --git a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt index 60c994543..d9624a760 100644 --- a/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/kernel/CMakeLists.txt @@ -31,32 +31,39 @@ target_link_options(alkos.kernel PRIVATE -lgcc # Link against GCC ) -######################### Setting Custom Properties ########################## - -target_link_libraries(alkos.kernel PRIVATE - target.properties -) - ########################## CXX Global Constructors ########################### -set(SRTI_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cxx/crti.nasm") -set(SRTN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cxx/crtn.nasm") - -add_library(alkos.kernel.crts OBJECT - ${SRTI_FILE} - ${SRTN_FILE} +add_library(alkos.kernel.crti OBJECT + cxx/crti.nasm ) +add_library(alkos.kernel.crtn OBJECT + cxx/crtn.nasm +) + +# TODO: Maybe later we can get this code to work +# set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "$") +# set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "$") +# I used combination of the above code, and target_link_libraries to link in specific order +# Worked but introduced a bug where no tests were detected +# So I reverted to the old way of linking the object files -# Set the CRT object paths -set(CRTI_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crti.nasm.o" PARENT_SCOPE) -set(CRTN_OBJ "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crts.dir/cxx/crtn.nasm.o" PARENT_SCOPE) +set(CRTI_OBJ_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crti.dir/cxx/crti.nasm.o") +set(CRTN_OBJ_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/alkos.kernel.crtn.dir/cxx/crtn.nasm.o") +set_property(TARGET alkos.kernel.config PROPERTY CRTI_OBJ "${CRTI_OBJ_FILE_PATH}") +set_property(TARGET alkos.kernel.config PROPERTY CRTN_OBJ "${CRTN_OBJ_FILE_PATH}") -add_dependencies(alkos.kernel alkos.kernel.crts) +add_dependencies(alkos.kernel alkos.kernel.crti alkos.kernel.crtn) ############################### Link Libraries ############################### -target_link_libraries(alkos.kernel PRIVATE +target_link_libraries(alkos.kernel.deps INTERFACE + target.properties arch.common.all.64 arch.common.kernel-loader.64 - AutoGenLib +) + +# This makes the interface also properly link to object files +target_sources(alkos.kernel.deps INTERFACE + $ + $ ) diff --git a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt index 6da19e8e1..697cdfd6b 100644 --- a/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/loader32/CMakeLists.txt @@ -12,7 +12,6 @@ alkos_target_sources(alkos.loader32) ############################## Finding CXX Compiler ############################ -message(STATUS "32 bit compiler: ${CMAKE_CXX_COMPILER_32}") set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_COMPILER_32} -o ") ############################## Finding Headers ############################### @@ -21,8 +20,6 @@ target_include_directories(alkos.loader32 PRIVATE .) ################################ Exec Flags ################################## -target_link_libraries(alkos.loader32 PRIVATE target.properties.32) - set(CMAKE_ASM_NASM_COMPILE_OBJECT " -o ") ################################ Linker Flags ################################ @@ -42,8 +39,10 @@ target_compile_definitions(alkos.loader32 PUBLIC __i386__=1 ) +################################### Linking #################################### + target_link_libraries(alkos.loader32 PRIVATE - gcc + target.properties.32 arch.common.all.32 libk.32 alkos.kernel.headers diff --git a/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt b/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt index 820a36c26..2a12ad1a9 100644 --- a/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt +++ b/alkos/kernel/arch/x86_64/loader64/CMakeLists.txt @@ -28,10 +28,11 @@ target_link_options(alkos.loader64 PRIVATE ############################### Link Libraries ############################### target_link_libraries(alkos.loader64 PRIVATE - gcc + target.properties libk arch.common.all.64 arch.common.kernel-loader.64 alkos.kernel.headers AutoGenLib + gcc ) diff --git a/alkos/kernel/thirdparty/CMakeLists.txt b/alkos/kernel/thirdparty/CMakeLists.txt index 530ad2952..9c2237786 100644 --- a/alkos/kernel/thirdparty/CMakeLists.txt +++ b/alkos/kernel/thirdparty/CMakeLists.txt @@ -1,14 +1,12 @@ +message(STATUS "Adding third-party libraries...") include(FetchContent) -set(THIRD_PARTY_LIBRARIES "") +add_library(alkos.kernel.thirdparty INTERFACE) -# Iterate over all dependencies and add them to the project +# Iterate over all dependencies and add them to the thirdparty library file(GLOB directories RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) foreach(dir ${directories}) if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir}) endif() endforeach() - -# Propagate the third-party libraries to the parent scope -set(THIRD_PARTY_LIBRARIES ${THIRD_PARTY_LIBRARIES} PARENT_SCOPE) diff --git a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt index 11f047951..2548db338 100644 --- a/alkos/kernel/thirdparty/uacpi/CMakeLists.txt +++ b/alkos/kernel/thirdparty/uacpi/CMakeLists.txt @@ -1,3 +1,5 @@ +message(STATUS "-> uACPI...") + ####################################################################### # uACPI # ####################################################################### @@ -40,5 +42,6 @@ target_link_libraries(uacpi PRIVATE target.properties ) -# Propagate the uACPI library to the parent scope -set(THIRD_PARTY_LIBRARIES ${THIRD_PARTY_LIBRARIES} uacpi PARENT_SCOPE) +################################ Export itself ################################# + +target_link_libraries(alkos.kernel.thirdparty INTERFACE uacpi) diff --git a/alkos/libc/CMakeLists.txt b/alkos/libc/CMakeLists.txt index 97b4ff544..975b8d80e 100644 --- a/alkos/libc/CMakeLists.txt +++ b/alkos/libc/CMakeLists.txt @@ -28,10 +28,6 @@ add_subdirectory(arch/${ARCH}) add_library(lib${LIB_NAME} STATIC ${LIB_SOURCES}) set_target_properties(lib${LIB_NAME} PROPERTIES OUTPUT_NAME "${LIB_NAME}") -############################# Setting Custom Properties ######################### - -target_link_libraries(lib${LIB_NAME} PUBLIC target.properties) - ############################### Adding includes ############################### target_include_directories(lib${LIB_NAME} PUBLIC @@ -42,9 +38,13 @@ target_include_directories(lib${LIB_NAME} PRIVATE internal ) -target_link_libraries(lib${LIB_NAME} PRIVATE gcc) +############################### Adding dependencies ############################### -target_link_libraries(lib${LIB_NAME} PRIVATE AutoGenLib) +target_link_libraries(lib${LIB_NAME} PRIVATE + target.properties + gcc + AutoGenLib +) if (SYSTEM_LIB_TYPE STREQUAL "k" OR SYSTEM_LIB_TYPE STREQUAL "K") target_link_libraries(lib${LIB_NAME} PRIVATE alkos.kernel.headers) diff --git a/alkos/libc/arch/x86_64/CMakeLists.txt b/alkos/libc/arch/x86_64/CMakeLists.txt index 05b8784c2..4ce8a1ba4 100644 --- a/alkos/libc/arch/x86_64/CMakeLists.txt +++ b/alkos/libc/arch/x86_64/CMakeLists.txt @@ -3,8 +3,6 @@ add_library(lib${LIB_NAME}.32 STATIC ${LIB_SOURCES}) set_target_properties(lib${LIB_NAME}.32 PROPERTIES OUTPUT_NAME "${LIB_NAME}.32") -target_compile_options(lib${LIB_NAME}.32 PRIVATE -m32) - ############################### Adding includes ############################### target_include_directories(lib${LIB_NAME}.32 PUBLIC @@ -23,16 +21,19 @@ target_link_libraries(lib${LIB_NAME}.32 PUBLIC target.properties.32) add_dependencies(lib${LIB_NAME}.32 lib${LIB_NAME}) +target_link_libraries(lib${LIB_NAME}.32 PUBLIC + target.properties.32 + AutoGenLib + gcc +) + if (SYSTEM_LIB_TYPE STREQUAL "k" OR SYSTEM_LIB_TYPE STREQUAL "K") target_link_libraries(lib${LIB_NAME}.32 PRIVATE alkos.kernel.headers) endif () -target_link_libraries(lib${LIB_NAME}.32 PRIVATE AutoGenLib) - ############################### Processing output ############################### set_target_properties(lib${LIB_NAME}.32 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${SYSROOT}/usr/lib LIBRARY_OUTPUT_DIRECTORY ${SYSROOT}/usr/lib ) -target_link_libraries(lib${LIB_NAME}.32 PRIVATE gcc) diff --git a/alkos/toolchains/x86_64-conf.cmake b/alkos/toolchains/x86_64-conf.cmake index e4e9e363c..e49edd21c 100644 --- a/alkos/toolchains/x86_64-conf.cmake +++ b/alkos/toolchains/x86_64-conf.cmake @@ -55,6 +55,10 @@ target_compile_options(target.properties INTERFACE "$<$:-mno-red-zone>" "$<$:-f elf64>" ) +target_compile_definitions(target.properties INTERFACE + "__x86_64__=1" +) + #------------------------------------------------------------------------------# # 32 bit # #------------------------------------------------------------------------------# @@ -65,4 +69,6 @@ target_compile_options(target.properties.32 INTERFACE "$<$:-m32>" "$<$:-f elf32>" ) - +target_compile_definitions(target.properties.32 INTERFACE + "__i386__=1" +) diff --git a/scripts/env/clean_build_dir.bash b/scripts/env/clean_build_dir.bash index 7412d2ee1..2e178f9be 100755 --- a/scripts/env/clean_build_dir.bash +++ b/scripts/env/clean_build_dir.bash @@ -6,9 +6,6 @@ CONF_BUILD_DIR="${CLEAN_BUILD_SCRIPT_DIR}/../../build" source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/conf_handlers.bash" -source_conf_file -verify_conf_var_exists CONF_BUILD_DIR - source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/pretty_print.bash" source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/helpers.bash" source "${CLEAN_BUILD_SCRIPT_DIR}/../utils/argparse.bash" diff --git a/scripts/env/toolchain_versions.txt b/scripts/env/toolchain_versions.txt index 8d882acdc..910c4eeda 100644 --- a/scripts/env/toolchain_versions.txt +++ b/scripts/env/toolchain_versions.txt @@ -1,3 +1,3 @@ -binutils=2.43.1 +binutils=2.44 gdb=16.3 -gcc=14.2.0 +gcc=15.1.0