BuildSystem: userspace has cmake target

This commit is contained in:
Bananymous 2023-05-11 16:19:53 +03:00
parent 729ff267d7
commit 177b205c48
8 changed files with 122 additions and 32 deletions

View File

@ -22,6 +22,7 @@ project(banan-os CXX)
set(BANAN_SYSROOT ${CMAKE_BINARY_DIR}/sysroot)
set(BANAN_INCLUDE ${BANAN_SYSROOT}/usr/include)
set(BANAN_LIB ${BANAN_SYSROOT}/usr/lib)
set(BANAN_BIN ${BANAN_SYSROOT}/usr/bin)
set(BANAN_BOOT ${BANAN_SYSROOT}/boot)
set(DISK_IMAGE_PATH ${CMAKE_BINARY_DIR}/banan-os.img)
@ -29,6 +30,7 @@ add_subdirectory(kernel)
add_subdirectory(BAN)
add_subdirectory(libc)
add_subdirectory(LibELF)
add_subdirectory(userspace)
add_custom_target(sysroot
COMMAND mkdir -p ${BANAN_SYSROOT}
@ -52,11 +54,11 @@ add_custom_target(toolchain
)
add_custom_target(image
COMMAND ${CMAKE_CXX_COMPILER} -x c ${CMAKE_SOURCE_DIR}/userspace/test.c -o ${BANAN_SYSROOT}/bin/test
COMMAND ${CMAKE_COMMAND} -E env SYSROOT="${BANAN_SYSROOT}" DISK_IMAGE_PATH="${DISK_IMAGE_PATH}" ${CMAKE_SOURCE_DIR}/image.sh
DEPENDS kernel-install
DEPENDS ban-install
DEPENDS libc-install
DEPENDS userspace-install
USES_TERMINAL
)
@ -65,6 +67,7 @@ add_custom_target(image-full
DEPENDS kernel-install
DEPENDS ban-install
DEPENDS libc-install
DEPENDS userspace-install
USES_TERMINAL
)

View File

@ -180,7 +180,7 @@ static void init2(void* tty1)
((TTY*)tty1)->initialize_device();
MUST(Process::create_userspace("/bin/test"sv));
MUST(Process::create_userspace("/usr/bin/test"sv));
return;
Process::create_kernel(

20
userspace/CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.26)
project(userspace CXX)
set(USERSPACE_PROJECTS
test
yes
)
foreach(USERSPACE_PROJECT ${USERSPACE_PROJECTS})
add_subdirectory(${USERSPACE_PROJECT})
endforeach()
add_custom_target(userspace)
add_custom_target(userspace-install DEPENDS userspace)
foreach(USERSPACE_PROJECT ${USERSPACE_PROJECTS})
add_dependencies(userspace ${USERSPACE_PROJECT})
add_dependencies(userspace-install ${USERSPACE_PROJECT}-install)
endforeach()

View File

@ -1,30 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#define ERROR(msg) { perror(msg); return 1; }
#define BUF_SIZE 1024
int main()
{
FILE* fp = fopen("/usr/include/stdio.h", "r");
if (fp == NULL)
ERROR("fopen");
char* buffer = malloc(BUF_SIZE);
if (buffer == NULL)
ERROR("malloc");
for (;;)
{
size_t n_read = fread(buffer, 1, BUF_SIZE - 1, fp);
if (n_read == 0)
break;
buffer[n_read] = '\0';
printf("%s", buffer);
}
free(buffer);
fclose(fp);
return 0;
}

View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.26)
project(test CXX)
set(TEST_SOURCES
test.cpp
)
add_executable(test ${TEST_SOURCES})
target_compile_options(test PUBLIC -O2 -g)
add_dependencies(test libc-install)
target_link_options(test PUBLIC -nodefaultlibs -lc)
add_custom_target(test-install
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/test ${BANAN_BIN}/
DEPENDS test
)

55
userspace/test/test.cpp Normal file
View File

@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ERROR(msg) { perror(msg); return 1; }
#define BUF_SIZE 1024
int main()
{
printf("%.2e\n", 1230.0);
printf("%.2e\n", 123.0);
printf("%.2e\n", 12.3);
printf("%.2e\n", 1.23);
printf("%.2e\n", 0.123);
printf("%.2e\n", 0.0123);
printf("%.2e\n", 0.00123);
printf("%e\n", 123.456);
printf("%.2e\n", 123.456);
printf("%.0e\n", 123.456);
printf("%#.0e\n", 123.456);
printf("%e\n", -123.456);
printf("%.2e\n", -123.456);
printf("%.0e\n", -123.456);
printf("%#.0e\n", -123.456);
printf("%e\n", 0.0);
printf("%e\n", -0.0);
return 0;
FILE* fp = fopen("/usr/include/stdio.h", "r");
if (fp == NULL)
ERROR("fopen");
char* buffer = (char*)malloc(BUF_SIZE);
if (buffer == NULL)
ERROR("malloc");
for (;;)
{
size_t n_read = fread(buffer, 1, BUF_SIZE - 1, fp);
if (n_read == 0)
break;
buffer[n_read] = '\0';
printf("%s", buffer);
}
free(buffer);
fclose(fp);
return 0;
}

View File

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.26)
project(yes CXX)
set(SOURCES
main.cpp
)
add_executable(yes ${SOURCES})
target_compile_options(yes PUBLIC -O2 -g)
add_dependencies(yes libc-install)
target_link_options(yes PUBLIC -nodefaultlibs -lc)
add_custom_target(yes-install
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/yes ${BANAN_BIN}/
DEPENDS yes
)

8
userspace/yes/main.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <stdio.h>
int main()
{
for (;;)
puts("y");
return 0;
}