1 # Copyright 2008, Google Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ##################################################################
31 # Description: Main makefile for NativeClient toolchain.
32 # This is currently incomplete, because it does not build app_lib
33 # and move it to the proper location.
34 # TODO: Consolidate with app_lib build.
35 ##################################################################
39 ##################################################################
40 # Describe where to find the sources, where the SDK goes, etc.
41 # SDKROOT has to exist, which requires some extra work, especially
43 # TODO: Figure out how to get SDKROOT not to be absolute
44 # while keeping prefix set correctly.
45 ##################################################################
47 THISMAKEFILE
:= $(lastword
$(MAKEFILE_LIST
))
50 SDKLOC?
=$(shell cd ..
&& pwd
)/tools_bin
/linux
/sdk
52 SDKROOT
=$(SDKLOC
)/$(SDKNAME
)
53 BUILDNCCDIR
=$(SDKROOT
)/$(CROSSARCH
)
55 ifeq ($(shell uname
-s
), Darwin
)
58 # No 'uname -o' on OSX
59 PLATFORM
:=$(shell uname
-o
)
62 SRCDIR
=..
/..
/..
/third_party
64 ifeq ($(PLATFORM
), Cygwin
)
65 # Ugh, Cygwin and spaces in paths don't work well.
66 # I'm explicitly coding the path.
67 BUILDPATH
=$(SDKROOT
)/bin
:/usr
/local
/bin
:/usr
/bin
:/bin
:/cygdrive
/c
/Python25
/:/usr
/X11R6
/bin
:/cygdrive
/c
/WINDOWS
/system32
:/cygdrive
/c
/WINDOWS
:/cygdrive
/c
/WINDOWS
/system32
/WBEM
:/cygdrive
/c
/WINDOWS
/system32
/WindowsPowerShell
/v1.0
:/usr
/lib
/lapack
69 SDKLOC_NATIVE
=$(shell cygpath
-m
$(SDKLOC
))
70 CYGWIN_DLL_COPY
=cp
-f ..
/..
/third_party
/gnu_binutils
/files
/cygwin1.dll
$(SDKROOT
)/bin
72 BUILDPATH
=$(SDKROOT
)/bin
:$(PATH
)
74 SDKLOC_NATIVE
=$(SDKLOC
)
75 CYGWIN_DLL_COPY
=echo
"Cygwin not used on this platform"
78 ##################################################################
79 # The default alignment used by the tools.
80 # DEFAULT_ALIGN_BYTES is the alignment constraint that is enforced
81 # by the tools. No instruction may span a multiple of this value.
82 # DEFAULT_ALIGN_POW2 is the log base 2 of DEFAULT_ALIGN_BYTES.
83 # Both of these variables are used to set the default values of
84 # alignment for gcc and gas. Command-line flags may override the
86 ##################################################################
87 DEFAULT_ALIGN_BYTES
=32
90 ##################################################################
91 # The version numbers for the tools we will be building.
92 ##################################################################
98 ##################################################################
99 # Copying the sources, applying patches, etc.
100 ##################################################################
101 # Create the BUILD subdirectory:
105 # # copy binutils, apply patches
106 # BUILD/binutils-$(BINUTILS_VERSION): | BUILD
107 # @echo "Unpacking binutils-$(BINUTILS_VERSION)"
108 # cd BUILD && tar xf $(SRCDIR)/binutils/binutils-$(BINUTILS_VERSION).tar.bz2
109 # cd BUILD && patch -p0 < ../patches/binutils-$(BINUTILS_VERSION).patch
111 # # create binutils source directory, and mark that we've done that
112 # BUILD/stamp-binutils-$(BINUTILS_VERSION): Makefile
113 # rm -rf BUILD/binutils-$(BINUTILS_VERSION)
114 # $(MAKE) -f $(THISMAKEFILE) BUILD/binutils-$(BINUTILS_VERSION)
117 # copy newlib, apply patches
118 BUILD
/newlib-
$(NEWLIB_VERSION
): | BUILD
119 @echo
"Unpacking newlib-$(NEWLIB_VERSION)"
120 cd BUILD
&& tar xf
$(SRCDIR
)/newlib
/newlib-
$(NEWLIB_VERSION
).
tar.gz
121 cd BUILD
&& patch
-p0
< ..
/patches
/newlib-
$(NEWLIB_VERSION
).patch
123 # create newlib source directory, and mark that we've done that
124 BUILD
/stamp-newlib-
$(NEWLIB_VERSION
): Makefile
125 rm -rf BUILD
/newlib-
$(NEWLIB_VERSION
)
126 $(MAKE
) -f
$(THISMAKEFILE
) BUILD
/newlib-
$(NEWLIB_VERSION
)
129 # # copy gcc, apply patches
130 # BUILD/gcc-$(GCC_VERSION): | BUILD
131 # @echo "Unpacking gcc-$(GCC_VERSION)"
132 # cd BUILD && tar xf $(SRCDIR)/gcc/gcc-core-$(GCC_VERSION).tar.bz2
133 # cd BUILD && tar xf $(SRCDIR)/gcc/gcc-g++-$(GCC_VERSION).tar.bz2
134 # cd BUILD && patch -p0 < ../patches/gcc-$(GCC_VERSION).patch
136 # # create gcc source directory, and mark that we've done that
137 # BUILD/stamp-gcc-$(GCC_VERSION): Makefile
138 # rm -rf BUILD/gcc-$(GCC_VERSION)
139 # $(MAKE) -f $(THISMAKEFILE) BUILD/gcc-$(GCC_VERSION)
142 # copy gdb, apply patches
143 BUILD
/gdb-
$(GDB_VERSION
): | BUILD
144 @echo
"Unpacking gdb-$(GDB_VERSION)"
145 cd BUILD
&& tar xf
$(SRCDIR
)/gdb
/gdb-
$(GDB_VERSION
).
tar.bz2
146 cd BUILD
&& patch
-p0
< ..
/patches
/gdb-
$(GDB_VERSION
).patch
148 # create gdb source directory, and mark that we've done that
149 BUILD
/stamp-gdb-
$(GDB_VERSION
): #Makefile
150 rm -rf BUILD
/gdb-
$(GDB_VERSION
)
151 $(MAKE
) -f
$(THISMAKEFILE
) BUILD
/gdb-
$(GDB_VERSION
)
154 ##################################################################
155 # Create the SDK output directories.
156 ##################################################################
161 $(SDKROOT
)/$(CROSSARCH
)/include \
162 $(SDKROOT
)/$(CROSSARCH
)/lib \
166 echo
"Creating the SDK tree at $(SDKROOT)"
167 @for d in
$(SDKDIRS
); do \
168 if
[ ! -d
$$d ]; then \
169 echo
install -m
755 -d
$$d; \
170 install -m
755 -d
$$d; \
174 ##################################################################
176 # Builds the cross assembler, linker, archiver, etc.
177 ##################################################################
178 BUILD
/stamp-binutils
: BUILD
/stamp-binutils-
$(BINUTILS_VERSION
) Makefile
179 rm -rf BUILD
/build-binutils-
$(CROSSARCH
)
180 mkdir BUILD
/build-binutils-
$(CROSSARCH
)
181 cd BUILD
/build-binutils-
$(CROSSARCH
) && \
183 CFLAGS
="-DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
185 ..
/binutils-
$(BINUTILS_VERSION
)/configure \
186 --prefix=$(SDKROOT
) \
187 --target
=${CROSSARCH}
188 $(MAKE
) -C BUILD
/build-binutils-
$(CROSSARCH
) all
189 $(MAKE
) -C BUILD
/build-binutils-
$(CROSSARCH
) install
193 binutils
: BUILD
/stamp-binutils
195 ##################################################################
197 # Builds the cross gcc used to build the libraries.
198 ##################################################################
199 BUILD
/stamp-pregcc
: BUILD
/stamp-gcc-
$(GCC_VERSION
) Makefile
200 rm -rf BUILD
/build-pregcc-
$(CROSSARCH
)
201 mkdir BUILD
/build-pregcc-
$(CROSSARCH
)
202 cd BUILD
/build-pregcc-
$(CROSSARCH
) && \
203 PATH
=$(BUILDPATH
) CC
="gcc" \
204 CFLAGS
="-Dinhibit_libc -D__gthr_posix_h -DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
206 ..
/gcc-
$(GCC_VERSION
)/configure \
207 --prefix=$(SDKROOT
) \
209 --disable-libmudflap \
211 --enable-languages
=c \
213 --disable-libstdcxx-pch \
215 --target
=$(CROSSARCH
)
217 $(MAKE
) -C BUILD
/build-pregcc-
$(CROSSARCH
) \
218 CFLAGS_FOR_TARGET
="-O2 -g" \
219 CXXFLAGS_FOR_TARGET
="-O2 -g" \
222 $(MAKE
) -C BUILD
/build-pregcc-
$(CROSSARCH
) \
223 CFLAGS_FOR_TARGET
="-O2 -g" \
224 CXXFLAGS_FOR_TARGET
="-O2 -g" \
226 cp
$(SDKROOT
)/lib
/gcc
/$(CROSSARCH
)/$(GCC_VERSION
)/libgcc.a \
227 $(SDKROOT
)/lib
/gcc
/$(CROSSARCH
)/$(GCC_VERSION
)/libgcc_eh.a
231 pregcc
: BUILD
/stamp-pregcc
233 ##################################################################
235 # Builds the bare-bones library used by NativeClient applications.
236 # NOTE: removes the default pthread.h to enable correct install
237 # by the Native Client threads package build.
238 ##################################################################
239 BUILD
/stamp-newlib
: BUILD
/stamp-newlib-
$(NEWLIB_VERSION
) Makefile
240 rm -rf BUILD
/build-newlib-
$(CROSSARCH
)
241 mkdir BUILD
/build-newlib-
$(CROSSARCH
)
242 ..
/service_runtime
/export_header.py ..
/service_runtime
/include \
243 BUILD
/newlib-
$(NEWLIB_VERSION
)/newlib
/libc
/sys
/nacl
244 cd BUILD
/build-newlib-
$(CROSSARCH
) && \
246 CFLAGS
="-m32 -march=i486 -msse2 -mfpmath=sse" \
247 ..
/newlib-
$(NEWLIB_VERSION
)/configure \
248 --prefix=$(SDKROOT
) \
249 --target
=$(CROSSARCH
)
251 $(MAKE
) -C BUILD
/build-newlib-
$(CROSSARCH
) \
252 CFLAGS_FOR_TARGET
="-m32 -march=i486 -msse2 -mfpmath=sse -O2" \
253 CXXFLAGS_FOR_TARGET
="-m32 -march=i486 -msse2 -mfpmath=sse -O2" \
256 $(MAKE
) -C BUILD
/build-newlib-
$(CROSSARCH
) \
257 install_root
=$(SDKROOT
)/$(CROSSARCH
) install
258 rm $(SDKROOT
)/$(CROSSARCH
)/include/pthread.h
262 newlib
: BUILD
/stamp-newlib
264 ##################################################################
266 # Builds the gcc that will be used to build applications.
267 ##################################################################
268 BUILD
/stamp-gcc
: BUILD
/stamp-gcc-
$(GCC_VERSION
) Makefile
269 rm -rf BUILD
/build-gcc-
$(CROSSARCH
)
270 mkdir BUILD
/build-gcc-
$(CROSSARCH
)
271 cd BUILD
/build-gcc-
$(CROSSARCH
) && \
272 PATH
=$(BUILDPATH
) CC
="gcc" \
273 CFLAGS
="-Dinhibit_libc -DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
274 CFLAGS_FOR_TARGET
="-O2 -g" \
275 CXXFLAGS_FOR_TARGET
="-O2 -g" \
277 ..
/gcc-
$(GCC_VERSION
)/configure \
278 --prefix=$(SDKROOT
) \
280 --enable-threads
=nacl \
282 --disable-libmudflap \
286 --disable-libstdcxx-pch \
287 --enable-languages
="c,c++" \
288 --target
=$(CROSSARCH
)
290 $(MAKE
) -C BUILD
/build-gcc-
$(CROSSARCH
) \
291 CFLAGS_FOR_TARGET
="-O2 -g" \
292 CXXFLAGS_FOR_TARGET
="-O2 -g" \
295 $(MAKE
) -C BUILD
/build-gcc-
$(CROSSARCH
) \
296 CFLAGS_FOR_TARGET
="-O2 -g" \
297 CXXFLAGS_FOR_TARGET
="-O2 -g" \
304 ##################################################################
307 ##################################################################
308 # FIXME: This currently forces a 32-bit host.
309 # Only linux is supported.
310 BUILD
/stamp-gdb
: BUILD
/stamp-gdb-
$(GDB_VERSION
) #Makefile
311 case
$$(BUILD
/gdb-
$(GDB_VERSION
)/config.guess
) in \
313 *) echo
"Unsupported host" >&2 ; false
;; \
315 rm -rf BUILD
/build-gdb-
$(CROSSARCH
)
316 mkdir BUILD
/build-gdb-
$(CROSSARCH
)
319 case
$$(BUILD
/gdb-
$(GDB_VERSION
)/config.guess
) in \
320 x86_64-
*) CC
="gcc -m32" ; BUILD
=--build
=i686-linux
;; \
322 cd BUILD
/build-gdb-
$(CROSSARCH
) && \
325 ..
/gdb-
$(GDB_VERSION
)/configure \
326 --prefix=$(SDKROOT
) \
328 --target
=${CROSSARCH}
329 $(MAKE
) -C BUILD
/build-gdb-
$(CROSSARCH
) all
330 $(MAKE
) -C BUILD
/build-gdb-
$(CROSSARCH
) install
336 ##################################################################
337 # Build the libraries and c runtime stubs.
338 ##################################################################
341 .
/$(SCONS
) naclsdk_mode
=custom
:$(SDKLOC_NATIVE
)/nacl-sdk \
342 MODE
=nacl_extra_sdk install_libpthread
344 nacl_libraries
: ALWAYS
346 .
/$(SCONS
) naclsdk_mode
=custom
:$(SDKLOC_NATIVE
)/nacl-sdk \
347 MODE
=nacl_extra_sdk extra_sdk_update
349 sdk_minimal_test
: ALWAYS
351 .
/$(SCONS
) naclsdk_mode
=custom
:$(SDKLOC_NATIVE
)/nacl-sdk \
352 MODE
=nacl sdk_minimal_test
355 ##################################################################
356 # Build the entire sdk
357 ##################################################################
360 $(MAKE
) -f
$(THISMAKEFILE
) sdkdirs
362 cp
-f ..
/..
/third_party
/gcc
/COPYING
$(SDKROOT
)
363 $(MAKE
) -f
$(THISMAKEFILE
) BUILD
/stamp-binutils
364 $(MAKE
) -f
$(THISMAKEFILE
) BUILD
/stamp-pregcc
365 $(MAKE
) -f
$(THISMAKEFILE
) BUILD
/stamp-newlib
366 $(MAKE
) -f
$(THISMAKEFILE
) nc_threads
367 $(MAKE
) -f
$(THISMAKEFILE
) BUILD
/stamp-gcc
368 case
$$(BUILD
/binutils-
$(BINUTILS_VERSION
)/config.guess
) in \
369 *-linux
*) $(MAKE
) -f
$(THISMAKEFILE
) BUILD
/stamp-gdb
;; \
371 $(MAKE
) -f
$(THISMAKEFILE
) nacl_libraries
372 $(MAKE
) -f
$(THISMAKEFILE
) sdk_minimal_test
374 ##################################################################
375 # Build an updated set of patches from the current build versions.
376 ##################################################################
380 cd PRISTINE
&& tar xf
$(SRCDIR
)/binutils
/binutils-
$(BINUTILS_VERSION
).
tar.bz2
381 cd PRISTINE
&& tar xf
$(SRCDIR
)/newlib
/newlib-
$(NEWLIB_VERSION
).
tar.gz
382 cd PRISTINE
&& tar xf
$(SRCDIR
)/gcc
/gcc-core-
$(GCC_VERSION
).
tar.bz2
383 cd PRISTINE
&& tar xf
$(SRCDIR
)/gcc
/gcc-g
++-$(GCC_VERSION
).
tar.bz2
384 cd PRISTINE
&& tar xf
$(SRCDIR
)/gdb
/gdb-
$(GDB_VERSION
).
tar.bz2
386 BUILD
/binutils_patchfile
: | PRISTINE
388 diff
-Naur ..
/PRISTINE
/binutils-
$(BINUTILS_VERSION
) \
389 binutils-
$(BINUTILS_VERSION
) > binutils_patchfile
)
391 BUILD
/newlib_patchfile
: | PRISTINE
393 diff
-Naur ..
/PRISTINE
/newlib-
$(NEWLIB_VERSION
) \
394 newlib-
$(NEWLIB_VERSION
) > newlib_patchfile
)
396 BUILD
/gcc_patchfile
: | PRISTINE
398 diff
-Naur ..
/PRISTINE
/gcc-
$(GCC_VERSION
) \
399 gcc-
$(GCC_VERSION
) > gcc_patchfile
)
401 BUILD
/gdb_patchfile
: | PRISTINE
403 diff
-Naur ..
/PRISTINE
/gdb-
$(GDB_VERSION
) \
404 gdb-
$(GDB_VERSION
) > gdb_patchfile
)
406 patches
: BUILD
/binutils_patchfile \
407 BUILD
/newlib_patchfile \
408 BUILD
/gcc_patchfile \
411 ##################################################################
412 # Build an SDK tarball.
413 ##################################################################
414 TARBALL_FILE
=$(shell pwd
)/BUILD
/nacl-sdk.
tar
416 (cd
$(SDKLOC
); tar -cvhf
$(TARBALL_FILE
) $(SDKNAME
); gzip
$(TARBALL_FILE
))
418 ##################################################################
419 # Remove the BUILD directory and PRISTINE versions used for patches.
420 # Library builds are maintained by scons.
421 ##################################################################
423 -rm -rf BUILD PRISTINE