CC := gcc CFLAGS := -Wall -Wextra -std=gnu23 -I include -O3 SRC_DIR := src BUILD_DIR := build PROGRAM_NAME := criscv # Find all .c files in src directory SRCS := $(wildcard $(SRC_DIR)/*.c) # Generate corresponding .o file names in obj directory OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/obj/%.o,$(SRCS)) # Name of the final executable TARGET := $(BUILD_DIR)/$(PROGRAM_NAME) .PHONY: all clean all: $(TARGET) $(TARGET): $(OBJS) | $(BUILD_DIR) $(CC) $(CFLAGS) $^ -o $@ $(BUILD_DIR)/obj/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)/obj $(CC) $(CFLAGS) -c $< -o $@ $(BUILD_DIR) $(BUILD_DIR)/obj: mkdir -p $@ clean: rm -rf $(BUILD_DIR)