BuildSystem: userspace has cmake target
This commit is contained in:
20
userspace/CMakeLists.txt
Normal file
20
userspace/CMakeLists.txt
Normal 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()
|
||||
@@ -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;
|
||||
}
|
||||
17
userspace/test/CMakeLists.txt
Normal file
17
userspace/test/CMakeLists.txt
Normal 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
55
userspace/test/test.cpp
Normal 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;
|
||||
}
|
||||
17
userspace/yes/CMakeLists.txt
Normal file
17
userspace/yes/CMakeLists.txt
Normal 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
8
userspace/yes/main.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
for (;;)
|
||||
puts("y");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user