首页 > 代码库 > 编写Makefile单项目模板

编写Makefile单项目模板

CC = gcc
CXX = g++
TARGET = process
INSTALLDIR = ~/work/
COMMON_PATH := /home/shengkaishan/tmp

INCLUDES := -I$(COMMON_PATH)/libev/include -I./
LIBS := -L$(COMMON_PATH)/libev/lib -lev -lrt -lpthread

CFLAGS =
CPPFLAGS := -g -std=c++11
CPPFLAGS +=

#add macro
#CPPFLAGS += -D __linux__
##

SRCDIRS := .
SRCEXTS := .cpp
C_SOURCES = $(wildcard *.c)
C_OBJS = $(patsubst %.c, %.o, $(C_SOURCES))
#CPP_SOURCES = $(wildcard *.cpp)
CPP_SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
CPP_OBJS = $(patsubst %.cpp, %.o, $(CPP_SOURCES))

all: $(TARGET)
$(TARGET): $(CPP_SOURCES)
    $(CXX) $(CPPFLAGS) $^ -o $(TARGET) $(INCLUDES) $(LIBS)

install:
    mkdir -p $(INSTALLDIR)
    cp -f $(TARGET) $(INSTALLDIR)
ifneq ($(wildcard *.conf), )
    cp -f *.conf $(INSTALLDIR)
endif

clean:
    rm -f $(CPP_OBJS) $(C_OBJS)
    rm -f $(TARGET)

rebuild: clean all

 

编写Makefile单项目模板