1# Main makefile for VLC 3rd party libraries ("contrib")
2# Copyright (C) 2003-2011 the VideoLAN team
3#
4# This file is under the same license as the vlc package.
5
6all: install
7
8SRC := $(TOPSRC)/src
9SRC_BUILT := $(TOPSRC_BUILT)/src
10TARBALLS := $(TOPSRC)/tarballs
11VLC_TOOLS ?= $(TOPSRC)/../extras/tools/build
12
13PATH :=$(abspath $(VLC_TOOLS)/bin):$(PATH)
14export PATH
15
16PKGS_ALL := $(patsubst $(SRC)/%/rules.mak,%,$(wildcard $(SRC)/*/rules.mak))
17DATE := $(shell date +%Y%m%d)
18VPATH := $(TARBALLS)
19
20# Common download locations
21GNU ?= http://ftp.gnu.org/gnu
22SF := https://netcologne.dl.sourceforge.net/
23VIDEOLAN := http://downloads.videolan.org/pub/videolan
24CONTRIB_VIDEOLAN := http://downloads.videolan.org/pub/contrib
25GITHUB := https://github.com/
26
27#
28# Machine-dependent variables
29#
30
31PREFIX ?= $(TOPDST)/$(HOST)
32PREFIX := $(abspath $(PREFIX))
33BUILDPREFIX ?= $(TOPDST)
34BUILDPREFIX := $(abspath $(BUILDPREFIX))
35BUILDBINDIR ?= $(BUILDPREFIX)/bin
36ifneq ($(HOST),$(BUILD))
37HAVE_CROSS_COMPILE = 1
38endif
39ARCH := $(shell $(SRC)/get-arch.sh $(HOST))
40
41ifeq ($(ARCH)-$(HAVE_WIN32),x86_64-1)
42HAVE_WIN64 := 1
43endif
44ifeq ($(ARCH)-$(HAVE_WIN32),aarch64-1)
45HAVE_WIN64 := 1
46endif
47
48ifdef HAVE_CROSS_COMPILE
49need_pkg = 1
50else
51need_pkg = $(shell $(PKG_CONFIG) $(1) || echo 1)
52endif
53
54#
55# Default values for tools
56#
57ifndef HAVE_CROSS_COMPILE
58ifneq ($(findstring $(origin CC),undefined default),)
59CC := gcc
60endif
61ifneq ($(findstring $(origin CXX),undefined default),)
62CXX := g++
63endif
64ifneq ($(findstring $(origin LD),undefined default),)
65LD := ld
66endif
67ifneq ($(findstring $(origin AR),undefined default),)
68AR := ar
69endif
70ifneq ($(findstring $(origin RANLIB),undefined default),)
71RANLIB := ranlib
72endif
73ifneq ($(findstring $(origin STRIP),undefined default),)
74STRIP := strip
75endif
76ifneq ($(findstring $(origin WIDL),undefined default),)
77WIDL := widl
78endif
79ifneq ($(findstring $(origin WINDRES),undefined default),)
80WINDRES := windres
81endif
82else
83ifneq ($(findstring $(origin CC),undefined default),)
84CC := $(HOST)-gcc
85endif
86ifneq ($(findstring $(origin CXX),undefined default),)
87CXX := $(HOST)-g++
88endif
89ifneq ($(findstring $(origin LD),undefined default),)
90LD := $(HOST)-ld
91endif
92ifneq ($(findstring $(origin AR),undefined default),)
93AR := $(HOST)-ar
94endif
95ifneq ($(findstring $(origin RANLIB),undefined default),)
96RANLIB := $(HOST)-ranlib
97endif
98ifneq ($(findstring $(origin STRIP),undefined default),)
99STRIP := $(HOST)-strip
100endif
101ifneq ($(findstring $(origin WIDL),undefined default),)
102WIDL := $(HOST)-widl
103endif
104ifneq ($(findstring $(origin WINDRES),undefined default),)
105WINDRES := $(HOST)-windres
106endif
107endif
108
109ifdef HAVE_ANDROID
110ifneq ($(findstring $(origin CC),undefined default),)
111CC :=  clang
112endif
113ifneq ($(findstring $(origin CXX),undefined default),)
114CXX := clang++
115endif
116endif
117
118# -fno-stack-check is a workaround for a possible
119# bug in Xcode 11 or macOS 10.15+
120ifdef HAVE_DARWIN_OS
121EXTRA_CFLAGS += -fno-stack-check
122XCODE_FLAGS += OTHER_CFLAGS=-fno-stack-check
123endif
124
125ifdef HAVE_MACOSX
126EXTRA_CXXFLAGS += -stdlib=libc++
127ifeq ($(ARCH),aarch64)
128XCODE_FLAGS += -arch arm64
129else
130XCODE_FLAGS += -arch $(ARCH)
131endif
132endif
133
134CCAS=$(CC) -c
135
136ifdef HAVE_IOS
137ifdef HAVE_NEON
138AS=perl $(abspath $(VLC_TOOLS)/bin/gas-preprocessor.pl) $(CC)
139CCAS=gas-preprocessor.pl $(CC) -c
140endif
141endif
142
143LN_S = ln -s
144ifdef HAVE_WIN32
145ifneq ($(shell $(CC) $(CFLAGS) -E -dM -include _mingw.h - < /dev/null | grep -E __MINGW64_VERSION_MAJOR),)
146HAVE_MINGW_W64 := 1
147endif
148ifndef HAVE_CROSS_COMPILE
149LN_S = cp -R
150endif
151endif
152
153ifdef HAVE_SOLARIS
154ifeq ($(ARCH),x86_64)
155EXTRA_CFLAGS += -m64
156EXTRA_LDFLAGS += -m64
157else
158EXTRA_CFLAGS += -m32
159EXTRA_LDFLAGS += -m32
160endif
161endif
162
163ifneq ($(findstring clang, $(shell $(CC) --version)),)
164HAVE_CLANG := 1
165endif
166
167cppcheck = $(shell $(CC) $(CFLAGS) -E -dM - < /dev/null | grep -E $(1))
168
169EXTRA_CFLAGS += -I$(PREFIX)/include
170CPPFLAGS := $(CPPFLAGS) $(EXTRA_CFLAGS)
171CFLAGS := $(CFLAGS) $(EXTRA_CFLAGS)
172CXXFLAGS := $(CXXFLAGS) $(EXTRA_CFLAGS) $(EXTRA_CXXFLAGS)
173LDFLAGS := $(LDFLAGS) -L$(PREFIX)/lib $(EXTRA_LDFLAGS)
174
175# Do not export those! Use HOSTVARS.
176
177# Do the FPU detection, after we have figured out our compilers and flags.
178ifneq ($(findstring $(ARCH),aarch64 i386 ppc ppc64 sparc sparc64 x86_64),)
179# This should be consistent with include/vlc_cpu.h
180HAVE_FPU = 1
181else ifneq ($(findstring $(ARCH),arm),)
182ifneq ($(call cppcheck, __VFP_FP__)),)
183ifeq ($(call cppcheck, __SOFTFP__),)
184HAVE_FPU = 1
185endif
186endif
187else ifneq ($(call cppcheck, __mips_hard_float),)
188HAVE_FPU = 1
189endif
190
191ACLOCAL_AMFLAGS += -I$(PREFIX)/share/aclocal
192ifneq ($(wildcard $(VLC_TOOLS)/share/aclocal/*),)
193ACLOCAL_AMFLAGS += -I$(abspath $(VLC_TOOLS)/share/aclocal)
194endif
195export ACLOCAL_AMFLAGS
196
197#########
198# Tools #
199#########
200
201PKG_CONFIG ?= pkg-config
202ifdef HAVE_CROSS_COMPILE
203# This inhibits .pc file from within the cross-compilation toolchain sysroot.
204# Hopefully, nobody ever needs that.
205PKG_CONFIG_PATH := /usr/share/pkgconfig
206PKG_CONFIG_LIBDIR := /usr/$(HOST)/lib/pkgconfig
207export PKG_CONFIG_LIBDIR
208endif
209PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH)
210export PKG_CONFIG_PATH
211
212ifndef GIT
213ifeq ($(shell git --version >/dev/null 2>&1 || echo FAIL),)
214GIT = git
215endif
216endif
217GIT ?= $(error git not found!)
218
219ifndef SVN
220ifeq ($(shell svn --version >/dev/null 2>&1 || echo FAIL),)
221SVN = svn
222endif
223endif
224SVN ?= $(error subversion client (svn) not found!)
225
226ifeq ($(shell curl --version >/dev/null 2>&1 || echo FAIL),)
227download = curl -f -L -- "$(1)" > "$@"
228else ifeq ($(shell wget --version >/dev/null 2>&1 || echo FAIL),)
229download = (rm -f $@.tmp && \
230	wget --passive -c -p -O $@.tmp "$(1)" && \
231	touch $@.tmp && \
232	mv $@.tmp $@ )
233else ifeq ($(which fetch >/dev/null 2>&1 || echo FAIL),)
234download = (rm -f $@.tmp && \
235	fetch -p -o $@.tmp "$(1)" && \
236	touch $@.tmp && \
237	mv $@.tmp $@)
238else
239download = $(error Neither curl nor wget found!)
240endif
241
242download_pkg = $(call download,$(CONTRIB_VIDEOLAN)/$(2)/$(lastword $(subst /, ,$(@)))) || \
243	( $(call download,$(1)) && echo "Please upload this package $(lastword $(subst /, ,$(@))) to our FTP" )
244
245ifeq ($(shell which xz >/dev/null 2>&1 || echo FAIL),)
246XZ = xz
247else
248XZ ?= $(error XZ (LZMA) compressor not found!)
249endif
250
251ifeq ($(shell sha512sum --version >/dev/null 2>&1 || echo FAIL),)
252SHA512SUM = sha512sum --check
253else ifeq ($(shell shasum --version >/dev/null 2>&1 || echo FAIL),)
254SHA512SUM = shasum -a 512 --check
255else ifeq ($(shell openssl version >/dev/null 2>&1 || echo FAIL),)
256SHA512SUM = openssl dgst -sha512
257else
258SHA512SUM = $(error SHA-512 checksumming not found!)
259endif
260
261ifeq ($(shell protoc --version >/dev/null 2>&1 || echo FAIL),)
262PROTOC = protoc
263else
264PROTOC ?= $(error Protobuf compiler (protoc) not found!)
265endif
266
267#
268# Common helpers
269#
270HOSTCONF := --prefix="$(PREFIX)"
271HOSTCONF += --datarootdir="$(PREFIX)/share"
272HOSTCONF += --includedir="$(PREFIX)/include"
273HOSTCONF += --libdir="$(PREFIX)/lib"
274HOSTCONF += --build="$(BUILD)" --host="$(HOST)" --target="$(HOST)"
275HOSTCONF += --program-prefix=""
276# libtool stuff:
277HOSTCONF += --enable-static --disable-shared --disable-dependency-tracking
278ifdef HAVE_WIN32
279HOSTCONF += --without-pic
280PIC :=
281else
282HOSTCONF += --with-pic
283PIC := -fPIC
284endif
285
286HOSTTOOLS := \
287	CC="$(CC)" CXX="$(CXX)" LD="$(LD)" \
288	AR="$(AR)" CCAS="$(CCAS)" RANLIB="$(RANLIB)" STRIP="$(STRIP)" \
289	PATH="$(PREFIX)/bin:$(PATH)" \
290	PKG_CONFIG="$(PKG_CONFIG)"
291
292HOSTVARS_MESON := $(HOSTTOOLS) \
293	CPPFLAGS="$(CPPFLAGS)" \
294	CFLAGS="$(CFLAGS)" \
295	CXXFLAGS="$(CXXFLAGS)" \
296	LDFLAGS="$(LDFLAGS)"
297
298# Add these flags after Meson consumed the CFLAGS/CXXFLAGS
299# as when setting those for Meson, it would apply to tests
300# and cause the check if symbols have underscore prefix to
301# incorrectly report they have not, even if they have.
302ifndef WITH_OPTIMIZATION
303CFLAGS := $(CFLAGS) -g -O0
304CXXFLAGS := $(CXXFLAGS) -g -O0
305else
306CFLAGS := $(CFLAGS) -g -O2
307CXXFLAGS := $(CXXFLAGS) -g -O2
308endif
309
310ifdef ENABLE_PDB
311ifdef HAVE_CLANG
312ifneq ($(findstring $(ARCH),i686 x86_64),)
313CFLAGS := $(CFLAGS) -gcodeview
314CXXFLAGS := $(CXXFLAGS) -gcodeview
315endif
316endif
317endif
318
319HOSTVARS := $(HOSTTOOLS) \
320	CPPFLAGS="$(CPPFLAGS)" \
321	CFLAGS="$(CFLAGS)" \
322	CXXFLAGS="$(CXXFLAGS)" \
323	LDFLAGS="$(LDFLAGS)"
324HOSTVARS_PIC := $(HOSTTOOLS) \
325	CPPFLAGS="$(CPPFLAGS) $(PIC)" \
326	CFLAGS="$(CFLAGS) $(PIC)" \
327	CXXFLAGS="$(CXXFLAGS) $(PIC)" \
328	LDFLAGS="$(LDFLAGS)"
329
330download_git = \
331	rm -Rf -- "$(@:.tar.xz=)" && \
332	$(GIT) init --bare "$(@:.tar.xz=)" && \
333	(cd "$(@:.tar.xz=)" && \
334	$(GIT) remote add origin "$(1)" && \
335	$(GIT) fetch origin "$(2)") && \
336	(cd "$(@:.tar.xz=)" && \
337	$(GIT) archive --prefix="$(notdir $(@:.tar.xz=))/" \
338		--format=tar "$(3)") > "$(@:.xz=)" && \
339	echo "$(3) $(@)" > "$(@:.tar.xz=.githash)" && \
340	rm -Rf -- "$(@:.tar.xz=)" && \
341	$(XZ) --stdout "$(@:.xz=)" > "$@.tmp" && \
342	rm -f "$(@:.xz=)" && \
343	mv -f -- "$@.tmp" "$@"
344check_githash = \
345	h=`sed -e "s,^\([0-9a-fA-F]\{40\}\) .*/$(notdir $<),\1,g" \
346		< "$(<:.tar.xz=.githash)"` && \
347	test "$$h" = "$1"
348
349checksum = \
350	$(foreach f,$(filter $(TARBALLS)/%,$^), \
351		grep -- " $(f:$(TARBALLS)/%=%)$$" \
352			"$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS" &&) \
353	(cd $(TARBALLS) && $(1) /dev/stdin) < \
354		"$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS"
355CHECK_SHA512 = $(call checksum,$(SHA512SUM),SHA512)
356UNPACK = $(RM) -R $@ \
357	$(foreach f,$(filter %.tar.gz %.tgz,$^), && tar xvzfo $(f)) \
358	$(foreach f,$(filter %.tar.bz2,$^), && tar xvjfo $(f)) \
359	$(foreach f,$(filter %.tar.xz,$^), && tar xvJfo $(f)) \
360	$(foreach f,$(filter %.zip,$^), && unzip $(f))
361UNPACK_DIR = $(patsubst %.tar,%,$(basename $(notdir $<)))
362APPLY = (cd $(UNPACK_DIR) && patch -fp1) <
363pkg_static = (cd $(UNPACK_DIR) && $(SRC_BUILT)/pkg-static.sh $(1))
364MOVE = mv $(UNPACK_DIR) $@ && touch $@
365
366AUTOMAKE_DATA_DIRS=$(foreach n,$(foreach n,$(subst :, ,$(shell echo $$PATH)),$(abspath $(n)/../share)),$(wildcard $(n)/automake*))
367UPDATE_AUTOCONFIG = for dir in $(AUTOMAKE_DATA_DIRS); do \
368		if test -f "$${dir}/config.sub" -a -f "$${dir}/config.guess"; then \
369			cp "$${dir}/config.sub" "$${dir}/config.guess" $(UNPACK_DIR); \
370			break; \
371		fi; \
372	done
373
374ifdef HAVE_DARWIN_OS
375AUTORECONF = AUTOPOINT=true autoreconf
376else
377AUTORECONF = autoreconf
378endif
379RECONF = mkdir -p -- $(PREFIX)/share/aclocal && \
380	cd $< && $(AUTORECONF) -fiv $(ACLOCAL_AMFLAGS)
381CMAKEBUILD := cmake --build
382CMAKE = cmake . -DCMAKE_TOOLCHAIN_FILE=$(abspath toolchain.cmake) \
383		-DCMAKE_INSTALL_PREFIX=$(PREFIX) \
384		-DBUILD_SHARED_LIBS:BOOL=OFF
385ifdef HAVE_WIN32
386CMAKE += -DCMAKE_DEBUG_POSTFIX:STRING=
387endif
388ifeq ($(findstring mingw32,$(BUILD)),mingw32)
389CMAKE += -DCMAKE_LINK_LIBRARY_SUFFIX:STRING=.a
390endif
391
392MESONFLAGS = --default-library static --prefix "$(PREFIX)" --backend ninja \
393	-Dlibdir=lib
394ifndef WITH_OPTIMIZATION
395MESONFLAGS += --buildtype debug
396else
397MESONFLAGS += --buildtype debugoptimized
398endif
399
400ifdef HAVE_CROSS_COMPILE
401# When cross-compiling meson uses the env vars like
402# CC, CXX, etc. and CFLAGS, CXXFLAGS, etc. for the
403# build machine compiler and not like most other
404# buildsystems for the host compilation. Therefore
405# we clear the enviornment variables using the env
406# command, except PATH, which is needed.
407# The values of the mentioned relevant env variables
408# are passed for the host compilation using the
409# generated crossfile, so everything should work as
410# expected.
411MESONFLAGS += --cross-file $(abspath crossfile.meson)
412MESON = env -i PATH="$(PREFIX)/bin:$(PATH)" PKG_CONFIG_LIBDIR="$(PKG_CONFIG_LIBDIR)" \
413	PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" meson $(MESONFLAGS)
414else
415MESON = meson $(MESONFLAGS)
416endif
417
418ifdef GPL
419REQUIRE_GPL =
420else
421REQUIRE_GPL = @echo "Package \"$<\" requires the GPL license." >&2; exit 1
422endif
423ifdef GNUV3
424REQUIRE_GNUV3 =
425else
426REQUIRE_GNUV3 = \
427	@echo "Package \"$<\" requires the version 3 of GNU licenses." >&2; \
428	exit 1
429endif
430
431#
432# Per-package build rules
433#
434PKGS_FOUND :=
435include $(SRC)/*/rules.mak
436
437ifeq ($(PKGS_DISABLE), all)
438PKGS :=
439endif
440#
441# Targets
442#
443ifneq ($(filter $(PKGS_DISABLE),$(PKGS_ENABLE)),)
444$(error Same package(s) disabled and enabled at the same time)
445endif
446# Apply automatic selection (= remove distro packages):
447PKGS_AUTOMATIC := $(filter-out $(PKGS_FOUND),$(PKGS))
448# Apply manual selection (from bootstrap):
449PKGS_MANUAL := $(sort $(PKGS_ENABLE) $(filter-out $(PKGS_DISABLE),$(PKGS_AUTOMATIC)))
450# Resolve dependencies:
451PKGS_DEPS := $(filter-out $(PKGS_FOUND) $(PKGS_MANUAL),$(sort $(foreach p,$(PKGS_MANUAL),$(DEPS_$(p)))))
452PKGS := $(sort $(PKGS_MANUAL) $(PKGS_DEPS))
453
454fetch: $(PKGS:%=.sum-%)
455fetch-all: $(PKGS_ALL:%=.sum-%)
456install: $(PKGS:%=.%)
457
458mostlyclean:
459	-$(RM) $(foreach p,$(PKGS_ALL),.$(p) .sum-$(p) .dep-$(p))
460	-$(RM) toolchain.cmake
461	-$(RM) crossfile.meson
462	-$(RM) -R "$(PREFIX)"
463	-$(RM) -R "$(BUILDBINDIR)"
464	-$(RM) -R */
465
466clean: mostlyclean
467	-$(RM) $(TARBALLS)/*.*
468
469distclean: clean
470	$(RM) config.mak
471	unlink Makefile
472
473PREBUILT_URL=http://download.videolan.org/pub/videolan/contrib/$(HOST)/vlc-contrib-$(HOST)-latest.tar.bz2
474
475vlc-contrib-$(HOST)-latest.tar.bz2:
476	$(call download,$(PREBUILT_URL))
477
478prebuilt: vlc-contrib-$(HOST)-latest.tar.bz2
479	$(RM) -r $(PREFIX)
480	-$(UNPACK)
481	mv $(HOST) $(PREFIX)
482	cd $(PREFIX) && $(abspath $(SRC))/change_prefix.sh
483ifdef HAVE_WIN32
484ifndef HAVE_CROSS_COMPILE
485	$(RM) `find $(PREFIX)/bin | file -f- | grep ELF | awk -F: '{print $$1}' | xargs`
486endif
487endif
488
489package: install
490	rm -Rf tmp/
491	mkdir -p tmp/
492	cp -R $(PREFIX) tmp/
493	# remove useless files
494	cd tmp/$(notdir $(PREFIX)); \
495		cd share; rm -Rf man doc gtk-doc info lua projectM; cd ..; \
496		rm -Rf man sbin etc lib/lua lib/sidplay
497	cd tmp/$(notdir $(PREFIX)) && $(abspath $(SRC))/change_prefix.sh $(PREFIX) @@CONTRIB_PREFIX@@
498ifneq ($(notdir $(PREFIX)),$(HOST))
499	(cd tmp && mv $(notdir $(PREFIX)) $(HOST))
500endif
501	(cd tmp && tar c $(HOST)/) | bzip2 -c > ../vlc-contrib-$(HOST)-$(DATE).tar.bz2
502
503list:
504	@echo All packages:
505	@echo '  $(PKGS_ALL)' | tr " " "\n" | sort | tr "\n" " " |fmt
506	@echo Distribution-provided packages:
507	@echo '  $(PKGS_FOUND)' | tr " " "\n" | sort | tr "\n" " " |fmt
508	@echo Automatically selected packages:
509	@echo '  $(PKGS_AUTOMATIC)' | tr " " "\n" | sort | tr "\n" " " |fmt
510	@echo Manually deselected packages:
511	@echo '  $(PKGS_DISABLE)' | tr " " "\n" | sort | tr "\n" " " |fmt
512	@echo Manually selected packages:
513	@echo '  $(PKGS_ENABLE)' | tr " " "\n" | sort | tr "\n" " " |fmt
514	@echo Depended-on packages:
515	@echo '  $(PKGS_DEPS)' | tr " " "\n" | sort | tr "\n" " " |fmt
516	@echo To-be-built packages:
517	@echo '  $(PKGS)' | tr " " "\n" | sort | tr "\n" " " |fmt
518
519help:
520	@cat $(SRC)/help.txt
521
522.PHONY: all fetch fetch-all install mostlyclean clean distclean package list help prebuilt
523
524CMAKE_SYSTEM_NAME =
525ifdef HAVE_WIN32
526CMAKE_SYSTEM_NAME = Windows
527ifdef HAVE_VISUALSTUDIO
528ifdef HAVE_WINSTORE
529CMAKE_SYSTEM_NAME = WindowsStore
530endif
531ifdef HAVE_WINDOWSPHONE
532CMAKE_SYSTEM_NAME = WindowsPhone
533endif
534endif
535endif
536ifdef HAVE_DARWIN_OS
537CMAKE_SYSTEM_NAME = Darwin
538endif
539
540# CMake toolchain
541toolchain.cmake:
542	$(RM) $@
543ifndef WITH_OPTIMIZATION
544	echo "set(CMAKE_BUILD_TYPE Debug)" >> $@
545else
546	echo "set(CMAKE_BUILD_TYPE RelWithDebInfo)" >> $@
547endif
548	echo "set(CMAKE_SYSTEM_PROCESSOR $(ARCH))" >> $@
549	if test -n "$(CMAKE_SYSTEM_NAME)"; then \
550		echo "set(CMAKE_SYSTEM_NAME $(CMAKE_SYSTEM_NAME))" >> $@; \
551	fi;
552ifdef HAVE_WIN32
553ifdef HAVE_CROSS_COMPILE
554	echo "set(CMAKE_RC_COMPILER $(WINDRES))" >> $@
555endif
556endif
557ifdef HAVE_DARWIN_OS
558	echo "set(CMAKE_C_FLAGS \"$(CFLAGS)\")" >> $@
559	echo "set(CMAKE_CXX_FLAGS \"$(CXXFLAGS)\")" >> $@
560	echo "set(CMAKE_LD_FLAGS \"$(LDFLAGS)\")" >> $@
561	echo "set(CMAKE_AR ar CACHE FILEPATH \"Archiver\")" >> $@
562ifdef HAVE_IOS
563	echo "set(CMAKE_OSX_SYSROOT $(IOS_SDK))" >> $@
564else
565	echo "set(CMAKE_OSX_SYSROOT $(MACOSX_SDK))" >> $@
566endif
567else
568	echo "set(CMAKE_AR $(AR) CACHE FILEPATH \"Archiver\")" >> $@
569endif
570ifdef HAVE_CROSS_COMPILE
571	echo "set(_CMAKE_TOOLCHAIN_PREFIX $(HOST)-)" >> $@
572ifdef HAVE_ANDROID
573# cmake will overwrite our --sysroot with a native (host) one on Darwin
574# Set it to "" right away to short-circuit this behaviour
575	echo "set(CMAKE_CXX_SYSROOT_FLAG \"\")" >> $@
576	echo "set(CMAKE_C_SYSROOT_FLAG \"\")" >> $@
577endif
578endif
579	echo "set(CMAKE_C_COMPILER $(CC))" >> $@
580	echo "set(CMAKE_CXX_COMPILER $(CXX))" >> $@
581ifeq ($(findstring msys,$(BUILD)),msys)
582	echo "set(CMAKE_FIND_ROOT_PATH `cygpath -m $(PREFIX)`)" >> $@
583else
584	echo "set(CMAKE_FIND_ROOT_PATH $(PREFIX))" >> $@
585endif
586	echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> $@
587ifdef HAVE_CROSS_COMPILE
588	echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> $@
589	echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> $@
590endif
591
592MESON_SYSTEM_NAME =
593ifdef HAVE_WIN32
594	MESON_SYSTEM_NAME = windows
595else
596ifdef HAVE_DARWIN_OS
597	MESON_SYSTEM_NAME = darwin
598else
599ifdef HAVE_ANDROID
600	MESON_SYSTEM_NAME = android
601else
602ifdef HAVE_LINUX
603	# android has also system = linux and defines HAVE_LINUX
604	MESON_SYSTEM_NAME = linux
605else
606	$(error "No meson system name known for this target")
607endif
608endif
609endif
610endif
611
612
613crossfile.meson: $(SRC)/gen-meson-crossfile.py
614	$(HOSTVARS_MESON) \
615	WINDRES="$(WINDRES)" \
616	PKG_CONFIG="$(PKG_CONFIG)" \
617	HOST_SYSTEM="$(MESON_SYSTEM_NAME)" \
618	HOST_ARCH="$(subst i386,x86,$(ARCH))" \
619	HOST="$(HOST)" \
620	$(SRC)/gen-meson-crossfile.py $@
621	cat $@
622
623# Default pattern rules
624.sum-%: $(SRC)/%/SHA512SUMS
625	$(CHECK_SHA512)
626	touch $@
627
628.sum-%:
629	$(error Download and check target not defined for $*)
630
631# Dummy dependency on found packages
632$(patsubst %,.dep-%,$(PKGS_FOUND)): .dep-%:
633	touch $@
634
635# Real dependency on missing packages
636$(patsubst %,.dep-%,$(filter-out $(PKGS_FOUND),$(PKGS_ALL))): .dep-%: .%
637	touch -r $< $@
638
639.SECONDEXPANSION:
640
641# Dependency propagation (convert 'DEPS_foo = bar' to '.foo: .bar')
642$(foreach p,$(PKGS_ALL),.$(p)): .%: $$(foreach d,$$(DEPS_$$*),.dep-$$(d))
643
644.DELETE_ON_ERROR:
645