-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
54 lines (46 loc) · 1.54 KB
/
Makefile
File metadata and controls
54 lines (46 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Stack VM 编译器 Makefile
CC = gcc
CFLAGS = -Wall -Wextra -Werror -std=c99
# 显示帮助信息
help:
@echo "Stack VM 编译器 Makefile 帮助"
@echo "================================"
@echo "使用方法: make [目标]"
@echo ""
@echo "可用目标:"
@echo " all - 编译 stack-vm-compiler (默认目标)"
@echo " stack-vm-compiler - 编译编译器"
@echo " stack-vm - 编译虚拟机"
@echo " clean - 清理编译产物"
@echo " test - 运行测试"
@echo " help - 显示此帮助信息"
@echo ""
@echo "示例:"
@echo " make # 编译编译器"
@echo " make clean # 清理所有编译产物"
@echo " make test # 运行测试"
# 目标文件
all: stack-vm-compiler
# 编译编译器
stack-vm-compiler: stack-vm-compiler.c stack-vm.c stack-vm.h
$(CC) $(CFLAGS) -DCOMPILER_TEST -o stack-vm-compiler stack-vm-compiler.c stack-vm.c
# 编译虚拟机(用于直接测试虚拟机)
stack-vm: stack-vm.c stack-vm.h
$(CC) $(CFLAGS) -o stack-vm stack-vm.c
# 清理编译产物
clean:
rm -f stack-vm-compiler stack-vm *.o *.bin
# 测试编译器
test:
@echo "创建测试文件..."
@echo 'var x = 10; var y = 20; var z = x + y; print(z);' > test.txt
@echo "测试直接执行..."
./stack-vm-compiler -e test.txt
@echo "测试编译到文件..."
./stack-vm-compiler test.txt test.bin
@echo "测试输出到标准输出..."
./stack-vm-compiler -c test.txt | hexdump -C | head -20
@echo "清理测试文件..."
@rm -f test.txt test.bin
@echo "所有测试通过!"
.PHONY: all clean test