aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-19 10:38:49 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-19 10:38:49 -0700
commit471886467ee05046e8bd9e3621878e06ca9cbd5f (patch)
tree8acca61746e2d6a2be9ea5e1cc81b248a6b67819
parent5a25f38de6d3e2506838191c55af94cb56c9f641 (diff)
feat: added skeleton libc and updated generated makefiles to correctly set target specific flags
-rw-r--r--Makefile12
-rwxr-xr-xbin/initmk6
-rw-r--r--compile_commands.json58
-rw-r--r--include/libc.h12
-rw-r--r--sys/libc/rules.mk9
5 files changed, 64 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 1a21e76..344b88b 100644
--- a/Makefile
+++ b/Makefile
@@ -15,15 +15,11 @@ INCS := -I$(INC_DIR)
CFLAGS := -g -fno-strict-aliasing -fwrapv -fms-extensions
AFLAGS := -f elf64
-TGTFLAG :=
-TGTINCS :=
-TGTLIBS :=
-
# Named generic rules (must be evaluated lazily)
-COMPILE = $(CC) -MMD $(CFLAGS) $(TGTFLAGS) $(INCS) $(TGTINCS) -o $@ -c $<
-LINK = $(CC) -MMD $(CFLAGS) $(TGTFLAGS) -o $@ $^ $(LIBS) $(TGTLIBS)
-COMPLINK = $(CC) -MMD $(CFLAGS) $(TGTFLAGS) $(INCS) $(TGTINCS) -o $@ $^ $(LIBS)
-ASSEMBLE = $(AS) $(AFLAGS) $(TGTFLAGS) -o $@ $<
+COMPILE = $(CC) -MMD $(CFLAGS) $(TCFLAGS) $(INCS) $(TCINCS) -o $@ -c $<
+LINK = $(CC) -MMD $(CFLAGS) $(TCFLAGS) -o $@ $^ $(LIBS) $(TCLIBS)
+COMPLINK = $(CC) -MMD $(CFLAGS) $(TCFLAGS) $(INCS) $(TCINCS) -o $@ $^ $(LIBS) $(TCLIBS)
+ASSEMBLE = $(AS) $(AFLAGS) $(TCFLAGS) -o $@ $<
ARCHIVE = $(AR) crs $@ $^
include rules.mk
diff --git a/bin/initmk b/bin/initmk
index eb0098a..ca3f92a 100755
--- a/bin/initmk
+++ b/bin/initmk
@@ -29,9 +29,9 @@ BINS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(BINS_$(d)))
BINS := $(BINS) $(BINS_$(d))
# Local rules
-# $(LIBS_$(d)) := TGTFLAGS :=
-# $(LIBS_$(d)) := TGTINCS :=
-# $(LIBS_$(d)) := TGTLIBS :=
+# $(LIBS_$(d)) = TCFLAGS :=
+# $(LIBS_$(d)) = TCINCS :=
+# $(LIBS_$(d)) = TCLIBS :=
$(LIBS_$(d)): $(OBJS_$(d))
$(ARCHIVE)
diff --git a/compile_commands.json b/compile_commands.json
index a125285..31a2936 100644
--- a/compile_commands.json
+++ b/compile_commands.json
@@ -9,11 +9,11 @@
"-fms-extensions",
"-Iinclude",
"-o",
- "build/bufio/bufio.o",
- "src/bufio/bufio.c"
+ "build/libn/error.o",
+ "sys/libn/error.c"
],
"directory": "/home/nolln/root",
- "file": "src/bufio/bufio.c"
+ "file": "sys/libn/error.c"
},
{
"arguments": [
@@ -25,11 +25,11 @@
"-fms-extensions",
"-Iinclude",
"-o",
- "build/error.o",
- "src/error.c"
+ "build/libn/coro.o",
+ "sys/libn/coro.c"
],
"directory": "/home/nolln/root",
- "file": "src/error.c"
+ "file": "sys/libn/coro.c"
},
{
"arguments": [
@@ -39,13 +39,16 @@
"-fno-strict-aliasing",
"-fwrapv",
"-fms-extensions",
+ "-ffreestanding",
+ "-fno-builtin",
+ "-nostdlib",
"-Iinclude",
"-o",
- "build/string.o",
- "src/string.c"
+ "build/libc/stdio.o",
+ "sys/libc/stdio.c"
],
"directory": "/home/nolln/root",
- "file": "src/string.c"
+ "file": "sys/libc/stdio.c"
},
{
"arguments": [
@@ -57,11 +60,11 @@
"-fms-extensions",
"-Iinclude",
"-o",
- "build/memory.o",
- "src/memory.c"
+ "build/libn/string.o",
+ "sys/libn/string.c"
],
"directory": "/home/nolln/root",
- "file": "src/memory.c"
+ "file": "sys/libn/string.c"
},
{
"arguments": [
@@ -73,11 +76,11 @@
"-fms-extensions",
"-Iinclude",
"-o",
- "build/test.o",
- "src/test.c"
+ "build/libn/memory.o",
+ "sys/libn/memory.c"
],
"directory": "/home/nolln/root",
- "file": "src/test.c"
+ "file": "sys/libn/memory.c"
},
{
"arguments": [
@@ -89,10 +92,29 @@
"-fms-extensions",
"-Iinclude",
"-o",
- "build/coro.o",
- "src/coro.c"
+ "build/libn/test.o",
+ "sys/libn/test.c"
],
"directory": "/home/nolln/root",
- "file": "src/coro.c"
+ "file": "sys/libn/test.c"
+ },
+ {
+ "arguments": [
+ "clang",
+ "-c",
+ "-g",
+ "-fno-strict-aliasing",
+ "-fwrapv",
+ "-fms-extensions",
+ "-ffreestanding",
+ "-fno-builtin",
+ "-nostdlib",
+ "-Iinclude",
+ "-o",
+ "build/libc/string.o",
+ "sys/libc/string.c"
+ ],
+ "directory": "/home/nolln/root",
+ "file": "sys/libc/string.c"
}
] \ No newline at end of file
diff --git a/include/libc.h b/include/libc.h
new file mode 100644
index 0000000..7d42f97
--- /dev/null
+++ b/include/libc.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <u.h>
+
+void *memset(void*, int, intptr);
+void *memcopy(void*, void*, intptr);
+void *memmove(void*, void*, intptr);
+int memcmp(void*, void*, intptr);
+
+int strlen(byte* s);
+
+error printf(byte* fmt, ...);
diff --git a/sys/libc/rules.mk b/sys/libc/rules.mk
index 6234a1e..36cf1a7 100644
--- a/sys/libc/rules.mk
+++ b/sys/libc/rules.mk
@@ -15,7 +15,7 @@ OBJS := $(OBJS) $(OBJS_$(d))
DEPS := $(DEPS) $(DEPS_$(d))
# Local targets
-LIBS_$(d) :=
+LIBS_$(d) := $(d)/libc.a
LIBS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(LIBS_$(d)))
LIBS := $(LIBS) $(LIBS_$(d))
@@ -24,9 +24,10 @@ BINS_$(d) := $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(BINS_$(d)))
BINS := $(BINS) $(BINS_$(d))
# Local rules
-# $(LIBS_$(d)) := TGTFLAGS :=
-# $(LIBS_$(d)) := TGTINCS :=
-# $(LIBS_$(d)) := TGTLIBS :=
+# $(LIBS_$(d)) = TGTINCS :=
+# $(LIBS_$(d)) = TGTLIBS :=
+
+$(LIBS_$(d)): TCFLAGS := -ffreestanding -fno-builtin -nostdlib
$(LIBS_$(d)): $(OBJS_$(d))
$(ARCHIVE)