diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a8b9a9..a837c6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,12 @@ file(GLOB_RECURSE photon_libc_headers ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/in file(GLOB photon_libc_crt ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/machine/${machine}/crt*.s) +message(STATUS "CRT files: ${photon_libc_crt}") -add_library(crt OBJECT ${photon_libc_crt}) -target_compile_options(crt PRIVATE -c -ffreestanding -nostdlib) +add_custom_target(crt ALL + DEPENDS ${photon_libc_crt} + COMMAND mx.clang -c -ffreestanding ${photon_libc_crt} + COMMENT "Generating CRT files") file(GLOB platform_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/*.c @@ -76,13 +79,13 @@ file(GLOB platform_headers set(photon_libc_sources ${photon_libc_sources} ${malloc_sources} ${platform_sources}) set(photon_libc_headers ${photon_libc_headers} ${platform_headers}) -add_framework(photon STATIC +add_framework(photon SHARED BUNDLE_ID net.doorstuck.photon SOURCES ${photon_libc_sources} ${photon_libc_headers} HEADERS ${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include/*) bundle_compile_options(photon PRIVATE -ffreestanding -nostdlib -fPIC -fPIE) -bundle_link_libraries(photon ${photon_platform_libs}) +bundle_link_libraries(photon ${photon_platform_libs} -ffreestanding) bundle_link_frameworks(photon ${photon_platform_frameworks}) bundle_include_directories(photon PRIVATE diff --git a/photon/libc/include/stdio.h b/photon/libc/include/stdio.h index 7ca7374..11191bc 100644 --- a/photon/libc/include/stdio.h +++ b/photon/libc/include/stdio.h @@ -23,9 +23,11 @@ extern "C" { typedef struct __io_file FILE; -extern FILE *stdin; -extern FILE *stdout; -extern FILE *stderr; +extern FILE *__get_stdio_file(int); + +#define stdin (__get_stdio_file(0)) +#define stdout (__get_stdio_file(0)) +#define stderr (__get_stdio_file(0)) extern FILE *fopen(const char *path, const char *mode); extern FILE *freopen(const char *path, const char *mode, FILE *fp); diff --git a/photon/libc/sys/magenta/fio.c b/photon/libc/sys/magenta/fio.c index d40413f..59855d3 100644 --- a/photon/libc/sys/magenta/fio.c +++ b/photon/libc/sys/magenta/fio.c @@ -1,19 +1,30 @@ +#include #include "sys/types.h" #include "__fio.h" -struct __io_file __stdin = {}; -struct __io_file __stdout = {}; -struct __io_file __stderr = {}; - -struct __io_file *stdin = &__stdin; -struct __io_file *stdout = &__stdout; -struct __io_file *stderr = &__stderr; +static struct __io_file __stdin = {}; +static struct __io_file __stdout = {}; +static struct __io_file __stderr = {}; static int flags_from_mode(const char *r) { return 0; } +FILE *__get_stdio_file(int i) +{ + switch (i) { + case 0: + return &__stdin; + case 1: + return &__stdout; + case 2: + return &__stderr; + default: + return NULL; + } +} + void __fio_init(int in, int out, int err) { __stdin.fd = in; diff --git a/scripts/add-framework-crt.sh b/scripts/add-framework-crt.sh index 901e466..4981e28 100755 --- a/scripts/add-framework-crt.sh +++ b/scripts/add-framework-crt.sh @@ -3,9 +3,9 @@ framework_path=$1 binary_dir=$2 -crt_files=$(find $binary_dir -name "crt*.s.o") +crt_files=$(find $binary_dir -name "crt*.o") for crt_file in $crt_files; do - out="$framework_path/Binary/$(basename $crt_file .s.o).o" + out="$framework_path/bin/$(basename $crt_file .o).o" cp -f $crt_file $out done