upgrade t0 openexr-2.4.0, fix file probe for openexr
[goodguy/cinelerra.git] / cinelerra-5.1 / thirdparty / Makefile
1 # to see the make rules:
2 #   make rules
3 #
4 # command uses:
5 #   make <name>-clean
6 #   make <name>
7 #   make rules
8 #   make val-<var>
9 #
10 # to add a new library:
11 #   vi ../configure.ac
12 #     add PKG_3RD(pkg,<yes/no/auto>, <ver_basename>, <lib_paths>, <inc_paths>)
13 #     add CHECK_LIB(pkg, <syslib>, <entry_pt>, [opt libs]) if may be in system
14 #     add CHECK_HEADERS(pkg, <title>, <entry_pt>) to check for devel headers
15 #     add CHECK_WANT(<want>, <title>, [ checks ]) around tests if conditional
16 #     see openexr check for example if c++ lib
17 #     add PKG_PROVIDE(pkg,<cond>) to instance pkg if probe succeeds
18 #     add to exec > global_config if additional environment needed
19 #   vi Makefile
20 #     add pkg.<data> (pkg.x = .flags, .vars, .params)
21 #     add $(call rules,$(call std-build,<name>,<dep>...))
22 #     add deps to other call rules if they require the new library
23 #     add config enables if other libraries use the new library
24 #     add pc_<pkg>=<pkgcfg names> if needed for system build
25 #
26
27 TOPDIR ?= $(CURDIR)/..
28 include $(TOPDIR)/global_config
29 -include $(TOPDIR)/cin_config
30 BLD := $(THIRDPARTY)/build
31
32 ifneq ($(WANT_CIN_3RDPARTY),no)
33
34 # package build flags, if needed
35 # need frame pointer for debugs and helps with profiling
36 # NOTE: the trailing blank is MANDITORY or the builds fail
37 # due to bugs in the build scripts from auto*
38 CFLAGS_ ?= -g -O2 -fno-omit-frame-pointer
39 CFLAGS ?= $(CFLAGS_) 
40 LDFLAGS += $(LDFLAGS_) 
41 CXXFLAGS += $(CXXFLAGS_) 
42
43 pkg-source=$(BLD)/$(1).source
44 pkg-config=$(BLD)/$(1).configure
45 pkg-built=$(BLD)/$(1).built
46
47 ext=$(lastword $(subst ., ,$(1)))
48 tarball=$(if $($(1).git),$(1).git,$(lastword $(sort $(wildcard src/$(1)*.tar.*))))
49 unpack=$(call unpack_$(call ext,$(1)),$(1))
50 unpack_git=git clone $($(1)) $(1)
51 unpack_gz=tar -xzf $(1)
52 unpack_bz2=tar -xjf $(1)
53 unpack_xz=tar -xJf $(1)
54 bld_depends=$(if $(ver_$(1)),$(call pkg-built,$(1)))
55 bld_path=$(ver_$(1))/$(2)
56 if_pkg=$(if $(ver_$(1)),$(2),$(3))
57 if_npkg=$(if $(ver_$(1)),,$(2))
58 if_shr=$(if $(findstring $(1),$(shared_pkgs)),$(2),$(3))
59 pkg_conf=$(call if_shr,$(1),$(foreach p,$(pc_$(1)), $(shell pkg-config 2> /dev/null $(2) $(p))))
60 inc_path=$(call if_pkg,$(1),$(inc_$(1)), $(call pkg_conf,$(1),--cflags))
61 ld_path=$(call if_pkg,$(1),-L$(call bld_path,$(1),$(2)) $(lib_$(1)))
62 if_ena=$(if $(or $(ver_$(1)),$(findstring $(1),$(shared_pkgs))),$(2))
63 if_want=$(if $(findstring x$(WANT_$(1)),xyes),$(2),$(3))
64
65 #$(eval $(call std-build,pkg,deps...))
66 #$(pkg.cflags) added as CFLAGS+=$(cflags) to pkg.vars
67 #$(pkg.cppflags) added as CPPFLAGS+=$(cppflags) to pkg.vars
68 #$(pkg.cfg_vars) prepended to configure
69 #$(pkg.cfg_params) appended to configure
70 #$(pkg.mak_vars) prepended to make
71 #$(pkg.mak_params) appended to make
72
73 define std-build
74 # $(1)
75 .PHONY: $(1) $(1)-configure $(1)-src $(1)-clean
76 $(1): $(call pkg-built,$(1))
77 $(1)-configure: $(call pkg-config,$(1))
78 $(1)-src: $(call pkg-source,$(1))
79 $(1)-clean:
80         rm -rf $(1)* $(BLD)/$(1).*
81
82 $(call pkg-source,$(1)):
83         $(call unpack,$(call tarball,$(1))) \
84         $(foreach pch,$(sort $(wildcard src/$(notdir $(ver_$(1))).patch*)),
85                 patch -d $(1)* -p1 < $(pch))
86         touch $$@
87
88 $(call pkg-config,$(1)): $(call pkg-source,$(1)) $(foreach dep,$(2),$(call bld_depends,$(dep)))
89         @echo "CONFIGURING $(1)"
90         cd $(1)* && \
91                 $($(1).cfg_vars) $(CFG_VARS) ./configure $($(1).cfg_params) $(CFG_PARAMS)
92         touch $$@
93
94 $(call pkg-built,$(1)): $(call pkg-config,$(1))
95         +$($(1).mak_vars) $(MAK_VARS) $(MAKE) -C $(1)* $($(1).mak_params) $(MAK_PARAMS)
96         touch $$@
97
98 endef
99
100 TARGETS := $(static_blds)
101
102 all:    $(TARGETS)
103
104 $(TARGETS):     $(BLD)
105
106 $(BLD):
107         mkdir $(BLD)
108
109 # pkg-config names
110 pc_libaom=aom
111 pc_dav1d=dav1d
112 pc_libwebp=libwebp libwebpmux
113 pc_opus=opus
114 pc_openjpeg=libopenjp2
115 pc_libvorbis=vorbis vorbisenc
116 pc_libvpx=vpx
117 pc_x264=x264
118 pc_x265=x265
119
120 # vars first
121 encore.cfg_vars= true ||
122 esound.cfg_vars:= AUDIOFILE_CFLAGS="$(call inc_path,audiofile) -laudiofile"
123 esound.cfg_vars+= AUDIOFILE_LIBS="$(call ld_path,audiofile,libaudiofile/.libs)"
124 esound.cfg_params= --enable-shared=no --with-pic
125 esound.mak_vars+= CFLAGS="" 
126 esound.ldflags=" -lm -lstdc++"
127 fftw.cfg_params= --disable-fortran --enable-shared=no
128 ffmpeg.cfg_params= \
129         --enable-pthreads --enable-gpl --disable-ffplay \
130         $(call if_want,VAAPI,--enable-vaapi,--disable-vaapi) \
131         $(call if_want,VDPAU,--enable-vdpau,--disable-vdpau) \
132         $(call if_want,NV, --enable-nvenc --enable-nvdec --enable-ffnvcodec) \
133         $(call if_ena,twolame,--enable-libtwolame) \
134         $(call if_ena,openjpeg,--enable-libopenjpeg) \
135         $(call if_ena,lame,--enable-libmp3lame) \
136         $(call if_ena,libaom,--enable-libaom) \
137         $(call if_ena,dav1d,--enable-libdav1d) \
138         $(call if_ena,libwebp,--enable-libwebp) \
139         $(call if_ena,opus,--enable-libopus) \
140         $(call if_ena,libvorbis,--enable-libvorbis) \
141         $(call if_ena,libtheora,--enable-libtheora) \
142         $(call if_ena,libvpx,--enable-libvpx) \
143         $(call if_ena,x264,--enable-libx264) \
144         $(call if_ena,x265,--enable-libx265) \
145         --extra-cflags="-Wno-attributes \
146                 $(call if_want,NV,$(inc_ffnvcodec)) \
147                 $(call inc_path,twolame) \
148                 $(call inc_path,lame) \
149                 $(call inc_path,libaom) \
150                 $(call inc_path,dav1d) \
151                 $(call inc_path,libwebp) \
152                 $(call inc_path,openjpeg) \
153                 $(call inc_path,libogg) \
154                 $(call inc_path,opus) \
155                 $(call inc_path,libvorbis) \
156                 $(call inc_path,libtheora) \
157                 $(call inc_path,libvpx) \
158                 $(call inc_path,x264) \
159                 $(call inc_path,x265)" \
160         --extra-cxxflags="-D__STDC_CONSTANT_MACROS" \
161         --pkg-config=true \
162         --extra-libs="-Wl,--start-group \
163                 $(call ld_path,twolame,libtwolame/.libs) \
164                 $(call ld_path,lame,libmp3lame/.libs) \
165                 $(call ld_path,libaom,usr/local/lib) \
166                 $(call ld_path,dav1d,usr/local/lib) \
167                 $(call ld_path,libwebp,usr/local/lib) \
168                 $(call ld_path,openjpeg,bin) \
169                 $(call ld_path,opus,.libs) \
170                 $(call ld_path,libogg,lib/.libs) \
171                 $(call ld_path,libvorbis,lib/.libs) \
172                 $(call ld_path,libtheora,lib/.libs) \
173                 $(call ld_path,libvpx) \
174                 $(call ld_path,x264) \
175                 $(call ld_path,x265) \
176                 $(shared_libs) \
177                 -Wl,--end-group -lm -lstdc++ -pthread \
178                 $(EXTRA_LIBS)" $(FFMPEG_EXTRA_CFG) \
179
180 #cmake_config=echo "exec cmake \$$$$@ $(1)" > ./configure; chmod +x ./configure;
181 cmake_config=echo 'cmake "$$$$@" "$(1)"' > ./configure; chmod +x ./configure;
182 a52dec.mak_params?= ; cd $(call bld_path,a52dec,include); ln -sf . a52dec
183 a52dec.cfg_vars?= CFLAGS+=" -U__FreeBSD__ $(call inc_path,djbfft)" LIBS+=" $(call ld_path,djbfft)"
184 a52dec.cfg_params?=--enable-djbfft
185 djbfft.cfg_vars?=echo "$(call bld_path,djbfft)" > conf-home; \
186  (CFLAGS="$(CFLAGS)"; $(CFG_VARS)$(if $(CFG_VARS),; )echo "$(CC) $$$$CFLAGS") > conf-cc; \
187  echo > ./configure; chmod +x ./configure;
188 djbfft.mak_params?=; cd $(call bld_path,djbfft); ln -sf djbfft.a libdjbfft.a
189 audiofile.cfg_params?=--enable-shared=no
190 audiofile.mak_params?=LIBS="-lm -lstdc++"
191 flac.cfg_params?= --enable-shared=no
192 flac.cflags?="$(call inc_path,libogg) $(call ld_path,libogg,src/.libs)"
193 giflib.cfg_params=echo "exec true" > ./configure; chmod +x ./configure;
194 lame.cfg_vars?= CFLAGS+=" -O"
195 lame.cfg_params?=--enable-shared=no
196 lame.mak_params?= ; cd $(call bld_path,lame,include); ln -sf . lame
197 libaom.cfg_vars?=$(call cmake_config,aom-master)
198 libaom.cfg_params?= -DENABLE_SHARED=no -DCMAKE_INSTALL_LIBDIR=lib \
199  -DCMAKE_INSTALL_PREFIX=$(call bld_path,libaom)/usr/local
200 libaom.mak_params?= ; $(MAKE) -C libaom* install
201 dav1d.cfg_vars?=echo "echo dav1d custom make" >> configure; chmod +x ./configure;
202 dav1d.mak_params?=; $(MAKE) -C dav1d* install DESTDIR="$(call bld_path,dav1d)"
203 libwebp.cfg_vars?= mkdir build && cd build && $(call cmake_config,..)
204 libwebp.mak_params?= -C build all install DESTDIR=$(call bld_path,libwebp)
205 mjpegtools.cflags?="$(call inc_path,libjpeg) $(call ld_path,libjpeg,.libs)"
206 mjpegtools.mak_params?=; ln -s . $(call bld_path,mjpegtools,utils)/mjpegtools 
207 mjpegtools.cfg_params?= --enable-shared=no --without-libsdl --without-v4l
208 ladspa.cfg_vars?= CFLAGS+=' -Dinline="" '
209 ladspa.mak_params?=; $(MAKE) -C ladspa* install DESTDIR=$(call bld_path,ladspa)
210 libavc1394.cfg_vars?=PKG_CONFIG_PATH=$(call bld_path,libraw1394)
211 libavc1394.cflags?="$(call inc_path,libraw1394)"
212 libavc1394.ldflags?="$(call ld_path,libraw1394,src/.libs)"
213 libavc1394.cfg_params?= --enable-shared=no
214 libavc1394.mak_params?=; cd $(call bld_path,libavc1394); ln -sf ../librom1394/rom1394.h libavc1394/.
215 libdv.cfg_params?= --disable-gtk --enable-shared=no
216 libiec61883.cfg_vars?=PKG_CONFIG_PATH=$(call bld_path,libraw1394)
217 libiec61883.cflags?="$(call inc_path,libraw1394)"
218 libiec61883.ldflags?="$(call ld_path,libraw1394,src/.libs)"
219 libiec61883.cfg_params?= --enable-shared=no
220 libiec61883.mak_params?=; cd $(call bld_path,libiec61883,src); ln -sf . libiec61883
221 libjpeg.cfg_params?= --enable-shared=no
222 libogg.cfg_params?= --enable-shared=no
223 libraw1394.cfg_params?=  --enable-shared=no; ln -sf src libraw1394
224 libtheora.cfg_vars?=PKG_CONFIG_PATH=$(call bld_path,libogg):$(call bld_path,libvorbis)
225 libtheora.cflags?="$(call inc_path,libogg) $(call inc_path,libvorbis)"
226 libtheora.ldflags?="$(call ld_path,libvorbis,lib/.libs) $(call ld_path,libogg,src/.libs)"
227 libtheora.cfg_params?= --disable-examples --disable-spec --enable-shared=no
228 libuuid.cfg_params?=--enable-shared=no
229 libvorbis.cfg_params?= --disable-oggtest --enable-shared=no
230 openjpeg.cfg_params?= -DBUILD_SHARED_LIBS:BOOL=OFF
231 openjpeg.cfg_vars?=$(call cmake_config,.)
232 openjpeg.mak_params?= ; cd $(call bld_path,openjpeg,src/lib/openjp2); ln -sf . openjpeg-2.1
233 opencv.cfg_vars?=$(call cmake_config,.)
234 opencv.cfg_params?= -DBUILD_SHARED_LIBS:BOOL=OFF
235 openexr.cfg_params?=\
236  -DILMBASE_BUILD_BOTH_STATIC_SHARED:BOOL=ON \
237  -DOPENEXR_BUILD_BOTH_STATIC_SHARED:BOOL=ON \
238  -DILMBASE_LIB_SUFFIX= -DILMBASE_STATIC_LIB_SUFFIX= \
239  -DOPENEXR_LIB_SUFFIX= -DOPENEXR_STATIC_LIB_SUFFIX= \
240  -DCMAKE_INSTALL_LIBDIR=lib
241 openexr.cfg_vars?= mkdir build && cd build && $(call cmake_config,..)
242 openexr.mak_params?= -C build install DESTDIR=.
243 speech_tools.mak_params?=-j1
244 tiff.cfg_params+= --enable-shared=no --disable-zstd $(call if_npkg,libwebp,--without-webp)
245 twolame.cfg_params?=--enable-shared=no
246 x264.cfg_params?= --enable-static --enable-pic
247 x265.cfg_vars?=$(call cmake_config,source)
248 x265.cfg_params?= -DENABLE_SHARED=no
249 libvpx.cfg_params?= --enable-pic
250
251 DS:=$$$$$$$$
252 pkg_cfg=$(call bld_path,$(1),usr/local/lib/pkgconfig):
253 LV2_PKGCFG:=$(subst : ,:,$(foreach p,lv2 serd sord sratom lilv suil,$(call pkg_cfg,$(p))))
254
255 # lv2
256 define waf-setup
257 $(1).cfg_vars+=./waf --version; find .waf* -type f -name "*.py" | \
258  while read f; do sed -e '/StopIter/d' -i "$(DS)f"; done; \
259  echo 'exec ./waf configure "$(DS)@"' > ./configure; chmod +x \
260  ./configure;  PKG_CONFIG_PATH=$(LV2_PKGCFG) LD_LIBRARY_PATH=$(LV2_LIBPATH) 
261 $(1).cfg_params+=\
262  CFLAGS="-I$(call bld_path,lv2) $(foreach f,$(2), $(call inc_path,$(f))) -fPIC -std=c99"\
263  LDFLAGS="-lm $(foreach f,$(2), $(call ld_path,$(f),usr/local/lib)) "
264 $(1).mak_vars=(echo "all:"; echo "      ./waf -v build") > $(call bld_path,$(1),Makefile); 
265 $(1).mak_params+=; ( cd $(1)*; ./waf install --destdir=$(call bld_path,$(1)) )
266 endef
267
268 SYS_LIB:=$(notdir $(lastword $(wildcard /usr/lib /usrlib32 /usr/lib64)))
269 SYS_LV2:=$(lastword $(wildcard /usr/$(SYS_LIB)/lv2 /usr/local/$(SYS_LIB)/lv2))
270 $(if $(SYS_LV2),,$(eval SYS_LV2:=/usr/$(SYS_LIB)/lv2))
271 lv2.cfg_params?= --lv2dir=$(SYS_LV2)
272 SYS_LV2_PATH:=/usr/$(SYS_LIB)/lv2: /usr/local/$(SYS_LIB)/lv2:
273 DFT_LV2_PATH:= /usr/lib64/lv2: /usr/lib/lv2: /usr/local/lib64/lv2: /usr/local/lib/lv2: 
274 LV2_PATH:=$(subst : ,:,$(SYS_LV2_PATH)$(filter-out $(SYS_LV2_PATH),$(DFT_LV2_PATH)))
275 lilv.cfg_params?= --static --default-lv2-path=$(LV2_PATH)
276 sratom.cfg_params?= --static --no-shared
277 serd.cfg_params?= --static --no-shared
278 sord.cfg_params?= --static --no-shared
279 lilv.cfg_params?= --static --dyn-manifest
280 suil.cfg_params?= --static --no-qt
281
282 $(eval $(call waf-setup,lv2))
283 $(eval $(call waf-setup,serd))
284 $(eval $(call waf-setup,sord, serd))
285 $(eval $(call waf-setup,sratom, serd sord lv2))
286 $(eval $(call waf-setup,lilv, lv2 sratom serd sord))
287 $(eval $(call waf-setup,suil, lv2))
288
289 # add softlinks for legacy paths
290 waf_link=$(1).mak_params+=; (cd $(1)*; ln -s $(1)-0/$(1) usr/local/include/.)
291 $(foreach p,sratom serd sord lilv suil,$(eval $(call waf_link,$(p))))
292
293 # compile flag vars
294 $(foreach tgt,$(TARGETS), \
295         $(if $($(tgt).cflags),$(eval $(tgt).cfg_vars+=CFLAGS+=$($(tgt).cflags))))
296 $(foreach tgt,$(TARGETS), \
297         $(if $($(tgt).cppflags),$(eval $(tgt).cfg_vars+=CPPFLAGS+=$($(tgt).cppflags))))
298 $(foreach tgt,$(TARGETS), \
299         $(if $($(tgt).ldflags),$(eval $(tgt).cfg_vars+=LDFLAGS+=$($(tgt).ldflags))))
300
301 # build rules
302 .PHONY: rules
303 rules:
304
305 #$(eval $(call std-build,pkg,deps...))
306
307 ifeq ($(MAKECMDGOALS),rules)
308 rules=$(info $(1))
309 else
310 rules=$(eval $(1))
311 endif
312
313 $(call rules,$(call std-build,a52dec,djbfft))
314 $(call rules,$(call std-build,djbfft))
315 $(call rules,$(call std-build,audiofile))
316 $(call rules,$(call std-build,encore))
317 $(call rules,$(call std-build,esound,audiofile))
318 $(call rules,$(call std-build,ffmpeg, twolame lame openjpeg opus \
319         libtheora x264 x265 libvpx libaom dav1d libwebp \
320         $(call if_want,NV, ffnvcodec)))
321 $(call rules,$(call std-build,fftw))
322 $(call rules,$(call std-build,flac,libogg))
323 $(call rules,$(call std-build,giflib))
324 $(call rules,$(call std-build,ladspa))
325 $(call rules,$(call std-build,lame))
326 $(call rules,$(call std-build,libaom))
327 $(call rules,$(call std-build,dav1d))
328 $(call rules,$(call std-build,libwebp))
329 $(call rules,$(call std-build,libavc1394,libraw1394))
330 $(call rules,$(call std-build,libdv))
331 $(call rules,$(call std-build,libiec61883,libraw1394))
332 $(call rules,$(call std-build,libjpeg))
333 $(call rules,$(call std-build,libogg))
334 $(call rules,$(call std-build,libraw1394))
335 $(call rules,$(call std-build,libsndfile))
336 $(call rules,$(call std-build,libtheora, libogg libvorbis))
337 $(call rules,$(call std-build,libuuid))
338 $(call rules,$(call std-build,libvorbis))
339 $(call rules,$(call std-build,mjpegtools, libjpeg))
340 $(call rules,$(call std-build,opencv))
341 $(call rules,$(call std-build,openexr))
342 $(call rules,$(call std-build,openjpeg))
343 $(call rules,$(call std-build,opus))
344 $(call rules,$(call std-build,speech_tools))
345 $(call rules,$(call std-build,tiff))
346 $(call rules,$(call std-build,twolame))
347 $(call rules,$(call std-build,x264))
348 $(call rules,$(call std-build,x265))
349 $(call rules,$(call std-build,libvpx))
350 $(call rules,$(call std-build,lv2))
351 $(call rules,$(call std-build,serd))
352 $(call rules,$(call std-build,sord, serd))
353 $(call rules,$(call std-build,sratom, serd sord lv2))
354 $(call rules,$(call std-build,lilv, lv2 sratom serd sord))
355 $(call rules,$(call std-build,suil, lv2))
356 $(call rules,$(call std-build,ffnvcodec))
357
358 # specialize festival, multiple tarballs
359 festival:
360 .PHONY: festival festival-configure festival-src
361 festival: $(call pkg-built,festival)
362 festival-configure: $(call pkg-config,festival)
363 festival-src: $(call pkg-source,festival)
364 festival-clean:
365         rm -rf festival* $(BLD)/festival.*
366
367 $(call pkg-source,festival):
368         for f in src/festival* src/festlex_* src/festvox_*; do tar -xJf $$f; done
369         touch $@
370
371 $(call pkg-config,festival): $(call pkg-source,festival) $(call pkg-built,speech_tools)
372         cd festival* && [ -f ./configure ] && \
373                 ./configure
374         touch $@
375
376 $(call pkg-built,festival): $(call pkg-config,festival)
377         $(MAKE) -C festival* -j1
378         touch $@
379
380 clean:
381         for f in $(static_pkgs); do rm -rf $$f*; done
382         rm -rf $(BLD)
383
384 install:
385         cp -a $(ver_mjpegtools)/mpeg2enc/mpeg2enc $(BINDIR)/.
386         cp -a $(ver_mjpegtools)/mplex/mplex $(BINDIR)/.
387 else
388 # not WANT_CIN_3RDPARTY
389 all:
390 clean:
391 install:
392
393 endif
394 val-%:
395         @echo $($(subst val-,,$@))
396