Article Title: detailed analysis of makefile instances in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source. Three commands:
(1) ifeq: contains two parameters separated by commas and enclosed in parentheses. A space is required between ifeq and left parenthesis.
(2) else
(3) endif: End Condition Statement.
Example 1:
TARGET=helloworldCC=gccCFLAGS=-Wall -O -gSRC=$(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
|
Example 2:
VPATH=OBJECTS=mmain.o ./pchild/pchild.oTARGET=mmCC=ccall:$(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 $@
|
Example 3:
VPATH=OBJECTS=mmain.o ./pchild/pchild.oYESNO=NOifeq ($(YESNO),YES)TARGET=mmelseTARGET=nnendifCC=ccall:$(TARGET)$(TARGET):$(OBJECTS)$(CC) $(OBJECTS) -o $@rm -f $(OBJECTS)
|