contrib: define CMAKE_SYSTEM_NAME when building for Android
[vlc.git] / contrib / src / main.mak
blob4537508078989138037e7cd78d7b020433408367
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.
6 all: install
8 # bootstrap configuration
9 include config.mak
11 TOPSRC ?= ../../contrib
12 TOPDST ?= ..
13 SRC := $(TOPSRC)/src
14 TARBALLS := $(TOPSRC)/tarballs
16 PATH :=$(abspath ../../extras/tools/build/bin):$(PATH)
17 export PATH
19 PKGS_ALL := $(patsubst $(SRC)/%/rules.mak,%,$(wildcard $(SRC)/*/rules.mak))
20 DATE := $(shell date +%Y%m%d)
21 VPATH := $(TARBALLS)
23 # Common download locations
24 GNU ?= http://ftp.gnu.org/gnu
25 SF := http://heanet.dl.sourceforge.net/sourceforge
26 VIDEOLAN := http://downloads.videolan.org/pub/videolan
27 CONTRIB_VIDEOLAN := http://downloads.videolan.org/pub/contrib
30 # Machine-dependent variables
33 PREFIX ?= $(TOPDST)/$(HOST)
34 PREFIX := $(abspath $(PREFIX))
35 BUILDPREFIX ?= $(TOPDST)
36 BUILDPREFIX := $(abspath $(BUILDPREFIX))
37 BUILDBINDIR ?= $(BUILDPREFIX)/bin
38 ifneq ($(HOST),$(BUILD))
39 HAVE_CROSS_COMPILE = 1
40 endif
41 ARCH := $(shell $(SRC)/get-arch.sh $(HOST))
43 ifeq ($(ARCH)-$(HAVE_WIN32),x86_64-1)
44 HAVE_WIN64 := 1
45 endif
47 ifdef HAVE_CROSS_COMPILE
48 need_pkg = 1
49 else
50 need_pkg = $(shell $(PKG_CONFIG) $(1) || echo 1)
51 endif
54 # Default values for tools
56 ifndef HAVE_CROSS_COMPILE
57 ifneq ($(findstring $(origin CC),undefined default),)
58 CC := gcc
59 endif
60 ifneq ($(findstring $(origin CXX),undefined default),)
61 CXX := g++
62 endif
63 ifneq ($(findstring $(origin LD),undefined default),)
64 LD := ld
65 endif
66 ifneq ($(findstring $(origin AR),undefined default),)
67 AR := ar
68 endif
69 ifneq ($(findstring $(origin RANLIB),undefined default),)
70 RANLIB := ranlib
71 endif
72 ifneq ($(findstring $(origin STRIP),undefined default),)
73 STRIP := strip
74 endif
75 ifneq ($(findstring $(origin WIDL),undefined default),)
76 WIDL := widl
77 endif
78 else
79 ifneq ($(findstring $(origin CC),undefined default),)
80 CC := $(HOST)-gcc
81 endif
82 ifneq ($(findstring $(origin CXX),undefined default),)
83 CXX := $(HOST)-g++
84 endif
85 ifneq ($(findstring $(origin LD),undefined default),)
86 LD := $(HOST)-ld
87 endif
88 ifneq ($(findstring $(origin AR),undefined default),)
89 AR := $(HOST)-ar
90 endif
91 ifneq ($(findstring $(origin RANLIB),undefined default),)
92 RANLIB := $(HOST)-ranlib
93 endif
94 ifneq ($(findstring $(origin STRIP),undefined default),)
95 STRIP := $(HOST)-strip
96 endif
97 ifneq ($(findstring $(origin WIDL),undefined default),)
98 WIDL := $(HOST)-widl
99 endif
100 endif
102 ifdef HAVE_ANDROID
103 CC := clang
104 CXX := clang++
105 endif
107 ifdef HAVE_MACOSX
108 MIN_OSX_VERSION=10.7
109 CC=xcrun cc
110 CXX=xcrun c++
111 AR=xcrun ar
112 LD=xcrun ld
113 STRIP=xcrun strip
114 RANLIB=xcrun ranlib
115 EXTRA_CFLAGS += -isysroot $(MACOSX_SDK) -mmacosx-version-min=$(MIN_OSX_VERSION) -DMACOSX_DEPLOYMENT_TARGET=$(MIN_OSX_VERSION)
116 EXTRA_CXXFLAGS += -stdlib=libc++
117 EXTRA_LDFLAGS += -Wl,-syslibroot,$(MACOSX_SDK) -mmacosx-version-min=$(MIN_OSX_VERSION) -isysroot $(MACOSX_SDK) -DMACOSX_DEPLOYMENT_TARGET=$(MIN_OSX_VERSION)
118 ifeq ($(ARCH),x86_64)
119 EXTRA_CFLAGS += -m64
120 EXTRA_LDFLAGS += -m64
121 else
122 EXTRA_CFLAGS += -m32
123 EXTRA_LDFLAGS += -m32
124 endif
126 XCODE_FLAGS = MACOSX_DEPLOYMENT_TARGET=$(MIN_OSX_VERSION) -sdk macosx$(OSX_VERSION) -arch $(ARCH)
128 endif
130 CCAS=$(CC) -c
132 ifdef HAVE_IOS
133 CC=xcrun clang
134 CXX=xcrun clang++
135 ifdef HAVE_NEON
136 AS=perl $(abspath ../../extras/tools/build/bin/gas-preprocessor.pl) $(CC)
137 CCAS=gas-preprocessor.pl $(CC) -c
138 else
139 CCAS=$(CC) -c
140 endif
141 AR=xcrun ar
142 LD=xcrun ld
143 STRIP=xcrun strip
144 RANLIB=xcrun ranlib
145 EXTRA_CFLAGS += $(CFLAGS)
146 EXTRA_LDFLAGS += $(LDFLAGS)
147 endif
149 ifdef HAVE_WIN32
150 ifneq ($(shell $(CC) $(CFLAGS) -E -dM -include _mingw.h - < /dev/null | grep -E __MINGW64_VERSION_MAJOR),)
151 HAVE_MINGW_W64 := 1
152 endif
153 endif
155 ifdef HAVE_SOLARIS
156 ifeq ($(ARCH),x86_64)
157 EXTRA_CFLAGS += -m64
158 EXTRA_LDFLAGS += -m64
159 else
160 EXTRA_CFLAGS += -m32
161 EXTRA_LDFLAGS += -m32
162 endif
163 endif
165 cppcheck = $(shell $(CC) $(CFLAGS) -E -dM - < /dev/null | grep -E $(1))
167 EXTRA_CFLAGS += -I$(PREFIX)/include
168 CPPFLAGS := $(CPPFLAGS) $(EXTRA_CFLAGS)
169 CFLAGS := $(CFLAGS) $(EXTRA_CFLAGS) -g
170 CXXFLAGS := $(CXXFLAGS) $(EXTRA_CFLAGS) $(EXTRA_CXXFLAGS) -g
171 EXTRA_LDFLAGS += -L$(PREFIX)/lib
172 LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
174 ifndef WITH_OPTIMIZATION
175 CFLAGS := $(CFLAGS) -O0
176 CXXFLAGS := $(CXXFLAGS) -O0
177 else
178 CFLAGS := $(CFLAGS) -O2
179 CXXFLAGS := $(CXXFLAGS) -O2
180 endif
182 # Do not export those! Use HOSTVARS.
184 # Do the FPU detection, after we have figured out our compilers and flags.
185 ifneq ($(findstring $(ARCH),aarch64 i386 ppc ppc64 sparc sparc64 x86_64),)
186 # This should be consistent with include/vlc_cpu.h
187 HAVE_FPU = 1
188 else ifneq ($(findstring $(ARCH),arm),)
189 ifneq ($(call cppcheck, __VFP_FP__)),)
190 ifeq ($(call cppcheck, __SOFTFP__),)
191 HAVE_FPU = 1
192 endif
193 endif
194 else ifneq ($(call cppcheck, __mips_hard_float),)
195 HAVE_FPU = 1
196 endif
198 ACLOCAL_AMFLAGS += -I$(PREFIX)/share/aclocal
199 export ACLOCAL_AMFLAGS
201 #########
202 # Tools #
203 #########
205 PKG_CONFIG ?= pkg-config
206 ifdef HAVE_CROSS_COMPILE
207 # This inhibits .pc file from within the cross-compilation toolchain sysroot.
208 # Hopefully, nobody ever needs that.
209 PKG_CONFIG_PATH := /usr/share/pkgconfig
210 PKG_CONFIG_LIBDIR := /usr/$(HOST)/lib/pkgconfig
211 export PKG_CONFIG_LIBDIR
212 endif
213 PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH)
214 export PKG_CONFIG_PATH
216 ifndef GIT
217 ifeq ($(shell git --version >/dev/null 2>&1 || echo FAIL),)
218 GIT = git
219 endif
220 endif
221 GIT ?= $(error git not found!)
223 ifndef SVN
224 ifeq ($(shell svn --version >/dev/null 2>&1 || echo FAIL),)
225 SVN = svn
226 endif
227 endif
228 SVN ?= $(error subversion client (svn) not found!)
230 ifeq ($(shell curl --version >/dev/null 2>&1 || echo FAIL),)
231 download = curl -f -L -- "$(1)" > "$@"
232 else ifeq ($(shell wget --version >/dev/null 2>&1 || echo FAIL),)
233 download = (rm -f $@.tmp && \
234 wget --passive -c -p -O $@.tmp "$(1)" && \
235 touch $@.tmp && \
236 mv $@.tmp $@ )
237 else ifeq ($(which fetch >/dev/null 2>&1 || echo FAIL),)
238 download = (rm -f $@.tmp && \
239 fetch -p -o $@.tmp "$(1)" && \
240 touch $@.tmp && \
241 mv $@.tmp $@)
242 else
243 download = $(error Neither curl nor wget found!)
244 endif
246 download_pkg = $(call download,$(CONTRIB_VIDEOLAN)/$(2)/$(lastword $(subst /, ,$(@)))) || \
247 ( $(call download,$(1)) && echo "Please upload this package $(lastword $(subst /, ,$(@))) to our FTP" )
249 ifeq ($(shell which xzcat >/dev/null 2>&1 || echo FAIL),)
250 XZCAT = xzcat
251 else
252 XZCAT ?= $(error xz and lzma client not found!)
253 endif
255 ifeq ($(shell which bzcat >/dev/null 2>&1 || echo FAIL),)
256 BZCAT = bzcat
257 else
258 BZCAT ?= $(error Bunzip2 client (bzcat) not found!)
259 endif
261 ifeq ($(shell gzcat --version >/dev/null 2>&1 || echo FAIL),)
262 ZCAT = gzcat
263 else ifeq ($(shell zcat --version >/dev/null 2>&1 || echo FAIL),)
264 ZCAT = zcat
265 else
266 ZCAT ?= $(error Gunzip client (zcat) not found!)
267 endif
269 ifeq ($(shell sha512sum --version >/dev/null 2>&1 || echo FAIL),)
270 SHA512SUM = sha512sum --check
271 else ifeq ($(shell shasum --version >/dev/null 2>&1 || echo FAIL),)
272 SHA512SUM = shasum -a 512 --check
273 else ifeq ($(shell openssl version >/dev/null 2>&1 || echo FAIL),)
274 SHA512SUM = openssl dgst -sha512
275 else
276 SHA512SUM = $(error SHA-512 checksumming not found!)
277 endif
279 ifeq ($(shell protoc --version >/dev/null 2>&1 || echo FAIL),)
280 PROTOC = protoc
281 else
282 PROTOC ?= $(error Protobuf compiler (protoc) not found!)
283 endif
286 # Common helpers
288 HOSTCONF := --prefix="$(PREFIX)"
289 HOSTCONF += --datarootdir="$(PREFIX)/share"
290 HOSTCONF += --includedir="$(PREFIX)/include"
291 HOSTCONF += --libdir="$(PREFIX)/lib"
292 HOSTCONF += --build="$(BUILD)" --host="$(HOST)" --target="$(HOST)"
293 HOSTCONF += --program-prefix=""
294 # libtool stuff:
295 HOSTCONF += --enable-static --disable-shared --disable-dependency-tracking
296 ifdef HAVE_WIN32
297 HOSTCONF += --without-pic
298 PIC :=
299 else
300 HOSTCONF += --with-pic
301 PIC := -fPIC
302 endif
304 HOSTTOOLS := \
305 CC="$(CC)" CXX="$(CXX)" LD="$(LD)" \
306 AR="$(AR)" CCAS="$(CCAS)" RANLIB="$(RANLIB)" STRIP="$(STRIP)" \
307 PATH="$(PREFIX)/bin:$(PATH)"
308 HOSTVARS := $(HOSTTOOLS) \
309 CPPFLAGS="$(CPPFLAGS)" \
310 CFLAGS="$(CFLAGS)" \
311 CXXFLAGS="$(CXXFLAGS)" \
312 LDFLAGS="$(LDFLAGS)"
313 HOSTVARS_PIC := $(HOSTTOOLS) \
314 CPPFLAGS="$(CPPFLAGS) $(PIC)" \
315 CFLAGS="$(CFLAGS) $(PIC)" \
316 CXXFLAGS="$(CXXFLAGS) $(PIC)" \
317 LDFLAGS="$(LDFLAGS)"
319 download_git = \
320 rm -Rf $(@:.tar.xz=) && \
321 $(GIT) clone $(subst HEAD, --depth 1,$(findstring HEAD, $3)) $(2:%=--branch %) $(1) $(@:.tar.xz=) && \
322 (cd $(@:.tar.xz=) && $(GIT) checkout $(3:%= %)) && \
323 rm -Rf $(@:%.tar.xz=%)/.git && \
324 (cd $(dir $@) && \
325 tar cvJ $(notdir $(@:.tar.xz=))) > $@ && \
326 rm -Rf $(@:.tar.xz=)
327 checksum = \
328 $(foreach f,$(filter $(TARBALLS)/%,$^), \
329 grep -- " $(f:$(TARBALLS)/%=%)$$" \
330 "$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS" &&) \
331 (cd $(TARBALLS) && $(1) /dev/stdin) < \
332 "$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS"
333 CHECK_SHA512 = $(call checksum,$(SHA512SUM),SHA512)
334 UNPACK = $(RM) -R $@ \
335 $(foreach f,$(filter %.tar.gz %.tgz,$^), && tar xvzf $(f)) \
336 $(foreach f,$(filter %.tar.bz2,$^), && tar xvjf $(f)) \
337 $(foreach f,$(filter %.tar.xz,$^), && tar xvJf $(f)) \
338 $(foreach f,$(filter %.zip,$^), && unzip $(f))
339 UNPACK_DIR = $(patsubst %.tar,%,$(basename $(notdir $<)))
340 APPLY = (cd $(UNPACK_DIR) && patch -fp1) <
341 pkg_static = (cd $(UNPACK_DIR) && ../../../contrib/src/pkg-static.sh $(1))
342 MOVE = mv $(UNPACK_DIR) $@ && touch $@
344 AUTOMAKE_DATA_DIRS=$(foreach n,$(foreach n,$(subst :, ,$(shell echo $$PATH)),$(abspath $(n)/../share)),$(wildcard $(n)/automake*))
345 UPDATE_AUTOCONFIG = for dir in $(AUTOMAKE_DATA_DIRS); do \
346 if test -f "$${dir}/config.sub" -a -f "$${dir}/config.guess"; then \
347 cp "$${dir}/config.sub" "$${dir}/config.guess" $(UNPACK_DIR); \
348 break; \
349 fi; \
350 done
352 ifdef HAVE_IOS
353 AUTORECONF = AUTOPOINT=true autoreconf
354 else
355 AUTORECONF = autoreconf
356 endif
357 RECONF = mkdir -p -- $(PREFIX)/share/aclocal && \
358 cd $< && $(AUTORECONF) -fiv $(ACLOCAL_AMFLAGS)
359 CMAKE = cmake . -DCMAKE_TOOLCHAIN_FILE=$(abspath toolchain.cmake) \
360 -DCMAKE_INSTALL_PREFIX=$(PREFIX) $(CMAKE_GENERATOR)
363 # Per-package build rules
365 PKGS_FOUND :=
366 include $(SRC)/*/rules.mak
368 ifeq ($(PKGS_DISABLE), all)
369 PKGS :=
370 endif
372 # Targets
374 ifneq ($(filter $(PKGS_DISABLE),$(PKGS_ENABLE)),)
375 $(error Same package(s) disabled and enabled at the same time)
376 endif
377 # Apply automatic selection (= remove distro packages):
378 PKGS_AUTOMATIC := $(filter-out $(PKGS_FOUND),$(PKGS))
379 # Apply manual selection (from bootstrap):
380 PKGS_MANUAL := $(sort $(PKGS_ENABLE) $(filter-out $(PKGS_DISABLE),$(PKGS_AUTOMATIC)))
381 # Resolve dependencies:
382 PKGS_DEPS := $(filter-out $(PKGS_FOUND) $(PKGS_MANUAL),$(sort $(foreach p,$(PKGS_MANUAL),$(DEPS_$(p)))))
383 PKGS := $(sort $(PKGS_MANUAL) $(PKGS_DEPS))
385 fetch: $(PKGS:%=.sum-%)
386 fetch-all: $(PKGS_ALL:%=.sum-%)
387 install: $(PKGS:%=.%)
389 mostlyclean:
390 -$(RM) $(foreach p,$(PKGS_ALL),.$(p) .sum-$(p) .dep-$(p))
391 -$(RM) toolchain.cmake
392 -$(RM) -R "$(PREFIX)"
393 -$(RM) -R "$(BUILDBINDIR)"
394 -$(RM) -R */
396 clean: mostlyclean
397 -$(RM) $(TARBALLS)/*.*
399 distclean: clean
400 $(RM) config.mak
401 unlink Makefile
403 PREBUILT_URL=ftp://ftp.videolan.org/pub/videolan/contrib/$(HOST)/vlc-contrib-$(HOST)-latest.tar.bz2
405 vlc-contrib-$(HOST)-latest.tar.bz2:
406 $(call download,$(PREBUILT_URL))
408 prebuilt: vlc-contrib-$(HOST)-latest.tar.bz2
409 -$(UNPACK)
410 $(RM) -r $(TOPDST)/$(HOST)
411 mv $(HOST) $(TOPDST)
412 cd $(TOPDST)/$(HOST) && $(SRC)/change_prefix.sh
413 ifdef HAVE_WIN32
414 ifndef HAVE_CROSS_COMPILE
415 $(RM) `find $(TOPDST)/$(HOST)/bin | file -f- | grep ELF | awk -F: '{print $$1}' | xargs`
416 endif
417 endif
419 package: install
420 rm -Rf tmp/
421 mkdir -p tmp/
422 cp -R $(PREFIX) tmp/
423 # remove useless files
424 cd tmp/$(notdir $(PREFIX)); \
425 cd share; rm -Rf man doc gtk-doc info lua projectM; cd ..; \
426 rm -Rf man sbin etc lib/lua lib/sidplay
427 cd tmp/$(notdir $(PREFIX)) && $(abspath $(SRC))/change_prefix.sh $(PREFIX) @@CONTRIB_PREFIX@@
428 (cd tmp && tar c $(notdir $(PREFIX))/) | bzip2 -c > ../vlc-contrib-$(HOST)-$(DATE).tar.bz2
430 list:
431 @echo All packages:
432 @echo ' $(PKGS_ALL)' | tr " " "\n" | sort | tr "\n" " " |fmt
433 @echo Distribution-provided packages:
434 @echo ' $(PKGS_FOUND)' | tr " " "\n" | sort | tr "\n" " " |fmt
435 @echo Automatically selected packages:
436 @echo ' $(PKGS_AUTOMATIC)' | tr " " "\n" | sort | tr "\n" " " |fmt
437 @echo Manually deselected packages:
438 @echo ' $(PKGS_DISABLE)' | tr " " "\n" | sort | tr "\n" " " |fmt
439 @echo Manually selected packages:
440 @echo ' $(PKGS_ENABLE)' | tr " " "\n" | sort | tr "\n" " " |fmt
441 @echo Depended-on packages:
442 @echo ' $(PKGS_DEPS)' | tr " " "\n" | sort | tr "\n" " " |fmt
443 @echo To-be-built packages:
444 @echo ' $(PKGS)' | tr " " "\n" | sort | tr "\n" " " |fmt
446 help:
447 @cat $(SRC)/help.txt
449 .PHONY: all fetch fetch-all install mostlyclean clean distclean package list help prebuilt
451 # CMake toolchain
452 toolchain.cmake:
453 $(RM) $@
454 ifdef HAVE_WIN32
455 ifdef HAVE_WINDOWSPHONE
456 echo "set(CMAKE_SYSTEM_NAME WindowsPhone)" >> $@
457 else
458 ifdef HAVE_WINSTORE
459 echo "set(CMAKE_SYSTEM_NAME WindowsStore)" >> $@
460 else
461 echo "set(CMAKE_SYSTEM_NAME Windows)" >> $@
462 endif
463 endif
464 echo "set(CMAKE_RC_COMPILER $(HOST)-windres)" >> $@
465 endif
466 ifdef HAVE_DARWIN_OS
467 echo "set(CMAKE_SYSTEM_NAME Darwin)" >> $@
468 echo "set(CMAKE_C_FLAGS $(CFLAGS))" >> $@
469 echo "set(CMAKE_CXX_FLAGS $(CFLAGS) $(EXTRA_CXXFLAGS))" >> $@
470 echo "set(CMAKE_LD_FLAGS $(LDFLAGS))" >> $@
471 echo "set(CMAKE_AR ar CACHE FILEPATH "Archiver")" >> $@
472 ifdef HAVE_IOS
473 echo "set(CMAKE_OSX_SYSROOT $(IOS_SDK))" >> $@
474 else
475 echo "set(CMAKE_OSX_SYSROOT $(MACOSX_SDK))" >> $@
476 endif
477 endif
478 ifdef HAVE_CROSS_COMPILE
479 echo "set(_CMAKE_TOOLCHAIN_PREFIX $(HOST)-)" >> $@
480 ifdef HAVE_ANDROID
481 # cmake will overwrite our --sysroot with a native (host) one on Darwin
482 # Set it to "" right away to short-circuit this behaviour
483 echo "set(CMAKE_CXX_SYSROOT_FLAG \"\")" >> $@
484 echo "set(CMAKE_C_SYSROOT_FLAG \"\")" >> $@
485 echo "set(CMAKE_SYSTEM_NAME Android)" >> $@
486 endif
487 endif
488 echo "set(CMAKE_C_COMPILER $(CC))" >> $@
489 echo "set(CMAKE_CXX_COMPILER $(CXX))" >> $@
490 echo "set(CMAKE_FIND_ROOT_PATH $(PREFIX))" >> $@
491 echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> $@
492 echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> $@
493 echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> $@
495 # Default pattern rules
496 .sum-%: $(SRC)/%/SHA512SUMS
497 $(CHECK_SHA512)
498 touch $@
500 .sum-%:
501 $(error Download and check target not defined for $*)
503 # Dummy dependency on found packages
504 $(patsubst %,.dep-%,$(PKGS_FOUND)): .dep-%:
505 touch $@
507 # Real dependency on missing packages
508 $(patsubst %,.dep-%,$(filter-out $(PKGS_FOUND),$(PKGS_ALL))): .dep-%: .%
509 touch -r $< $@
511 .SECONDEXPANSION:
513 # Dependency propagation (convert 'DEPS_foo = bar' to '.foo: .bar')
514 $(foreach p,$(PKGS_ALL),.$(p)): .%: $$(foreach d,$$(DEPS_$$*),.dep-$$(d))
516 .DELETE_ON_ERROR: