From 6ffe96d1e3f0289c2070e050cf8e1a30288e6d91 Mon Sep 17 00:00:00 2001 From: Alexey Gavrilov Date: Fri, 27 Mar 2026 14:03:55 +0700 Subject: Cmake build generator support: build stage Multi-target architecture implementation: each root source code directory presents the one *INTERFACE* target to it's subdirectory subtargets that link only as *STATIC* library. For instance, *arch* directory presents *Architecture* target then *Architecture* target has *CPUID*, *IO*, *PORT* and etc. dependencies Exact order of linking targets is: boot.o CRTIBUNDLE CRTNBUNDLE. Sequence destruction cause to UB. Please to pay attention to this. TODO - Debug information - Build type - Toolchain file - Image creation - Build by WinGW compiler on Windows platform (optional) Signed-off-by: Alexey Gavrilov --- libgcc/CMakeLists.txt | 25 +++++++++++++++++++++++++ libgcc/x86/CMakeLists.txt | 15 +++++++++++++++ libgcc/x86/crti.nasm | 5 +++++ libgcc/x86/crti.s | 5 ----- libgcc/x86/crtn.nasm | 3 +++ libgcc/x86/crtn.s | 3 --- 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 libgcc/CMakeLists.txt create mode 100644 libgcc/x86/CMakeLists.txt create mode 100644 libgcc/x86/crti.nasm delete mode 100644 libgcc/x86/crti.s create mode 100644 libgcc/x86/crtn.nasm delete mode 100644 libgcc/x86/crtn.s (limited to 'libgcc') diff --git a/libgcc/CMakeLists.txt b/libgcc/CMakeLists.txt new file mode 100644 index 0000000..b5b2abc --- /dev/null +++ b/libgcc/CMakeLists.txt @@ -0,0 +1,25 @@ +macro(setup_crt_object_file object_file target_name) + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=${object_file} + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE PATH + ERROR_VARIABLE ERROR_MESSAGE + RESULT_VARIABLE RESULT + ) + + if(RESULT) + message(FATAL_ERROR ${ERROR_MESSAGE}) + endif() + + add_library(${target_name} OBJECT IMPORTED GLOBAL) + set_target_properties(${target_name} PROPERTIES + IMPORTED_OBJECTS ${PATH} + ) + +endmacro() + +# TODO: set platform specific CRT objects +setup_crt_object_file(crtbegin.o CRTBEGIN) +setup_crt_object_file(crtend.o CRTEND) + +add_subdirectory(${ARCH}) diff --git a/libgcc/x86/CMakeLists.txt b/libgcc/x86/CMakeLists.txt new file mode 100644 index 0000000..2a1bec9 --- /dev/null +++ b/libgcc/x86/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(CRTI INTERFACE) +add_library(CRTIBUNDLE STATIC) +target_sources(CRTIBUNDLE PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/crti.nasm + $ +) +target_link_libraries(CRTI INTERFACE CRTIBUNDLE) + +add_library(CRTN INTERFACE) +add_library(CRTNBUNDLE STATIC) +target_sources(CRTNBUNDLE PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/crtn.nasm + $ +) +target_link_libraries(CRTN INTERFACE CRTNBUNDLE) diff --git a/libgcc/x86/crti.nasm b/libgcc/x86/crti.nasm new file mode 100644 index 0000000..57cb8c1 --- /dev/null +++ b/libgcc/x86/crti.nasm @@ -0,0 +1,5 @@ +section .init +global _init:function +_init: + push ebp + mov ebp, esp diff --git a/libgcc/x86/crti.s b/libgcc/x86/crti.s deleted file mode 100644 index 57cb8c1..0000000 --- a/libgcc/x86/crti.s +++ /dev/null @@ -1,5 +0,0 @@ -section .init -global _init:function -_init: - push ebp - mov ebp, esp diff --git a/libgcc/x86/crtn.nasm b/libgcc/x86/crtn.nasm new file mode 100644 index 0000000..537fa65 --- /dev/null +++ b/libgcc/x86/crtn.nasm @@ -0,0 +1,3 @@ +section .init + pop ebp + ret diff --git a/libgcc/x86/crtn.s b/libgcc/x86/crtn.s deleted file mode 100644 index 537fa65..0000000 --- a/libgcc/x86/crtn.s +++ /dev/null @@ -1,3 +0,0 @@ -section .init - pop ebp - ret -- cgit v1.2.3