diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..503cd83 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# Aux functions +rwildcard = $(foreach d, $(wildcard $(1:=/*)), $(call rwildcard ,$d, $2) $(filter $(subst *, %, $2), $d)) + +# Compiler +CXX = gcc +CC = $(CROSS_COMPILE)$(CXX) + +# Compiler flags +CFLAGS = -O3 -Wall -Wextra -g +LFLAGS = -lm + +# Files and directories +SRCDIR = src +OBJDIR = temp +BINDIR = build +OUTFILE = noja + +# Find all files +SRC = $(call rwildcard, $(SRCDIR), *.c) +OBJS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRC)) + + +# Compile everything to object files +$(OBJDIR)/%.o: $(SRCDIR)/%.c + @ echo $(shell tput setaf 3) [C] $(shell tput setaf 5) [SRC] $(shell tput setaf 7) $^ + @ mkdir -p $(@D) + @ $(CC) $(CFLAGS) -c $^ -o $@ + + +# Clean all artifacts and rebuild the whole thing +all: clean $(OBJS) build + +# Link all object files +build: + @ echo !==== LINKING + @ mkdir -p $(BINDIR) + @ $(CC) -o $(BINDIR)/$(OUTFILE) $(OBJS) $(LFLAGS) + +clean: + @ rm -rf $(BINDIR) + @ rm -rf $(OBJDIR) diff --git a/README.md b/README.md index 31e8774..6935fe1 100644 --- a/README.md +++ b/README.md @@ -56,16 +56,10 @@ The interpreter is fully functional, but lots of built-in functions that one wou ## Build To build it, just run: ```sh -$ ./build.sh +$ make ``` it will create a `build` folder where the interpreter's executable will be generated. -You may need to give executable permissions to the script. You can do so with by running: - -```sh -$ chmod +x build.sh -``` - ## Usage You can run files by doing: ```sh @@ -75,4 +69,4 @@ location/of/noja run or you can run strings by doing: ```sh location/of/noja run inline -``` \ No newline at end of file +``` diff --git a/src/compiler/parse.c b/src/compiler/parse.c index 9424cfb..ef5f67b 100644 --- a/src/compiler/parse.c +++ b/src/compiler/parse.c @@ -1795,7 +1795,7 @@ static Node *parse_ifelse_statement(Context *ctx) static Node *parse_compound_statement(Context *ctx, TokenKind end) { - int end_offset; + int end_offset = 0; Node *head, **tail; tail = &head;