標準的make file 模板

一個make file的模板,通喫所有項目。隨時可以備用。


# define variable
SUFFIX = process
OUTPUT_PATH = ./output
BUILD = debug
OUTPUT_PATH = ./temp
OUT_PATH = $(OUTPUT_PATH)/$(BUILD)/bin
OBJ_PATH = $(TMPOBJ_PATH)/$(BUILD)/logtodbd
#define the output binary
TARGET = $(OUT_PATH)/test

#Use STLPort
CFLAGS += $(STLPORT_CFLAGS)
LDFLAGS += $(STLPORT_LDFLAGS)

#Predefines
CFLAGS += -DUSE_PERF_LOG

# Define the ARCH and platform depend flag
ifeq "Linux" "$(OS)"
    LDFLAGS += -lrt
else
ifeq "SunOS" "$(OS)"
    LDFLAGS += -lsocket -lnsl -ldl -lrt
else
    ARCH = unknown
endif
endif

LDFLAGS += -lpthread

#Includes
CFLAGS += \
    -I. \

#Libraries
LDFLAGS += \
    -Wl,-rpath-link,$(OUT_PATH)/lib \
# C source files
C_SOURCES = \
    ./tfork.c

C_OBJFILES = $(patsubst %.c,$(OBJ_PATH)/%.o,$(notdir $(C_SOURCES)))

#C++ Source files
SOURCES = \
    ./mutithread.cpp

OBJFILES = $(patsubst %.cpp,$(OBJ_PATH)/%.o,$(notdir $(SOURCES)))

#vpath
vpath %.cpp $(dir $(SOURCES))
vpath %.c $(dir $(C_SOURCES))
vpath %.o $(OBJ_PATH)

######
# this will be the first job to be executed (the first target)
target: $(TARGET)

$(C_OBJFILES): $(OBJ_PATH)/%.o: %.c
    -mkdir -p $(OBJ_PATH)
    $(CC) -c $(CFLAGS) -o $@ $<
    #

$(OBJFILES): $(OBJ_PATH)/%.o: %.cpp
    -mkdir -p $(OBJ_PATH)
    $(CXX) -c $(CFLAGS) -o $@ $<
    #

$(TARGET): $(OBJFILES) $(C_OBJFILES)
    -mkdir -p $(OUT_PATH)
    $(CXX) $(LDFLAGS) -o $@ $^
    #

clean:
    -rm -rf $(OBJ_PATH)
    -rm -f $(TARGET)

all: target	
		



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章