Contributed Speed PerCent video plugin
[goodguy/cinelerra.git] / cinelerra-5.1 / opencv_build
1 # builds opencv using want_var to create bld from src
2 # want_var set as: "" (empty) or "bld=typ" or "bld=typ,src=typ"
3 #   empty: defaults to bld=sys
4 #   bld=typ   sta,dyn,sys: sta=static, dyn=shared, sys=system libraries
5 #   src=typ   git,tar,git=url,tar=url: git (default git_url), tar (default: tar_url)
6 # once thirdparty/opencv is built, it will be reused.
7 # use target "mrclean" to remove thirdparty/opencv*
8 #
9 ifeq (no,$(shell [ -d $(THIRDPARTY) ] && echo yes || echo no))
10 $(error THIRDPARTY is not a directory: '$(THIRDPARTY)')
11 endif
12
13 blddir:=$(shell cd $(THIRDPARTY) && pwd)
14 srcdir:=$(blddir)/src
15 opencv:=$(blddir)/opencv
16 opencv_prefix:=$(opencv)/build/usr/local
17
18 # if previous build stamped, use that bld
19 ifneq (,$(wildcard $(opencv).sta))
20 bld:=sta
21 else ifneq (,$(wildcard $(opencv).dyn))
22 bld:=dyn
23 else ifneq (,$(wildcard $(opencv).sys))
24 bld:=sys
25 endif
26
27 comma=,
28 params:=$(subst $(comma), ,$(want_var))
29
30 # code: src=tar/tar=tar_url;git/git=git_url, build: bld=sta/dyn/sys
31 $(foreach p,$(params),\
32  $(if $(bld),,$(eval var:=$(filter sta dyn sys,$(p)))\
33   $(if $(var),$(eval bld:=$(var))))\
34  $(if $(src),,$(eval var:=$(filter git tar,$(p)))\
35   $(if $(var),$(eval src:=$(var)),\
36    $(if $(filter git=%,$(p)),$(eval src:=git)$(eval git_url=$(patsubst git=%,%,$(p))),\
37     $(if $(filter tar=%,$(p)),$(eval src:=tar)$(eval tar_url=$(patsubst tar=%,%,$(p))))))))
38
39 # defaults: src=git, bld=sys
40 src?=git
41 bld?=sys
42 git_url?=https://github.com/opencv
43 tar_url?=https://www.cinelerra-gg.org/download/opencv/opencv-20180401.tgz
44 opencv_tar:=$(notdir $(tar_url))
45
46 cpus:=$(shell grep -c "^proc" /proc/cpuinfo)
47 jobs:=-j$(shell echo $$(($(cpus) + $(cpus)/2 +2)))
48
49 #opencv4 breaks SIFT/SURF findobj
50 CFLAGS += -I$(opencv_prefix)/include/opencv4
51 CFLAGS += -I$(opencv_prefix)/include
52
53 ifeq ($(src),git)
54 $(opencv).src:
55         cd $(blddir) && rm -rf opencv opencv_contrib opencv.*
56         git -C $(blddir) clone --depth 1 $(git_url)/opencv.git
57         git -C $(blddir) clone --depth 1 $(git_url)/opencv_contrib.git
58         touch $@
59 else ifeq ($(src),tar)
60 $(srcdir)/$(opencv_tar):
61         cd $(srcdir) && rm -f $(opencv_tar)
62         wget -P $(srcdir) "$(tar_url)"
63
64 $(opencv).src: $(srcdir)/$(opencv_tar)
65         cd $(blddir) && rm -rf opencv opencv_contrib opencv.*
66         tar -C $(blddir) -xzf $(srcdir)/$(opencv_tar);
67         $(foreach pch,$(sort $(wildcard $(srcdir)/$(opencv_tar).patch*)),\
68                 patch -d $(blddir) -p1 < $(pch);)
69         touch $@
70 else
71 $(error src not git/tar)
72 endif
73
74 ifeq ($(bld),sta)
75 $(opencv)/build: $(opencv).src
76         mkdir -p $@
77         cd $@ && cmake \
78   -DCMAKE_BUILD_TYPE=RELEASE \
79   -DWITH_IPP=OFF \
80   -DWITH_LAPACK=OFF \
81   -DWITH_GPHOTO2=OFF \
82   -DBUILD_SHARED_LIBS=OFF \
83   -DINSTALL_C_EXAMPLES=OFF \
84   -DINSTALL_PYTHON_EXAMPLES=OFF \
85   -DBUILD_EXAMPLES=OFF .. \
86   -DBUILD_opencv_python3=no \
87   -DCMAKE_INSTALL_PREFIX=/usr/local \
88   -DOPENCV_EXTRA_MODULES_PATH="$(opencv)_contrib/modules/"
89
90 LFLAGS += -Wl,--start-group
91 LFLAGS += $(shell find $(opencv_prefix)/lib* -name "libopencv_*.a" 2> /dev/null)
92 #opencv4 breaks SIFT/SURF findobj
93 LFLAGS += $(shell find $(opencv_prefix)/lib*/opencv4/3rdparty/lib* -name "lib*.a" 2> /dev/null)
94 LFLAGS += $(shell find $(opencv_prefix)/share/OpenCV/3rdparty/lib* -name "lib*.a" 2> /dev/null)
95 LFLAGS += -Wl,--end-group
96 else ifeq ($(bld),dyn)
97 $(opencv)/build: $(opencv).src
98         mkdir -p $@
99         cd $@ && cmake \
100   -DCMAKE_BUILD_TYPE=RELEASE \
101   -DWITH_IPP=OFF \
102   -DWITH_LAPACK=OFF \
103   -DWITH_GPHOTO2=OFF \
104   -DBUILD_SHARED_LIBS=ON \
105   -DINSTALL_C_EXAMPLES=ON \
106   -DINSTALL_PYTHON_EXAMPLES=ON \
107   -DBUILD_EXAMPLES=ON .. \
108   -DBUILD_opencv_python3=no \
109   -DCMAKE_INSTALL_PREFIX=/usr/local \
110   -DOPENCV_EXTRA_MODULES_PATH="$(opencv)_contrib/modules/"
111
112 SYSLIB := $(lastword $(wildcard /usr/lib /usrlib32 /usr/lib64))
113 CVLIBS := $(dir $(shell find $(opencv_prefix) -name libopencv_core.so))
114 LFLAGS += -L$(CVLIBS) $(patsubst $(CVLIBS)/lib%.so,-l%,$(wildcard $(CVLIBS)/libopencv_*.so))
115 LFLAGS += $(patsubst $(SYSLIB)/lib%.so,-l%,$(wildcard $(SYSLIB)/lib{Half,Imath,Ilm,Iex}*.so))
116 static_libs :=
117 static_incs :=
118 else ifeq ($(bld),sys)
119 $(opencv)/build:
120
121 SYSLIB := $(lastword $(wildcard /usr/lib /usrlib32 /usr/lib64))
122 LFLAGS += $(patsubst $(SYSLIB)/lib%.so,-l%,$(wildcard $(SYSLIB)/libopencv_*.so))
123 LFLAGS += $(patsubst $(SYSLIB)/lib%.so,-l%,$(wildcard $(SYSLIB)/lib{Half,Imath,Ilm,Iex}*.so))
124 static_libs :=
125 static_incs :=
126 CFLAGS += -I/usr/include/opencv4
127 else
128 $(error bld not sta/dyn/sys)
129 endif
130
131 $(opencv).sta $(opencv).dyn: $(opencv)/build
132         cd $(opencv)/build && make $(jobs) 2>&1 | tee log
133         cd $(opencv)/build && make install DESTDIR=`pwd`
134         touch $@
135
136 $(opencv).sys:
137         touch $@
138
139 mrclean:        clean
140         rm -rf $(blddir)/opencv* $(srcdir)/$(opencv_tar)
141
142 opencv: $(opencv).$(bld)
143