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