Project restructure and rewrote Makefile
This commit is contained in:
parent
ee9197d681
commit
c7830193cd
|
@ -1,2 +1,2 @@
|
||||||
*~
|
*~
|
||||||
builds
|
build
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
printf("%s\n", "Hello, World!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
93
src/Makefile
93
src/Makefile
|
@ -1,53 +1,58 @@
|
||||||
CC=cc
|
CC=cc
|
||||||
|
|
||||||
LIBLINUXHEADERS=
|
LIBLINUXHEADERS=
|
||||||
LIBLINUXDIR=
|
LIBLINUXDIR=
|
||||||
LIBLINUXFILE=liblinux.a
|
LIBLINUXFILE=liblinux.a
|
||||||
CFILES=stdio.c string.c
|
|
||||||
OBJFILES=../builds/olibc/stdio.o ../builds/olibc/stdlib.o ../builds/olibc/string.o ../builds/olibc/ctype.o
|
BUILDDIR=../build
|
||||||
LIBFILE=../builds/olibc.a
|
TESTDIR=tests
|
||||||
OLIBCHEADERS=include/
|
|
||||||
OLIBCDIR=../builds
|
OLIBCCFILES=$(wildcard *.c)
|
||||||
|
OLIBCOFILES=$(patsubst %.c, $(BUILDDIR)/%.o, $(OLIBCCFILES))
|
||||||
|
EXAMPLESCFILES=$(wildcard examples/*.c)
|
||||||
|
EXAMPLESOFILES=$(patsubst %.c, $(BUILDDIR)/%.o, $(EXAMPLESCFILES))
|
||||||
|
TESTCFILES=$(wildcard $(TESTDIR)/stdio/*.c $(TESTDIR)/string/*.c)
|
||||||
|
TESTOFILES=$(patsubst %.c, $(BUILDDIR)/%.o, $(TESTCFILES))
|
||||||
|
|
||||||
|
LIBFILE=$(BUILDDIR)/olibc.a
|
||||||
|
|
||||||
DEBUGFLAGS=-fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=pointer-compare -lasan
|
DEBUGFLAGS=-fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=pointer-compare -lasan
|
||||||
LIBFLAGS=-l:$(LIBLINUXFILE)
|
DEBUGFLAGS=-g
|
||||||
CFLAGS=--std=c11 -ffreestanding -fno-stack-protector -nostdlib -pedantic -Wall -Wextra -I$(LIBLINUXHEADERS) -I$(OLIBCHEADERS) -L$(LIBLINUXDIR) -L$(OLIBCDIR)
|
INCLUDEFLAGS=-I$(LIBLINUXHEADERS) -Iinclude
|
||||||
|
LIBFLAGS=-l:olibc.a
|
||||||
|
LINKFLAGS=-L$(LIBLINUXDIR) -L$(BUILDDIR) -l:$(LIBLINUXFILE)
|
||||||
|
CFLAGS=--std=c11 -ffreestanding -fno-stack-protector -nostdlib -pedantic -Wall -Wextra $(INCLUDEFLAGS)
|
||||||
|
|
||||||
lib:
|
.PHONY: all lib examples test clean
|
||||||
mkdir -p ../builds/olibc
|
.SUFFIXES: .o .c
|
||||||
$(CC) -c stdio.c $(CFLAGS) -o ../builds/olibc/stdio.o $(LIBFLAGS) -g
|
|
||||||
$(CC) -c stdlib.c $(CFLAGS) -o ../builds/olibc/stdlib.o $(LIBFLAGS) -g
|
|
||||||
$(CC) -c string.c $(CFLAGS) -o ../builds/olibc/string.o $(LIBFLAGS) -g
|
|
||||||
$(CC) -c ctype.c $(CFLAGS) -o ../builds/olibc/ctype.o $(LIBFLAGS) -g
|
|
||||||
ar ruv $(LIBFILE) $(OBJFILES)
|
|
||||||
ranlib $(LIBFILE)
|
|
||||||
|
|
||||||
examples:
|
all: lib
|
||||||
mkdir -p ../builds/examples
|
|
||||||
$(CC) ../examples/hello.c $(CFLAGS) -o ../builds/examples/hello -l:olibc.a $(LIBFLAGS)
|
|
||||||
|
|
||||||
tests:
|
$(BUILDDIR)/%.o: %.c
|
||||||
mkdir -p ../builds/tests/string/
|
@mkdir -p $(@D)
|
||||||
$(CC) ../tests/string/strlen.c $(CFLAGS) -o ../builds/tests/string/strlen -l:olibc.a $(LIBFLAGS)
|
$(CC) $< $(CFLAGS) -o $@ $(LINKFLAGS) $(DEBUGFLAGS)
|
||||||
$(CC) ../tests/string/strcmp.c $(CFLAGS) -o ../builds/tests/string/strcmp -l:olibc.a $(LIBFLAGS)
|
|
||||||
$(CC) ../tests/string/strncmp.c $(CFLAGS) -o ../builds/tests/string/strncmp -l:olibc.a $(LIBFLAGS)
|
$(OLIBCOFILES): CFLAGS += -c
|
||||||
$(CC) ../tests/string/memcmp.c $(CFLAGS) -o ../builds/tests/string/memcmp -l:olibc.a $(LIBFLAGS)
|
$(OLIBCOFILES): $(OLIBCCFILES)
|
||||||
$(CC) ../tests/string/strcpy.c $(CFLAGS) -o ../builds/tests/string/strcpy -l:olibc.a $(LIBFLAGS)
|
|
||||||
$(CC) ../tests/string/strncpy.c $(CFLAGS) -o ../builds/tests/string/strncpy -l:olibc.a $(LIBFLAGS)
|
$(LIBFILE): $(OLIBCOFILES)
|
||||||
$(CC) ../tests/string/memcpy.c $(CFLAGS) -o ../builds/tests/string/memcpy -l:olibc.a $(LIBFLAGS)
|
ar ruv $@ $(OLIBCOFILES)
|
||||||
$(CC) ../tests/string/strchr.c $(CFLAGS) -o ../builds/tests/string/strchr -l:olibc.a $(LIBFLAGS)
|
ranlib $@
|
||||||
$(CC) ../tests/string/strrchr.c $(CFLAGS) -o ../builds/tests/string/strrchr -l:olibc.a $(LIBFLAGS)
|
|
||||||
$(CC) ../tests/string/memchr.c $(CFLAGS) -o ../builds/tests/string/memchr -l:olibc.a $(LIBFLAGS)
|
lib: $(LIBFILE)
|
||||||
$(CC) ../tests/string/strcat.c $(CFLAGS) -o ../builds/tests/string/strcat -l:olibc.a $(LIBFLAGS)
|
|
||||||
$(CC) ../tests/string/strncat.c $(CFLAGS) -o ../builds/tests/string/strncat -l:olibc.a $(LIBFLAGS)
|
$(EXAMPLESOFILES): LINKFLAGS:=$(LIBFLAGS) $(LINKFLAGS)
|
||||||
$(CC) ../tests/string/memmove.c $(CFLAGS) -o ../builds/tests/string/memmove -l:olibc.a $(LIBFLAGS)
|
$(EXAMPLESOFILES): $(EXAMPLESCFILES)
|
||||||
$(CC) ../tests/string/strstr.c $(CFLAGS) -o ../builds/tests/string/strstr -l:olibc.a $(LIBFLAGS)
|
|
||||||
$(CC) ../tests/string/strspn.c $(CFLAGS) -o ../builds/tests/string/strspn -l:olibc.a $(LIBFLAGS)
|
examples: lib $(EXAMPLESOFILES)
|
||||||
$(CC) ../tests/string/strcspn.c $(CFLAGS) -o ../builds/tests/string/strcspn -l:olibc.a $(LIBFLAGS)
|
|
||||||
$(CC) ../tests/string/memset.c $(CFLAGS) -o ../builds/tests/string/memset -l:olibc.a $(LIBFLAGS)
|
$(TESTOFILES): LINKFLAGS:=$(LIBFLAGS) $(LINKFLAGS)
|
||||||
$(CC) ../tests/string/strpbrk.c $(CFLAGS) -o ../builds/tests/string/strpbrk -l:olibc.a $(LIBFLAGS)
|
$(TESTOFILES): $(TESTCFILES)
|
||||||
$(CC) ../tests/string/strtok.c $(CFLAGS) -o ../builds/tests/string/strtok -l:olibc.a $(LIBFLAGS)
|
|
||||||
# stdio
|
test: lib $(TESTOFILES)
|
||||||
mkdir -p ../builds/tests/stdio/
|
$(TESTDIR)/test.sh string
|
||||||
$(CC) ../tests/stdio/printf.c $(CFLAGS) -o ../builds/tests/stdio/printf -l:olibc.a $(LIBFLAGS)
|
$(TESTDIR)/test.sh stdio
|
||||||
../tests/test.sh string
|
|
||||||
../tests/test.sh stdio
|
clean:
|
||||||
|
rm -rf $(BUILDDIR)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf("Hello, World!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
CC=cc
|
CC=cc
|
||||||
|
|
||||||
cd ../builds/tests
|
cd ../build/tests
|
||||||
|
|
||||||
if [[ -z $@ ]]
|
if [[ -z $@ ]]
|
||||||
then
|
then
|
||||||
|
@ -70,7 +70,7 @@ for i in $headerslist; do
|
||||||
for j in $(ls); do
|
for j in $(ls); do
|
||||||
if [ -x $j ] && [[ $j != *"-cc"* ]]
|
if [ -x $j ] && [[ $j != *"-cc"* ]]
|
||||||
then
|
then
|
||||||
cat $(cd ../../../tests/$i ; pwd)/$j.c | sed 's/put_int(/printf("%d\\n",/' | cc -x c -o $j-cc -
|
cat $(echo ../../../src/tests/$i/$j | sed 's/\.o/\.c/g') | cc -x c -o $j-cc -
|
||||||
./$j > tmp
|
./$j > tmp
|
||||||
./$j-cc > tmp-cc
|
./$j-cc > tmp-cc
|
||||||
if [ "$(diff tmp tmp-cc)" == "" ]
|
if [ "$(diff tmp tmp-cc)" == "" ]
|
Loading…
Reference in New Issue