makefile 小例子

 

CXXFLAGS = -Wno-unused-parameter -std=c++11

LDFLAGS = -ldl

 

CC=g++

 

#VPATH = src src/example_lib include/example_lib test

#vpath % $(sort $(dir Makefile))

 

SOURCES   = ./src test include

BUILD_DIR = .

TARGET=cppunit_example

# ------------------------------------------------------------------------------

# Search Input and calculate output

# ------------------------------------------------------------------------------

SRCS := $(shell find -L $(SOURCES) -type f -regex ".*\.c\(c\|pp\|xx\)?")

OBJS := $(patsubst %,$(BUILD_DIR)/%.o,$(basename $(SRCS))) 

 

 

./%.o: %.cpp

$(CC) $(CXXFLAGS) -I./include -c $<

 

all: $(TARGET)

 

$(TARGET): $(OBJS)

g++ $(LDFLAGS) -o $@ $(BUILD_DIR)/*.o -L/usr/lib -lcppunit 

 

 

clean:

@rm -f $(BUILD_DIR)/*.o

@rm -f $(TARGET)

你可能感兴趣的:(cpp)