andrew file-exr/png/tiff mods, png add depth/compression, exr add b44-dwab, tiff...
[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 $(filter $(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)),$(filter $(1),$(shared_pkgs))),$(2))
63 if_want=$(if $(filter x$(WANT_$(1)),xyes),$(2),$(3))
64 sysincs:=usr/include usr/local/include
65 syslibs:=usr/lib usr/lib32 usr/lib64 lib lib32 lib64 usr/local/lib usr/local/lib32 usr/local/lib64
66 pkg_incl=$(lastword $(wildcard $(foreach f,$(sysincs), $(call bld_path,$(1),$(f)))))
67 pkg_libs=$(lastword $(wildcard $(foreach f,$(syslibs), $(call bld_path,$(1),$(f)))))
68
69 #$(eval $(call std-build,pkg,deps...))
70 #$(pkg.cflags) added as CFLAGS+=$(cflags) to pkg.vars
71 #$(pkg.cppflags) added as CPPFLAGS+=$(cppflags) to pkg.vars
72 #$(pkg.cfg_vars) prepended to configure
73 #$(pkg.cfg_params) appended to configure
74 #$(pkg.mak_vars) prepended to make
75 #$(pkg.mak_params) appended to make
76
77 define std-build
78 # $(1)
79 .PHONY: $(1) $(1)-configure $(1)-src $(1)-clean
80 $(1): $(call pkg-built,$(1))
81 $(1)-configure: $(call pkg-config,$(1))
82 $(1)-src: $(call pkg-source,$(1))
83 $(1)-clean:
84         rm -rf $(1)* $(BLD)/$(1).*
85
86 $(call pkg-source,$(1)):
87         $(call unpack,$(call tarball,$(1))) \
88         $(foreach pch,$(sort $(wildcard src/$(notdir $(ver_$(1))).patch*)),
89                 patch -d $(1)* -p1 < $(pch))
90         touch $$@
91
92 $(call pkg-config,$(1)): $(call pkg-source,$(1)) $(foreach dep,$(2),$(call bld_depends,$(dep)))
93         @echo "CONFIGURING $(1)"
94         cd $(1)* && \
95                 $($(1).cfg_vars) $(CFG_VARS) ./configure $($(1).cfg_params) $(CFG_PARAMS)
96         touch $$@
97
98 $(call pkg-built,$(1)): $(call pkg-config,$(1))
99         +$($(1).mak_vars) $(MAK_VARS) $(MAKE) -C $(1)* $($(1).mak_params) $(MAK_PARAMS)
100         touch $$@
101
102 endef
103
104 TARGETS := $(static_blds)
105
106 all:    $(TARGETS)
107
108 $(TARGETS):     $(BLD)
109
110 $(BLD):
111         mkdir $(BLD)
112
113 # pkg-config names
114 pc_libaom=aom
115 pc_dav1d=dav1d
116 pc_libwebp=libwebp libwebpmux
117 pc_opus=opus
118 pc_openjpeg=libopenjp2
119 pc_libvorbis=vorbis vorbisenc
120 pc_libvpx=vpx
121 pc_x264=x264
122 pc_x265=x265
123
124 # vars first
125 encore.cfg_vars= true ||
126 esound.cfg_vars:= AUDIOFILE_CFLAGS="$(call inc_path,audiofile) -laudiofile"
127 esound.cfg_vars+= AUDIOFILE_LIBS="$(call ld_path,audiofile,libaudiofile/.libs)"
128 esound.cfg_params= --enable-shared=no --with-pic
129 esound.mak_vars+= CFLAGS="" 
130 esound.ldflags=" -lm -lstdc++"
131 fftw.cfg_params= --disable-fortran --enable-shared=no
132 ffmpeg.cfg_params= \
133         --enable-pthreads --enable-gpl --disable-ffplay \
134         $(call if_want,VAAPI,--enable-vaapi,--disable-vaapi) \
135         $(call if_want,VDPAU,--enable-vdpau,--disable-vdpau) \
136         $(call if_want,NV, --enable-nvenc --enable-nvdec --enable-ffnvcodec) \
137         $(call if_ena,twolame,--enable-libtwolame) \
138         $(call if_ena,openjpeg,--enable-libopenjpeg) \
139         $(call if_ena,lame,--enable-libmp3lame) \
140         $(call if_ena,libaom,--enable-libaom) \
141         $(call if_ena,dav1d,--enable-libdav1d) \
142         $(call if_ena,libwebp,--enable-libwebp) \
143         $(call if_ena,opus,--enable-libopus) \
144         $(call if_ena,libvorbis,--enable-libvorbis) \
145         $(call if_ena,libtheora,--enable-libtheora) \
146         $(call if_ena,libvpx,--enable-libvpx) \
147         $(call if_ena,x264,--enable-libx264) \
148         $(call if_ena,x265,--enable-libx265) \
149         --extra-cflags="-Wno-attributes \
150                 $(call if_want,NV,$(inc_ffnvcodec)) \
151                 $(call inc_path,twolame) \
152                 $(call inc_path,lame) \
153                 $(call inc_path,libaom) \
154                 $(call inc_path,dav1d) \
155                 $(call inc_path,libwebp) \
156                 $(call inc_path,openjpeg) \
157                 $(call inc_path,libogg) \
158                 $(call inc_path,opus) \
159                 $(call inc_path,libvorbis) \
160                 $(call inc_path,libtheora) \
161                 $(call inc_path,libvpx) \
162                 $(call inc_path,x264) \
163                 $(call inc_path,x265)" \
164         --extra-cxxflags="-D__STDC_CONSTANT_MACROS" \
165         --pkg-config=true \
166         --extra-libs="-Wl,--start-group \
167                 $(call ld_path,twolame,libtwolame/.libs) \
168                 $(call ld_path,lame,libmp3lame/.libs) \
169                 $(call ld_path,libaom,usr/local/lib) \
170                 $(call ld_path,dav1d,usr/local/lib) \
171                 $(call ld_path,libwebp,usr/local/lib) \
172                 $(call ld_path,openjpeg,bin) \
173                 $(call ld_path,opus,.libs) \
174                 $(call ld_path,libogg,lib/.libs) \
175                 $(call ld_path,libvorbis,lib/.libs) \
176                 $(call ld_path,libtheora,lib/.libs) \
177                 $(call ld_path,libvpx) \
178                 $(call ld_path,x264) \
179                 $(call ld_path,x265) \
180                 $(shared_libs) \
181                 -Wl,--end-group -lm -lstdc++ -pthread \
182                 $(EXTRA_LIBS)" $(FFMPEG_EXTRA_CFG) \
183
184 #cmake_config=echo "exec cmake \$$$$@ $(1)" > ./configure; chmod +x ./configure;
185 cmake_config=echo 'cmake "$$$$@" "$(1)"' > ./configure; chmod +x ./configure;
186 a52dec.mak_params?= ; cd $(call bld_path,a52dec,include); ln -sf . a52dec
187 a52dec.cfg_vars?= CFLAGS+=" -U__FreeBSD__ $(call inc_path,djbfft)" LIBS+=" $(call ld_path,djbfft)"
188 a52dec.cfg_params?=--enable-djbfft
189 djbfft.cfg_vars?=echo "$(call bld_path,djbfft)" > conf-home; \
190  (CFLAGS="$(CFLAGS)"; $(CFG_VARS)$(if $(CFG_VARS),; )echo "$(CC) $$$$CFLAGS") > conf-cc; \
191  echo > ./configure; chmod +x ./configure;
192 djbfft.mak_params?=; cd $(call bld_path,djbfft); ln -sf djbfft.a libdjbfft.a
193 audiofile.cfg_params?=--enable-shared=no
194 audiofile.mak_params?=LIBS="-lm -lstdc++"
195 flac.cfg_params?= --enable-shared=no
196 flac.cflags?="$(call inc_path,libogg) $(call ld_path,libogg,src/.libs)"
197 giflib.cfg_params=echo "exec true" > ./configure; chmod +x ./configure;
198 ilmbase.cfg_vars= CFLAGS+=" -Wno-narrowing" CXXFLAGS+=" -Wno-narrowing"
199 ilmbase.cfg_params?=--prefix=$(call bld_path,ilmbase,usr)
200 ilmbase.mak_params?=; $(MAKE) -C ilmbase* install; cd $(call bld_path,ilmbase); ln -sf lib64 usr/lib
201 lame.cfg_vars?= CFLAGS+=" -O"
202 lame.cfg_params?=--enable-shared=no
203 lame.mak_params?= ; cd $(call bld_path,lame,include); ln -sf . lame
204 libaom.cfg_vars?=$(call cmake_config,aom-master)
205 libaom.cfg_params?= -DENABLE_SHARED=no -DCMAKE_INSTALL_LIBDIR=lib \
206  -DCMAKE_INSTALL_PREFIX=$(call bld_path,libaom)/usr/local
207 libaom.mak_params?= ; $(MAKE) -C libaom* install
208 dav1d.cfg_vars?=echo "echo dav1d custom make" >> configure; chmod +x ./configure;
209 dav1d.mak_params?=; $(MAKE) -C dav1d* install DESTDIR="$(call bld_path,dav1d)"
210 libwebp.cfg_vars?= mkdir build && cd build && $(call cmake_config,..)
211 libwebp.mak_params?= -C build all install DESTDIR=$(call bld_path,libwebp)
212 mjpegtools.cflags?="$(call inc_path,libjpeg) $(call ld_path,libjpeg,build)"
213 mjpegtools.cfg_vars?= ./autogen.sh; 
214 mjpegtools.cfg_params?= --enable-shared=no --without-libsdl --without-sdlgfx --without-v4l
215 mjpegtools.mak_params?= all
216 ladspa.cfg_vars?= CFLAGS+=' -Dinline="" '
217 ladspa.mak_params?=; $(MAKE) -C ladspa* install DESTDIR=$(call bld_path,ladspa)
218 libavc1394.cfg_vars?=PKG_CONFIG_PATH=$(call bld_path,libraw1394)
219 libavc1394.cflags?="$(call inc_path,libraw1394)"
220 libavc1394.ldflags?="$(call ld_path,libraw1394,src/.libs)"
221 libavc1394.cfg_params?= --enable-shared=no
222 libavc1394.mak_params?=; cd $(call bld_path,libavc1394); ln -sf ../librom1394/rom1394.h libavc1394/.
223 libdv.cfg_params?= --disable-gtk --enable-shared=no
224 libiec61883.cfg_vars?=PKG_CONFIG_PATH=$(call bld_path,libraw1394)
225 libiec61883.cflags?="$(call inc_path,libraw1394)"
226 libiec61883.ldflags?="$(call ld_path,libraw1394,src/.libs)"
227 libiec61883.cfg_params?= --enable-shared=no
228 libiec61883.mak_params?=; cd $(call bld_path,libiec61883,src); ln -sf . libiec61883
229 libjpeg.cfg_vars?= mkdir build && cd build && $(call cmake_config,..)
230 libjpeg.cfg_params?= -DENABLE_SHARED=no -DCMAKE_INSTALL_LIBDIR=lib 
231 libjpeg.mak_params?= -C build all install DESTDIR=$(call bld_path,libjpeg)
232 libogg.cfg_params?= --enable-shared=no
233 libraw1394.cfg_params?=  --enable-shared=no; ln -sf src libraw1394
234 libtheora.cfg_vars?=PKG_CONFIG_PATH=$(call bld_path,libogg):$(call bld_path,libvorbis)
235 libtheora.cflags?="$(call inc_path,libogg) $(call inc_path,libvorbis)"
236 libtheora.ldflags?="$(call ld_path,libvorbis,lib/.libs) $(call ld_path,libogg,src/.libs)"
237 libtheora.cfg_params?= --disable-examples --disable-spec --enable-shared=no
238 libuuid.cfg_params?=--enable-shared=no
239 libvorbis.cfg_params?= --disable-oggtest --enable-shared=no
240 openjpeg.cfg_params?= -DBUILD_SHARED_LIBS:BOOL=OFF
241 openjpeg.cfg_vars?=$(call cmake_config,.)
242 openjpeg.mak_params?= ; cd $(call bld_path,openjpeg,src/lib/openjp2); ln -sf . openjpeg-2.1
243 opencv.cfg_vars?=$(call cmake_config,.)
244 opencv.cfg_params?= -DBUILD_SHARED_LIBS:BOOL=OFF
245 openexr.cfg_vars?=LD_LIBRARY_PATH=$(call bld_path,ilmbase,usr/lib)
246 openexr.cfg_params?=--enable-shared=no --with-ilmbase-prefix=$(call bld_path,ilmbase,usr)
247 speech_tools.mak_params?=-j1
248 tiff.cfg_vars+=LIBS+=" -lpthread"
249 tiff.cfg_params+= --enable-shared=no --disable-zstd $(call if_pkg,libwebp,\
250  --with-webp-include-dir=$(call pkg_incl,libwebp)\
251  --with-webp-lib-dir=$(call pkg_libs,libwebp))
252 twolame.cfg_params?=--enable-shared=no
253 x264.cfg_params?= --enable-static --enable-pic
254 x265.cfg_vars?=$(call cmake_config,source)
255 x265.cfg_params?= -DENABLE_SHARED=no
256 libvpx.cfg_params?= --enable-pic
257
258 DS:=$$$$$$$$
259 pkg_cfg=$(call bld_path,$(1),usr/local/lib/pkgconfig):
260 LV2_PKGCFG:=$(subst : ,:,$(foreach p,lv2 serd sord sratom lilv suil,$(call pkg_cfg,$(p))))
261
262 # lv2
263 define waf-setup
264 $(1).cfg_vars+=./waf --version; find .waf* -type f -name "*.py" | \
265  while read f; do sed -e '/StopIter/d' -i "$(DS)f"; done; \
266  echo 'exec ./waf configure "$(DS)@"' > ./configure; chmod +x \
267  ./configure;  PKG_CONFIG_PATH=$(LV2_PKGCFG) LD_LIBRARY_PATH=$(LV2_LIBPATH) 
268 $(1).cfg_params+=\
269  CFLAGS="-I$(call bld_path,lv2) $(foreach f,$(2), $(call inc_path,$(f))) -fPIC -std=c99"\
270  LDFLAGS="-lm $(foreach f,$(2), $(call ld_path,$(f),usr/local/lib)) "
271 $(1).mak_vars=(echo "all:"; echo "      ./waf -v build") > $(call bld_path,$(1),Makefile); 
272 $(1).mak_params+=; ( cd $(1)*; ./waf install --destdir=$(call bld_path,$(1)) )
273 endef
274
275 SYS_LIB:=$(notdir $(lastword $(wildcard /usr/lib /usrlib32 /usr/lib64)))
276 SYS_LV2:=$(lastword $(wildcard /usr/$(SYS_LIB)/lv2 /usr/local/$(SYS_LIB)/lv2))
277 $(if $(SYS_LV2),,$(eval SYS_LV2:=/usr/$(SYS_LIB)/lv2))
278 lv2.cfg_params?= --lv2dir=$(SYS_LV2)
279 SYS_LV2_PATH:=/usr/$(SYS_LIB)/lv2: /usr/local/$(SYS_LIB)/lv2:
280 DFT_LV2_PATH:= /usr/lib64/lv2: /usr/lib/lv2: /usr/local/lib64/lv2: /usr/local/lib/lv2: 
281 LV2_PATH:=$(subst : ,:,$(SYS_LV2_PATH)$(filter-out $(SYS_LV2_PATH),$(DFT_LV2_PATH)))
282 lilv.cfg_params?= --static --default-lv2-path=$(LV2_PATH)
283 sratom.cfg_params?= --static --no-shared
284 serd.cfg_params?= --static --no-shared
285 sord.cfg_params?= --static --no-shared
286 lilv.cfg_params?= --static --dyn-manifest
287 suil.cfg_params?= --static --no-qt
288
289 $(eval $(call waf-setup,lv2))
290 $(eval $(call waf-setup,serd))
291 $(eval $(call waf-setup,sord, serd))
292 $(eval $(call waf-setup,sratom, serd sord lv2))
293 $(eval $(call waf-setup,lilv, lv2 sratom serd sord))
294 $(eval $(call waf-setup,suil, lv2))
295
296 # add softlinks for legacy paths
297 waf_link=$(1).mak_params+=; (cd $(1)*; ln -s $(1)-0/$(1) usr/local/include/.)
298 $(foreach p,sratom serd sord lilv suil,$(eval $(call waf_link,$(p))))
299
300 # compile flag vars
301 $(foreach tgt,$(TARGETS), \
302         $(if $($(tgt).cflags),$(eval $(tgt).cfg_vars+=CFLAGS+=$($(tgt).cflags))))
303 $(foreach tgt,$(TARGETS), \
304         $(if $($(tgt).cppflags),$(eval $(tgt).cfg_vars+=CPPFLAGS+=$($(tgt).cppflags))))
305 $(foreach tgt,$(TARGETS), \
306         $(if $($(tgt).ldflags),$(eval $(tgt).cfg_vars+=LDFLAGS+=$($(tgt).ldflags))))
307
308 # build rules
309 .PHONY: rules
310 rules:
311
312 #$(eval $(call std-build,pkg,deps...))
313
314 ifeq ($(MAKECMDGOALS),rules)
315 rules=$(info $(1))
316 else
317 rules=$(eval $(1))
318 endif
319
320 $(call rules,$(call std-build,a52dec,djbfft))
321 $(call rules,$(call std-build,djbfft))
322 $(call rules,$(call std-build,audiofile))
323 $(call rules,$(call std-build,encore))
324 $(call rules,$(call std-build,esound,audiofile))
325 $(call rules,$(call std-build,ffmpeg, twolame lame openjpeg opus \
326         libtheora x264 x265 libvpx libaom dav1d libwebp \
327         $(call if_want,NV, ffnvcodec)))
328 $(call rules,$(call std-build,fftw))
329 $(call rules,$(call std-build,flac,libogg))
330 $(call rules,$(call std-build,giflib))
331 $(call rules,$(call std-build,ilmbase))
332 $(call rules,$(call std-build,ladspa))
333 $(call rules,$(call std-build,lame))
334 $(call rules,$(call std-build,libaom))
335 $(call rules,$(call std-build,dav1d))
336 $(call rules,$(call std-build,libwebp))
337 $(call rules,$(call std-build,libavc1394,libraw1394))
338 $(call rules,$(call std-build,libdv))
339 $(call rules,$(call std-build,libiec61883,libraw1394))
340 $(call rules,$(call std-build,libjpeg))
341 $(call rules,$(call std-build,libogg))
342 $(call rules,$(call std-build,libraw1394))
343 $(call rules,$(call std-build,libsndfile))
344 $(call rules,$(call std-build,libtheora, libogg libvorbis))
345 $(call rules,$(call std-build,libuuid))
346 $(call rules,$(call std-build,libvorbis))
347 $(call rules,$(call std-build,mjpegtools, libjpeg))
348 $(call rules,$(call std-build,opencv))
349 $(call rules,$(call std-build,openexr, ilmbase))
350 $(call rules,$(call std-build,openjpeg))
351 $(call rules,$(call std-build,opus))
352 $(call rules,$(call std-build,speech_tools))
353 $(call rules,$(call std-build,tiff, libwebp))
354 $(call rules,$(call std-build,twolame))
355 $(call rules,$(call std-build,x264))
356 $(call rules,$(call std-build,x265))
357 $(call rules,$(call std-build,libvpx))
358 $(call rules,$(call std-build,lv2))
359 $(call rules,$(call std-build,serd))
360 $(call rules,$(call std-build,sord, serd))
361 $(call rules,$(call std-build,sratom, serd sord lv2))
362 $(call rules,$(call std-build,lilv, lv2 sratom serd sord))
363 $(call rules,$(call std-build,suil, lv2))
364 $(call rules,$(call std-build,ffnvcodec))
365
366 # specialize festival, multiple tarballs
367 festival:
368 .PHONY: festival festival-configure festival-src
369 festival: $(call pkg-built,festival)
370 festival-configure: $(call pkg-config,festival)
371 festival-src: $(call pkg-source,festival)
372 festival-clean:
373         rm -rf festival* $(BLD)/festival.*
374
375 $(call pkg-source,festival):
376         for f in src/festival* src/festlex_* src/festvox_*; do tar -xJf $$f; done
377         touch $@
378
379 $(call pkg-config,festival): $(call pkg-source,festival) $(call pkg-built,speech_tools)
380         cd festival* && [ -f ./configure ] && \
381                 ./configure
382         touch $@
383
384 $(call pkg-built,festival): $(call pkg-config,festival)
385         $(MAKE) -C festival* -j1
386         touch $@
387
388 clean:
389         for f in $(static_pkgs); do rm -rf $$f*; done
390         rm -rf $(BLD)
391
392 install:
393         cp -a $(ver_mjpegtools)/mpeg2enc/mpeg2enc $(BINDIR)/.
394         cp -a $(ver_mjpegtools)/mplex/mplex $(BINDIR)/.
395 else
396 # not WANT_CIN_3RDPARTY
397 all:
398 clean:
399 install:
400
401 endif
402 val-%:
403         @echo $($(subst val-,,$@))
404