1# Copyright (c) 2012 The Native Client Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5##############################################################################
6# Helper script for NaCl toolchain development workflow.
7#
8# Buildbots:
9# - Sync needed sources at pinned revision and build newlib-based toolchain:
10#     make buildbot-build-with-newlib TOOLCHAINLOC=<where-to-install-the-toolchain>
11#  or
12#     make buildbot-build-with-glibc TOOLCHAINLOC=<where-to-install-the-toolchain>
13#
14# Development:
15# - Sync all sources at pinned revision:
16#     make sync-pinned
17# - Sync all sources at most recent revision:
18#     make sync
19# - Build newlib-based toolchain from current sources:
20#     make build-with-newlib TOOLCHAINLOC=<where-to-install-the-toolchain>
21# - Build glibc-based toolchain from current sources:
22#     make build-with-glibc TOOLCHAINLOC=<where-to-install-the-toolchain>
23#
24##############################################################################
25
26default: build-with-glibc
27
28# Delete the target file if the recipe fails after beginning to change the file
29# http://www.gnu.org/software/make/manual/make.html#Errors (Errors in Recipes)
30.DELETE_ON_ERROR: ;
31
32THISMAKEFILE := $(lastword $(MAKEFILE_LIST))
33
34SHELL = /bin/bash
35
36GIT_BASE_URL = https://chromium.googlesource.com/native_client
37
38CROSSARCH = x86_64-nacl
39TOOLCHAINLOC ?= out
40SDKLOC ?= $(abspath $(TOOLCHAINLOC))
41TOOLCHAINNAME ?= nacl-sdk
42SDKNAME ?= $(TOOLCHAINNAME)
43SDKROOT ?= $(SDKLOC)/$(SDKNAME)
44DESTDIR ?=
45
46# We can't use CFLAGS and LDFLAGS since they are passed to sub-makes and
47# those override configure parameters.
48USER_CFLAGS = -O2 -g
49USER_LDFLAGS = -s
50
51# By default all toolchain executables are x86-32 executables, use
52# HOST_TOOLCHAIN_BITS=64 to make them x86-64 executables.
53HOST_TOOLCHAIN_BITS = 32
54
55# If CANNED_REVISION is "no" then it's "from git build": Makefile uses file
56# named "REVISIONS" to pull infomation from git and builds that.
57# If CANNED_REVISION is set to some revision then Makefile will try to download
58# sources from storage.googleapis.com and use them.
59# You can also set CANNED_REVISION to "yes" if you want to just build sources
60# already unpacked and ready to be built from SRC subdirectory.
61CANNED_REVISION = no
62ifeq ($(CANNED_REVISION), no)
63include REVISIONS
64endif
65export NACL_FAKE_SONAME = $(shell commit=$(NACL_GLIBC_COMMIT);echo $${commit:0:8})
66
67# Recent version of makeinfo (such as the one in ubuntu trusty) fail to
68# compile the info files in our version of gcc. Setting this variable to
69# no stops gcc from detecteing a modern version of makeinfo and effectivly
70# stops it from building the info files.
71export gcc_cv_prog_makeinfo_modern=no
72
73# Toplevel installation directory.
74# MUST be an absolute pathname, for configure --prefix=$(PREFIX)
75PREFIX = $(abspath $(SDKROOT))
76
77# Convert CROSSARCH (nacl or nacl64) to (32 or 64).
78BITSPLATFORM = 64
79
80LINUX_HEADERS = "$(abspath $(dir $(THISMAKEFILE)))/SRC/linux-headers-for-nacl/include"
81HPREFIX = SRC/newlib/newlib/libc/sys/nacl
82
83# No 'uname -o' on OSX
84ifeq ($(shell uname -s), Darwin)
85  PLATFORM = mac
86  # Ensure that the resulting toolchain works on Mac OS X 10.5, since that
87  # is not the default in newer versions of Xcode.
88  export MACOSX_DEPLOYMENT_TARGET = 10.5
89else
90ifeq ($(shell uname -o), Cygwin)
91  PLATFORM = win
92else
93ifeq ($(shell uname -o), Msys)
94  PLATFORM = win
95else
96  PLATFORM = linux
97endif
98endif
99endif
100
101# SRCDIR should contain tarball for gcc-extras: gmp mpfr.
102# You can skip use of these tarball if you make SRCDIR value empty.  In this
103# case system-wide libraries will be used (they should be available for such
104# use, obviously - and this is not always the case: for example they are not
105# available on MacOS, on 64bit linux you generally can find 64bit versions of
106# them, but not 32bit versions, etc).
107SRCDIR = ../../../third_party
108
109ifeq ($(PLATFORM), win)
110  # Ugh, Cygwin and spaces in paths don't work well.
111  # I'm explicitly coding the path.
112  BUILDPATH = $(DESTDIR)$(PREFIX)/bin:/usr/local/bin:/usr/bin:/bin
113  SCONS ?= scons.bat
114  GIT ?= $(shell python ../../build/find_depot_tools.py)/git.bat
115  REVISION ?= $(shell $(GIT) rev-parse HEAD | tr -d $$"\r")
116  PREFIX_NATIVE = $(shell cygpath -m $(PREFIX))
117  CREATE_REDIRECTORS = ./create_redirectors_cygwin.sh
118else
119  BUILDPATH = $(DESTDIR)$(PREFIX)/bin:$(PATH)
120  SCONS ?= scons
121  GIT ?= git
122  REVISION ?= $(shell git rev-parse HEAD)
123  PREFIX_NATIVE = $(DESTDIR)$(PREFIX)
124  CREATE_REDIRECTORS = ./create_redirectors.sh
125endif
126
127REVISION_DATE ?= $(shell $(GIT) show --no-patch --format=%cd --date=short $(REVISION) | sed -e s'+\(....\)-\(..\)-\(..\).*+\1\2\3+')
128
129##################################################################
130#  The version numbers for the tools we will be building.
131##################################################################
132GMP_VERSION = 5.0.2
133MPFR_VERSION = 3.0.1
134define GCC_EXTRAS
135gmp: $(GMP_VERSION), \
136mpfr: $(MPFR_VERSION)
137endef
138BINUTILS_VERSION = 2.24.0
139NACL_BINUTILS_GIT_BASE = 237df3fa4a1d939e6fd1af0c3e5029a25a137310
140GCC_VERSION = 4.4.3
141NACL_GCC_GIT_BASE = 4e0ae761f59baae95282ab07efa9b831ac524642
142NEWLIB_VERSION = 2.1.0
143NACL_NEWLIB_GIT_BASE = e14046f93c76ef701d8ad133d0ea2b96d3c1b578
144GLIBC_VERSION = 2.9
145NACL_GLIBC_GIT_BASE = 5c46008d0874c9b9d5f5f201a10e975d1fe84787
146
147##################################################################
148# Get or update the sources.
149##################################################################
150
151SRC:
152	mkdir SRC
153
154git-sources := binutils gcc glibc linux-headers-for-nacl newlib
155
156nacl-name = $(patsubst nacl-linux-headers-for-nacl,linux-headers-for-nacl,nacl-$*)
157
158all-git-sources = $(git-sources:%=SRC/%)
159$(all-git-sources): SRC/%: | SRC
160ifeq ($(CANNED_REVISION), no)
161	git clone $(GIT_BASE_URL)/$(nacl-name).git SRC/$*
162else
163	./download_SRC.sh $(CANNED_REVISION)
164endif
165
166all-fetched-git-sources = $(git-sources:%=fetched-src-%)
167.PHONY: $(all-fetched-git-sources)
168$(all-fetched-git-sources): fetched-src-%: | SRC/%
169	cd SRC/$* && git fetch
170
171# Note that we can not change names of variables in REVISIONS files since they
172# are used in other places, not just in this Makefile.  Small amount of sh-fu
173# will convert linux-headers-for-nacl to LINUX_HEADERS_FOR_NACL_COMMIT.
174all-pinned-git-sources = $(git-sources:%=pinned-src-%)
175.PHONY: $(all-pinned-git-sources)
176$(all-pinned-git-sources): pinned-src-%: fetched-src-%
177	cd SRC/$* && git checkout \
178	    "$($(shell echo $(nacl-name)| tr '[:lower:]-' '[:upper:]_')_COMMIT)"
179
180all-latest-git-sources = $(git-sources:%=latest-src-%)
181.PHONY: $(all-latest-git-sources)
182$(all-latest-git-sources): latest-src-%: fetched-src-%
183	./update_to_latest.sh SRC/$*
184
185.PHONY: sync-pinned
186sync-pinned: | $(all-pinned-git-sources)
187
188.PHONY: sync
189sync: | $(all-latest-git-sources)
190
191# Requisites: libraries needed for GCC, but without any nacl-specific patches.
192# They are only updated when pre-requisites version changes.
193.PHONY: gcc-extras
194gcc-extras:
195	if [[ "$$(cat BUILD/.gcc-extras-version)" != "$(GCC_EXTRAS)" ]]; then \
196	    rm -rf BUILD/.gcc-extra-* SRC/.gcc-extra-* && \
197	    $(MAKE) -f $(THISMAKEFILE) install-gcc-extras && \
198	    echo -n "$(GCC_EXTRAS)" > BUILD/.gcc-extras-version; \
199	fi
200
201gcc-extras := gmp mpfr
202
203gcc_extra_version = $($(shell echo $*| tr '[:lower:]-' '[:upper:]_')_VERSION)
204
205all-src-gcc-extras = $(gcc-extras:%=SRC/.gcc-extra-%)
206$(all-src-gcc-extras): SRC/.gcc-extra-%: | SRC
207	rm -rf SRC/.gcc-extra-$*
208	cd SRC && tar xpf $(SRCDIR)/$*/$*-$(gcc_extra_version).tar.*
209	mv SRC/$*-$(gcc_extra_version) SRC/.gcc-extra-$*
210
211# All Macs need Core2 assembly and --enable-fat is broken with stock MacOS gcc.
212ifneq ($(PLATFORM), mac)
213gmp_use_fat_binary = --enable-fat
214else
215gmp_use_fat_binary =
216endif
217
218define gcc-extra-configure
219rm -rf $@
220mkdir -p $@
221BUILD=$$PWD/BUILD && cd $@ && \
222  ../../SRC/.gcc-extra-$(@:BUILD/.gcc-extra-build-%=%)/configure \
223  CC="$(GCC_CC)" \
224  CXX="$(GCC_CXX)" \
225  CFLAGS="$(CFLAGS)" \
226  CXXFLAGS="$(CXXFLAGS)" \
227  CPPFLAGS="-fexceptions $(CPPFLAGS)" \
228  --prefix=$$BUILD/.gcc-extra-install-$(@:BUILD/.gcc-extra-build-%=%) \
229  --disable-shared
230endef
231
232BUILD/.gcc-extra-build-gmp: | BUILD SRC/.gcc-extra-gmp
233	$(gcc-extra-configure) \
234	    --enable-cxx $(gmp_use_fat_binary) \
235	    ABI="$(HOST_TOOLCHAIN_BITS)"
236
237BUILD/.gcc-extra-build-mpfr: | SRC/.gcc-extra-mpfr BUILD/.gcc-extra-install-gmp
238	$(gcc-extra-configure) --with-gmp=$$BUILD/.gcc-extra-install-gmp
239
240all-install-gcc-extras = $(gcc-extras:%=BUILD/.gcc-extra-install-%)
241$(all-install-gcc-extras): BUILD/.gcc-extra-install-%: | SRC \
242                                                        BUILD/.gcc-extra-build-%
243	if mkdir BUILD/.gcc-extra-install-$*; then \
244	    mkdir BUILD/.gcc-extra-install-$*/include && \
245	    mkdir BUILD/.gcc-extra-install-$*/lib && \
246	    ln -s lib BUILD/.gcc-extra-install-$*/lib64 && \
247	    ln -s lib BUILD/.gcc-extra-install-$*/lib32; \
248	fi
249	cd BUILD/.gcc-extra-build-$* && $(MAKE) install
250
251install-gcc-extras: | BUILD SRC $(all-install-gcc-extras)
252
253# Create the build directories for compiled binaries.
254BUILD:
255	mkdir BUILD
256
257##################################################################
258# Create the SDK output directories.
259##################################################################
260
261# Create directory structure for the toolchain.
262# On win, non-cygwin binaries do not follow cygwin symlinks. In case when we
263# need multiple names for the directory, the name that might be used by win
264# tools goes to the real directory and other names go to symlinks.
265# Installers create real directories when they do not find an existing one
266# to use. To prevent installers from creating a real directory instead of what
267# should be a symlink we create everything in advance.
268sdkdirs:
269	echo "Creating the SDK tree at $(DESTDIR)$(PREFIX)"
270	# Create installation directory for 64-bit libraries
271	# See http://code.google.com/p/nativeclient/issues/detail?id=1975
272	install -m 755 -d "$(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib"
273	# Create alias for libgcc_s.so
274	# TODO: fix MULTILIB_OSDIRNAMES in gcc/config/i386/t-nacl64
275	#       and get rid of this!
276	ln -sfn lib $(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib64
277	# Create installation directory for 32-bit libraries
278	install -m 755 -d "$(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib32"
279	# Create alias for newlib
280	# Newlib uses "gcc -print-multi-lib" to determine multilib subdirectory
281	# names and installs under $prefix accordingly. This seems confusing,
282	# as "-print-multi-lib" uses MULTILIB_DIRNAMES, which is for libgcc,
283	# while for newlib it looks better to use MULTILIB_OSDIRNAMES, which is
284	# for system libraries. In our case these are "/lib" and "/lib/32" vs.
285	# "/lib" and "/lib32" respectively. As a result, 32-bit newlib is
286	# installed under "/lib/32" but searched under "/lib32".
287	# We fix this by making "/lib/32" an alias for "/lib32".
288	# TODO: sounds odd - probably my understanding is wrong?
289	#       Go ask someone smart...
290	ln -sfn ../lib32 $(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib/32
291
292##################################################################
293# binutils:
294# Builds the cross assembler, linker, archiver, etc.
295##################################################################
296BUILD/stamp-$(CROSSARCH)-binutils: | SRC/binutils BUILD
297	rm -rf BUILD/build-binutils-$(CROSSARCH)
298	mkdir BUILD/build-binutils-$(CROSSARCH)
299	# We'd like to build binutils with -Werror, but there are a
300	# number of warnings in the Mac version of GCC that prevent
301	# us from building with -Werror today.
302	cd BUILD/build-binutils-$(CROSSARCH) && \
303	  CC="$(GCC_CC)" \
304	  CFLAGS="$(USER_CFLAGS)" \
305	  LDFLAGS="$(USER_LDFLAGS)" \
306	  ../../SRC/binutils/configure \
307	    --prefix=$(PREFIX) \
308	    --target=$(CROSSARCH) \
309	    --with-sysroot=$(PREFIX)/$(CROSSARCH) \
310	    --disable-werror --enable-deterministic-archives --without-zlib
311	$(MAKE) -C BUILD/build-binutils-$(CROSSARCH) all
312	$(MAKE) -C BUILD/build-binutils-$(CROSSARCH) DESTDIR=$(DESTDIR) install
313	touch $@
314
315.PHONY: binutils
316binutils: BUILD/stamp-$(CROSSARCH)-binutils
317
318##################################################################
319# pregcc:
320# Builds the cross gcc used to build the libraries.
321##################################################################
322
323GCC_SRC_DIR = $(abspath SRC/gcc)
324
325GMP_DIR = $(abspath BUILD/.gcc-extra-install-gmp)
326MPFR_DIR = $(abspath BUILD/.gcc-extra-install-mpfr)
327
328# For Linux we want to make sure we don't dynamically link in libstdc++
329# because it ties our binaries to a host GCC version that other places
330# the toolchain gets installed might not match.
331ifeq ($(PLATFORM),linux)
332lstdc++ = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
333else
334lstdc++ = -lstdc++
335endif
336
337ifneq ($(SRCDIR),)
338GCC_EXTRAS_FLAGS = \
339    --with-gmp=$(GMP_DIR) \
340    --with-mpfr=$(MPFR_DIR) \
341    --with-host-libstdcxx="-lpwl $(lstdc++) -lm"
342else
343GCC_EXTRAS_FLAGS = \
344    --with-gmp \
345    --with-mpfr
346endif
347
348GCC_CONFIGURE_FLAGS = \
349    --disable-decimal-float \
350    --disable-libgomp \
351    --disable-libmudflap \
352    --disable-libssp \
353    --disable-libstdcxx-pch \
354    --target=$(CROSSARCH) \
355    --enable-linker-build-id \
356    $(GCC_EXTRAS_FLAGS)
357
358ifdef MULTILIB
359ifeq ($(MULTILIB),no)
360GCC_CONFIGURE_FLAGS += --disable-multilib
361else
362$(error MULTILIB: Bad value)
363endif
364endif
365
366ifeq ($(PLATFORM), mac)
367GCC_CC = clang -m$(HOST_TOOLCHAIN_BITS) -fgnu89-inline
368GCC_CXX = clang++ -m$(HOST_TOOLCHAIN_BITS)
369else
370GCC_CC = gcc -m$(HOST_TOOLCHAIN_BITS)
371GCC_CXX = g++ -m$(HOST_TOOLCHAIN_BITS)
372endif
373
374GCC_DEFINES = \
375    -Dinhibit_libc \
376    -D__gthr_posix_h
377
378
379GCC_CFLAGS_FOR_TARGET-nolibc =
380GCC_CONFIGURE_FLAGS-nolibc = --disable-shared \
381			     --disable-threads \
382			     --enable-languages="c" \
383			     --without-headers
384
385GCC_CFLAGS_FOR_TARGET-newlib = -I$(HEADERS_FOR_BUILD)
386
387GCC_CONFIGURE_FLAGS-newlib = --disable-shared \
388			     --enable-languages="c,c++,objc" \
389			     --enable-threads=nacl \
390			     --enable-tls \
391			     --with-newlib
392
393GCC_CFLAGS_FOR_TARGET-glibc =
394GCC_CONFIGURE_FLAGS-glibc = --enable-shared \
395			    --enable-languages="c,c++,objc,obj-c++,fortran" \
396			    --enable-threads=posix \
397			    --enable-tls
398
399
400BUILD/stamp-$(CROSSARCH)-pregcc: | SRC/gcc BUILD
401ifneq ($(SRCDIR),)
402	$(MAKE) -f $(THISMAKEFILE) gcc-extras
403endif
404	rm -rf BUILD/build-pregcc-$(CROSSARCH)
405	mkdir BUILD/build-pregcc-$(CROSSARCH)
406	cd BUILD/build-pregcc-$(CROSSARCH) && \
407	PATH=$(BUILDPATH) \
408	$(GCC_SRC_DIR)/configure \
409	    CC="$(GCC_CC)" \
410	    CFLAGS="$(USER_CFLAGS) $(GCC_DEFINES)" \
411	    LDFLAGS="$(USER_LDFLAGS)" \
412	    CFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-nolibc)" \
413	    CXXFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-nolibc)" \
414	    --prefix=$(PREFIX) \
415	    $(GCC_CONFIGURE_FLAGS) \
416	    $(GCC_CONFIGURE_FLAGS-nolibc)
417	PATH=$(BUILDPATH) $(MAKE) \
418	    -C BUILD/build-pregcc-$(CROSSARCH) \
419	    all-gcc all-target-libgcc
420	PATH=$(BUILDPATH) $(MAKE) \
421	    -C BUILD/build-pregcc-$(CROSSARCH) \
422	    DESTDIR=$(DESTDIR) \
423	    install-gcc install-target-libgcc
424	cp $(DESTDIR)$(PREFIX)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/libgcc.a \
425		$(DESTDIR)$(PREFIX)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/libgcc_eh.a
426	cp $(DESTDIR)$(PREFIX)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/32/libgcc.a \
427		$(DESTDIR)$(PREFIX)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/32/libgcc_eh.a |\
428	true
429	touch $@
430
431.PHONY: pregcc
432pregcc: BUILD/stamp-$(CROSSARCH)-pregcc
433
434
435##################################################################
436# pregcc-standalone:
437# Builds the cross gcc used to build glibc.
438# TODO(eaeltsin): now works for Linux only, enable for Windows/Mac
439# TODO(eaeltsin): get rid of pregcc in favor of pregcc-standalone
440##################################################################
441
442# Toplevel installation directory for pregcc.
443# MUST be an absolute pathname, for configure --prefix=$(PREGCC_PREFIX)
444# Pregcc is installed separately so that it is not overwritten with full gcc.
445# Pregcc is needed for rebuilding glibc, while full gcc can't do that because
446# of its incompatible libgcc.
447PREGCC_PREFIX = $(abspath BUILD/install-pregcc-$(CROSSARCH))
448
449# Build directory for pregcc.
450PREGCC_BUILD_DIR = BUILD/build-pregcc-$(CROSSARCH)
451
452# Build pregcc:
453# create links to binutils:
454#   Alternate approaches are to make PATH point to nacl binutils or to use
455#   pregcc with -B option. Both seem unreliable, as after full gcc is installed
456#   the search path will include full gcc stuff that should not be picked.
457# make install:
458#   DESTDIR should be ignored at this step.
459BUILD/stamp-$(CROSSARCH)-pregcc-standalone: \
460  BUILD/stamp-$(CROSSARCH)-binutils | SRC/gcc BUILD
461ifneq ($(SRCDIR),)
462	$(MAKE) -f $(THISMAKEFILE) gcc-extras
463endif
464	rm -rf $(PREGCC_PREFIX)
465	mkdir -p $(PREGCC_PREFIX)/$(CROSSARCH)/bin
466	for f in '$(DESTDIR)$(PREFIX)/$(CROSSARCH)/bin/*'; do \
467	    ln -s $$f $(PREGCC_PREFIX)/$(CROSSARCH)/bin; \
468	    done
469	rm -rf $(PREGCC_BUILD_DIR)
470	mkdir $(PREGCC_BUILD_DIR)
471	cd $(PREGCC_BUILD_DIR) && \
472	PATH=$(BUILDPATH) \
473	$(GCC_SRC_DIR)/configure \
474	    CC="$(GCC_CC)" \
475	    CFLAGS="$(USER_CFLAGS) $(GCC_DEFINES)" \
476	    LDFLAGS="$(USER_LDFLAGS)" \
477	    CFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-nolibc)" \
478	    CXXFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-nolibc)" \
479	    --prefix=$(PREGCC_PREFIX) \
480	    $(GCC_CONFIGURE_FLAGS) \
481	    $(GCC_CONFIGURE_FLAGS-nolibc)
482	PATH=$(BUILDPATH) $(MAKE) \
483	    -C $(PREGCC_BUILD_DIR) \
484	    all-gcc \
485	    all-target-libgcc \
486	    DESTDIR=
487	PATH=$(BUILDPATH) $(MAKE) \
488	    -C $(PREGCC_BUILD_DIR) \
489	    install-gcc \
490	    install-target-libgcc \
491	    DESTDIR=
492	touch $@
493
494
495##################################################################
496# newlib:
497# Builds the bare-bones library used by NativeClient applications.
498# NOTE: removes the default pthread.h to enable correct install
499# by the Native Client threads package build.
500##################################################################
501
502NEWLIB_CFLAGS = -O2
503
504BUILD/stamp-$(CROSSARCH)-newlib: | SRC/newlib BUILD newlib-libc-script
505	rm -rf BUILD/build-newlib-$(CROSSARCH)
506	mkdir BUILD/build-newlib-$(CROSSARCH)
507	PATH=$(BUILDPATH) && export PATH && \
508	  cd BUILD/build-newlib-$(CROSSARCH) && \
509	  ../../SRC/newlib/configure \
510		      --disable-libgloss \
511		      --enable-newlib-iconv \
512		      --enable-newlib-iconv-from-encodings=UTF-8,UTF-16LE,UCS-4LE,UTF-16,UCS-4 \
513		      --enable-newlib-iconv-to-encodings=UTF-8,UTF-16LE,UCS-4LE,UTF-16,UCS-4 \
514		      --enable-newlib-io-long-long \
515		      --enable-newlib-io-long-double \
516		      --enable-newlib-io-c99-formats \
517		      --enable-newlib-mb \
518	    --prefix=$(PREFIX) \
519	    CFLAGS="$(USER_CFLAGS)" \
520	    CFLAGS_FOR_TARGET='$(NEWLIB_CFLAGS)' \
521	    CXXFLAGS_FOR_TARGET='$(NEWLIB_CFLAGS)' \
522	    --target=$(CROSSARCH) && \
523	  $(MAKE) && \
524	  $(MAKE) DESTDIR=$(DESTDIR) install
525ifeq ($(CANNED_REVISION), no)
526# The buildbot script that creates the source tarball adds all the headers to
527# the tarball itself (see buildbot/buildbot_linux-glibc-makefile.sh)
528	cp -f $(addprefix ../src/untrusted/pthread/, pthread.h semaphore.h) \
529	  $(DESTDIR)$(PREFIX)/$(CROSSARCH)/include
530endif
531	for bits in 32 64; do \
532	  mv $(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib$$bits/libc.a \
533	     $(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib$$bits/libcrt_common.a; \
534	  if [[ "$$bits" = "32" ]]; then \
535	    objformat=elf32-i386-nacl ; \
536	  else \
537	    objformat=elf64-x86-64-nacl ; \
538	  fi ; \
539	  sed "s/@OBJFORMAT@/$$objformat/" newlib-libc-script \
540	    > $(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib$$bits/libc.a; \
541	done
542	touch $@
543
544.PHONY: newlib
545newlib: BUILD/stamp-$(CROSSARCH)-newlib
546
547
548##################################################################
549# glibc:
550##################################################################
551
552# Build directory for glibc.
553GLIBC_BUILD_DIR = BUILD/build-glibc-$(CROSSARCH)
554
555# Glibc is built with pregcc.
556GLIBC_CC = $(PREGCC_PREFIX)/bin/$(CROSSARCH)-gcc
557
558# CFLAGS for building glibc.
559GLIBC_CFLAGS = -O2 -g
560
561ARCH_DEST = $(DESTDIR)$(PREFIX)/$(CROSSARCH)
562ARCH_DEST_INC_NATIVE = $(PREFIX_NATIVE)/$(CROSSARCH)/include
563
564# LIB_BITS is used with different values to execute targets in this Makefile for
565# different architectures (32, 64) when building libraries (glibc and nacl).
566# CROSSARCH and BITSPLATFORM could be used for this, but we better avoid
567# redefining variables with recursive $(MAKE) calls.
568LIB_BITS ?= 64
569ARCH_DEST_LIB_NATIVE = $(PREFIX_NATIVE)/$(CROSSARCH)/$(if $(filter 32,$(LIB_BITS)),lib32,lib)
570
571BUILD/stamp-glibc32: BUILD/stamp-$(CROSSARCH)-pregcc-standalone | SRC/glibc
572	if [[ ! -d $(LINUX_HEADERS) ]] ; then \
573	  $(MAKE) -f $(THISMAKEFILE) SRC/linux-headers-for-nacl ; \
574	fi
575	rm -rf BUILD/build-glibc32
576	mkdir -p BUILD/build-glibc32/lib
577	cd BUILD/build-glibc32 && ../../SRC/glibc/configure \
578	    BUILD_CC="gcc -O2 -g" \
579	    CC="$(GLIBC_CC) -m32" \
580	    CFLAGS="-pipe -fno-strict-aliasing -mno-tls-direct-seg-refs -march=i486 $(GLIBC_CFLAGS)" \
581	    libc_cv_forced_unwind=yes \
582	    libc_cv_c_cleanup=yes \
583	    libc_cv_slibdir=/lib32 \
584	    libc_cv_z_combreloc=no \
585	    --prefix= \
586	    --libdir=/lib32 \
587	    --host=i486-linux-gnu \
588	    --with-headers=$(LINUX_HEADERS) \
589	    --enable-kernel=2.6.18
590	$(MAKE) -C BUILD/build-glibc32
591	$(MAKE) -C BUILD/build-glibc32 install_root=$(DESTDIR)$(PREFIX)/$(CROSSARCH) install
592	touch $@
593
594BUILD/stamp-glibc64: BUILD/stamp-$(CROSSARCH)-pregcc-standalone | SRC/glibc
595	if [[ ! -d $(LINUX_HEADERS) ]] ; then \
596	  $(MAKE) -f $(THISMAKEFILE) SRC/linux-headers-for-nacl ; \
597	fi
598	rm -rf BUILD/build-glibc64
599	mkdir -p BUILD/build-glibc64
600	cd BUILD/build-glibc64 && ../../SRC/glibc/configure \
601	    BUILD_CC="gcc -O2 -g" \
602	    CC="$(GLIBC_CC) -m64" \
603	    CFLAGS="-pipe -fno-strict-aliasing -mno-tls-direct-seg-refs $(GLIBC_CFLAGS)" \
604	    libc_cv_forced_unwind=yes \
605	    libc_cv_c_cleanup=yes \
606	    libc_cv_slibdir=/lib \
607	    libc_cv_z_combreloc=no \
608	    --prefix= \
609	    --libdir=/lib \
610	    --host=x86_64-linux-gnu \
611	    --with-headers=$(LINUX_HEADERS) \
612	    --enable-kernel=2.6.18
613	$(MAKE) -C BUILD/build-glibc64
614	$(MAKE) -C BUILD/build-glibc64 install_root=$(DESTDIR)$(PREFIX)/$(CROSSARCH) install
615	touch $@
616
617# Can be used to make a glibc archive separately from the main install tree.
618# Used, i.e., on buildbots.
619INST_GLIBC_PREFIX ?= $(PREFIX)
620.PHONY: install-glibc
621install-glibc: BUILD/stamp-glibc32 BUILD/stamp-glibc64
622	rm -rf "$(INST_GLIBC_PREFIX)"/glibc
623	mkdir "$(INST_GLIBC_PREFIX)"/glibc
624	$(MAKE) -f $(THISMAKEFILE) sdkdirs \
625	  DESTDIR="" PREFIX="$(INST_GLIBC_PREFIX)/glibc"
626	$(MAKE) -f $(THISMAKEFILE) -C BUILD/build-glibc32 \
627	  install_root="$(INST_GLIBC_PREFIX)/glibc/$(CROSSARCH)" install
628	$(MAKE) -f $(THISMAKEFILE) -C BUILD/build-glibc64 \
629	  install_root="$(INST_GLIBC_PREFIX)/glibc/$(CROSSARCH)" install
630
631.PHONY: export-headers
632export-headers: SRC/newlib
633ifeq ($(CANNED_REVISION), no)
634	rm -rf $(HPREFIX)/{bits,sys,machine}
635	../src/trusted/service_runtime/export_header.py \
636	  ../src/trusted/service_runtime/include $(HPREFIX)
637else
638	true
639endif
640
641##################################################################
642# Ad hoc linker scripts and a selection of NaCl headers for GCC.
643##################################################################
644.PHONY: glibc-adhoc-files
645glibc-adhoc-files: | SRC/glibc
646	if [[ ! -d $(LINUX_HEADERS) ]] ; then \
647	  $(MAKE) -f $(THISMAKEFILE) SRC/linux-headers-for-nacl ; \
648	fi
649	install -m 755 -d  $(ARCH_DEST)/lib/ldscripts
650	cp -f SRC/glibc/nacl/dyn-link/ldscripts/* \
651	    $(ARCH_DEST)/lib/ldscripts/
652	mkdir -p $(ARCH_DEST)/include/machine
653	cp -rf $(LINUX_HEADERS)/{asm*,linux} $(ARCH_DEST)/include
654ifeq ($(CANNED_REVISION), no)
655	cp ../src/untrusted/include/machine/_default_types.h \
656	    $(ARCH_DEST)/include/machine/_default_types.h
657else
658	cp _default_types.h \
659	    $(ARCH_DEST)/include/machine/_default_types.h
660endif
661	for f in catchsegv gencat getconf getent iconv ldd locale \
662	    localedef mtrace pcprofiledump rpcgen sprof tzselect xtrace; do \
663	    rm -f $(ARCH_DEST)/bin/$$f ; \
664	done
665	# These libraries are in link lines because newlib needs them.
666	# Since glibc doesn't need them, we just stub them out as empty
667	# linker scripts.  For -lfoo the linker looks for libfoo.so first
668	# and then libfoo.a, but only the latter under -static, so install
669	# under .a names to cover both cases.
670	for libdir in lib32 lib; do \
671	  for lib in nacl nosys; do \
672	    echo '/* Intentionally empty */' > \
673		$(PREFIX_NATIVE)/$(CROSSARCH)/$${libdir}/lib$${lib}.a; \
674	  done; \
675	done
676
677##################################################################
678# gcc:
679#   Builds GCC with glibc as a C library.
680##################################################################
681SYSINCLUDE_HACK_TARGET = $(DESTDIR)$(PREFIX)/$(CROSSARCH)/sys-include
682
683BUILD/stamp-$(CROSSARCH)-full-gcc: glibc-adhoc-files
684ifneq ($(SRCDIR),)
685	$(MAKE) -f $(THISMAKEFILE) gcc-extras
686endif
687	rm -rf BUILD/build-full-gcc-$(CROSSARCH)
688	mkdir BUILD/build-full-gcc-$(CROSSARCH){,/lib}
689	ln -s $(DESTDIR)$(PREFIX)/$(CROSSARCH)/lib \
690	  BUILD/build-full-gcc-$(CROSSARCH)/lib/gcc
691	# See http://code.google.com/p/nativeclient/issues/detail?id=854
692	rm -rf $(SYSINCLUDE_HACK_TARGET)
693	ln -s include $(SYSINCLUDE_HACK_TARGET)
694	cd BUILD/build-full-gcc-$(CROSSARCH) && \
695	PATH=$(BUILDPATH) \
696	$(GCC_SRC_DIR)/configure \
697	    CC="$(GCC_CC)" \
698	    CFLAGS="$(USER_CFLAGS) $(GCC_DEFINES)" \
699	    LDFLAGS="$(USER_LDFLAGS)" \
700	    CFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-glibc)" \
701	    CXXFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-glibc)" \
702	    --prefix=$(PREFIX) \
703	    $(GCC_CONFIGURE_FLAGS) \
704	    $(GCC_CONFIGURE_FLAGS-glibc)
705ifeq ($(PLATFORM), linux)
706	if [[ "$(CROSSARCH)" = "x86_64-nacl" ]] ; then \
707	  if file BUILD/build-pregcc-x86_64-nacl/gcc/cc1 | grep -q x86-64; \
708	  then \
709	    export LD_PRELOAD=/lib64/libgcc_s.so.1 ; \
710	  fi ; \
711	else \
712	  if ! (file BUILD/build-pregcc-x86_64-nacl/gcc/cc1 | grep -q x86-64); \
713	  then \
714	    export LD_PRELOAD=/lib/libgcc_s.so.1 ; \
715	  fi ; \
716	fi ; \
717	PATH=$(BUILDPATH) $(MAKE) \
718	    -C BUILD/build-full-gcc-$(CROSSARCH) \
719	    all
720else
721	PATH=$(BUILDPATH) $(MAKE) \
722	    -C BUILD/build-full-gcc-$(CROSSARCH) \
723	    all
724endif
725	PATH=$(BUILDPATH) $(MAKE) \
726	    -C BUILD/build-full-gcc-$(CROSSARCH) \
727	    DESTDIR=$(DESTDIR) \
728	    install
729	# See http://code.google.com/p/nativeclient/issues/detail?id=854
730	rm -rf $(SYSINCLUDE_HACK_TARGET)
731	touch $@
732
733##################################################################
734# gcc:
735# Builds the gcc that will be used to build applications.
736##################################################################
737BUILD/stamp-$(CROSSARCH)-gcc: BUILD/stamp-$(CROSSARCH)-newlib \
738  | SRC/gcc BUILD
739ifneq ($(SRCDIR),)
740	$(MAKE) -f $(THISMAKEFILE) gcc-extras
741endif
742	rm -rf BUILD/build-gcc-$(CROSSARCH)
743	mkdir BUILD/build-gcc-$(CROSSARCH)
744	mkdir -p $(SYSINCLUDE_HACK_TARGET)
745	# See http://code.google.com/p/nativeclient/issues/detail?id=854
746	rm -rf $(SYSINCLUDE_HACK_TARGET)
747	ln -s include $(SYSINCLUDE_HACK_TARGET)
748	cd BUILD/build-gcc-$(CROSSARCH) && \
749	PATH=$(BUILDPATH) \
750	$(GCC_SRC_DIR)/configure \
751	    CC="$(GCC_CC)" \
752	    CFLAGS="$(USER_CFLAGS) $(GCC_DEFINES)" \
753	    LDFLAGS="$(USER_LDFLAGS)" \
754	    CFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-newlib)" \
755	    CXXFLAGS_FOR_TARGET="-O2 -g $(GCC_CFLAGS_FOR_TARGET-newlib)" \
756	    --prefix=$(PREFIX) \
757	    $(GCC_CONFIGURE_FLAGS) \
758	    $(GCC_CONFIGURE_FLAGS-newlib)
759	PATH=$(BUILDPATH) $(MAKE) \
760	    -C BUILD/build-gcc-$(CROSSARCH) \
761	    all
762	PATH=$(BUILDPATH) $(MAKE) \
763	    -C BUILD/build-gcc-$(CROSSARCH) \
764	    DESTDIR=$(DESTDIR) \
765	    install
766	# See http://code.google.com/p/nativeclient/issues/detail?id=854
767	rm -rf $(SYSINCLUDE_HACK_TARGET)
768	touch $@
769
770.PHONY: gcc
771gcc: BUILD/stamp-$(CROSSARCH)-gcc
772
773##################################################################
774# Install headers from the NaCl tree locally for the gcc build to see.
775##################################################################
776.PHONY: headers_for_build
777headers_for_build:
778	cd .. && \
779	  ./$(SCONS) nacl_newlib_dir=$(PREFIX_NATIVE) \
780		     --verbose platform=x86-$(BITSPLATFORM) \
781		     install_headers includedir=$(HEADERS_FOR_BUILD_NATIVE)
782
783HEADERS_FOR_BUILD = \
784	$(abspath $(dir $(THISMAKEFILE)))/BUILD/headers_for_build
785
786ifeq ($(PLATFORM), win)
787  HEADERS_FOR_BUILD_NATIVE = `cygpath -m $(HEADERS_FOR_BUILD)`
788else
789  HEADERS_FOR_BUILD_NATIVE = $(HEADERS_FOR_BUILD)
790endif
791
792##################################################################
793# Build the entire toolchain.
794##################################################################
795
796# On platforms where glibc build is slow or unavailable you can specify
797# glibc_download.sh (or any other program) to download glibc
798INST_GLIBC_PROGRAM ?= none
799.PHONY: build-with-glibc
800build-with-glibc: SRC/gcc
801	$(MAKE) -f $(THISMAKEFILE) sdkdirs
802	cp -f SRC/gcc/COPYING* $(DESTDIR)$(PREFIX)
803	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-$(CROSSARCH)-binutils
804ifeq ($(INST_GLIBC_PROGRAM), none)
805	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-$(CROSSARCH)-pregcc-standalone
806	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-glibc32
807	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-glibc64
808else
809	$(INST_GLIBC_PROGRAM) "$(DESTDIR)$(PREFIX)"
810endif
811	cp -f SRC/glibc/sysdeps/nacl/{irt_syscalls,nacl_stat,nacl_dirent}.h \
812	  "$(DESTDIR)$(PREFIX)/$(CROSSARCH)"/include
813	$(MAKE) -f $(THISMAKEFILE) export-headers
814	$(MAKE) -f $(THISMAKEFILE) glibc-adhoc-files
815	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-$(CROSSARCH)-full-gcc
816	$(CREATE_REDIRECTORS) "$(DESTDIR)$(PREFIX)"
817	for dir in lib32 lib64 ; do ( \
818	  cd $(DESTDIR)$(PREFIX)/$(CROSSARCH)/$$dir ; \
819	  for lib in BrokenLocale anl c cidn crypt dl m nsl \
820	    nss_{compat,dns,files,hesiod,nis,nisplus} pthread \
821	    resolv rt util ; do \
822	    for fulllib in lib$$lib.so.* ; do \
823	      mv lib$$lib-$(GLIBC_VERSION).so "$$fulllib" ; \
824	      ln -sfn "$$fulllib" lib$$lib-$(GLIBC_VERSION).so ; \
825	    done ; \
826	  done ; \
827	  for fulllib in ld-linux.so.* ld-linux-x86-64.so.* ; do \
828	    if [[ "$$fulllib" != *\** ]] ; then \
829	      mv ld-$(GLIBC_VERSION).so "$$fulllib" ; \
830	      ln -sfn "$$fulllib" ld-$(GLIBC_VERSION).so ; \
831	    fi ; \
832	  done ; \
833	  for fulllib in libthread_db.so.* ; do \
834	    mv libthread_db-1.0.so "$$fulllib" ; \
835	    ln -sfn "$$fulllib" libthread_db-1.0.so ; \
836	  done ; \
837	  chmod a+x libgcc_s.so.1 ; \
838	  for fulllib in libgfortran.so.3.* ; do \
839	    mv "$$fulllib" libgfortran.so.3 ; \
840	    ln -sfn libgfortran.so.3 "$$fulllib" ; \
841	    ln -sfn libgfortran.so.3 libgfortran.so ; \
842	  done ; \
843	  for fulllib in libobjc.so.2.* ; do \
844	    mv "$$fulllib" libobjc.so.2 ; \
845	    ln -sfn libobjc.so.2 "$$fulllib" ; \
846	    ln -sfn libobjc.so.2 libobjc.so ; \
847	  done ; \
848	  for fulllib in libstdc++.so.6.* ; do \
849	    mv "$$fulllib" libstdc++.so.6 ; \
850	    ln -sfn libstdc++.so.6 "$$fulllib" ; \
851	    ln -sfn libstdc++.so.6 libstdc++.so ; \
852	  done ; \
853	) ; done
854	rm -rf "$(DESTDIR)$(PREFIX)"/{include,lib/*.a*,$(CROSSARCH)/lib{,32}/*.la}
855	rm -rf "$(DESTDIR)$(PREFIX)"/{lib/{*/*/*/*{,/*}.la,*.so*},lib{32,64}}
856
857.PHONY: build-with-newlib
858build-with-newlib: SRC/gcc
859	$(MAKE) -f $(THISMAKEFILE) sdkdirs
860	cp -f SRC/gcc/COPYING* $(DESTDIR)$(PREFIX)
861	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-$(CROSSARCH)-binutils
862	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-$(CROSSARCH)-pregcc
863	$(MAKE) -f $(THISMAKEFILE) export-headers
864	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-$(CROSSARCH)-newlib
865	$(CREATE_REDIRECTORS) "$(DESTDIR)$(PREFIX)"
866ifeq ($(CANNED_REVISION), no)
867	$(MAKE) -f $(THISMAKEFILE) headers_for_build
868endif
869	$(MAKE) -f $(THISMAKEFILE) BUILD/stamp-$(CROSSARCH)-gcc
870	$(CREATE_REDIRECTORS) "$(DESTDIR)$(PREFIX)"
871	rm -rf "$(DESTDIR)$(PREFIX)"/{include,lib/*.a*,lib/*.so*,lib32,lib64}
872
873ifeq ($(CANNED_REVISION), no)
874# Newlib toolchain for buildbot.
875.PHONY: buildbot-build-with-newlib
876buildbot-build-with-newlib: | \
877  buildbot-mark-version \
878  pinned-src-newlib
879	find SRC -print0 | xargs -0 touch -r SRC
880	$(MAKE) -f $(THISMAKEFILE) build-with-newlib
881
882# Don't generate patch files for things like gmp or linux-headers-for-nacl
883# because these are not changed from upstream.
884BINUTILS_PATCHNAME := naclbinutils-$(BINUTILS_VERSION)-$(REVISION)
885GCC_PATCHNAME := naclgcc-$(GCC_VERSION)-$(REVISION)
886GLIBC_PATCHNAME := naclglibc-$(GLIBC_VERSION)-$(REVISION)
887NEWLIB_PATCHNAME := naclnewlib-$(NEWLIB_VERSION)-$(REVISION)
888
889patch-names = $(BINUTILS_PATCHNAME) $(GCC_PATCHNAME) \
890	      $(GLIBC_PATCHNAME) $(NEWLIB_PATCHNAME)
891patch-list = $(patch-names:%=SRC/%.patch)
892
893$(patch-list): SRC/%.patch:
894	package=$@ && \
895	package=$${package#SRC/nacl} && \
896	package=$${package/.patch/} && \
897	basename=$${package/-*-*} && \
898	cd SRC/$${basename} && \
899	  git diff --patience --patch-with-stat --no-renames \
900	    --src-prefix=$$basename/ \
901	    --dst-prefix=$$basename/ \
902	    $(NACL_$(shell n=$@ ; n=$${n#SRC/nacl} ; echo $${n/-*-*/} | \
903	             tr '[:lower:]-' '[:upper:]_')_GIT_BASE) \
904	    > ../../$@
905
906.PHONY: patches
907patches: $(patch-list)
908
909# Glibc toolchain for buildbot.
910.PHONY: buildbot-build-with-glibc
911buildbot-build-with-glibc: | \
912  buildbot-mark-version \
913  pinned-src-glibc \
914  pinned-src-linux-headers-for-nacl \
915  pinned-src-newlib
916	rm -rf SRC/gcc/gmp-* SRC/gcc/mpfr-*
917	find SRC -print0 | xargs -0 touch -r SRC
918	$(MAKE) -f $(THISMAKEFILE) build-with-glibc
919
920.PHONY: buildbot-mark-version
921buildbot-mark-version: | \
922  pinned-src-binutils \
923  pinned-src-gcc
924	printf -- "--- SRC/binutils/bfd/version.h\n\
925	+++ SRC/binutils/bfd/version.h\n\
926	@@ -3 +3 @@\n\
927	-#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@\n\
928	+#define BFD_VERSION_STRING  @bfd_version_package@ @bfd_version_string@ \" $(REVISION_DATE) (Native Client $(REVISION), Git Commit `cd SRC/binutils ; LC_ALL=C git rev-parse HEAD`)\"\n" |\
929	patch -p0
930	echo $(REVISION_DATE) > SRC/gcc/gcc/DATESTAMP
931	echo "Native Client $(REVISION), Git Commit `cd SRC/gcc ; LC_ALL=C git rev-parse HEAD`" > SRC/gcc/gcc/DEV-PHASE
932endif
933
934##################################################################
935# Run DejaGnu tests.
936##################################################################
937
938SEL_LDR = $(abspath ../scons-out/opt-$(PLATFORM)-x86-$(BITSPLATFORM)/staging/sel_ldr)
939DEJAGNU_TIMESTAMP := $(shell date +%y%m%d%H%M%S)
940
941.PHONY: $(SEL_LDR)
942$(SEL_LDR):
943	(cd .. && \
944	  ./$(SCONS) nacl_glibc_dir=$(DESTDIR)$(PREFIX) \
945	    --mode=opt-host,nacl platform=x86-$(BITSPLATFORM) \
946	    --verbose sel_ldr)
947
948.PHONY: check
949check: $(SEL_LDR)
950	(cd .. && \
951	  ./$(SCONS) nacl_glibc_dir=$(DESTDIR)$(PREFIX) \
952	    --mode=opt-host,nacl platform=x86-$(BITSPLATFORM) \
953	    --verbose run_hello_world_test)
954	mkdir BUILD/build-gcc-$(CROSSARCH)/results.$(DEJAGNU_TIMESTAMP)
955	$(MAKE) \
956	    -C BUILD/build-gcc-$(CROSSARCH) \
957	    DEJAGNU=$(abspath dejagnu/site.exp) \
958	    RUNTESTFLAGS=" \
959	        --target_board=nacl \
960	        --outdir=$(abspath BUILD/build-gcc-$(CROSSARCH)/results.$(DEJAGNU_TIMESTAMP)) \
961	        SIM=$(SEL_LDR)" \
962	    LDFLAGS_FOR_TARGET="-lnosys" \
963	    check
964
965
966##################################################################
967# Run GlibC tests.
968##################################################################
969
970.PHONY: glibc-check
971glibc-check: $(SEL_LDR)
972	GLIBC_TST_COLLECT2="$(PREGCC_PREFIX)/libexec/gcc/$(CROSSARCH)/$(GCC_VERSION)/collect2" \
973	GLIBC_TST_STATIC_LDSCRIPT="$(DESTDIR)$(PREFIX)/$(CROSSARCH)"/lib/ldscripts/elf64_nacl.x.static \
974	GLIBC_TST_NACL_LOADER="$(SEL_LDR)" \
975	GLIBC_TST_NACL_LIBDIR="$(DESTDIR)$(PREFIX)/$(CROSSARCH)"/lib \
976	  glibc-tests/run_tests.sh $(BITSPLATFORM)
977
978.PHONY: glibc-check32
979glibc-check32: $(SEL_LDR)
980	GLIBC_TST_COLLECT2="$(PREGCC_PREFIX)/libexec/gcc/$(CROSSARCH)/$(GCC_VERSION)/collect2" \
981	GLIBC_TST_STATIC_LDSCRIPT="$(DESTDIR)$(PREFIX)/$(CROSSARCH)"/lib/ldscripts/elf_nacl.x.static \
982	GLIBC_TST_NACL_LOADER="$(SEL_LDR)" \
983	GLIBC_TST_NACL_LIBDIR="$(DESTDIR)$(PREFIX)/$(CROSSARCH)"/lib32 \
984	  glibc-tests/run_tests.sh $(BITSPLATFORM)
985
986
987##################################################################
988# Compile Native Client tests with the toolchain and run them.
989##################################################################
990.PHONY: nacl-check
991nacl-check:
992	(cd .. && \
993	  ./$(SCONS) -k \
994	    $(SCONS_DESTINATIONS_NOLIB) \
995	    --mode=opt-host,nacl platform=x86-$(BITSPLATFORM) \
996	    --nacl_glibc --verbose small_tests)
997
998
999##################################################################
1000# Remove the BUILD directory.
1001# Library builds are maintained by scons.
1002##################################################################
1003
1004.PHONY: clean
1005clean:
1006	rm -rf BUILD/*
1007