aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2021-05-13 13:47:15 +0200
committerMarvin Borner2021-05-13 13:47:15 +0200
commita086d68bea0004b52a78482daa9292bde6e36e8c (patch)
tree4932f50c408f2b1003155c2178954ffeebe83fd9
parentf181a8f04dfdfd8829861e0d0d549f39e40081e6 (diff)
liblib
-rw-r--r--Makefile2
-rw-r--r--src/context.c4
-rw-r--r--src/inc/context.h2
-rw-r--r--src/inc/lib.h33
-rw-r--r--src/lint.c2
-rw-r--r--src/log.c4
-rw-r--r--src/preprocess.c4
-rw-r--r--src/tokenize.c5
8 files changed, 40 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 6517207..7e61d70 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ SOURCES = $(wildcard $(SOURCEDIR)/*.c)
OBJS = $(patsubst $(SOURCEDIR)/%.c, $(BUILDDIR)/%.o, $(SOURCES))
CC = gcc
-CFLAGS = -Ofast -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=1 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wlogical-op -Wunreachable-code -Wundef -Wold-style-definition -Wvla -std=c99 -fsanitize=address -fsanitize=undefined -I$(SOURCEDIR)/inc/
+CFLAGS = -Ofast -Wall -Wextra -Werror -pedantic -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=1 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wlogical-op -Wunreachable-code -Wundef -Wold-style-definition -Wvla -std=c99 -fsanitize=address -fsanitize=undefined -I$(SOURCEDIR)/inc/
all: $(OBJS)
@$(CC) -o ./$(BUILDDIR)/out $(CFLAGS) $^
diff --git a/src/context.c b/src/context.c
index 3a98a64..c0898d8 100644
--- a/src/context.c
+++ b/src/context.c
@@ -1,7 +1,5 @@
-#include <assert.h>
#include <context.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <lib.h>
#include <tokenize.h>
struct ctx *context_create(const char *path)
diff --git a/src/inc/context.h b/src/inc/context.h
index 81a2ca4..603f42e 100644
--- a/src/inc/context.h
+++ b/src/inc/context.h
@@ -1,7 +1,7 @@
#ifndef CONTEXT_H
#define CONTEXT_H
-#include <string.h>
+#include <lib.h>
struct ctx {
size_t line;
diff --git a/src/inc/lib.h b/src/inc/lib.h
new file mode 100644
index 0000000..0402990
--- /dev/null
+++ b/src/inc/lib.h
@@ -0,0 +1,33 @@
+#ifndef LIB_H
+#define LIB_H
+
+// Compatibility imports (mainly for Melvix)
+
+#ifdef __melvix__
+
+#include <arg.h>
+#include <assert.h>
+#include <def.h>
+#include <mem.h>
+#include <print.h>
+#include <str.h>
+#include <sys.h>
+typedef size_t u32;
+
+#elif defined(__linux__) || defined(unix) || defined(__unix__) || defined(__unix) || \
+ defined(__APPLE__) || defined(__FreeBSD)
+
+#include <assert.h>
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+
+#else
+#error "Unknown operating system"
+#endif
+
+#endif
diff --git a/src/lint.c b/src/lint.c
index 576c554..6b7fd44 100644
--- a/src/lint.c
+++ b/src/lint.c
@@ -1,6 +1,6 @@
+#include <lib.h>
#include <lint.h>
#include <log.h>
-#include <string.h>
#include <tokenize.h>
void lint(struct ctx *ctx)
diff --git a/src/log.c b/src/log.c
index efcf9db..ee06313 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,7 +1,5 @@
+#include <lib.h>
#include <log.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
static void context_print(FILE *fd, struct ctx *ctx)
{
diff --git a/src/preprocess.c b/src/preprocess.c
index 673bd20..e721207 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -1,8 +1,6 @@
-#include <assert.h>
+#include <lib.h>
#include <log.h>
#include <preprocess.h>
-#include <string.h>
-#include <sys/param.h>
static void preprocess_erase(struct ctx *ctx, size_t start)
{
diff --git a/src/tokenize.c b/src/tokenize.c
index 3424454..69f17c9 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -1,8 +1,5 @@
-#include <assert.h>
-#include <ctype.h>
+#include <lib.h>
#include <log.h>
-#include <stdbool.h>
-#include <stdio.h>
#include <tokenize.h>
static char next_non_alnum(struct ctx *ctx, size_t start)