Skip to content

Commit 2b965e3

Browse files
committed
build: ensure that the crt is copied properly
Make crt1 a static library so that we can have a post-build command copy the object file to the correct location and rename it properly. Unfortunately, renaming the object file itself is somewhat challenging.
1 parent c6b8a2d commit 2b965e3

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,16 @@ add_custom_target(sysroot-headers DEPENDS ${CMAKE_BINARY_DIR}/sysroot)
272272

273273

274274
# startup files
275-
add_library(startup-files OBJECT
275+
add_library(crt1 OBJECT
276276
libc-bottom-half/crt/crt1.c)
277-
add_dependencies(startup-files sysroot-headers)
277+
add_dependencies(crt1 sysroot-headers)
278+
279+
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/sysroot/lib/crt1.o
280+
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/sysroot/lib
281+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_OBJECTS:crt1> ${CMAKE_BINARY_DIR}/sysroot/lib/crt1.o)
282+
add_custom_target(crt1.o ALL
283+
DEPENDS ${CMAKE_BINARY_DIR}/sysroot/lib/crt1.o)
284+
add_dependencies(crt1.o crt1)
278285

279286

280287
add_library(c-printscan-no-floating-point

0 commit comments

Comments
 (0)