Lots of work on the build system
This commit is contained in:
@@ -33,7 +33,6 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM})
|
||||
message(FATAL_ERROR "Unsupported platform: ${PLATFORM}")
|
||||
endif ()
|
||||
|
||||
|
||||
message(STATUS "Target platform: ${PLATFORM}")
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS
|
||||
@@ -47,26 +46,42 @@ foreach (dir ${generic_dirs})
|
||||
set(photon_libc_sources ${photon_libc_sources} ${dir_sources})
|
||||
endforeach (dir)
|
||||
|
||||
file(GLOB_RECURSE photon_libc_includes ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include/*.h)
|
||||
file(GLOB_RECURSE photon_libc_headers ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include/*.h)
|
||||
|
||||
file(GLOB photon_libc_crt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM}/machine/${MACHINE}/crt*.s)
|
||||
|
||||
add_library(crt OBJECT ${photon_libc_crt})
|
||||
message(STATUS "CRT sources: ${photon_libc_crt}")
|
||||
|
||||
file(GLOB platform_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/*.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.s)
|
||||
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM}/*.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM}/machine/${MACHINE}/*.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${PLATFORM}/machine/${MACHINE}/*.s)
|
||||
|
||||
add_library(c STATIC ${photon_libc_sources} ${photon_libc_includes})
|
||||
foreach (crt_source ${photon_libc_crt})
|
||||
list(REMOVE_ITEM platform_sources ${crt_source})
|
||||
endforeach (crt_source)
|
||||
|
||||
file(GLOB platform_headers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/*.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/photon/sys/${PLATFORM}/machine/${MACHINE}/*.h)
|
||||
|
||||
set(photon_libc_sources ${photon_libc_sources} ${platform_sources})
|
||||
set(photon_libc_headers ${photon_libc_headers} ${platform_headers})
|
||||
|
||||
add_library(c STATIC ${photon_libc_sources} ${photon_libc_headers})
|
||||
target_compile_options(c PRIVATE -ffreestanding -nostdlib -nostdinc)
|
||||
target_link_libraries(c crt)
|
||||
|
||||
target_include_directories(c PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/include)
|
||||
|
||||
add_custom_target(sysroot
|
||||
DEPENDS ${photon_libc_headers}
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/create-sysroot.sh
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${PLATFORM} ${MACHINE})
|
||||
|
||||
add_dependencies(c sysroot)
|
||||
|
||||
add_subdirectory(tests)
|
||||
|
||||
@@ -48,6 +48,4 @@ typedef __uintmax_t uintmax_t;
|
||||
typedef __intptr_t intptr_t;
|
||||
typedef __uintptr_t uintptr_t;
|
||||
|
||||
typedef
|
||||
|
||||
#endif /* STDINT_H_ */
|
||||
|
||||
30
photon/libc/include/stdio.h
Normal file
30
photon/libc/include/stdio.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef STDIO_H_
|
||||
#define STDIO_H_
|
||||
|
||||
#include <sys/_fconst.h>
|
||||
|
||||
#if defined(__FILENAME_MAX)
|
||||
#define FILENAME_MAX __FILENAME_MAX
|
||||
#else
|
||||
#define FILENAME_MAX 1024
|
||||
#endif
|
||||
|
||||
#define SEEK_SET __SEEK_SET
|
||||
#define SEEK_CUR __SEEK_CUR
|
||||
#define SEEK_END __SEEK_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct __io_file FILE;
|
||||
|
||||
extern FILE *stdin;
|
||||
extern FILE *stdout;
|
||||
extern FILE *stderr;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
20
photon/libc/sys/linux/__fio.h
Normal file
20
photon/libc/sys/linux/__fio.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef SYS_LINUX___FIO_H_
|
||||
#define SYS_LINUX___FIO_H_
|
||||
|
||||
#define __FIO_BUFSZ 512
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct __io_file {
|
||||
char buf[__FIO_BUFSZ];
|
||||
unsigned int buf_idx;
|
||||
unsigned int fd;
|
||||
};
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
10
photon/libc/sys/linux/_fconst.h
Normal file
10
photon/libc/sys/linux/_fconst.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef SYS_LINUX__FCONST_H_
|
||||
#define SYS_LINUX__FCONST_H_
|
||||
|
||||
#define __FILENAME_MAX 1024
|
||||
|
||||
#define __SEEK_SET 0
|
||||
#define __SEEK_CUR 1
|
||||
#define __SEEK_END 2
|
||||
|
||||
#endif
|
||||
16
photon/libc/sys/linux/fio.c
Normal file
16
photon/libc/sys/linux/fio.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#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;
|
||||
|
||||
void __fio_init()
|
||||
{
|
||||
__stdin.fd = 0;
|
||||
__stdout.fd = 1;
|
||||
__stderr.fd = 2;
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
.extern __fio_init
|
||||
.type __fio_init, @function
|
||||
|
||||
.extern main
|
||||
.type main, @function
|
||||
|
||||
@@ -9,6 +12,7 @@ _start:
|
||||
pop %rdi
|
||||
mov %rsp, %rsi
|
||||
andq $-16, %rsp
|
||||
call __fio_init
|
||||
call main
|
||||
movq %rax, %rdi
|
||||
movq $60, %rax
|
||||
|
||||
20
scripts/create-sysroot.sh
Executable file
20
scripts/create-sysroot.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
source_dir=$1
|
||||
build_dir=$2
|
||||
platform=$3
|
||||
machine=$4
|
||||
|
||||
echo "Building $machine-$platform sysroot"
|
||||
mkdir -p $build_dir/sysroot/usr/include/{sys,machine}
|
||||
|
||||
cp $source_dir/photon/libc/include/*.h $build_dir/sysroot/usr/include
|
||||
|
||||
platform_headers=$(find $source_dir/photon/libc/sys/$platform -type f \( -iname "*.h" ! -iname "__*" \))
|
||||
cp -t $build_dir/sysroot/usr/include/sys $platform_headers
|
||||
|
||||
machine_arch_headers=$(find $source_dir/photon/libc/machine/$machine/ \
|
||||
-type f \( -iname "*.h" ! -iname "__*" \))
|
||||
machine_generic_headers=$(find $source_dir/photon/libc/include/machine/ \
|
||||
-type f \( -iname "*.h" ! -iname "__*" \))
|
||||
cp -t $build_dir/sysroot/usr/include/machine $machine_generic_headers $machine_arch_headers
|
||||
@@ -4,5 +4,7 @@ foreach (test ${test_sources})
|
||||
get_filename_component(test_name ${test} NAME_WE)
|
||||
add_executable(${test_name} ${test} $<TARGET_OBJECTS:crt>)
|
||||
target_compile_options(${test_name} PRIVATE -ffreestanding -nostdlib -nostdinc)
|
||||
target_include_directories(${test_name} PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../sysroot/usr/include)
|
||||
target_link_libraries(${test_name} c)
|
||||
endforeach (test)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return 42;
|
||||
|
||||
Reference in New Issue
Block a user