55 lines
No EOL
1.4 KiB
Makefile
55 lines
No EOL
1.4 KiB
Makefile
# Compiler to use
|
|
CC := gcc
|
|
|
|
# Compiler flags:
|
|
# -Wall: Enable all warnings
|
|
# -Wextra: Enable extra warnings
|
|
# -std=gnu23: Use GNU C23 standard
|
|
# -I include: Add 'include' directory to the include path
|
|
# -O3: Optimize code (level 3)
|
|
# -Wno-unused-variable: Disable warnings for unused variables
|
|
ifeq ($(DEBUG),1)
|
|
CFLAGS := -Wall -Wextra -std=gnu23 -I include -O0 -g -lelf
|
|
else
|
|
CFLAGS := -Wall -Wextra -std=gnu23 -I include -O3 -lelf
|
|
endif
|
|
|
|
# Directory for build outputs
|
|
BUILD_DIR := build
|
|
|
|
# Name of the output program
|
|
PROGRAM_NAME := criscv
|
|
|
|
# Find all .c files in the source directory
|
|
SRCS := $(wildcard src/*.c)
|
|
|
|
# Generate corresponding .o file names in the build/obj directory
|
|
OBJS := $(patsubst src/%.c,$(BUILD_DIR)/obj/%.o,$(SRCS))
|
|
|
|
# Name of the final executable
|
|
TARGET := $(BUILD_DIR)/$(PROGRAM_NAME)
|
|
|
|
|
|
|
|
# Declare 'all' and 'clean' as phony targets (not files)
|
|
.PHONY: all clean
|
|
|
|
# Default target: build the executable
|
|
all: $(TARGET)
|
|
|
|
# Rule to link object files into the final executable
|
|
$(TARGET): $(OBJS) | $(BUILD_DIR)
|
|
$(CC) $(CFLAGS) $^ -o $@
|
|
du -b $(TARGET) # Size of the executable in bytes
|
|
|
|
# Rule to compile source files into object files
|
|
$(BUILD_DIR)/obj/%.o: src/%.c | $(BUILD_DIR)/obj
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
# Create build directories if they don't exist
|
|
$(BUILD_DIR) $(BUILD_DIR)/obj:
|
|
mkdir -p $@
|
|
|
|
# Clean target: remove the build directory
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|