forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
104 lines (79 loc) · 3.02 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
# Detect OS
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
# Specify BACKEND=V4L2 or BACKEND=LIBUVC to build a specific backend
BACKEND := V4L2
ifeq ($(uname_S),Darwin)
# OSX defaults to libuvc instead of V4L
BACKEND := LIBUVC
endif
LIBUSB_FLAGS := `pkg-config --cflags --libs libusb-1.0`
CFLAGS := -std=c11 -fPIC -pedantic -DRS_USE_$(BACKEND)_BACKEND $(LIBUSB_FLAGS)
CXXFLAGS := -std=c++11 -fPIC -pedantic -Ofast -Wno-missing-field-initializers
# Use SSE if feature is available - cpuinfo has features such as SSE on x86, NEON on ARM
cpufeature = $(if $(findstring $(1),$(shell cat /proc/cpuinfo)),$(2))
PARAMS_SSE = $(call cpufeature,sse,-msse) $(call cpufeature,sse2,-msse2) $(call cpufeature,sse3,-msse3) \
$(call cpufeature,sse4,-msse4) $(call cpufeature,sse4_1,-msse4.1) \
$(call cpufeature,sse4_2,-msse4.2)
ifneq ($(strip $(PARAMS_SSE)),)
CFLAGS += $(PARAMS_SSE)
CXXFLAGS += $(PARAMS_SSE)
endif
CXXFLAGS += -Wno-switch -Wno-multichar -DRS_USE_$(BACKEND)_BACKEND $(LIBUSB_FLAGS)
# Add specific include paths for OSX
ifeq ($(uname_S),Darwin)
CFLAGS += -I/usr/local/include
CXXFLAGS += -I/usr/local/include
endif
# Compute list of all *.o files that participate in librealsense.so
OBJECTS = verify
OBJECTS += $(notdir $(basename $(wildcard src/*.cpp)))
OBJECTS += $(addprefix libuvc/, $(notdir $(basename $(wildcard src/libuvc/*.c))))
OBJECTS := $(addprefix obj/, $(addsuffix .o, $(OBJECTS)))
# Sets of flags used by the example programs
REALSENSE_FLAGS := -Iinclude -Llib -lrealsense -lm
ifeq ($(uname_S),Darwin)
# OSX uses OpenGL as a framework
GLFW3_FLAGS := `pkg-config --cflags --libs glfw3` -lglfw3 -framework OpenGL
else
# otherwise pkg-config finds OpenGL
GLFW3_FLAGS := `pkg-config --cflags --libs glfw3 glu gl`
endif
# Compute a list of all example program binaries
EXAMPLES := $(wildcard examples/*.c)
EXAMPLES += $(wildcard examples/*.cpp)
EXAMPLES := $(addprefix bin/, $(notdir $(basename $(EXAMPLES))))
# Aliases for convenience
all: examples $(EXAMPLES)
install: library
install -m755 -d /usr/local/include/librealsense
cp -r include/librealsense/* /usr/local/include/librealsense
cp lib/librealsense.so /usr/local/lib
ldconfig
clean:
rm -rf obj
rm -rf lib
rm -rf bin
library: lib/librealsense.so
prepare:
mkdir -p obj/libuvc
mkdir -p lib
mkdir -p bin
# Rules for building the sample programs
bin/c-%: examples/c-%.c library
$(CC) $< $(REALSENSE_FLAGS) $(GLFW3_FLAGS) -o $@
bin/cpp-%: examples/cpp-%.cpp library
$(CXX) $< -std=c++11 $(REALSENSE_FLAGS) $(GLFW3_FLAGS) -o $@
# Rules for building the library itself
lib/librealsense.so: prepare $(OBJECTS)
$(CXX) -std=c++11 -shared $(OBJECTS) $(LIBUSB_FLAGS) -o $@
lib/librealsense.a: prepare $(OBJECTS)
ar rvs $@ `find obj/ -name "*.o"`
# Rules for compiling librealsense source
obj/%.o: src/%.cpp
$(CXX) $< $(CXXFLAGS) -c -o $@
# Rules for compiling libuvc source
obj/libuvc/%.o: src/libuvc/%.c
$(CC) $< $(CFLAGS) -c -o $@
# Special rule to verify that rs.h can be included by a C89 compiler
obj/verify.o: src/verify.c
$(CC) $< -std=c89 -Iinclude -c -o $@