main.mak 15.7 KB
Newer Older
1 2 3 4 5 6 7
# Main makefile for VLC 3rd party libraries ("contrib")
# Copyright (C) 2003-2011 the VideoLAN team
#
# This file is under the same license as the vlc package.

all: install

8 9 10 11 12 13 14 15
# bootstrap configuration
include config.mak

TOPSRC ?= ../../contrib
TOPDST ?= ..
SRC := $(TOPSRC)/src
TARBALLS := $(TOPSRC)/tarballs

16 17 18
PATH :=$(abspath ../../extras/tools/build/bin):$(PATH)
export PATH

19
PKGS_ALL := $(patsubst $(SRC)/%/rules.mak,%,$(wildcard $(SRC)/*/rules.mak))
20
DATE := $(shell date +%Y%m%d)
21
VPATH := $(TARBALLS)
22 23

# Common download locations
24
GNU ?= http://ftp.gnu.org/gnu
25
SF := https://netcologne.dl.sourceforge.net/
26
VIDEOLAN := http://downloads.videolan.org/pub/videolan
27
CONTRIB_VIDEOLAN := http://downloads.videolan.org/pub/contrib
28
GITHUB := https://github.com/
29 30 31 32

#
# Machine-dependent variables
#
33

34
PREFIX ?= $(TOPDST)/$(HOST)
35
PREFIX := $(abspath $(PREFIX))
36 37 38
BUILDPREFIX ?= $(TOPDST)
BUILDPREFIX := $(abspath $(BUILDPREFIX))
BUILDBINDIR ?= $(BUILDPREFIX)/bin
39 40 41
ifneq ($(HOST),$(BUILD))
HAVE_CROSS_COMPILE = 1
endif
42
ARCH := $(shell $(SRC)/get-arch.sh $(HOST))
43

44 45 46
ifeq ($(ARCH)-$(HAVE_WIN32),x86_64-1)
HAVE_WIN64 := 1
endif
47 48 49
ifeq ($(ARCH)-$(HAVE_WIN32),aarch64-1)
HAVE_WIN64 := 1
endif
50 51 52 53

ifdef HAVE_CROSS_COMPILE
need_pkg = 1
else
54
need_pkg = $(shell $(PKG_CONFIG) $(1) || echo 1)
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
endif

#
# Default values for tools
#
ifndef HAVE_CROSS_COMPILE
ifneq ($(findstring $(origin CC),undefined default),)
CC := gcc
endif
ifneq ($(findstring $(origin CXX),undefined default),)
CXX := g++
endif
ifneq ($(findstring $(origin LD),undefined default),)
LD := ld
endif
ifneq ($(findstring $(origin AR),undefined default),)
AR := ar
endif
ifneq ($(findstring $(origin RANLIB),undefined default),)
RANLIB := ranlib
endif
ifneq ($(findstring $(origin STRIP),undefined default),)
STRIP := strip
endif
79 80 81
ifneq ($(findstring $(origin WIDL),undefined default),)
WIDL := widl
endif
82 83 84
ifneq ($(findstring $(origin WINDRES),undefined default),)
WINDRES := windres
endif
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
else
ifneq ($(findstring $(origin CC),undefined default),)
CC := $(HOST)-gcc
endif
ifneq ($(findstring $(origin CXX),undefined default),)
CXX := $(HOST)-g++
endif
ifneq ($(findstring $(origin LD),undefined default),)
LD := $(HOST)-ld
endif
ifneq ($(findstring $(origin AR),undefined default),)
AR := $(HOST)-ar
endif
ifneq ($(findstring $(origin RANLIB),undefined default),)
RANLIB := $(HOST)-ranlib
endif
ifneq ($(findstring $(origin STRIP),undefined default),)
STRIP := $(HOST)-strip
endif
104 105 106
ifneq ($(findstring $(origin WIDL),undefined default),)
WIDL := $(HOST)-widl
endif
107 108 109
ifneq ($(findstring $(origin WINDRES),undefined default),)
WINDRES := $(HOST)-windres
endif
110 111
endif

112
ifdef HAVE_ANDROID
113
ifneq ($(findstring $(origin CC),undefined default),)
114
CC :=  clang
115 116
endif
ifneq ($(findstring $(origin CXX),undefined default),)
117
CXX := clang++
118
endif
119
endif
120

121
ifdef HAVE_MACOSX
122
EXTRA_CXXFLAGS += -stdlib=libc++
123 124 125 126
ifeq ($(ARCH),x86_64)
EXTRA_CFLAGS += -m64
EXTRA_LDFLAGS += -m64
else
127 128 129
EXTRA_CFLAGS += -m32
EXTRA_LDFLAGS += -m32
endif
130

131
XCODE_FLAGS += -arch $(ARCH)
132

133
endif
134

135
CCAS=$(CC) -c
136

137
ifdef HAVE_IOS
138
ifdef HAVE_NEON
139
AS=perl $(abspath ../../extras/tools/build/bin/gas-preprocessor.pl) $(CC)
140
CCAS=gas-preprocessor.pl $(CC) -c
141
endif
142
EXTRA_CFLAGS += $(CFLAGS)
143 144
endif

145
LN_S = ln -s
146 147 148 149
ifdef HAVE_WIN32
ifneq ($(shell $(CC) $(CFLAGS) -E -dM -include _mingw.h - < /dev/null | grep -E __MINGW64_VERSION_MAJOR),)
HAVE_MINGW_W64 := 1
endif
150 151 152
ifndef HAVE_CROSS_COMPILE
LN_S = cp -R
endif
153 154 155
ifneq ($(findstring clang, $(shell $(CC) --version)),)
HAVE_CLANG := 1
endif
156 157
endif

158 159 160 161 162 163 164 165 166 167
ifdef HAVE_SOLARIS
ifeq ($(ARCH),x86_64)
EXTRA_CFLAGS += -m64
EXTRA_LDFLAGS += -m64
else
EXTRA_CFLAGS += -m32
EXTRA_LDFLAGS += -m32
endif
endif

168
cppcheck = $(shell $(CC) $(CFLAGS) -E -dM - < /dev/null | grep -E $(1))
169

170 171
EXTRA_CFLAGS += -I$(PREFIX)/include
CPPFLAGS := $(CPPFLAGS) $(EXTRA_CFLAGS)
172
CFLAGS := $(CFLAGS) $(EXTRA_CFLAGS) -g
173
CXXFLAGS := $(CXXFLAGS) $(EXTRA_CFLAGS) $(EXTRA_CXXFLAGS) -g
174
LDFLAGS := $(LDFLAGS) -L$(PREFIX)/lib $(EXTRA_LDFLAGS)
175 176 177 178

ifndef WITH_OPTIMIZATION
CFLAGS := $(CFLAGS) -O0
CXXFLAGS := $(CXXFLAGS) -O0
179 180 181
else
CFLAGS := $(CFLAGS) -O2
CXXFLAGS := $(CXXFLAGS) -O2
182 183
endif

184 185
# Do not export those! Use HOSTVARS.

186
# Do the FPU detection, after we have figured out our compilers and flags.
187
ifneq ($(findstring $(ARCH),aarch64 i386 ppc ppc64 sparc sparc64 x86_64),)
188 189 190 191 192 193 194 195
# This should be consistent with include/vlc_cpu.h
HAVE_FPU = 1
else ifneq ($(findstring $(ARCH),arm),)
ifneq ($(call cppcheck, __VFP_FP__)),)
ifeq ($(call cppcheck, __SOFTFP__),)
HAVE_FPU = 1
endif
endif
196 197
else ifneq ($(call cppcheck, __mips_hard_float),)
HAVE_FPU = 1
198 199
endif

200
ACLOCAL_AMFLAGS += -I$(PREFIX)/share/aclocal
201 202 203
ifneq ($(wildcard $(TOPSRC)/../extras/tools/build/share/aclocal/*),)
ACLOCAL_AMFLAGS += -I$(abspath $(TOPSRC)/../extras/tools/build/share/aclocal)
endif
204 205
export ACLOCAL_AMFLAGS

206 207 208 209
#########
# Tools #
#########

210 211 212 213
PKG_CONFIG ?= pkg-config
ifdef HAVE_CROSS_COMPILE
# This inhibits .pc file from within the cross-compilation toolchain sysroot.
# Hopefully, nobody ever needs that.
214 215
PKG_CONFIG_PATH := /usr/share/pkgconfig
PKG_CONFIG_LIBDIR := /usr/$(HOST)/lib/pkgconfig
216 217
export PKG_CONFIG_LIBDIR
endif
218
PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH)
219 220
export PKG_CONFIG_PATH

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
ifndef GIT
ifeq ($(shell git --version >/dev/null 2>&1 || echo FAIL),)
GIT = git
endif
endif
GIT ?= $(error git not found!)

ifndef SVN
ifeq ($(shell svn --version >/dev/null 2>&1 || echo FAIL),)
SVN = svn
endif
endif
SVN ?= $(error subversion client (svn) not found!)

ifeq ($(shell curl --version >/dev/null 2>&1 || echo FAIL),)
236 237
download = curl -f -L -- "$(1)" > "$@"
else ifeq ($(shell wget --version >/dev/null 2>&1 || echo FAIL),)
238
download = (rm -f $@.tmp && \
239
	wget --passive -c -p -O $@.tmp "$(1)" && \
240
	touch $@.tmp && \
241
	mv $@.tmp $@ )
242
else ifeq ($(which fetch >/dev/null 2>&1 || echo FAIL),)
243
download = (rm -f $@.tmp && \
244 245
	fetch -p -o $@.tmp "$(1)" && \
	touch $@.tmp && \
246
	mv $@.tmp $@)
247 248
else
download = $(error Neither curl nor wget found!)
249
endif
250

251
download_pkg = $(call download,$(CONTRIB_VIDEOLAN)/$(2)/$(lastword $(subst /, ,$(@)))) || \
252
	( $(call download,$(1)) && echo "Please upload this package $(lastword $(subst /, ,$(@))) to our FTP" )
253

254 255 256 257 258 259
ifeq ($(shell which xz >/dev/null 2>&1 || echo FAIL),)
XZ = xz
else
XZ ?= $(error XZ (LZMA) compressor not found!)
endif

260
ifeq ($(shell sha512sum --version >/dev/null 2>&1 || echo FAIL),)
261
SHA512SUM = sha512sum --check
262
else ifeq ($(shell shasum --version >/dev/null 2>&1 || echo FAIL),)
263 264 265
SHA512SUM = shasum -a 512 --check
else ifeq ($(shell openssl version >/dev/null 2>&1 || echo FAIL),)
SHA512SUM = openssl dgst -sha512
266 267 268 269
else
SHA512SUM = $(error SHA-512 checksumming not found!)
endif

270 271 272 273 274 275
ifeq ($(shell protoc --version >/dev/null 2>&1 || echo FAIL),)
PROTOC = protoc
else
PROTOC ?= $(error Protobuf compiler (protoc) not found!)
endif

276 277 278 279
#
# Common helpers
#
HOSTCONF := --prefix="$(PREFIX)"
280 281 282
HOSTCONF += --datarootdir="$(PREFIX)/share"
HOSTCONF += --includedir="$(PREFIX)/include"
HOSTCONF += --libdir="$(PREFIX)/lib"
283 284 285
HOSTCONF += --build="$(BUILD)" --host="$(HOST)" --target="$(HOST)"
HOSTCONF += --program-prefix=""
# libtool stuff:
286
HOSTCONF += --enable-static --disable-shared --disable-dependency-tracking
287 288
ifdef HAVE_WIN32
HOSTCONF += --without-pic
289
PIC :=
290 291
else
HOSTCONF += --with-pic
292 293 294 295 296
PIC := -fPIC
endif

HOSTTOOLS := \
	CC="$(CC)" CXX="$(CXX)" LD="$(LD)" \
297
	AR="$(AR)" CCAS="$(CCAS)" RANLIB="$(RANLIB)" STRIP="$(STRIP)" \
298
	PATH="$(PREFIX)/bin:$(PATH)"
299
HOSTVARS := \
300 301 302 303 304 305 306 307 308
	CPPFLAGS="$(CPPFLAGS)" \
	CFLAGS="$(CFLAGS)" \
	CXXFLAGS="$(CXXFLAGS)" \
	LDFLAGS="$(LDFLAGS)"
HOSTVARS_PIC := $(HOSTTOOLS) \
	CPPFLAGS="$(CPPFLAGS) $(PIC)" \
	CFLAGS="$(CFLAGS) $(PIC)" \
	CXXFLAGS="$(CXXFLAGS) $(PIC)" \
	LDFLAGS="$(LDFLAGS)"
309

310 311 312 313 314
# Keep a version of HOSTVARS without the tools, since meson requires the
# tools variables to point to the native ones
HOSTVARS_MESON := $(HOSTVARS)
HOSTVARS := $(HOSTTOOLS) $(HOSTVARS)

315
download_git = \
316 317 318 319 320 321
	rm -Rf -- "$(@:.tar.xz=)" && \
	$(GIT) init --bare "$(@:.tar.xz=)" && \
	(cd "$(@:.tar.xz=)" && \
	$(GIT) remote add origin "$(1)" && \
	$(GIT) fetch origin "$(2)") && \
	(cd "$(@:.tar.xz=)" && \
322
	$(GIT) archive --prefix="$(notdir $(@:.tar.xz=))/" \
323 324
		--format=tar "$(3)") > "$(@:.xz=)" && \
	echo "$(3) $(@)" > "$(@:.tar.xz=.githash)" && \
325
	rm -Rf -- "$(@:.tar.xz=)" && \
326
	$(XZ) --stdout "$(@:.xz=)" > "$@.tmp" && \
327
	rm -f "$(@:.xz=)" && \
328 329 330 331 332 333
	mv -f -- "$@.tmp" "$@"
check_githash = \
	h=`sed -n -e "s,^\([0-9a-fA-F]\{40\}\) $<,\1,p" \
		< "$(<:.tar.xz=.githash)"` && \
	test "$$h" = "$1"

334 335 336 337
checksum = \
	$(foreach f,$(filter $(TARBALLS)/%,$^), \
		grep -- " $(f:$(TARBALLS)/%=%)$$" \
			"$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS" &&) \
338
	(cd $(TARBALLS) && $(1) /dev/stdin) < \
339
		"$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS"
340
CHECK_SHA512 = $(call checksum,$(SHA512SUM),SHA512)
341 342 343 344 345
UNPACK = $(RM) -R $@ \
	$(foreach f,$(filter %.tar.gz %.tgz,$^), && tar xvzf $(f)) \
	$(foreach f,$(filter %.tar.bz2,$^), && tar xvjf $(f)) \
	$(foreach f,$(filter %.tar.xz,$^), && tar xvJf $(f)) \
	$(foreach f,$(filter %.zip,$^), && unzip $(f))
346
UNPACK_DIR = $(patsubst %.tar,%,$(basename $(notdir $<)))
347
APPLY = (cd $(UNPACK_DIR) && patch -fp1) <
348
pkg_static = (cd $(UNPACK_DIR) && ../../../contrib/src/pkg-static.sh $(1))
349
MOVE = mv $(UNPACK_DIR) $@ && touch $@
350

351
AUTOMAKE_DATA_DIRS=$(foreach n,$(foreach n,$(subst :, ,$(shell echo $$PATH)),$(abspath $(n)/../share)),$(wildcard $(n)/automake*))
352 353
UPDATE_AUTOCONFIG = for dir in $(AUTOMAKE_DATA_DIRS); do \
		if test -f "$${dir}/config.sub" -a -f "$${dir}/config.guess"; then \
354
			cp "$${dir}/config.sub" "$${dir}/config.guess" $(UNPACK_DIR); \
355 356 357 358
			break; \
		fi; \
	done

359
ifdef HAVE_DARWIN_OS
360 361 362 363
AUTORECONF = AUTOPOINT=true autoreconf
else
AUTORECONF = autoreconf
endif
364
RECONF = mkdir -p -- $(PREFIX)/share/aclocal && \
365
	cd $< && $(AUTORECONF) -fiv $(ACLOCAL_AMFLAGS)
366
CMAKE = cmake . -DCMAKE_TOOLCHAIN_FILE=$(abspath toolchain.cmake) \
367
		-DCMAKE_INSTALL_PREFIX=$(PREFIX) $(CMAKE_GENERATOR)
368

369 370 371 372
ifeq ($(V),1)
CMAKE += -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
endif

373 374 375 376 377 378 379 380
MESON = meson --default-library static --prefix "$(PREFIX)" --backend ninja \
	-Dlibdir=lib
ifndef WITH_OPTIMIZATION
MESON += --buildtype debug
else
MESON += --buildtype release
endif

381 382 383
ifdef HAVE_CROSS_COMPILE
MESON += --cross-file $(abspath crossfile.meson)
endif
384

385 386 387 388 389
ifdef GPL
REQUIRE_GPL =
else
REQUIRE_GPL = @echo "Package \"$<\" requires the GPL license." >&2; exit 1
endif
390 391 392 393 394 395 396
ifdef GNUV3
REQUIRE_GNUV3 =
else
REQUIRE_GNUV3 = \
	@echo "Package \"$<\" requires the version 3 of GNU licenses." >&2; \
	exit 1
endif
397

398 399 400
#
# Per-package build rules
#
401
PKGS_FOUND :=
402
include $(SRC)/*/rules.mak
403

404 405 406
ifeq ($(PKGS_DISABLE), all)
PKGS :=
endif
407 408 409
#
# Targets
#
410 411 412
ifneq ($(filter $(PKGS_DISABLE),$(PKGS_ENABLE)),)
$(error Same package(s) disabled and enabled at the same time)
endif
413 414 415 416 417 418 419
# Apply automatic selection (= remove distro packages):
PKGS_AUTOMATIC := $(filter-out $(PKGS_FOUND),$(PKGS))
# Apply manual selection (from bootstrap):
PKGS_MANUAL := $(sort $(PKGS_ENABLE) $(filter-out $(PKGS_DISABLE),$(PKGS_AUTOMATIC)))
# Resolve dependencies:
PKGS_DEPS := $(filter-out $(PKGS_FOUND) $(PKGS_MANUAL),$(sort $(foreach p,$(PKGS_MANUAL),$(DEPS_$(p)))))
PKGS := $(sort $(PKGS_MANUAL) $(PKGS_DEPS))
420

421
fetch: $(PKGS:%=.sum-%)
422
fetch-all: $(PKGS_ALL:%=.sum-%)
423 424 425
install: $(PKGS:%=.%)

mostlyclean:
426
	-$(RM) $(foreach p,$(PKGS_ALL),.$(p) .sum-$(p) .dep-$(p))
427
	-$(RM) toolchain.cmake
428
	-$(RM) crossfile.meson
429
	-$(RM) -R "$(PREFIX)"
430
	-$(RM) -R "$(BUILDBINDIR)"
431
	-$(RM) -R */
432 433 434 435 436 437 438 439

clean: mostlyclean
	-$(RM) $(TARBALLS)/*.*

distclean: clean
	$(RM) config.mak
	unlink Makefile

440
PREBUILT_URL=http://download.videolan.org/pub/videolan/contrib/$(HOST)/vlc-contrib-$(HOST)-latest.tar.bz2
441

442
vlc-contrib-$(HOST)-latest.tar.bz2:
443 444
	$(call download,$(PREBUILT_URL))

445
prebuilt: vlc-contrib-$(HOST)-latest.tar.bz2
446
	-$(UNPACK)
447 448 449
	$(RM) -r $(TOPDST)/$(HOST)
	mv $(HOST) $(TOPDST)
	cd $(TOPDST)/$(HOST) && $(SRC)/change_prefix.sh
450 451
ifdef HAVE_WIN32
ifndef HAVE_CROSS_COMPILE
452
	$(RM) `find $(TOPDST)/$(HOST)/bin | file -f- | grep ELF | awk -F: '{print $$1}' | xargs`
453 454
endif
endif
455

456
package: install
457 458
	rm -Rf tmp/
	mkdir -p tmp/
459
	cp -R $(PREFIX) tmp/
460 461
	# remove useless files
	cd tmp/$(notdir $(PREFIX)); \
462
		cd share; rm -Rf man doc gtk-doc info lua projectM; cd ..; \
463
		rm -Rf man sbin etc lib/lua lib/sidplay
464
	cd tmp/$(notdir $(PREFIX)) && $(abspath $(SRC))/change_prefix.sh $(PREFIX) @@CONTRIB_PREFIX@@
465
	(cd tmp && tar c $(notdir $(PREFIX))/) | bzip2 -c > ../vlc-contrib-$(HOST)-$(DATE).tar.bz2
466

467 468
list:
	@echo All packages:
469
	@echo '  $(PKGS_ALL)' | tr " " "\n" | sort | tr "\n" " " |fmt
470
	@echo Distribution-provided packages:
471
	@echo '  $(PKGS_FOUND)' | tr " " "\n" | sort | tr "\n" " " |fmt
472
	@echo Automatically selected packages:
473
	@echo '  $(PKGS_AUTOMATIC)' | tr " " "\n" | sort | tr "\n" " " |fmt
474
	@echo Manually deselected packages:
475
	@echo '  $(PKGS_DISABLE)' | tr " " "\n" | sort | tr "\n" " " |fmt
476
	@echo Manually selected packages:
477
	@echo '  $(PKGS_ENABLE)' | tr " " "\n" | sort | tr "\n" " " |fmt
478
	@echo Depended-on packages:
479
	@echo '  $(PKGS_DEPS)' | tr " " "\n" | sort | tr "\n" " " |fmt
480
	@echo To-be-built packages:
481
	@echo '  $(PKGS)' | tr " " "\n" | sort | tr "\n" " " |fmt
482

483 484 485 486
help:
	@cat $(SRC)/help.txt

.PHONY: all fetch fetch-all install mostlyclean clean distclean package list help prebuilt
487

488 489 490
# CMake toolchain
toolchain.cmake:
	$(RM) $@
491 492 493 494 495
ifndef WITH_OPTIMIZATION
	echo "set(CMAKE_BUILD_TYPE Debug)" >> $@
else
	echo "set(CMAKE_BUILD_TYPE Release)" >> $@
endif
496
	echo "set(CMAKE_SYSTEM_PROCESSOR $(ARCH))" >> $@
497
ifdef HAVE_WIN32
498 499 500 501 502 503
ifdef HAVE_WINDOWSPHONE
	echo "set(CMAKE_SYSTEM_NAME WindowsPhone)" >> $@
else
ifdef HAVE_WINSTORE
	echo "set(CMAKE_SYSTEM_NAME WindowsStore)" >> $@
else
504
	echo "set(CMAKE_SYSTEM_NAME Windows)" >> $@
505
endif
506
endif
507
ifdef HAVE_CROSS_COMPILE
508 509
	echo "set(CMAKE_RC_COMPILER $(HOST)-windres)" >> $@
endif
510
endif
511
ifdef HAVE_DARWIN_OS
512
	echo "set(CMAKE_SYSTEM_NAME Darwin)" >> $@
513 514 515
	echo "set(CMAKE_C_FLAGS \"$(CFLAGS) $(EXTRA_CFLAGS)\")" >> $@
	echo "set(CMAKE_CXX_FLAGS \"$(CFLAGS) $(EXTRA_CXXFLAGS)\")" >> $@
	echo "set(CMAKE_LD_FLAGS \"$(LDFLAGS)\")" >> $@
516
	echo "set(CMAKE_AR ar CACHE FILEPATH "Archiver")" >> $@
517
ifdef HAVE_IOS
518 519 520
	echo "set(CMAKE_OSX_SYSROOT $(IOS_SDK))" >> $@
else
	echo "set(CMAKE_OSX_SYSROOT $(MACOSX_SDK))" >> $@
521
endif
522 523
else
	echo "set(CMAKE_AR $(AR) CACHE FILEPATH "Archiver")" >> $@
524 525 526
endif
ifdef HAVE_CROSS_COMPILE
	echo "set(_CMAKE_TOOLCHAIN_PREFIX $(HOST)-)" >> $@
527 528 529 530 531 532
ifdef HAVE_ANDROID
# cmake will overwrite our --sysroot with a native (host) one on Darwin
# Set it to "" right away to short-circuit this behaviour
	echo "set(CMAKE_CXX_SYSROOT_FLAG \"\")" >> $@
	echo "set(CMAKE_C_SYSROOT_FLAG \"\")" >> $@
endif
533 534 535 536 537
endif
	echo "set(CMAKE_C_COMPILER $(CC))" >> $@
	echo "set(CMAKE_CXX_COMPILER $(CXX))" >> $@
	echo "set(CMAKE_FIND_ROOT_PATH $(PREFIX))" >> $@
	echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> $@
538
ifdef HAVE_CROSS_COMPILE
539 540
	echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> $@
	echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> $@
541
	echo "set(PKG_CONFIG_EXECUTABLE $(PKG_CONFIG))" >> $@
542
endif
543

544 545 546 547 548 549 550 551
crossfile.meson:
	$(RM) $@
	echo "[binaries]" >> $@
	echo "c = '$(CC)'" >> $@
	echo "cpp = '$(CXX)'" >> $@
	echo "ar = '$(AR)'" >> $@
	echo "strip = '$(STRIP)'" >> $@
	echo "pkgconfig = '$(PKG_CONFIG)'" >> $@
552
	echo "windres = '$(WINDRES)'" >> $@
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
	echo "[properties]" >> $@
	echo "needs_exe_wrapper = true" >> $@
ifdef HAVE_CROSS_COMPILE
	echo "[host_machine]" >> $@
ifdef HAVE_WIN32
	echo "system = 'windows'" >> $@
else
ifdef HAVE_IOS
	echo "system = 'darwin'" >> $@
else
ifdef HAVE_ANDROID
	echo "system = 'linux'" >> $@
endif
endif
endif
	echo "cpu_family = '$(subst i386,x86,$(ARCH))'" >> $@
	echo "cpu = '`echo $(HOST) | cut -d - -f 1`'" >> $@
	echo "endian = 'little'" >> $@
endif

573 574 575 576 577
# Default pattern rules
.sum-%: $(SRC)/%/SHA512SUMS
	$(CHECK_SHA512)
	touch $@

578 579 580
.sum-%:
	$(error Download and check target not defined for $*)

581 582 583 584 585 586 587 588 589 590 591 592 593
# Dummy dependency on found packages
$(patsubst %,.dep-%,$(PKGS_FOUND)): .dep-%:
	touch $@

# Real dependency on missing packages
$(patsubst %,.dep-%,$(filter-out $(PKGS_FOUND),$(PKGS_ALL))): .dep-%: .%
	touch -r $< $@

.SECONDEXPANSION:

# Dependency propagation (convert 'DEPS_foo = bar' to '.foo: .bar')
$(foreach p,$(PKGS_ALL),.$(p)): .%: $$(foreach d,$$(DEPS_$$*),.dep-$$(d))

594
.DELETE_ON_ERROR: