makefile 经典例子

###############################################
#                Sample Build File            #
###############################################

CC = gcc

DIRS :=$(shell find . -maxdepth 4 -type d)
SOURCE  := $(foreach dir,$(DIRS),$(wildcard $(dir)/*.c))

OBJS    := $(patsubst %.c,%.o,$(SOURCE))

TARGET  := main_demo

LIBS := -lpthread -lm -lcurl -lm

LIBS += -L ./

INCLUDE := -I external_libs/include -I ./

DEFINES :=

CFLAGS  := -g -Wall -Wfatal-errors  $(DEFINES) $(INCLUDE)

LDFLAGS :=

.PHONY : all clean

all : $(TARGET)
$(TARGET) : $(OBJS)
    $(CC)   -o  $@ $(OBJS) $(CFLAGS) $(LDFLAGS) $(LIBS) 
%.o : %.c
    $(CC) -c  ${CFLAGS}  -o $@ $^

clean :
    @rm -rf $(OBJS)
    @rm -rf $(TARGET)

你可能感兴趣的:(makefile 经典例子)