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