diff --git a/CMakeLists.txt b/CMakeLists.txt index 873ee732..24773c9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,14 @@ set(CMAKE_FIND_ROOT_PATH ${LUNA_ROOT}/toolchain/${LUNA_ARCH}-luna) message(STATUS "Configuring Luna for ${LUNA_ARCH}") +set(COMMON_FLAGS -Wall -Wextra -Werror -Wvla + -Wdisabled-optimization -Wformat=2 -Winit-self + -Wmissing-include-dirs -Wswitch-default -Wcast-qual + -Wundef -Wcast-align -Wwrite-strings -Wlogical-op + -Wredundant-decls -Wshadow -Wconversion + -fno-asynchronous-unwind-tables -fno-omit-frame-pointer + -std=c++20 -fno-rtti -fno-exceptions) + add_subdirectory(libluna) add_subdirectory(libos) add_subdirectory(libc) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index f3386de5..cbd54d8f 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,6 +1,6 @@ function(luna_app SOURCE_FILE APP_NAME) add_executable(${APP_NAME} ${SOURCE_FILE}) - target_compile_options(${APP_NAME} PRIVATE -Os -Wall -Wextra -pedantic -Werror -Wno-write-strings) + target_compile_options(${APP_NAME} PRIVATE -Os ${COMMON_FLAGS} -Wno-write-strings) add_dependencies(${APP_NAME} libc) target_include_directories(${APP_NAME} PRIVATE ${LUNA_BASE}/usr/include) install(TARGETS ${APP_NAME} DESTINATION ${LUNA_ROOT}/initrd/bin) diff --git a/apps/sh.cpp b/apps/sh.cpp index 0b7e1a65..05926f63 100644 --- a/apps/sh.cpp +++ b/apps/sh.cpp @@ -21,7 +21,7 @@ static Result> split_command_into_argv(const char* cmd) for (;;) { - char* segment = strtok(NULL, " \n"); + segment = strtok(NULL, " \n"); TRY(result.try_append(segment)); if (segment == NULL) return result; diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index b9708673..2909560b 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -76,13 +76,8 @@ target_link_libraries(moon luna-freestanding) target_compile_definitions(moon PRIVATE IN_MOON) -target_compile_options(moon PRIVATE -Wall -Wextra -Werror -Wvla -Wsign-conversion) -target_compile_options(moon PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) -target_compile_options(moon PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) -target_compile_options(moon PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) -target_compile_options(moon PRIVATE -fno-rtti -ffreestanding -fno-exceptions) -target_compile_options(moon PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer) -target_compile_options(moon PRIVATE -nostdlib -mcmodel=kernel) +target_compile_options(moon PRIVATE ${COMMON_FLAGS}) +target_compile_options(moon PRIVATE -nostdlib -mcmodel=kernel -ffreestanding) if("${LUNA_ARCH}" MATCHES "x86_64") target_compile_options(moon PRIVATE -mno-red-zone) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 73a10bab..1fe7eb5b 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -40,8 +40,13 @@ target_link_libraries(bare_libc PUBLIC luna) target_include_directories(bare_libc PUBLIC include/) -target_compile_options(bare_libc PRIVATE -Os -Wall -Wextra -Werror -nostdlib) -target_compile_options(bare_libc PRIVATE -fno-exceptions -fno-rtti) +target_compile_options(bare_libc PRIVATE ${COMMON_FLAGS}) + +if(LUNA_DEBUG_SYMBOLS) + target_compile_options(bare_libc PRIVATE -ggdb) +else() + target_compile_options(bare_libc PRIVATE -Os) +endif() target_link_options(bare_libc PRIVATE -nostdlib) diff --git a/libc/src/dirent.cpp b/libc/src/dirent.cpp index 48dcf7e1..b0c98e8f 100644 --- a/libc/src/dirent.cpp +++ b/libc/src/dirent.cpp @@ -33,7 +33,7 @@ extern "C" long rc = syscall(SYS_getdents, stream->_fd, &ent, 1); if (rc < 0) { - errno = -rc; + errno = (int)-rc; return nullptr; } diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index 42c2b1c5..1a2469f9 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -278,19 +278,19 @@ extern "C" int vfprintf(FILE* stream, const char* format, va_list ap) { - usize rc = cstyle_format( - format, - [](char c, void* f) -> Result { - int rc = fputc(c, (FILE*)f); - if (rc == EOF) return err(errno); - return {}; - }, - stream, ap) - .value_or(-1); + usize count = cstyle_format( + format, + [](char c, void* f) -> Result { + int rc = fputc(c, (FILE*)f); + if (rc == EOF) return err(errno); + return {}; + }, + stream, ap) + .value_or(-1); - if (rc == (usize)-1) return -1; + if (count == (usize)-1) return -1; - return (int)rc; + return (int)count; } int fprintf(FILE* stream, const char* format, ...) diff --git a/libluna/CMakeLists.txt b/libluna/CMakeLists.txt index 86e411ad..3cba6861 100644 --- a/libluna/CMakeLists.txt +++ b/libluna/CMakeLists.txt @@ -33,24 +33,15 @@ set(SOURCES add_library(luna-freestanding ${FREESTANDING_SOURCES}) target_compile_definitions(luna-freestanding PRIVATE USE_FREESTANDING) -target_compile_options(luna-freestanding PRIVATE -Os -Wall -Wextra -Werror -Wvla) -target_compile_options(luna-freestanding PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self -Wsign-conversion) -target_compile_options(luna-freestanding PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) -target_compile_options(luna-freestanding PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) -target_compile_options(luna-freestanding PRIVATE -fno-rtti -ffreestanding -fno-exceptions) -target_compile_options(luna-freestanding PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer) -target_compile_options(luna-freestanding PRIVATE -nostdlib -mcmodel=kernel) +target_compile_options(luna-freestanding PRIVATE ${COMMON_FLAGS}) +target_compile_options(luna-freestanding PRIVATE -nostdlib -mcmodel=kernel -ffreestanding) target_include_directories(luna-freestanding PUBLIC include/) target_include_directories(luna-freestanding PRIVATE ${LUNA_ROOT}/kernel/src) set_target_properties(luna-freestanding PROPERTIES CXX_STANDARD 20) add_library(luna ${SOURCES}) -target_compile_options(luna PRIVATE -Os -Wall -Wextra -Werror -Wvla) -target_compile_options(luna PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) -target_compile_options(luna PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) -target_compile_options(luna PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) -target_compile_options(luna PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -std=c++20 -fno-rtti -fno-exceptions) +target_compile_options(luna PRIVATE ${COMMON_FLAGS}) target_include_directories(luna PUBLIC include/) target_include_directories(luna PUBLIC ${LUNA_BASE}/usr/include) @@ -65,4 +56,7 @@ if(LUNA_DEBUG_SYMBOLS) message(STATUS "Building Luna with debug symbols") target_compile_options(luna PRIVATE -ggdb) target_compile_options(luna-freestanding PRIVATE -ggdb) +else() + target_compile_options(luna PRIVATE -Os) + target_compile_options(luna-freestanding PRIVATE -Os) endif() diff --git a/libos/CMakeLists.txt b/libos/CMakeLists.txt index 9c0589c9..4629a903 100644 --- a/libos/CMakeLists.txt +++ b/libos/CMakeLists.txt @@ -8,11 +8,7 @@ set(SOURCES ) add_library(os ${SOURCES}) -target_compile_options(os PRIVATE -Os -Wall -Wextra -Werror -Wvla) -target_compile_options(os PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) -target_compile_options(os PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) -target_compile_options(os PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) -target_compile_options(os PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -std=c++20 -fno-rtti -fno-exceptions) +target_compile_options(os PRIVATE ${COMMON_FLAGS}) target_include_directories(os PUBLIC include/) target_include_directories(os PUBLIC ${LUNA_BASE}/usr/include) @@ -23,4 +19,6 @@ endif() if(LUNA_DEBUG_SYMBOLS) message(STATUS "Building libOS with debug symbols") target_compile_options(os PRIVATE -ggdb) +else() + target_compile_options(os PRIVATE -Os) endif()