Makefile now has recipes for example assembly programs

Dependencies are just ASM_OUT binary and the corresponding assembly
program for the bytecode output file.  Actually works very well, with
changes triggering a recompilation.  Also an `exec` recipe is
introduced to do the task of compiling an assembly program and
executing the corresponding bytecode all at once.
This commit is contained in:
2023-11-01 18:28:56 +00:00
parent cc34c9b9c3
commit dab1729f61

View File

@@ -40,8 +40,7 @@ ASM_OUT=$(DIST)/asm.out
## EXAMPLES setup ## EXAMPLES setup
EXAMPLES_DIST=$(DIST)/examples EXAMPLES_DIST=$(DIST)/examples
EXAMPLES_SRC=examples EXAMPLES_SRC=examples
EXAMPLES_CFLAGS=$(CFLAGS) EXAMPLES=$(EXAMPLES_DIST)/fib.out $(EXAMPLES_DIST)/factorial.out $(EXAMPLES_DIST)/instruction-test.out
EXAMPLES=$(DIST)/fib.out
# Things you want to build on `make` # Things you want to build on `make`
all: $(DIST) lib vm asm examples all: $(DIST) lib vm asm examples
@@ -82,24 +81,28 @@ $(ASM_DIST)/%.o: $(ASM_SRC)/%.c
@echo -e "$(TERM_YELLOW)$@$(TERM_RESET): $<" @echo -e "$(TERM_YELLOW)$@$(TERM_RESET): $<"
## EXAMPLES recipes ## EXAMPLES recipes
$(DIST)/fib.out: $(LIB_OBJECTS) $(VM_OBJECTS) $(ASM_OBJECTS) $(EXAMPLES_DIST)/fib.o $(EXAMPLES_DIST)/%.out: $(EXAMPLES_SRC)/%.asm $(ASM_OUT)
@$(CC) $(EXAMPLES_CFLAGS) $^ -o $@ $(LIBS) @$(ASM_OUT) $< $@
@echo -e "$(TERM_GREEN)$@$(TERM_RESET): $^" @echo -e "$(TERM_GREEN)$@$(TERM_RESET): $<"
$(EXAMPLES_DIST)/%.o: $(EXAMPLES_SRC)/%.c
@$(CC) $(EXAMPLES_CFLAGS) -MMD -c $< -o $@ $(LIBS)
@echo -e "$(TERM_YELLOW)$@$(TERM_RESET): $<"
OUT= OUT=
ARGS= ARGS=
.PHONY: run .PHONY: run
run: $(DIST)/$(OUT) run: $(DIST)/$(OUT)
./$^ $(ARGS) ./$^ $(ARGS)
.PHONY: .PHONY: clean
clean: clean:
rm -rfv $(DIST)/* rm -rfv $(DIST)/*
SOURCE=
BYTECODE=
.PHONY: exec
exec: $(ASM_OUT) $(VM_OUT)
@$(ASM_OUT) $(SOURCE) $(BYTECODE)
@$(VM_OUT) $(BYTECODE)
# Directories # Directories
$(DIST): $(DIST):
mkdir -p $(DIST) mkdir -p $(DIST)