aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-23 03:58:34 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-23 03:58:34 +0100
commitb44a61be41e44b415b1293fcbc1f1e8c4ce3373d (patch)
tree218cdb4901d23089ab0b54b4ff3097202c442acd
parent587f31a63b26fe3789acd0ba129474a2be200d37 (diff)
downloadovm-b44a61be41e44b415b1293fcbc1f1e8c4ce3373d.tar.gz
ovm-b44a61be41e44b415b1293fcbc1f1e8c4ce3373d.tar.bz2
ovm-b44a61be41e44b415b1293fcbc1f1e8c4ce3373d.zip
src->vm, Makefile is now a bit more abstracted and pretty colours
Changed folder names for sake of clarity (will be introducing a new build target soon), and Makefile can now easily support more targets.
-rw-r--r--Makefile65
-rw-r--r--vm/base.h (renamed from src/base.h)0
-rw-r--r--vm/darr.c (renamed from src/darr.c)0
-rw-r--r--vm/darr.h (renamed from src/darr.h)0
-rw-r--r--vm/fib.c (renamed from src/fib.c)0
-rw-r--r--vm/inst.c (renamed from src/inst.c)0
-rw-r--r--vm/inst.h (renamed from src/inst.h)0
-rw-r--r--vm/main.c (renamed from src/main.c)0
-rw-r--r--vm/runtime.c (renamed from src/runtime.c)0
-rw-r--r--vm/runtime.h (renamed from src/runtime.h)0
10 files changed, 39 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 1ba2079..57be35b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,43 +1,49 @@
CC=gcc
-
-FVERBOSE=0
-GENERAL-FLAGS=-Wall -Wextra -Werror -Wswitch-enum -std=c11 -D VERBOSE=$(FVERBOSE)
+GENERAL-FLAGS=-Wall -Wextra -Werror -Wswitch-enum -std=c11
DEBUG-FLAGS=-ggdb -fsanitize=address
RELEASE-FLAGS=-O3
-CFLAGS=$(GENERAL-FLAGS) $(DEBUG-FLAGS)
-
+CFLAGS:=$(GENERAL-FLAGS) $(DEBUG-FLAGS)
LIBS=
-ARGS=
-OUT=ovm.out
-
-SRC=src
DIST=build
+TERM_YELLOW:=$(shell echo -e "\e[0;33m")
+TERM_GREEN:=$(shell echo -e "\e[0;32m")
+TERM_RESET:=$(shell echo -e "\e[0;0m")
-CODE=$(addprefix $(SRC)/, darr.c inst.c runtime.c)
-OBJECTS=$(CODE:$(SRC)/%.c=$(DIST)/%.o)
-DEPS=$(OBJECTS:%.o=%.d) $(DIST)/fib.d $(DIST)/main.d
-
-.PHONY: all
-all: $(OUT) $(DIST)
+# Setup variables for source code, output, etc
+VM_DIST=$(DIST)/vm
+VM_SRC=vm
+VM_CODE:=$(addprefix $(VM_SRC)/, darr.c inst.c runtime.c)
+VM_OBJECTS:=$(VM_CODE:$(VM_SRC)/%.c=$(VM_DIST)/%.o)
+VM_DEPS:=$(VM_OBJECTS:%.o=%.d) $(VM_DIST)/fib.d $(VM_DIST)/main.d
+VM_VERBOSE=0
+VM_CFLAGS:=$(CFLAGS) -D VERBOSE=$(VM_VERBOSE)
-$(DIST):
- mkdir -p $(DIST)
+VM_OUT=$(VM_DIST)/ovm.out
-$(OUT): $(DIST)/$(OUT)
+# Things you want to build on `make`
+all: $(DIST) vm examples
+vm: $(VM_DIST) $(VM_OUT)
+examples: vm-examples
+vm-examples: $(VM_DIST) $(VM_DIST)/fib.out
-$(DIST)/$(OUT): $(DIST) $(OBJECTS) $(DIST)/main.o
- $(CC) $(CFLAGS) $(OBJECTS) $(DIST)/main.o -o $@ $(LIBS)
+# Recipes
--include $(DEPS)
+$(VM_OUT): $(VM_OBJECTS) $(VM_DIST)/main.o
+ @$(CC) $(VM_CFLAGS) $^ -o $@ $(LIBS)
+ @echo -e "$(TERM_GREEN)$@$(TERM_RESET)"
-$(DIST)/%.o: $(SRC)/%.c
- $(CC) $(CFLAGS) -MMD -c $< -o $@ $(LIBS)
+$(VM_DIST)/fib.out: $(VM_OBJECTS) $(VM_DIST)/fib.o
+ @$(CC) $(VM_CFLAGS) $^ -o $@ $(LIBS)
+ @echo -e "$(TERM_GREEN)$@$(TERM_RESET)"
-examples: $(DIST)/fib.out
+-include $(VM_DEPS)
-$(DIST)/fib.out: $(DIST) $(OBJECTS) $(SRC)/fib.c
- $(CC) $(CFLAGS) $(OBJECTS) $(SRC)/fib.c -o $@ $(LIBS)
+$(VM_DIST)/%.o: $(VM_SRC)/%.c
+ @$(CC) $(VM_CFLAGS) -MMD -c $< -o $@ $(LIBS)
+ @echo -e "$(TERM_GREEN)$@$(TERM_RESET)"
+OUT=
+ARGS=
.PHONY: run
run: $(DIST)/$(OUT)
./$^ $(ARGS)
@@ -45,3 +51,10 @@ run: $(DIST)/$(OUT)
.PHONY:
clean:
rm -rfv $(DIST)/*
+
+# Directories
+$(DIST):
+ mkdir -p $(DIST)
+
+$(VM_DIST): $(DIST)
+ mkdir -p $(VM_DIST)
diff --git a/src/base.h b/vm/base.h
index dbeec80..dbeec80 100644
--- a/src/base.h
+++ b/vm/base.h
diff --git a/src/darr.c b/vm/darr.c
index 4393c4b..4393c4b 100644
--- a/src/darr.c
+++ b/vm/darr.c
diff --git a/src/darr.h b/vm/darr.h
index 1d5820b..1d5820b 100644
--- a/src/darr.h
+++ b/vm/darr.h
diff --git a/src/fib.c b/vm/fib.c
index 7107c3e..7107c3e 100644
--- a/src/fib.c
+++ b/vm/fib.c
diff --git a/src/inst.c b/vm/inst.c
index 3980173..3980173 100644
--- a/src/inst.c
+++ b/vm/inst.c
diff --git a/src/inst.h b/vm/inst.h
index 8902757..8902757 100644
--- a/src/inst.h
+++ b/vm/inst.h
diff --git a/src/main.c b/vm/main.c
index 005b61e..005b61e 100644
--- a/src/main.c
+++ b/vm/main.c
diff --git a/src/runtime.c b/vm/runtime.c
index ccda9d0..ccda9d0 100644
--- a/src/runtime.c
+++ b/vm/runtime.c
diff --git a/src/runtime.h b/vm/runtime.h
index 83ffa17..83ffa17 100644
--- a/src/runtime.h
+++ b/vm/runtime.h