]> git.sesse.net Git - vlc/blob - contrib/src/main.mak
AVI: increase threshold for subtitles detection to 10MB
[vlc] / contrib / src / main.mak
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
6 all: install
7
8 # bootstrap configuration
9 include config.mak
10
11 TOPSRC ?= ../../contrib
12 TOPDST ?= ..
13 SRC := $(TOPSRC)/src
14 TARBALLS := $(TOPSRC)/tarballs
15
16 PATH :=$(abspath ../../extras/tools/build/bin):$(PATH)
17 export PATH
18
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 := http://heanet.dl.sourceforge.net/sourceforge
26 VIDEOLAN := http://downloads.videolan.org/pub/videolan
27 CONTRIB_VIDEOLAN := $(VIDEOLAN)/testing/contrib
28
29 #
30 # Machine-dependent variables
31 #
32
33 PREFIX ?= $(TOPDST)/$(HOST)
34 PREFIX := $(abspath $(PREFIX))
35 ifneq ($(HOST),$(BUILD))
36 HAVE_CROSS_COMPILE = 1
37 endif
38 ARCH := $(shell $(SRC)/get-arch.sh $(HOST))
39 ifneq ($(findstring $(ARCH),i386 sparc sparc64 ppc ppc64 x86_64),)
40 # This should be consistent with include/vlc_cpu.h
41 HAVE_FPU = 1
42 else ifneq ($(findstring $(ARCH),arm),)
43 ifneq ($(call cppcheck, __VFP_FP__)),)
44 ifeq ($(call cppcheck, __SOFTFP__),)
45 HAVE_FPU = 1
46 endif
47 endif
48 endif
49 ifeq ($(ARCH)-$(HAVE_WIN32),x86_64-1)
50 HAVE_WIN64 := 1
51 endif
52
53 ifdef HAVE_CROSS_COMPILE
54 need_pkg = 1
55 else
56 need_pkg = $(shell $(PKG_CONFIG) $(1) || echo 1)
57 endif
58
59 #
60 # Default values for tools
61 #
62 ifndef HAVE_CROSS_COMPILE
63 ifneq ($(findstring $(origin CC),undefined default),)
64 CC := gcc
65 endif
66 ifneq ($(findstring $(origin CXX),undefined default),)
67 CXX := g++
68 endif
69 ifneq ($(findstring $(origin LD),undefined default),)
70 LD := ld
71 endif
72 ifneq ($(findstring $(origin AR),undefined default),)
73 AR := ar
74 endif
75 ifneq ($(findstring $(origin RANLIB),undefined default),)
76 RANLIB := ranlib
77 endif
78 ifneq ($(findstring $(origin STRIP),undefined default),)
79 STRIP := strip
80 endif
81 else
82 ifneq ($(findstring $(origin CC),undefined default),)
83 CC := $(HOST)-gcc
84 endif
85 ifneq ($(findstring $(origin CXX),undefined default),)
86 CXX := $(HOST)-g++
87 endif
88 ifneq ($(findstring $(origin LD),undefined default),)
89 LD := $(HOST)-ld
90 endif
91 ifneq ($(findstring $(origin AR),undefined default),)
92 AR := $(HOST)-ar
93 endif
94 ifneq ($(findstring $(origin RANLIB),undefined default),)
95 RANLIB := $(HOST)-ranlib
96 endif
97 ifneq ($(findstring $(origin STRIP),undefined default),)
98 STRIP := $(HOST)-strip
99 endif
100 endif
101
102 ifdef HAVE_ANDROID
103 CC :=  $(HOST)-gcc --sysroot=$(ANDROID_NDK)/platforms/android-9/arch-$(PLATFORM_SHORT_ARCH)
104 CXX := $(HOST)-g++ --sysroot=$(ANDROID_NDK)/platforms/android-9/arch-$(PLATFORM_SHORT_ARCH)
105 endif
106
107 ifdef HAVE_MACOSX
108 MIN_OSX_VERSION=10.6
109 CC=xcrun gcc
110 CXX=xcrun g++
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_LDFLAGS += -Wl,-syslibroot,$(MACOSX_SDK) -mmacosx-version-min=$(MIN_OSX_VERSION) -isysroot $(MACOSX_SDK) -DMACOSX_DEPLOYMENT_TARGET=$(MIN_OSX_VERSION)
117 ifeq ($(ARCH),x86_64)
118 EXTRA_CFLAGS += -m64
119 EXTRA_LDFLAGS += -m64
120 else
121 EXTRA_CFLAGS += -m32
122 EXTRA_LDFLAGS += -m32
123 endif
124
125 XCODE_FLAGS = -sdk macosx$(OSX_VERSION)
126 ifeq ($(shell xcodebuild -version 2>/dev/null | tee /dev/null|head -1|cut -d\  -f2|cut -d. -f1),3)
127 XCODE_FLAGS += ARCHS=$(ARCH)
128 # XCode 3 doesn't support -arch
129 else
130 XCODE_FLAGS += -arch $(ARCH)
131 endif
132
133 endif
134
135 ifdef HAVE_IOS
136 CC=xcrun clang
137 CXX=xcrun clang++
138 ifeq ($(ARCH), arm)
139 AS=perl $(abspath ../../extras/tools/build/bin/gas-preprocessor.pl) $(CC)
140 else
141 AS=xcrun as
142 endif
143 AR=xcrun ar
144 LD=xcrun ld
145 STRIP=xcrun strip
146 RANLIB=xcrun ranlib
147 ifeq ($(ARCH), arm)
148 EXTRA_CFLAGS += -arch armv7 -mcpu=cortex-a8
149 EXTRA_LDFLAGS += -arch armv7
150 else
151 EXTRA_CFLAGS += -m32
152 EXTRA_LDFLAGS += -m32
153 endif
154 EXTRA_CFLAGS += -isysroot $(SDKROOT)  -miphoneos-version-min=5.0
155 EXTRA_LDFLAGS += -Wl,-syslibroot,$(SDKROOT) -isysroot $(SDKROOT) -miphoneos-version-min=5.0
156 endif
157
158 ifdef HAVE_WIN32
159 ifneq ($(shell $(CC) $(CFLAGS) -E -dM -include _mingw.h - < /dev/null | grep -E __MINGW64_VERSION_MAJOR),)
160 HAVE_MINGW_W64 := 1
161 endif
162 endif
163
164 cppcheck = $(shell $(CC) $(CFLAGS) -E -dM - < /dev/null | grep -E $(1))
165
166 EXTRA_CFLAGS += -I$(PREFIX)/include
167 CPPFLAGS := $(CPPFLAGS) $(EXTRA_CFLAGS)
168 CFLAGS := $(CFLAGS) $(EXTRA_CFLAGS) -g
169 CXXFLAGS := $(CXXFLAGS) $(EXTRA_CFLAGS) -g
170 EXTRA_LDFLAGS += -L$(PREFIX)/lib
171 LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
172 # Do not export those! Use HOSTVARS.
173
174 ACLOCAL_AMFLAGS += -I$(PREFIX)/share/aclocal
175 export ACLOCAL_AMFLAGS
176
177 PKG_CONFIG ?= pkg-config
178 ifdef HAVE_CROSS_COMPILE
179 # This inhibits .pc file from within the cross-compilation toolchain sysroot.
180 # Hopefully, nobody ever needs that.
181 PKG_CONFIG_PATH := /usr/share/pkgconfig
182 PKG_CONFIG_LIBDIR := /usr/$(HOST)/lib/pkgconfig
183 export PKG_CONFIG_LIBDIR
184 endif
185 PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(PREFIX)/lib/pkgconfig
186 export PKG_CONFIG_PATH
187
188 ifndef GIT
189 ifeq ($(shell git --version >/dev/null 2>&1 || echo FAIL),)
190 GIT = git
191 endif
192 endif
193 GIT ?= $(error git not found!)
194
195 ifndef SVN
196 ifeq ($(shell svn --version >/dev/null 2>&1 || echo FAIL),)
197 SVN = svn
198 endif
199 endif
200 SVN ?= $(error subversion client (svn) not found!)
201
202 ifeq ($(shell curl --version >/dev/null 2>&1 || echo FAIL),)
203 download = curl -f -L -- "$(1)" > "$@"
204 else ifeq ($(shell wget --version >/dev/null 2>&1 || echo FAIL),)
205 download = rm -f $@.tmp && \
206         wget --passive -c -p -O $@.tmp "$(1)" && \
207         touch $@.tmp && \
208         mv $@.tmp $@
209 else ifeq ($(which fetch >/dev/null 2>&1 || echo FAIL),)
210 download = rm -f $@.tmp && \
211         fetch -p -o $@.tmp "$(1)" && \
212         touch $@.tmp && \
213         mv $@.tmp $@
214 else
215 download = $(error Neither curl nor wget found!)
216 endif
217
218 ifeq ($(shell gzcat --version >/dev/null 2>&1 || echo FAIL),)
219 ZCAT = gzcat
220 else ifeq ($(shell zcat --version >/dev/null 2>&1 || echo FAIL),)
221 ZCAT = zcat
222 else
223 ZCAT ?= $(error Gunzip client (zcat) not found!)
224 endif
225
226 ifeq ($(shell sha512sum --version >/dev/null 2>&1 || echo FAIL),)
227 SHA512SUM = sha512sum --check
228 else ifeq ($(shell shasum --version >/dev/null 2>&1 || echo FAIL),)
229 SHA512SUM = shasum -a 512 --check
230 else ifeq ($(shell openssl version >/dev/null 2>&1 || echo FAIL),)
231 SHA512SUM = openssl dgst -sha512
232 else
233 SHA512SUM = $(error SHA-512 checksumming not found!)
234 endif
235
236 #
237 # Common helpers
238 #
239 HOSTCONF := --prefix="$(PREFIX)"
240 HOSTCONF += --build="$(BUILD)" --host="$(HOST)" --target="$(HOST)"
241 HOSTCONF += --program-prefix=""
242 # libtool stuff:
243 HOSTCONF += --enable-static --disable-shared --disable-dependency-tracking
244 ifdef HAVE_WIN32
245 HOSTCONF += --without-pic
246 PIC :=
247 else
248 HOSTCONF += --with-pic
249 PIC := -fPIC
250 endif
251
252 HOSTTOOLS := \
253         CC="$(CC)" CXX="$(CXX)" LD="$(LD)" \
254         AR="$(AR)" RANLIB="$(RANLIB)" STRIP="$(STRIP)" \
255         PATH="$(PREFIX)/bin:$(PATH)"
256 HOSTVARS := $(HOSTTOOLS) \
257         CPPFLAGS="$(CPPFLAGS)" \
258         CFLAGS="$(CFLAGS)" \
259         CXXFLAGS="$(CXXFLAGS)" \
260         LDFLAGS="$(LDFLAGS)"
261 HOSTVARS_PIC := $(HOSTTOOLS) \
262         CPPFLAGS="$(CPPFLAGS) $(PIC)" \
263         CFLAGS="$(CFLAGS) $(PIC)" \
264         CXXFLAGS="$(CXXFLAGS) $(PIC)" \
265         LDFLAGS="$(LDFLAGS)"
266
267 download_git = \
268         rm -Rf $(@:.tar.xz=) && \
269         $(GIT) clone $(2:%=--branch %) $(1) $(@:.tar.xz=) && \
270         (cd $(@:.tar.xz=) && $(GIT) checkout $(3:%= %)) && \
271         rm -Rf $(@:%.tar.xz=%)/.git && \
272         (cd $(dir $@) && \
273         tar cvJ $(notdir $(@:.tar.xz=))) > $@ && \
274         rm -Rf $(@:.tar.xz=)
275 checksum = \
276         $(foreach f,$(filter $(TARBALLS)/%,$^), \
277                 grep -- " $(f:$(TARBALLS)/%=%)$$" \
278                         "$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS" &&) \
279         (cd $(TARBALLS) && $(1) /dev/stdin) < \
280                 "$(SRC)/$(patsubst .sum-%,%,$@)/$(2)SUMS"
281 CHECK_SHA512 = $(call checksum,$(SHA512SUM),SHA512)
282 UNPACK = $(RM) -R $@ \
283         $(foreach f,$(filter %.tar.gz %.tgz,$^), && tar xvzf $(f)) \
284         $(foreach f,$(filter %.tar.bz2,$^), && tar xvjf $(f)) \
285         $(foreach f,$(filter %.tar.xz,$^), && tar xvJf $(f)) \
286         $(foreach f,$(filter %.zip,$^), && unzip $(f))
287 UNPACK_DIR = $(basename $(basename $(notdir $<)))
288 APPLY = (cd $(UNPACK_DIR) && patch -p1) <
289 pkg_static = (cd $(UNPACK_DIR) && ../../../contrib/src/pkg-static.sh $(1))
290 MOVE = mv $(UNPACK_DIR) $@ && touch $@
291
292 AUTOMAKE_DATA_DIRS=$(foreach n,$(foreach n,$(subst :, ,$(shell echo $$PATH)),$(abspath $(n)/../share)),$(wildcard $(n)/automake*))
293 UPDATE_AUTOCONFIG = for dir in $(AUTOMAKE_DATA_DIRS); do \
294                 if test -f "$${dir}/config.sub" -a -f "$${dir}/config.guess"; then \
295                         cp "$${dir}/config.sub" "$${dir}/config.guess" $(UNPACK_DIR); \
296                         break; \
297                 fi; \
298         done
299
300 RECONF = mkdir -p -- $(PREFIX)/share/aclocal && \
301         cd $< && autoreconf -fiv $(ACLOCAL_AMFLAGS)
302 CMAKE = cmake . -DCMAKE_TOOLCHAIN_FILE=$(abspath toolchain.cmake) \
303                 -DCMAKE_INSTALL_PREFIX=$(PREFIX)
304
305 #
306 # Per-package build rules
307 #
308 PKGS_FOUND :=
309 include $(SRC)/*/rules.mak
310
311 ifeq ($(PKGS_DISABLE), all)
312 PKGS :=
313 endif
314 #
315 # Targets
316 #
317 ifneq ($(filter $(PKGS_DISABLE),$(PKGS_ENABLE)),)
318 $(error Same package(s) disabled and enabled at the same time)
319 endif
320 # Apply automatic selection (= remove distro packages):
321 PKGS_AUTOMATIC := $(filter-out $(PKGS_FOUND),$(PKGS))
322 # Apply manual selection (from bootstrap):
323 PKGS_MANUAL := $(sort $(PKGS_ENABLE) $(filter-out $(PKGS_DISABLE),$(PKGS_AUTOMATIC)))
324 # Resolve dependencies:
325 PKGS_DEPS := $(filter-out $(PKGS_FOUND) $(PKGS_MANUAL),$(sort $(foreach p,$(PKGS_MANUAL),$(DEPS_$(p)))))
326 PKGS := $(sort $(PKGS_MANUAL) $(PKGS_DEPS))
327
328 fetch: $(PKGS:%=.sum-%)
329 fetch-all: $(PKGS_ALL:%=.sum-%)
330 install: $(PKGS:%=.%)
331
332 mostlyclean:
333         -$(RM) $(foreach p,$(PKGS_ALL),.$(p) .sum-$(p) .dep-$(p))
334         -$(RM) toolchain.cmake
335         -$(RM) -R "$(PREFIX)"
336         -$(RM) -R */
337
338 clean: mostlyclean
339         -$(RM) $(TARBALLS)/*.*
340
341 distclean: clean
342         $(RM) config.mak
343         unlink Makefile
344
345 PREBUILT_URL=ftp://ftp.videolan.org/pub/videolan/contrib/$(HOST)/vlc-contrib-$(HOST)-latest.tar.bz2
346
347 vlc-contrib-$(HOST)-latest.tar.bz2:
348         $(call download,$(PREBUILT_URL))
349
350 prebuilt: vlc-contrib-$(HOST)-latest.tar.bz2
351         -$(UNPACK)
352         mv $(HOST) $(TOPDST)
353         cd $(TOPDST)/$(HOST) && $(SRC)/change_prefix.sh
354
355 package: install
356         rm -Rf tmp/
357         mkdir -p tmp/
358         cp -r $(PREFIX) tmp/
359         # remove useless files
360         cd tmp/$(notdir $(PREFIX)); \
361                 cd share; rm -Rf man doc gtk-doc info lua projectM gettext; cd ..; \
362                 rm -Rf man sbin etc lib/lua lib/sidplay
363         cd tmp/$(notdir $(PREFIX)) && $(abspath $(SRC))/change_prefix.sh $(PREFIX) @@CONTRIB_PREFIX@@
364         (cd tmp && tar c $(notdir $(PREFIX))/) | bzip2 -c > ../vlc-contrib-$(HOST)-$(DATE).tar.bz2
365
366 list:
367         @echo All packages:
368         @echo '  $(PKGS_ALL)' | fmt
369         @echo Distribution-provided packages:
370         @echo '  $(PKGS_FOUND)' | fmt
371         @echo Automatically selected packages:
372         @echo '  $(PKGS_AUTOMATIC)' | fmt
373         @echo Manually deselected packages:
374         @echo '  $(PKGS_DISABLE)' | fmt
375         @echo Manually selected packages:
376         @echo '  $(PKGS_ENABLE)' | fmt
377         @echo Depended-on packages:
378         @echo '  $(PKGS_DEPS)' | fmt
379         @echo To-be-built packages:
380         @echo '  $(PKGS)' | fmt
381
382 .PHONY: all fetch fetch-all install mostlyclean clean distclean package list prebuilt
383
384 # CMake toolchain
385 toolchain.cmake:
386         $(RM) $@
387 ifdef HAVE_WIN32
388         echo "set(CMAKE_SYSTEM_NAME Windows)" >> $@
389         echo "set(CMAKE_RC_COMPILER $(HOST)-windres)" >> $@
390 endif
391 ifdef HAVE_DARWIN_OS
392         echo "set(CMAKE_SYSTEM_NAME Darwin)" >> $@
393         echo "set(CMAKE_C_FLAGS $(CFLAGS))" >> $@
394         echo "set(CMAKE_CXX_FLAGS $(CFLAGS))" >> $@
395         echo "set(CMAKE_LD_FLAGS $(LDFLAGS))" >> $@
396 endif
397         echo "set(CMAKE_C_COMPILER $(CC))" >> $@
398         echo "set(CMAKE_CXX_COMPILER $(CXX))" >> $@
399         echo "set(CMAKE_FIND_ROOT_PATH $(PREFIX))" >> $@
400         echo "set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> $@
401         echo "set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> $@
402         echo "set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> $@
403
404 # Default pattern rules
405 .sum-%: $(SRC)/%/SHA512SUMS
406         $(CHECK_SHA512)
407         touch $@
408
409 .sum-%:
410         $(error Download and check target not defined for $*)
411
412 # Dummy dependency on found packages
413 $(patsubst %,.dep-%,$(PKGS_FOUND)): .dep-%:
414         touch $@
415
416 # Real dependency on missing packages
417 $(patsubst %,.dep-%,$(filter-out $(PKGS_FOUND),$(PKGS_ALL))): .dep-%: .%
418         touch -r $< $@
419
420 .SECONDEXPANSION:
421
422 # Dependency propagation (convert 'DEPS_foo = bar' to '.foo: .bar')
423 $(foreach p,$(PKGS_ALL),.$(p)): .%: $$(foreach d,$$(DEPS_$$*),.dep-$$(d))
424
425 .DELETE_ON_ERROR: