Merge remote-tracking branch 'Userspace/master'

This commit is contained in:
EnderIce2
2024-11-20 05:02:06 +02:00
104 changed files with 11117 additions and 1 deletions

View File

@@ -0,0 +1,66 @@
WORKSPACE := ../../../
# Config file
include ../$(WORKSPACE)Makefile.conf
CC = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
CPP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)g++
LD = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)ld
AS = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)as
OBJDUMP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)objdump
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)
ifeq ($(OSARCH), amd64)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
else ifeq ($(OSARCH), i386)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
else ifeq ($(OSARCH), aarch64)
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
endif
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
SYSROOT = --sysroot=$(WORKSPACE)out/
FILENAME = echo
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
LDFLAGS =
CFLAGS = -I$(WORKSPACE)out/include \
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
WARNCFLAG = -Wall -Wextra
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
LDFLAGS += -ggdb3 -O0
endif
build: $(FILENAME)
mv $(FILENAME) $(WORKSPACE)out/bin/$(FILENAME)
$(FILENAME): $(OBJ)
$(info Linking $@)
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
%.o: %.c $(HEADERS)
$(info Compiling $<)
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
%.o: %.cpp $(HEADERS)
$(info Compiling $<)
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
%.o: %.S
$(info Compiling $<)
$(AS) -o $@ $<
clean:
rm -f $(OBJ)

View File

@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
int main(int argc, char *argv[])
{
int enableEscapes = 0;
int disableNewline = 0;
int opt;
while ((opt = getopt(argc, argv, "neE")) != -1)
{
switch (opt)
{
case 'n':
disableNewline = 1;
break;
case 'e':
enableEscapes = 1;
break;
case 'E':
enableEscapes = 0;
break;
case '?':
default:
exit(EXIT_FAILURE);
}
}
(void)enableEscapes;
size_t totalLength = 0;
for (int i = optind; i < argc; ++i)
totalLength += strlen(argv[i]) + 1;
char *result = (char *)malloc(totalLength);
if (!result)
{
perror("Memory allocation error");
exit(EXIT_FAILURE);
}
result[0] = '\0';
for (int i = optind; i < argc; ++i)
{
strcat(result, argv[i]);
if (i < argc - 1)
strcat(result, " ");
}
printf("%s", result);
if (!disableNewline)
printf("\n");
free(result);
return 0;
}