File size: 1,544 Bytes
09c675d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7daf654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
09c675d
 
 
 
 
 
 
 
 
7daf654
09c675d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# Makefile
# Jiayuan Mao, 2019-01-09 13:59
#

SRC_DIR = csrc
INC_DIR = csrc
OBJ_DIR = build/obj
TARGET = libpatchmatch.so

LIB_TARGET = $(TARGET)
INCLUDE_DIR = -I $(SRC_DIR) -I $(INC_DIR)

CXX = $(ENVIRONMENT_OPTIONS) g++
CXXFLAGS = -std=c++14
CXXFLAGS += -Ofast -ffast-math -w
# CXXFLAGS += -g

PKG_CONFIG := $(shell pkg-config --exists opencv || echo "no")
ifeq ($(PKG_CONFIG),no)
    PKG_CONFIG := $(shell pkg-config --exists opencv4 || echo "no")
    ifeq ($(PKG_CONFIG),no)
        $(error "opencv or opencv4 not found, please install OpenCV and try again.")
    else
        CXXFLAGS += $(shell pkg-config --cflags opencv4) -fPIC
        LDFLAGS = $(shell pkg-config --cflags --libs opencv4) -shared -fPIC
    endif
else
    CXXFLAGS += $(shell pkg-config --cflags opencv) -fPIC
    LDFLAGS = $(shell pkg-config --cflags --libs opencv) -shared -fPIC
endif

CXXFLAGS += $(INCLUDE_DIR)

CXXSOURCES = $(shell find $(SRC_DIR)/ -name "*.cpp")
OBJS = $(addprefix $(OBJ_DIR)/,$(CXXSOURCES:.cpp=.o))
DEPFILES = $(OBJS:.o=.d)

.PHONY: all clean rebuild test

all: $(LIB_TARGET)


$(OBJ_DIR)/%.o: %.cpp
	@echo "[CC] $< ..."
	@$(CXX) -c $< $(CXXFLAGS) -o $@

$(OBJ_DIR)/%.d: %.cpp
	@mkdir -pv $(dir $@)
	@echo "[dep] $< ..."
	@$(CXX) $(INCLUDE_DIR) $(CXXFLAGS) -MM -MT "$(OBJ_DIR)/$(<:.cpp=.o) $(OBJ_DIR)/$(<:.cpp=.d)" "$<" > "$@"

sinclude $(DEPFILES)

$(LIB_TARGET): $(OBJS)
	@echo "[link] $(LIB_TARGET) ..."
	@$(CXX) $(OBJS) -o $@ $(CXXFLAGS) $(LDFLAGS)

clean:
	rm -rf $(OBJ_DIR) $(LIB_TARGET)

rebuild:
	+@make clean
	+@make

# vim:ft=make
#