makefile 单独编译一个文件

时间:2022-02-08 13:48:35
#!/sh/bin

.SUFFIXES:.c.o

CDIR = /Users/shelley/c
BINDIR = $(CDIR)/bin
CC = gcc
CFLAGS = -g -O
RM = rm -f getoptOBJ = getopt.o
getopt:$(getoptOBJ)
$(CC) $(CFLAGS) -o $(BINDIR)/$@ $(BINDIR)/$^
$(RM) $(BINDIR)/$^ strchrOBJ = strchr.o
strchr:$(strchrOBJ)
$(CC) $(CFLAGS) -o $(BINDIR)/$@ $(BINDIR)/$^
$(RM) $(BINDIR)/$^ #模式规则
#%o:%c
# $(CC) $(CFLAGS) -o $(BINDIR)/$@ -c $< #后缀规则
.c.o:
$(CC) $(CFLAGS) -o $(BINDIR)/$@ -c $< .PHONY:clean clean:
$(RM) $(BINDIR)/*
@echo "this rm -f $(BINDIR)/*"