[置顶] 关于Linux操作系统makefile实例详细解析

例一:

TARGET=helloworld
CC=gcc
CFLAGS=-Wall -O -g
SRC=$(wildcard *.c) #所有的.c文件
OBJS=$(patsubst %.c,%.o,$(wildcard *.c))

$(TARGET):$(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $@
# $(RM) *.o

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm -rf *.o helloworld

例二:

VPATH=
OBJECTS=mmain.o ./pchild/pchild.o
TARGET=mm
CC=cc
all:$(TARGET)
$(TARGET):$(OBJECTS)
$(CC) $(OBJECTS) -o $@
rm -f $(OBJECTS)
mmain.o:mmain.c
$(CC) -c $< -o $@
pchild.o:pchild.c pchild.h
$(CC) -c $^ -o $@

例三:

VPATH=
OBJECTS=mmain.o ./pchild/pchild.o
YESNO=NO
ifeq ($(YESNO),YES)
TARGET=mm
else
TARGET=nn
endif
CC=cc
all:$(TARGET)
$(TARGET):$(OBJECTS)
$(CC) $(OBJECTS) -o $@
rm -f $(OBJECTS)

你可能感兴趣的:(linux,makefile,wildcard)