1 # Main makefile for VLC 3rd party libraries ("contrib")
2 # Copyright (C) 2003-2011 the VideoLAN team
4 # This file is under the same license as the vlc package.
9 SRC_BUILT
:= $(TOPSRC_BUILT
)/src
10 TARBALLS
:= $(TOPSRC
)/tarballs
11 VLC_TOOLS ?
= $(TOPSRC
)/..
/extras
/tools
/build
13 PATH
:=$(abspath
$(VLC_TOOLS
)/bin
):$(PATH
)
16 PKGS_ALL
:= $(patsubst $(SRC
)/%/rules.mak
,%,$(wildcard $(SRC
)/*/rules.mak
))
17 DATE
:= $(shell date
+%Y
%m
%d
)
20 # Common download locations
21 GNU ?
= http
://ftp.gnu.org
/gnu
22 SF
:= https
://netcologne.dl.sourceforge.net
/
23 VIDEOLAN
:= http
://downloads.videolan.org
/pub
/videolan
24 CONTRIB_VIDEOLAN
:= http
://downloads.videolan.org
/pub
/contrib
25 GITHUB
:= https
://github.com
/
28 # Machine-dependent variables
31 PREFIX ?
= $(TOPDST
)/$(HOST
)
32 PREFIX
:= $(abspath
$(PREFIX
))
33 BUILDPREFIX ?
= $(TOPDST
)
34 BUILDPREFIX
:= $(abspath
$(BUILDPREFIX
))
35 BUILDBINDIR ?
= $(BUILDPREFIX
)/bin
36 ifneq ($(HOST
),$(BUILD
))
37 HAVE_CROSS_COMPILE
= 1
39 ARCH
:= $(shell $(SRC
)/get-arch.sh
$(HOST
))
41 ifeq ($(ARCH
)-$(HAVE_WIN32
),x86_64-1
)
44 ifeq ($(ARCH
)-$(HAVE_WIN32
),aarch64-1
)
48 ifdef HAVE_CROSS_COMPILE
51 ifeq ($(findstring mingw32
,$(BUILD
)),mingw32
)
52 need_pkg
= $(shell PKG_CONFIG_LIBDIR
="${PKG_CONFIG_PATH}" $(PKG_CONFIG
) $(1) || echo
1)
54 need_pkg
= $(shell $(PKG_CONFIG
) $(1) || echo
1)
58 ifeq ($(findstring mingw32
,$(BUILD
)),mingw32
)
61 ifeq ($(findstring msys
,$(BUILD
)),msys
)
66 # Default values for tools
68 ifndef HAVE_CROSS_COMPILE
69 ifneq ($(findstring $(origin CC
),undefined default
),)
72 ifneq ($(findstring $(origin CXX
),undefined default
),)
75 ifneq ($(findstring $(origin LD
),undefined default
),)
78 ifneq ($(findstring $(origin AR
),undefined default
),)
81 ifneq ($(findstring $(origin RANLIB
),undefined default
),)
84 ifneq ($(findstring $(origin STRIP
),undefined default
),)
87 ifneq ($(findstring $(origin WIDL
),undefined default
),)
90 ifneq ($(findstring $(origin WINDRES
),undefined default
),)
94 ifneq ($(findstring $(origin CC
),undefined default
),)
97 ifneq ($(findstring $(origin CXX
),undefined default
),)
100 ifneq ($(findstring $(origin LD
),undefined default
),)
103 ifneq ($(findstring $(origin AR
),undefined default
),)
106 ifneq ($(findstring $(origin RANLIB
),undefined default
),)
107 RANLIB
:= $(HOST
)-ranlib
109 ifneq ($(findstring $(origin STRIP
),undefined default
),)
110 STRIP
:= $(HOST
)-strip
112 ifneq ($(findstring $(origin WIDL
),undefined default
),)
115 ifneq ($(findstring $(origin WINDRES
),undefined default
),)
116 WINDRES
:= $(HOST
)-windres
121 ifneq ($(findstring $(origin CC
),undefined default
),)
124 ifneq ($(findstring $(origin CXX
),undefined default
),)
130 EXTRA_CXXFLAGS
+= -stdlib
=libc
++
131 ifeq ($(ARCH
),x86_64
)
133 EXTRA_LDFLAGS
+= -m64
136 EXTRA_LDFLAGS
+= -m32
139 XCODE_FLAGS
+= -arch
$(ARCH
)
147 AS
=perl
$(abspath
$(VLC_TOOLS
)/bin
/gas-preprocessor.pl
) $(CC
)
148 CCAS
=gas-preprocessor.pl
$(CC
) -c
154 ifneq ($(shell $(CC
) $(CFLAGS
) -E
-dM
-include _mingw.h
- < /dev
/null | grep
-E __MINGW64_VERSION_MAJOR
),)
157 ifndef HAVE_CROSS_COMPILE
163 ifeq ($(ARCH
),x86_64
)
165 EXTRA_LDFLAGS
+= -m64
168 EXTRA_LDFLAGS
+= -m32
173 EXTRA_CFLAGS
+= -DWINSTORECOMPAT
174 EXTRA_LDFLAGS
+= -lwinstorecompat
177 ifneq ($(findstring clang
, $(shell $(CC
) --version
2>/dev
/null
)),)
181 cppcheck
= $(shell $(CC
) $(CFLAGS
) -E
-dM
- < /dev
/null | grep
-E
$(1))
183 EXTRA_CFLAGS
+= -I
$(PREFIX
)/include
184 CPPFLAGS
:= $(CPPFLAGS
) $(EXTRA_CFLAGS
)
185 CFLAGS
:= $(CFLAGS
) $(EXTRA_CFLAGS
) -g
186 CXXFLAGS
:= $(CXXFLAGS
) $(EXTRA_CFLAGS
) $(EXTRA_CXXFLAGS
) -g
187 LDFLAGS
:= $(LDFLAGS
) -L
$(PREFIX
)/lib
$(EXTRA_LDFLAGS
)
190 CFLAGS
:= $(CFLAGS
) -gcodeview
191 CXXFLAGS
:= $(CXXFLAGS
) -gcodeview
194 ifndef WITH_OPTIMIZATION
195 CFLAGS
:= $(CFLAGS
) -O0
196 CXXFLAGS
:= $(CXXFLAGS
) -O0
198 CFLAGS
:= $(CFLAGS
) -O2
199 CXXFLAGS
:= $(CXXFLAGS
) -O2
202 # Do not export those! Use HOSTVARS.
204 # Do the FPU detection, after we have figured out our compilers and flags.
205 ifneq ($(findstring $(ARCH
),aarch64 i386 ppc ppc64 sparc sparc64 x86_64
),)
206 # This should be consistent with include/vlc_cpu.h
208 else ifneq ($(findstring $(ARCH
),arm
),)
209 ifneq ($(call cppcheck
, __VFP_FP__
)),)
210 ifeq ($(call cppcheck
, __SOFTFP__
),)
214 else ifneq ($(call cppcheck
, __mips_hard_float
),)
218 ACLOCAL_AMFLAGS
+= -I
$(PREFIX
)/share
/aclocal
219 ifneq ($(wildcard $(VLC_TOOLS
)/share
/aclocal
/*),)
220 ACLOCAL_AMFLAGS
+= -I
$(abspath
$(VLC_TOOLS
)/share
/aclocal
)
222 export ACLOCAL_AMFLAGS
228 PKG_CONFIG ?
= pkg-config
229 ifdef HAVE_CROSS_COMPILE
230 # This inhibits .pc file from within the cross-compilation toolchain sysroot.
231 # Hopefully, nobody ever needs that.
232 PKG_CONFIG_PATH
:= /usr
/share
/pkgconfig
233 PKG_CONFIG_LIBDIR
:= /usr
/$(HOST
)/lib
/pkgconfig
234 export PKG_CONFIG_LIBDIR
236 PKG_CONFIG_PATH
:= $(PREFIX
)/lib
/pkgconfig
:$(PKG_CONFIG_PATH
)
237 ifeq ($(findstring mingw32
,$(BUILD
)),mingw32
)
238 PKG_CONFIG_PATH
:= $(shell cygpath
-pm
${PKG_CONFIG_PATH})
240 export PKG_CONFIG_PATH
243 ifeq ($(shell git
--version
>/dev
/null
2>&1 || echo FAIL
),)
247 GIT ?
= $(error git not found
)
250 ifeq ($(shell svn
--version
>/dev
/null
2>&1 || echo FAIL
),)
254 SVN ?
= $(error subversion client
(svn
) not found
)
256 ifeq ($(shell curl
--version
>/dev
/null
2>&1 || echo FAIL
),)
257 download
= curl
-f
-L
-- "$(1)" > "$@"
258 else ifeq ($(shell wget
--version
>/dev
/null
2>&1 || echo FAIL
),)
259 download
= (rm -f
$@.tmp
&& \
260 wget
--passive
-c
-p
-O
$@.tmp
"$(1)" && \
263 else ifeq ($(which fetch
>/dev
/null
2>&1 || echo FAIL
),)
264 download
= (rm -f
$@.tmp
&& \
265 fetch
-p
-o
$@.tmp
"$(1)" && \
269 download
= $(error Neither curl nor wget found
)
272 download_pkg
= $(call download
,$(CONTRIB_VIDEOLAN
)/$(2)/$(lastword
$(subst /, ,$(@
)))) || \
273 ( $(call download
,$(1)) && echo
"Please upload this package $(lastword $(subst /, ,$(@))) to our FTP" )
275 ifeq ($(shell which xz
>/dev
/null
2>&1 || echo FAIL
),)
278 XZ ?
= $(error XZ
(LZMA
) compressor not found
)
281 ifeq ($(shell sha512sum
--version
>/dev
/null
2>&1 || echo FAIL
),)
282 SHA512SUM
= sha512sum
--check
283 else ifeq ($(shell shasum
--version
>/dev
/null
2>&1 || echo FAIL
),)
284 SHA512SUM
= shasum
-a
512 --check
285 else ifeq ($(shell openssl version
>/dev
/null
2>&1 || echo FAIL
),)
286 SHA512SUM
= openssl dgst
-sha512
288 SHA512SUM
= $(error SHA-512 checksumming not found
)
291 ifeq ($(shell protoc
--version
>/dev
/null
2>&1 || echo FAIL
),)
294 PROTOC ?
= $(error Protobuf compiler
(protoc
) not found
)
300 HOSTCONF
:= --prefix="$(PREFIX)"
301 HOSTCONF
+= --datarootdir
="$(PREFIX)/share"
302 HOSTCONF
+= --includedir="$(PREFIX)/include"
303 HOSTCONF
+= --libdir="$(PREFIX)/lib"
304 HOSTCONF
+= --build
="$(BUILD)" --host
="$(HOST)" --target
="$(HOST)"
305 HOSTCONF
+= --program-prefix
=""
307 HOSTCONF
+= --enable-static
--disable-shared
--disable-dependency-tracking
309 HOSTCONF
+= --without-pic
312 HOSTCONF
+= --with-pic
317 CC
="$(CC)" CXX
="$(CXX)" LD
="$(LD)" \
318 AR
="$(AR)" CCAS
="$(CCAS)" RANLIB
="$(RANLIB)" STRIP
="$(STRIP)" \
319 PATH
="$(PREFIX)/bin:$(PATH)"
320 HOSTVARS
:= $(HOSTTOOLS
) \
321 CPPFLAGS
="$(CPPFLAGS)" \
323 CXXFLAGS
="$(CXXFLAGS)" \
325 HOSTVARS_PIC
:= $(HOSTTOOLS
) \
326 CPPFLAGS
="$(CPPFLAGS) $(PIC)" \
327 CFLAGS
="$(CFLAGS) $(PIC)" \
328 CXXFLAGS
="$(CXXFLAGS) $(PIC)" \
331 # For cross-compilation with meson, do not set compiler and flags
332 # in HOSTVARS as meson will always use them for the BUILD machine compiler!
333 ifdef HAVE_CROSS_COMPILE
334 HOSTVARS_MESON
:= PATH
="$(PREFIX)/bin:$(PATH)"
336 HOSTVARS_MESON
:= $(HOSTVARS
)
340 rm -Rf
-- "$(@:.tar.xz=)" && \
341 $(GIT
) init
--bare
"$(@:.tar.xz=)" && \
342 (cd
"$(@:.tar.xz=)" && \
343 $(GIT
) remote add
origin "$(1)" && \
344 $(GIT
) fetch
origin "$(2)") && \
345 (cd
"$(@:.tar.xz=)" && \
346 $(GIT
) archive
--prefix="$(notdir $(@:.tar.xz=))/" \
347 --format
=tar "$(3)") > "$(@:.xz=)" && \
348 echo
"$(3) $(@)" > "$(@:.tar.xz=.githash)" && \
349 rm -Rf
-- "$(@:.tar.xz=)" && \
350 $(XZ
) --stdout
"$(@:.xz=)" > "$@.tmp" && \
351 rm -f
"$(@:.xz=)" && \
352 mv
-f
-- "$@.tmp" "$@"
354 h
=`sed -e "s,^\([0-9a-fA-F]\{40\}\) .*/$(notdir $<),\1,g" \
355 < "$(<:.tar.xz=.githash)"` && \
359 $(foreach f
,$(filter $(TARBALLS
)/%,$^
), \
360 grep
-- " $(f:$(TARBALLS)/%=%)$$" \
361 "$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS" &&) \
362 (cd
$(TARBALLS
) && $(1) /dev
/stdin
) < \
363 "$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS"
364 CHECK_SHA512
= $(call checksum
,$(SHA512SUM
),SHA512
)
365 UNPACK
= $(RM
) -R
$@ \
366 $(foreach f
,$(filter %.
tar.gz
%.tgz
,$^
), && tar xvzfo
$(f
)) \
367 $(foreach f
,$(filter %.
tar.bz2
,$^
), && tar xvjfo
$(f
)) \
368 $(foreach f
,$(filter %.
tar.xz
,$^
), && tar xvJfo
$(f
)) \
369 $(foreach f
,$(filter %.zip
,$^
), && unzip
$(f
))
370 UNPACK_DIR
= $(patsubst %.
tar,%,$(basename $(notdir $<)))
371 APPLY
= (cd
$(UNPACK_DIR
) && patch
-fp1
) <
372 pkg_static
= (cd
$(UNPACK_DIR
) && $(SRC_BUILT
)/pkg-static.sh
$(1))
373 MOVE
= mv
$(UNPACK_DIR
) $@
&& touch
$@
375 AUTOMAKE_DATA_DIRS
=$(foreach n
,$(foreach n
,$(subst :, ,$(shell echo
$$PATH)),$(abspath
$(n
)/..
/share
)),$(wildcard $(n
)/automake
*))
376 UPDATE_AUTOCONFIG
= for
dir in
$(AUTOMAKE_DATA_DIRS
); do \
377 if
test -f
"$${dir}/config.sub" -a
-f
"$${dir}/config.guess"; then \
378 cp
"$${dir}/config.sub" "$${dir}/config.guess" $(UNPACK_DIR
); \
384 AUTORECONF
= AUTOPOINT
=true autoreconf
386 AUTORECONF
= autoreconf
388 RECONF
= mkdir
-p
-- $(PREFIX
)/share
/aclocal
&& \
389 cd
$< && $(AUTORECONF
) -fiv
$(ACLOCAL_AMFLAGS
)
390 CMAKE
= cmake .
-DCMAKE_TOOLCHAIN_FILE
=$(abspath toolchain.cmake
) \
391 -DCMAKE_INSTALL_PREFIX
=$(PREFIX
) $(CMAKE_GENERATOR
) -DCMAKE_DEBUG_POSTFIX
:STRING
=
393 CMAKE
+= -DCMAKE_LINK_LIBRARY_SUFFIX
:STRING
=.a
397 CMAKE
+= -DCMAKE_VERBOSE_MAKEFILE
:BOOL
=ON
400 MESON
= meson
--default-library static
--prefix "$(PREFIX)" --backend ninja \
402 ifndef WITH_OPTIMIZATION
403 MESON
+= --buildtype debug
405 MESON
+= --buildtype release
408 ifdef HAVE_CROSS_COMPILE
409 MESON
+= --cross-file
$(abspath crossfile.meson
)
415 REQUIRE_GPL
= @echo
"Package \"$<\" requires the GPL license." >&2; exit
1
421 @echo
"Package \"$<\" requires the version 3 of GNU licenses." >&2; \
426 # Per-package build rules
429 include $(SRC
)/*/rules.mak
431 ifeq ($(PKGS_DISABLE
), all)
437 ifneq ($(filter $(PKGS_DISABLE
),$(PKGS_ENABLE
)),)
438 $(error Same package
(s
) disabled and enabled at the same time
)
440 # Apply automatic selection (= remove distro packages):
441 PKGS_AUTOMATIC
:= $(filter-out $(PKGS_FOUND
),$(PKGS
))
442 # Apply manual selection (from bootstrap):
443 PKGS_MANUAL
:= $(sort $(PKGS_ENABLE
) $(filter-out $(PKGS_DISABLE
),$(PKGS_AUTOMATIC
)))
444 # Resolve dependencies:
445 PKGS_DEPS
:= $(filter-out $(PKGS_FOUND
) $(PKGS_MANUAL
),$(sort $(foreach p
,$(PKGS_MANUAL
),$(DEPS_
$(p
)))))
446 PKGS
:= $(sort $(PKGS_MANUAL
) $(PKGS_DEPS
))
448 fetch
: $(PKGS
:%=.sum-
%)
449 fetch-all
: $(PKGS_ALL
:%=.sum-
%)
450 install: $(PKGS
:%=.
%)
453 -$(RM
) $(foreach p
,$(PKGS_ALL
),.
$(p
) .sum-
$(p
) .dep-
$(p
))
454 -$(RM
) toolchain.cmake
455 -$(RM
) crossfile.meson
456 -$(RM
) -R
"$(PREFIX)"
457 -$(RM
) -R
"$(BUILDBINDIR)"
461 -$(RM
) $(TARBALLS
)/*.
*
467 PREBUILT_URL
=http
://download.videolan.org
/pub
/videolan
/contrib
/$(HOST
)/vlc-contrib-
$(HOST
)-latest.
tar.bz2
469 vlc-contrib-
$(HOST
)-latest.
tar.bz2
:
470 $(call download
,$(PREBUILT_URL
))
472 prebuilt
: vlc-contrib-
$(HOST
)-latest.
tar.bz2
476 cd
$(PREFIX
) && $(SRC
)/change_prefix.sh
478 ifndef HAVE_CROSS_COMPILE
479 $(RM
) `find $(PREFIX)/bin | file -f- | grep ELF | awk -F: '{print $$1}' | xargs`
487 # remove useless files
488 cd tmp
/$(notdir $(PREFIX
)); \
489 cd share
; rm -Rf man doc gtk-doc
info lua projectM
; cd ..
; \
490 rm -Rf man sbin etc lib
/lua lib
/sidplay
491 cd tmp
/$(notdir $(PREFIX
)) && $(abspath
$(SRC
))/change_prefix.sh
$(PREFIX
) @@CONTRIB_PREFIX@@
492 (cd tmp
&& tar c
$(notdir $(PREFIX
))/) | bzip2
-c
> ..
/vlc-contrib-
$(HOST
)-$(DATE
).
tar.bz2
496 @echo
' $(PKGS_ALL)' | tr
" " "\n" |
sort | tr
"\n" " " |fmt
497 @echo Distribution-provided packages
:
498 @echo
' $(PKGS_FOUND)' | tr
" " "\n" |
sort | tr
"\n" " " |fmt
499 @echo Automatically selected packages
:
500 @echo
' $(PKGS_AUTOMATIC)' | tr
" " "\n" |
sort | tr
"\n" " " |fmt
501 @echo Manually deselected packages
:
502 @echo
' $(PKGS_DISABLE)' | tr
" " "\n" |
sort | tr
"\n" " " |fmt
503 @echo Manually selected packages
:
504 @echo
' $(PKGS_ENABLE)' | tr
" " "\n" |
sort | tr
"\n" " " |fmt
505 @echo Depended-on packages
:
506 @echo
' $(PKGS_DEPS)' | tr
" " "\n" |
sort | tr
"\n" " " |fmt
507 @echo To-be-built packages
:
508 @echo
' $(PKGS)' | tr
" " "\n" |
sort | tr
"\n" " " |fmt
513 .PHONY
: all fetch fetch-all
install mostlyclean clean distclean package list help prebuilt
517 CMAKE_SYSTEM_NAME
= Windows
518 ifdef HAVE_VISUALSTUDIO
520 CMAKE_SYSTEM_NAME
= WindowsStore
522 ifdef HAVE_WINDOWSPHONE
523 CMAKE_SYSTEM_NAME
= WindowsPhone
528 CMAKE_SYSTEM_NAME
= Darwin
534 ifndef WITH_OPTIMIZATION
535 echo
"set(CMAKE_BUILD_TYPE Debug)" >> $@
537 echo
"set(CMAKE_BUILD_TYPE Release)" >> $@
539 echo
"set(CMAKE_SYSTEM_PROCESSOR $(ARCH))" >> $@
540 if
test -n
"$(CMAKE_SYSTEM_NAME)"; then \
541 echo
"set(CMAKE_SYSTEM_NAME $(CMAKE_SYSTEM_NAME))" >> $@
; \
544 ifdef HAVE_CROSS_COMPILE
545 echo
"set(CMAKE_RC_COMPILER $(WINDRES))" >> $@
549 echo
"set(CMAKE_C_FLAGS \"$(CFLAGS)\")" >> $@
550 echo
"set(CMAKE_CXX_FLAGS \"$(CXXFLAGS)\")" >> $@
551 echo
"set(CMAKE_LD_FLAGS \"$(LDFLAGS)\")" >> $@
552 echo
"set(CMAKE_AR ar CACHE FILEPATH "Archiver
")" >> $@
554 echo
"set(CMAKE_OSX_SYSROOT $(IOS_SDK))" >> $@
556 echo
"set(CMAKE_OSX_SYSROOT $(MACOSX_SDK))" >> $@
559 echo
"set(CMAKE_AR $(AR) CACHE FILEPATH "Archiver
")" >> $@
561 ifdef HAVE_CROSS_COMPILE
562 echo
"set(_CMAKE_TOOLCHAIN_PREFIX $(HOST)-)" >> $@
564 # cmake will overwrite our --sysroot with a native (host) one on Darwin
565 # Set it to "" right away to short-circuit this behaviour
566 echo
"set(CMAKE_CXX_SYSROOT_FLAG \"\")" >> $@
567 echo
"set(CMAKE_C_SYSROOT_FLAG \"\")" >> $@
570 echo
"set(CMAKE_C_COMPILER $(CC))" >> $@
571 echo
"set(CMAKE_CXX_COMPILER $(CXX))" >> $@
573 echo
"set(CMAKE_FIND_ROOT_PATH `cygpath -m $(PREFIX)`)" >> $@
575 echo
"set(CMAKE_FIND_ROOT_PATH $(PREFIX))" >> $@
577 echo
"set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> $@
578 ifdef HAVE_CROSS_COMPILE
579 echo
"set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> $@
580 echo
"set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> $@
581 echo
"set(PKG_CONFIG_EXECUTABLE $(PKG_CONFIG))" >> $@
586 MESON_SYSTEM_NAME
= windows
589 MESON_SYSTEM_NAME
= darwin
592 # android has also system = linux and defines HAVE_LINUX
593 MESON_SYSTEM_NAME
= linux
600 WINDRES
="$(WINDRES)" \
601 PKG_CONFIG
="$(PKG_CONFIG)" \
602 HOST_SYSTEM
="$(MESON_SYSTEM_NAME)" \
603 HOST_ARCH
="$(subst i386,x86,$(ARCH))" \
605 $(SRC
)/gen-meson-crossfile.py
$@
607 # Default pattern rules
608 .sum-
%: $(SRC
)/%/SHA512SUMS
613 $(error Download and
check target not defined for
$*)
615 # Dummy dependency on found packages
616 $(patsubst %,.dep-
%,$(PKGS_FOUND
)): .dep-
%:
619 # Real dependency on missing packages
620 $(patsubst %,.dep-
%,$(filter-out $(PKGS_FOUND
),$(PKGS_ALL
))): .dep-
%: .
%
625 # Dependency propagation (convert 'DEPS_foo = bar' to '.foo: .bar')
626 $(foreach p
,$(PKGS_ALL
),.
$(p
)): .
%: $$(foreach d
,$$(DEPS_
$$*),.dep-
$$(d
))