From c1c5b24fb07a5a738f8700dde469e886c30f4e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=9F=E5=AE=81?= Date: Wed, 5 Mar 2025 09:02:02 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index a282cea..251f4e0 100644 --- a/Makefile +++ b/Makefile @@ -4,20 +4,26 @@ include ./make.h -all: fork execlp +# 目标和源文件 +TARGETS = fork execlp +SOURCES = $(wildcard $(SRC_DIR)/*.c) # 找到所有的 .c 文件 +OBJECTS = $(patsubst $(SRC_DIR)/%.c,%.o,$(SOURCES)) # 将 .c 替换为 .o -fork: fork.o - $(CC) -o fork fork.o +# 默认目标 +all: $(TARGETS) - -execlp: execlp.o - $(CC) -o execlp execlp.o - - -.c.o: - $(CC) $(CFLAGS) $(COMMON_INCLUDE_DIRS) -c $(SRC_DIR)/*.c - -clean: - $(RM) -rf fork execlp *.o +# 链接目标文件生成可执行文件 +fork: fork.o + $(CC) -o fork fork.o + +execlp: execlp.o + $(CC) -o execlp execlp.o + +# 从 .c 文件编译生成 .o 文件 +%.o: $(SRC_DIR)/%.c + $(CC) $(CFLAGS) $(COMMON_INCLUDE_DIRS) -c $< -o $@ + +clean: + $(RM) -f $(TARGETS) $(OBJECTS)