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