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