(1)ifeq : 包含两个参数,被逗号分开,并被括在圆括号内。ifeq与左括号之间要有空格
(2)else
(3)endif : 结束条件语句。
例一:
引用:TARGET=helloworld
CC=gcc
CFLAGS=-Wall -O -g
SRC=$(wildcard *.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)