Photon is now built as a framework
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
#project(photon C ASM-ATT)
|
# project(photon C ASM-ATT)
|
||||||
|
|
||||||
macro(subdirlist result curdir)
|
macro(subdirlist result curdir)
|
||||||
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
||||||
@@ -13,6 +13,7 @@ macro(subdirlist result curdir)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake)
|
||||||
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Bundles.cmake)
|
||||||
platform_config(${PHOTON_TARGET})
|
platform_config(${PHOTON_TARGET})
|
||||||
|
|
||||||
message(STATUS "Target: ${machine}-${platform}")
|
message(STATUS "Target: ${machine}-${platform}")
|
||||||
@@ -73,21 +74,21 @@ file(GLOB platform_headers
|
|||||||
set(photon_libc_sources ${photon_libc_sources} ${malloc_sources} ${platform_sources})
|
set(photon_libc_sources ${photon_libc_sources} ${malloc_sources} ${platform_sources})
|
||||||
set(photon_libc_headers ${photon_libc_headers} ${platform_headers})
|
set(photon_libc_headers ${photon_libc_headers} ${platform_headers})
|
||||||
|
|
||||||
if (PHOTON_STATIC EQUAL 1)
|
add_framework(Photon STATIC
|
||||||
add_library(c STATIC ${photon_libc_sources} ${photon_libc_headers})
|
BUNDLE_ID net.doorstuck.photon
|
||||||
else ()
|
SOURCES ${photon_libc_sources} ${photon_libc_headers}
|
||||||
add_library(c SHARED ${photon_libc_sources} ${photon_libc_headers})
|
HEADERS ${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include/*)
|
||||||
endif ()
|
|
||||||
|
|
||||||
target_compile_options(c PRIVATE -ffreestanding -nostdlib)
|
framework_compile_options(Photon -ffreestanding -nostdlib)
|
||||||
target_link_libraries(c crt ${photon_platform_libs})
|
framework_link_libraries(Photon ${photon_platform_libs})
|
||||||
|
framework_link_frameworks(Photon ${photon_platform_frameworks})
|
||||||
|
|
||||||
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include
|
framework_include_directories(Photon ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include)
|
${CMAKE_CURRENT_BINARY_DIR}/sysroot/usr/include)
|
||||||
|
|
||||||
foreach (platform_include_dir ${photon_platform_extra_include_dirs})
|
foreach (platform_include_dir ${photon_platform_extra_include_dirs})
|
||||||
target_include_directories(c PRIVATE
|
framework_include_directories(Photon
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/${platform_include_dir})
|
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/${platform_include_dir})
|
||||||
endforeach (platform_include_dir)
|
endforeach (platform_include_dir)
|
||||||
|
|
||||||
@@ -98,10 +99,20 @@ add_custom_target(local-root
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
${platform} ${machine})
|
${platform} ${machine})
|
||||||
|
|
||||||
add_dependencies(c local-root)
|
framework_add_dependencies(Photon local-root)
|
||||||
|
|
||||||
|
add_custom_command(TARGET Photon POST_BUILD
|
||||||
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/add-framework-crt.sh
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/Photon.framework
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
target_link_libraries(c gcc)
|
framework_link_libraries(Photon gcc)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (TARGET early-sysroot)
|
||||||
|
# We are being built as part of asbestOS, make sure the sysroot is there.
|
||||||
|
framework_add_dependencies(Photon early-sysroot)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (PHOTON_TESTS EQUAL 1)
|
if (PHOTON_TESTS EQUAL 1)
|
||||||
|
|||||||
139
cmake/Bundles.cmake
Normal file
139
cmake/Bundles.cmake
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
find_program(BUNDLE_PROGRAM "bundle")
|
||||||
|
if (BUNDLE_PROGRAM STREQUAL BUNDLE_PROGRAM-NOTFOUND)
|
||||||
|
message(WARNING "Couldn't find Bundle generator. "
|
||||||
|
"Please install bundle from https://gitalb.com/doorstuck/magenta/bundle.git")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
function (add_framework name)
|
||||||
|
set(options STATIC SHARED)
|
||||||
|
set(one_value_args BUNDLE_ID)
|
||||||
|
set(multi_value_args HEADER_DIRS HEADERS SOURCES)
|
||||||
|
cmake_parse_arguments(ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
|
||||||
|
|
||||||
|
if (ARG_HEADER_DIRS STREQUAL "")
|
||||||
|
message(FATAL_ERROR "add_framework: No header directories specified for ${name}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (ARG_SOURCES STREQUAL "")
|
||||||
|
message(FATAL_ERROR "add_framework: No source files specified for ${name}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (ARG_BUNDLE_ID STREQUAL "")
|
||||||
|
message(FATAL_ERROR "add_framework: No bundle ID specified for ${name}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
string(TOLOWER ${name} lib_name)
|
||||||
|
|
||||||
|
if (NOT ARG_STATIC AND NOT ARG_SHARED)
|
||||||
|
message(FATAL_ERROR "add_framework: Neither STATIC nor SHARED specified for ${name}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
add_custom_target(${name} ALL)
|
||||||
|
|
||||||
|
if (ARG_STATIC)
|
||||||
|
add_library(${lib_name}_s STATIC ${ARG_SOURCES})
|
||||||
|
add_dependencies(${name} ${lib_name}_s)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (ARG_SHARED)
|
||||||
|
add_library(${lib_name} SHARED ${ARG_SOURCES})
|
||||||
|
add_dependencies(${name} ${lib_name})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(header_dirs_arg "")
|
||||||
|
foreach (header_dir ${ARG_HEADER_DIRS})
|
||||||
|
set(header_dirs_arg ${header_dirs_arg} --header-dir \"${header_dir}\")
|
||||||
|
endforeach (header_dir)
|
||||||
|
|
||||||
|
set(headers_arg "")
|
||||||
|
foreach (header ${ARG_HEADERS})
|
||||||
|
set(headers_arg ${headers_arg} --header \"${header}\")
|
||||||
|
endforeach (header)
|
||||||
|
|
||||||
|
set(binary_args "")
|
||||||
|
if (ARG_STATIC)
|
||||||
|
set(binary_args ${binary_args} --static-binary \"${CMAKE_CURRENT_BINARY_DIR}/lib${lib_name}_s.a\")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (ARG_SHARED)
|
||||||
|
set(binary_args ${binary_args} --shared-binary \"${CMAKE_CURRENT_BINARY_DIR}/lib${lib_name}.so\")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
string(ASCII 27 esc)
|
||||||
|
string(ASCII 10 lf)
|
||||||
|
string(ASCII 13 cr)
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${name}
|
||||||
|
POST_BUILD
|
||||||
|
COMMENT "[ -- ] Building framework bundle ${name}.framework"
|
||||||
|
COMMAND rm -rf ${name}.framework
|
||||||
|
COMMAND ${BUNDLE_PROGRAM} create-framework
|
||||||
|
-o ${name}.framework
|
||||||
|
-i ${ARG_BUNDLE_ID}
|
||||||
|
${headers_arg}
|
||||||
|
${header_dirs_arg}
|
||||||
|
${binary_args}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
endfunction (add_framework)
|
||||||
|
|
||||||
|
function (framework_compile_options name)
|
||||||
|
string(TOLOWER ${name} lib_name)
|
||||||
|
|
||||||
|
if (TARGET ${lib_name})
|
||||||
|
target_compile_options(${lib_name} PRIVATE ${ARGN})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (TARGET ${lib_name}_s)
|
||||||
|
target_compile_options(${lib_name}_s PRIVATE ${ARGN})
|
||||||
|
endif ()
|
||||||
|
endfunction (framework_compile_options)
|
||||||
|
|
||||||
|
function (framework_link_libraries name)
|
||||||
|
string(TOLOWER ${name} lib_name)
|
||||||
|
|
||||||
|
if (TARGET ${lib_name})
|
||||||
|
target_link_libraries(${lib_name} ${ARGN})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (TARGET ${lib_name}_s)
|
||||||
|
target_link_libraries(${lib_name}_s ${ARGN})
|
||||||
|
endif ()
|
||||||
|
endfunction (framework_link_libraries)
|
||||||
|
|
||||||
|
function (framework_include_directories name)
|
||||||
|
string(TOLOWER ${name} lib_name)
|
||||||
|
|
||||||
|
if (TARGET ${lib_name})
|
||||||
|
target_include_directories(${lib_name} PRIVATE ${ARGN})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (TARGET ${lib_name}_s)
|
||||||
|
target_include_directories(${lib_name}_s PRIVATE ${ARGN})
|
||||||
|
endif ()
|
||||||
|
endfunction (framework_include_directories)
|
||||||
|
|
||||||
|
function (framework_link_frameworks name)
|
||||||
|
string(TOLOWER ${name} lib_name)
|
||||||
|
|
||||||
|
foreach (framework ${ARGN})
|
||||||
|
if (TARGET ${lib_name})
|
||||||
|
target_compile_options(${lib_name} PRIVATE -framework ${framework})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (TARGET ${lib_name}_s)
|
||||||
|
target_compile_options(${lib_name}_s PRIVATE -framework ${framework})
|
||||||
|
endif ()
|
||||||
|
endforeach (framework)
|
||||||
|
endfunction (framework_link_frameworks)
|
||||||
|
|
||||||
|
function (framework_add_dependencies name)
|
||||||
|
string(TOLOWER ${name} lib_name)
|
||||||
|
|
||||||
|
if (TARGET ${lib_name})
|
||||||
|
add_dependencies(${lib_name} ${ARGN})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (TARGET ${lib_name}_s)
|
||||||
|
add_dependencies(${lib_name}_s ${ARGN})
|
||||||
|
endif ()
|
||||||
|
endfunction (framework_add_dependencies)
|
||||||
@@ -35,7 +35,7 @@ extern int fflush(FILE *fp);
|
|||||||
|
|
||||||
extern int fileno(FILE *fp);
|
extern int fileno(FILE *fp);
|
||||||
extern int fputs(const char *str, FILE *fp);
|
extern int fputs(const char *str, FILE *fp);
|
||||||
extern int fputc(char c, FILE *fp);
|
extern int fputc(int c, FILE *fp);
|
||||||
|
|
||||||
extern int printf(const char *restrict format, ...);
|
extern int printf(const char *restrict format, ...);
|
||||||
extern int fprintf(FILE *fp, const char *restrict format, ...);
|
extern int fprintf(FILE *fp, const char *restrict format, ...);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <__fio.h>
|
#include <__fio.h>
|
||||||
|
|
||||||
int fputc(char c, FILE *fp)
|
int fputc(int c, FILE *fp)
|
||||||
{
|
{
|
||||||
__fio_write(fp, &c, 1);
|
__fio_write(fp, &c, 1);
|
||||||
if (__fio_error(fp)) {
|
if (__fio_error(fp)) {
|
||||||
|
|||||||
0
photon/libc/sys/linux/config.cmake
Normal file
0
photon/libc/sys/linux/config.cmake
Normal file
@@ -2,4 +2,4 @@ set(photon_platform_extra_source_dirs libmagenta/libmagenta)
|
|||||||
set(photon_platform_extra_include_dirs
|
set(photon_platform_extra_include_dirs
|
||||||
libmagenta/libmagenta
|
libmagenta/libmagenta
|
||||||
libmagenta/libmagenta/arch/${machine})
|
libmagenta/libmagenta/arch/${machine})
|
||||||
set(photon_platform_libs magenta)
|
set(photon_platform_frameworks Magenta)
|
||||||
|
|||||||
11
scripts/add-framework-crt.sh
Executable file
11
scripts/add-framework-crt.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
framework_path=$1
|
||||||
|
binary_dir=$2
|
||||||
|
|
||||||
|
crt_files=$(find $binary_dir -name "crt*.s.o")
|
||||||
|
|
||||||
|
for crt_file in $crt_files; do
|
||||||
|
out="$framework_path/Binary/$(basename $crt_file .s.o).o"
|
||||||
|
cp -f $crt_file $out
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user