remove outdated openjpeg
[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 CFLAGS += -std=c++11
53
54 ifeq ($(src),git)
55 $(opencv).src:
56         cd $(blddir) && rm -rf opencv opencv_contrib opencv.*
57         git -C $(blddir) clone --depth 1 $(git_url)/opencv.git
58         git -C $(blddir) clone --depth 1 $(git_url)/opencv_contrib.git
59         touch $@
60 else ifeq ($(src),tar)
61 $(srcdir)/$(opencv_tar):
62         cd $(srcdir) && rm -f $(opencv_tar)
63         wget -P $(srcdir) "$(tar_url)"
64
65 $(opencv).src: $(srcdir)/$(opencv_tar)
66         cd $(blddir) && rm -rf opencv opencv_contrib opencv.*
67         tar -C $(blddir) -xzf $(srcdir)/$(opencv_tar);
68         $(foreach pch,$(sort $(wildcard $(srcdir)/$(opencv_tar).patch*)),\
69                 patch -d $(blddir) -p1 < $(pch);)
70         touch $@
71 else
72 $(error src not git/tar)
73 endif
74
75 ifeq ($(bld),sta)
76 $(opencv)/build: $(opencv).src
77         mkdir -p $@
78         cd $@ && cmake \
79   -DCMAKE_BUILD_TYPE=RELEASE \
80   -DWITH_IPP=OFF \
81   -DWITH_LAPACK=OFF \
82   -DWITH_GPHOTO2=OFF \
83   -DWITH_JASPER=OFF \
84   -DWITH_FFMPEG=OFF \
85   -DWITH_GSTREAMER=OFF \
86   -DWITH_ANDROID_MEDIANDK=OFF \
87   -DBUILD_SHARED_LIBS=OFF \
88   -DINSTALL_C_EXAMPLES=OFF \
89   -DINSTALL_PYTHON_EXAMPLES=OFF \
90   -DBUILD_EXAMPLES=OFF .. \
91   -DBUILD_PERF_TESTS=OFF \
92   -DBUILD_TESTS=OFF \
93   -DBUILD_opencv_apps=OFF \
94   -DBUILD_opencv_python3=no \
95   -DCMAKE_INSTALL_PREFIX=/usr/local \
96   -DOPENCV_EXTRA_MODULES_PATH="$(opencv)_contrib/modules/"
97
98 LFLAGS += -Wl,--start-group
99 LFLAGS += $(shell find $(opencv_prefix)/lib* -name "libopencv_*.a" 2> /dev/null)
100 #opencv4 breaks SIFT/SURF findobj
101 LFLAGS += $(shell find $(opencv_prefix)/lib*/opencv4/3rdparty/lib* -name "lib*.a" 2> /dev/null)
102 LFLAGS += $(shell find $(opencv_prefix)/share/OpenCV/3rdparty/lib* -name "lib*.a" 2> /dev/null)
103 LFLAGS += -Wl,--end-group
104 else ifeq ($(bld),dyn)
105 $(opencv)/build: $(opencv).src
106         mkdir -p $@
107         cd $@ && cmake \
108   -DCMAKE_BUILD_TYPE=RELEASE \
109   -DWITH_IPP=OFF \
110   -DWITH_LAPACK=OFF \
111   -DWITH_GPHOTO2=OFF \
112   -DWITH_JASPER=OFF \
113   -DWITH_FFMPEG=OFF \
114   -DWITH_GSTREAMER=OFF \
115   -DWITH_ANDROID_MEDIANDK=OFF \
116   -DBUILD_SHARED_LIBS=ON \
117   -DINSTALL_C_EXAMPLES=ON \
118   -DINSTALL_PYTHON_EXAMPLES=ON \
119   -DBUILD_EXAMPLES=ON .. \
120   -DBUILD_opencv_python3=no \
121   -DBUILD_PERF_TESTS=OFF \
122   -DBUILD_TESTS=OFF \
123   -DBUILD_opencv_apps=OFF \
124   -DCMAKE_INSTALL_PREFIX=/usr/local \
125   -DOPENCV_EXTRA_MODULES_PATH="$(opencv)_contrib/modules/"
126
127 SYSLIB := $(lastword $(wildcard /usr/lib /usr/lib32 /usr/lib64))
128 CVLIBS := $(dir $(shell find $(opencv_prefix) -name libopencv_core.so))
129 LFLAGS += -L$(CVLIBS) $(patsubst $(CVLIBS)/lib%.so,-l%,$(wildcard $(CVLIBS)/libopencv_*.so))
130 LFLAGS += $(patsubst $(SYSLIB)/lib%.so,-l%,$(wildcard $(SYSLIB)/lib{Half,Imath,Ilm,Iex}*.so))
131 static_libs :=
132 static_incs :=
133 else ifeq ($(bld),sys)
134 $(opencv)/build:
135
136 SYSLIB := $(lastword $(wildcard /usr/lib /usr/lib32 /usr/lib64))
137 LFLAGS += $(patsubst $(SYSLIB)/lib%.so,-l%,$(wildcard $(SYSLIB)/libopencv_*.so))
138 LFLAGS += $(patsubst $(SYSLIB)/lib%.so,-l%,$(wildcard $(SYSLIB)/lib{Half,Imath,Ilm,Iex}*.so))
139 static_libs :=
140 static_incs :=
141 CFLAGS += -I/usr/include/opencv4
142 else
143 $(error bld not sta/dyn/sys)
144 endif
145
146 $(opencv).sta $(opencv).dyn: $(opencv)/build
147         cd $(opencv)/build && make $(jobs) 2>&1 | tee log
148         cd $(opencv)/build && make install DESTDIR=`pwd`
149         touch $@
150
151 $(opencv).sys:
152         touch $@
153
154 mrclean:        clean
155         rm -rf $(blddir)/opencv* $(srcdir)/$(opencv_tar)
156
157 opencv: $(opencv).$(bld)
158