From ecbd89c1dddb20fefa01fae44a734bcc9146aeb1 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 17 Apr 2021 00:14:08 +0500 Subject: [PATCH] Updated makefile, fixed error --- .gitignore | 3 ++- Makefile | 36 ++++++++++++++++++------------------ src/run.c | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index b969127..140faf9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ .vscode/ -vgcore* \ No newline at end of file +vgcore* +test.* \ No newline at end of file diff --git a/Makefile b/Makefile index 1927932..5111c78 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,28 @@ -CFLAG=-Wall -ggdb3 -BUILD_DIR=build -SRC_DIR=src +TARGET_EXEC ?= stack_vm -all: build_dir stack_vm +BUILD_DIR ?= ./build +SRC_DIRS ?= ./src -build_dir: - mkdir -p $(BUILD_DIR) +SRCS := $(shell find $(SRC_DIRS) -name *.c) +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) -stack_vm: main.o run.o stack.o command.o - $(CC) $(BUILD_DIR)/main.o $(BUILD_DIR)/run.o $(BUILD_DIR)/stack.o $(BUILD_DIR)/command.o -o $(BUILD_DIR)/$@ +INC_DIRS := $(shell find $(SRC_DIRS) -type d) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) -main.o: - $(CC) -c $(SRC_DIR)/main.c $(CFLAG) -o $(BUILD_DIR)/$@ +CPPFLAGS ?= $(INC_FLAGS) -MMD -MP -run.o: - $(CC) -c $(SRC_DIR)/run.c $(CFLAG) -o $(BUILD_DIR)/$@ +$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) + $(CC) -ggdb3 $(OBJS) -o $@ $(LDFLAGS) -stack.o: - $(CC) -c $(SRC_DIR)/stack.c $(CFLAG) -o $(BUILD_DIR)/$@ +$(BUILD_DIR)/%.c.o: %.c + $(MKDIR_P) $(dir $@) + $(CC) -ggdb3 $(CPPFLAGS) $(CFLAGS) -c $< -o $@ -command.o: - $(CC) -c $(SRC_DIR)/command.c $(CFLAG) -o $(BUILD_DIR)/$@ +.PHONY: clean all + +all: $(BUILD_DIR)/$(TARGET_EXEC) clean: - rm -rf $(BUILD_DIR) + $(RM) -r $(BUILD_DIR) -.PHONY: all clean \ No newline at end of file +MKDIR_P ?= mkdir -p \ No newline at end of file diff --git a/src/run.c b/src/run.c index 40b503b..5a3b358 100644 --- a/src/run.c +++ b/src/run.c @@ -131,7 +131,7 @@ int exec(command_t cmd, stack_t *stack) case IN: { char input[512]; - scanf("%s", &input); + scanf("%s", input); int size = str_len(input); for (int pos = size; size >= 0; size--)