# 这是一个测试用的复杂 Makefile 示例
# 包含了各种 Makefile 语法特性用于测试解析器

# 简单变量赋值
SIMPLE_VAR = simple value

# 不同分隔符的变量赋值
COLON_VAR := immediately expanded value

# 多行变量定义
MULTILINE_VAR = first line \
    second line \
    third line

# 带注释的变量定义
WITH_COMMENT = value with trailing comment # 这是一个注释

# 定义函数
define MULTI_LINE_FUNCTION
	echo "This is line 1"
	echo "This is line 2"
	echo "This is line 3"
endef

# 使用 += 追加变量内容
APPEND_VAR = initial value
APPEND_VAR += appended value

# 条件语句
ifdef DEBUG
    LOG_LEVEL = debug
else
    LOG_LEVEL = info
endif

# 使用函数
SOURCES = main.c util.c driver.c
OBJECTS = $(patsubst %.c,%.o,$(SOURCES))

# 空变量定义
EMPTY_VAR = 

# 带特殊字符的变量定义
SPECIAL_CHARS = $$HOME/bin:/usr/local/bin:$$PATH

# 引用其他变量
COMPOUND_VAR = $(SIMPLE_VAR) and $(COLON_VAR)

# 内容中包含等号的变量
EQUAL_IN_VALUE = key1=value1 key2=value2

# 目标定义
all: build test

# 带多条命令的目标
build:
	@echo "Building..." # 注释
	$(CC) -o output $(SOURCES)
	@echo "Build complete"

# 依赖于多个目标的规则
test: unit_test integration_test
	@echo "All tests completed"

# 模式规则
%.o: %.c
	$(CC) -c -o $@ $<

# 伪目标
.PHONY: all clean test

# 复杂的多行命令
clean:
	@echo "Cleaning up..."
	rm -f *.o
	rm -f output
	@echo "Clean complete"

# 变量中包含换行
NEWLINE := line1$(shell echo)line2

# 带续行符的shell命令
test_shell:
	for file in $(SOURCES); do \
		echo "Processing $$file"; \
		cat $$file | grep "TODO"; \
	done

# 使用 ?= 条件赋值
CC ?= gcc

# 使用 != 执行命令并赋值
CURRENT_DIR != pwd

# 包含其他 Makefile
-include optional.mk
include required.mk

# 导出变量到环境变量
export PATH
export JAVA_HOME = /usr/lib/jvm/default-java

# 嵌套使用变量
NESTED = $($(VARNAME))

# 使用自动变量
auto_vars: file1.c file2.c
	@echo "First prerequisite: $<"
	@echo "All prerequisites: $^"
	@echo "Target name: $@"

# 使用通配符
HEADERS = $(wildcard *.h)

# 使用 vpath 指令
vpath %.c src
vpath %.h include

# 静态模式规则
MODULES = mod1 mod2 mod3
$(MODULES:%=%.o): %.o: %.c
	$(CC) -c -o $@ $<

# 字符串替换
TEXT = Hello World
REPLACED = $(subst Hello,Goodbye,$(TEXT))

# shell 命令输出作为变量内容
VERSION := $(shell git describe --tags)

# 路径处理
SRC_PATH = src/module/file.c
FILE_NAME = $(notdir $(SRC_PATH))