class="23192">
;
三個指令:
(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)