riscv_asm/Makefile

43 lines
940 B
Makefile
Raw Permalink Normal View History

2024-11-24 23:51:08 -05:00
# Compiler and flags
CC = clang
CFLAGS = --target=riscv32 -march=rv64gc_zbb -mabi=lp64 -mno-relax -g
# Directories and files
BUILD_DIR = build
ZOMUTILS_SRC = libzomutils.s
ZOMUTILS_OBJ = $(BUILD_DIR)/libzomutils.o
ZOMUTILS_LIB = $(BUILD_DIR)/libzomutils.a
HELLO_SRC = hello.s
HELLO_OBJ = $(BUILD_DIR)/hello.o
HELLO_BIN = $(BUILD_DIR)/hello
# Default target
all: $(HELLO_BIN)
# Ensure build directory exists
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Build libzomutils object file
$(ZOMUTILS_OBJ): $(ZOMUTILS_SRC) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Create static library libzomutils.a
$(ZOMUTILS_LIB): $(ZOMUTILS_OBJ)
ar rcs $@ $^
# Build hello object file
$(HELLO_OBJ): $(HELLO_SRC) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Link hello executable with libzomutils.a
$(HELLO_BIN): $(HELLO_OBJ) $(ZOMUTILS_LIB)
$(CC) $(CFLAGS) -nostdlib $^ -o $@
# Clean up generated files
clean:
rm -rf $(BUILD_DIR)
.PHONY: all clean