forked from samuelmurray/tracking-by-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
117 lines (92 loc) · 2.9 KB
/
makefile
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
SHELL = /bin/sh
# Compiler options
CXX = g++
CXXFLAGS = -std=c++11 -g -Wall -pedantic
LDFLAGS =
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
# External libraries
export PKG_CONFIG_PATH := ../config:$(PKG_CONFIG_PATH)
# OpenCV
CXXFLAGS += `pkg-config --cflags opencv`
LDFLAGS += `pkg-config --libs opencv`
# dlib
CXXFLAGS += `pkg-config --cflags dlib-1`
LDFLAGS += `pkg-config --libs dlib-1`
# Boost
CXXFLAGS += `pkg-config --cflags boost`
LDFLAGS += `pkg-config --libs boost`
# For compilation with Caffe
use_caffe = false
ifeq ($(use_caffe),true)
# Caffe
CXXFLAGS += -DUSE_CAFFE
CXXFLAGS += `pkg-config --cflags caffe`
LDFLAGS += `pkg-config --libs caffe`
# Cuda
CXXFLAGS += `pkg-config --cflags cuda`
LDFLAGS += `pkg-config --libs cuda`
endif
# Directories
SOURCEDIR = src
BUILDDIR = build
MAINDIR = examples
DEPDIR = .d
# Input/Output files
SOURCES := $(shell find $(SOURCEDIR) -name "*.cpp")
OBJECTS := $(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
DEPFILES := $(patsubst $(SOURCEDIR)/%.cpp,$(DEPDIR)/%.d,$(SOURCES))
TARGET_detect := detectApp.out
TARGET_track := trackApp.out
TARGET_detectAndTrack := detectAndTrackApp.out
TARGETS := $(TARGET_detect) $(TARGET_track) $(TARGET_detectAndTrack)
# For running DetectDemo.cpp
OBJECTS_detect := $(filter-out $(BUILDDIR)/$(MAINDIR)/%.o,$(OBJECTS))
OBJECTS_detect += $(BUILDDIR)/$(MAINDIR)/DetectDemo.o
# For running TrackDemo.cpp
OBJECTS_track := $(filter-out $(BUILDDIR)/$(MAINDIR)/%.o,$(OBJECTS))
OBJECTS_track += $(BUILDDIR)/$(MAINDIR)/TrackDemo.o
# For running DetectAndTrackDemo.cpp
OBJECTS_detectAndTrack := $(filter-out $(BUILDDIR)/$(MAINDIR)/%.o,$(OBJECTS))
OBJECTS_detectAndTrack += $(BUILDDIR)/$(MAINDIR)/DetectAndTrackDemo.o
# Build instructioncs
MKDIRIFNOTEXIST = @test -d $(@D) || mkdir -p $(@D)
COMPILE = $(CXX) $(DEPFLAGS) $(CXXFLAGS) -c
POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d
# Targets
.SECONDEXPANSION:
# Instructions
all:
@echo 'Call "make compile" to compile everything, or "make <target>" to compile and link a specific target'
# Print variable
print-% : ; @echo $* = $($*)
# Compile and link target
detect track detectAndTrack: compile $$(TARGET_$$@)
# Link target's objects
%App.out: $$(OBJECTS_%)
@echo '(link) CXX $@'
@$(CXX) -o $@ $^ $(LDFLAGS)
# Compile all files
compile: $(OBJECTS)
# Crazy alternative: [...]%.d | $(BUILDDIR)/$$(filter-out ./,$$(dir %)).dir --- %.dir: ; $(MKDIRIFNOTEXIST)
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.cpp $(DEPDIR)/%.d
@echo '(compile) CXX $<'
@$(MKDIRIFNOTEXIST)
@$(COMPILE) $< -o $@
@$(POSTCOMPILE)
$(DEPDIR)/%.d:
$(MKDIRIFNOTEXIST)
# Prevent files from being deleted as intermediate files by make
.PRECIOUS: $(OBJECTS) $(DEPFILES)
# Include dependency files
include $(wildcard $(DEPFILES))
# Rebuild all object files
force_rebuild = false
ifeq ($(force_rebuild),true)
$(shell rm $(OBJECTS))
endif
# Remove all generated files
.PHONY: clean
clean:
rm -f $(OBJECTS)
rm -f $(DEPFILES)
rm -f $(TARGETS)