-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
executable file
·46 lines (36 loc) · 911 Bytes
/
Copy pathmakefile
File metadata and controls
executable file
·46 lines (36 loc) · 911 Bytes
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
# Makefile for building and running the shell project
# 项目文件和目标
TARGET = xtxshell
# SRC = new_shell.c
SRC = xtxshell.c
OBJ = $(SRC:.c=.o)
# 编译器和选项
CC = gcc
CFLAGS = -Wall -g -I/usr/include
LDFLAGS = -lreadline -L/usr/lib
# 检查依赖
all: check_readline $(TARGET) cleanobj
# 编译目标
$(TARGET): $(OBJ)
$(CC) $(OBJ) -o $(TARGET) $(LDFLAGS)
# 编译源文件
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# 检查 readline 是否已安装
check_readline:
@if ! find /usr/include -name readline.h | grep -q readline.h; then \
echo "libreadline not found! Installing..."; \
sudo apt-get update && sudo apt-get install -y libreadline-dev; \
else \
echo "libreadline is already installed."; \
fi
# 清理构建
clean:
rm -f $(OBJ) $(TARGET)
# 清理obj
cleanobj:
rm -f $(OBJ)
# 运行 Shell 程序
run: $(TARGET)
./$(TARGET)
.PHONY: all clean run check_readline