Adds simple stdlib compilation.
This commit is contained in:
parent
98900c9069
commit
054dd7fba3
3 changed files with 69 additions and 0 deletions
42
prototypes/stdlib/Makefile
Normal file
42
prototypes/stdlib/Makefile
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
|
||||||
|
AS=gcc
|
||||||
|
CC=gcc
|
||||||
|
CXX=g++
|
||||||
|
LD=ld
|
||||||
|
AR=ar
|
||||||
|
|
||||||
|
FLAGS = -mno-sse -ffreestanding -m32 -Werror -Wall -iquote include -O3 -g
|
||||||
|
ASFLAGS = $(FLAGS)
|
||||||
|
CFLAGS = $(FLAGS)
|
||||||
|
CXXFLAGS = $(FLAGS) -std=c++14 -fno-rtti -fno-exceptions -fno-leading-underscore -fno-use-cxa-atexit -nostdlib -fno-builtin
|
||||||
|
|
||||||
|
ARTIFACT = libstd.a
|
||||||
|
|
||||||
|
SRCS = $(shell find -regextype egrep -regex '.*/.*\.(cpp|S|c)')
|
||||||
|
OBJS = $(addsuffix .o, $(notdir $(basename $(SRCS))))
|
||||||
|
|
||||||
|
all: $(ARTIFACT)
|
||||||
|
|
||||||
|
$(ARTIFACT): $(OBJS)
|
||||||
|
$(AR) rcs $(ARTIFACT) $(addprefix obj/, $^)
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o obj/$@ $<
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(ASFLAGS) -c -o obj/$@ $<
|
||||||
|
|
||||||
|
%.o: %.S
|
||||||
|
$(AS) $(CFLAGS) -c -o obj/$@ $<
|
||||||
|
|
||||||
|
%.o: src/%.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o obj/$@ $<
|
||||||
|
|
||||||
|
%.o: src/%.c
|
||||||
|
$(CC) $(ASFLAGS) -c -o obj/$@ $<
|
||||||
|
|
||||||
|
%.o: src/%.S
|
||||||
|
$(AS) $(CFLAGS) -c -o obj/$@ $<
|
||||||
|
|
||||||
|
deploy: $(ARTIFACT)
|
||||||
|
cp $(ARTIFACT) /srv/tftp/$(ARTIFACT)
|
7
prototypes/stdlib/include/string.h
Normal file
7
prototypes/stdlib/include/string.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
void * memcpy ( void * destination, const void * source, size_t num );
|
||||||
|
|
||||||
|
void * memset ( void * ptr, int value, size_t num );
|
20
prototypes/stdlib/src/string.c
Normal file
20
prototypes/stdlib/src/string.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
void * memcpy ( void * destination, const void * source, size_t num )
|
||||||
|
{
|
||||||
|
char *d = destination;
|
||||||
|
char const * s = source;
|
||||||
|
for(size_t i = 0; i < num; i++) {
|
||||||
|
d[i] = s[i];
|
||||||
|
}
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
void * memset ( void * ptr, int value, size_t num )
|
||||||
|
{
|
||||||
|
char *p = ptr;
|
||||||
|
for(size_t i = 0; i < num; i++) {
|
||||||
|
p[i] = value;
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
Loading…
Reference in a new issue