# Makefile for LVGL core library (cross-compiled for aarch64)
# Place this Makefile in the 'core' directory
# Usage: make clean && make

# Cross-compiler path (adjust to your actual path)
# CROSS_COMPILE := /home/lxb/LinuxSDK/T536/t536_f1_linux_sdk/out/toolchain/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
CROSS_COMPILE := aarch64-none-linux-gnu-

# Set up compiler and flags
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
RANLIB := $(CROSS_COMPILE)ranlib
CFLAGS := -Wall -O2 -std=gnu99 \
			-I. \
			-Ilvgl \
			-Ilvgl/src \
			-Ilvgl_driver 
LDFLAGS := -lm -lpthread

# Source files (using wildcard to include all .c files in specified directories)
SOURCES := \
	$(wildcard *.c) \
	$(wildcard lvgl_driver/*.c) \
	$(wildcard lvgl/src/*.c) \
	$(wildcard lvgl/src/*/*.c) \
	$(wildcard lvgl/src/*/*/*.c) \
	$(wildcard lvgl/src/*/*/*/*.c)

# Build directory (all .o files will be here)
BUILD_DIR := build
# Object files (in build directory)
OBJECTS := $(addprefix $(BUILD_DIR)/, $(SOURCES:.c=.o))

# Static library name (will be generated in core directory)
LIB_NAME := liblvgl.a

# Default target
all: $(LIB_NAME)

# Create build directory if not exists
$(BUILD_DIR):
	mkdir -p $@

# Compile all C files to object files (in build directory)
$(BUILD_DIR)/%.o: %.c
	@echo "Compiling $< -> $@"
	@mkdir -p $(dir $@)  # ȷĿ¼
	$(CC) $(CFLAGS) -c $< -o $@

# Create static library (in core directory)
$(LIB_NAME): $(OBJECTS) | $(BUILD_DIR)
	@echo "Creating static library: $@"
	$(AR) rcs $@ $^
	$(RANLIB) $@

# Clean up build artifacts
clean:
	@echo "Cleaning build artifacts..."
	-rm -f $(OBJECTS) $(LIB_NAME)
	-rm -rf $(BUILD_DIR)

# Show current build status
status:
	@echo "LVGL Core Library Build Status:"
	@echo "Target Architecture: aarch64"
	@echo "Compiler: $(CC)"
	@echo "Source files: $(SOURCES)"
	@echo "Objects: $(OBJECTS)"
	@echo "Library: $(LIB_NAME)"
	@echo "Build flags: $(CFLAGS)"