Block remapping or unmapping code mappings
[nativeclient.git] / tools / Makefile
blob0a7c7b0893722c2b72137f767c12d4f336ef758d
1 # Copyright 2008, Google Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
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
13 # distribution.
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 ##################################################################
37 default: build
39 ##################################################################
40 # Describe where to find the sources, where the SDK goes, etc.
41 # SDKROOT has to exist, which requires some extra work, especially
42 # on Linux.
43 # TODO: Figure out how to get SDKROOT not to be absolute
44 # while keeping prefix set correctly.
45 ##################################################################
47 THISMAKEFILE := $(lastword $(MAKEFILE_LIST))
49 CROSSARCH=nacl
50 SDKLOC?=$(shell cd .. && pwd)/tools_bin/linux/sdk
51 SDKNAME=nacl-sdk
52 SDKROOT=$(SDKLOC)/$(SDKNAME)
53 BUILDNCCDIR=$(SDKROOT)/$(CROSSARCH)
55 ifeq ($(shell uname -s), Darwin)
56 PLATFORM=osx
57 else
58 # No 'uname -o' on OSX
59 PLATFORM:=$(shell uname -o)
60 endif
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
68 SCONS?=scons.bat
69 SDKLOC_NATIVE=$(shell cygpath -m $(SDKLOC))
70 CYGWIN_DLL_COPY=cp -f ../../third_party/gnu_binutils/files/cygwin1.dll $(SDKROOT)/bin
71 else
72 BUILDPATH=$(SDKROOT)/bin:$(PATH)
73 SCONS?=scons
74 SDKLOC_NATIVE=$(SDKLOC)
75 CYGWIN_DLL_COPY=echo "Cygwin not used on this platform"
76 endif
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
85 # values.
86 ##################################################################
87 DEFAULT_ALIGN_BYTES=32
88 DEFAULT_ALIGN_POW2=5
90 ##################################################################
91 # The version numbers for the tools we will be building.
92 ##################################################################
93 BINUTILS_VERSION=2.18
94 NEWLIB_VERSION=1.16.0
95 GCC_VERSION=4.2.2
96 GDB_VERSION=6.8
98 ##################################################################
99 # Copying the sources, applying patches, etc.
100 ##################################################################
101 # Create the BUILD subdirectory:
102 BUILD:
103 mkdir BUILD
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)
115 touch $@
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)
127 touch $@
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)
140 touch $@
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)
152 touch $@
154 ##################################################################
155 # Create the SDK output directories.
156 ##################################################################
157 SDKDIRS=\
158 $(SDKROOT)/bin \
159 $(SDKROOT)/lib \
160 $(SDKROOT)/include \
161 $(SDKROOT)/$(CROSSARCH)/include \
162 $(SDKROOT)/$(CROSSARCH)/lib \
164 .PHONY: sdkdirs
165 sdkdirs:
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; \
171 fi; \
172 done
174 ##################################################################
175 # binutils:
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) && \
182 CC="gcc" \
183 CFLAGS="-DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
184 LDFLAGS="-s" \
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
190 touch $@
192 .PHONY: binutils
193 binutils: BUILD/stamp-binutils
195 ##################################################################
196 # pregcc:
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)" \
205 LDFLAGS="-s" \
206 ../gcc-$(GCC_VERSION)/configure \
207 --prefix=$(SDKROOT) \
208 --without-headers \
209 --disable-libmudflap \
210 --disable-libssp \
211 --enable-languages=c \
212 --disable-threads \
213 --disable-libstdcxx-pch \
214 --disable-shared \
215 --target=$(CROSSARCH)
216 PATH=$(BUILDPATH) \
217 $(MAKE) -C BUILD/build-pregcc-$(CROSSARCH) \
218 CFLAGS_FOR_TARGET="-O2 -g" \
219 CXXFLAGS_FOR_TARGET="-O2 -g" \
220 all-gcc
221 PATH=$(BUILDPATH) \
222 $(MAKE) -C BUILD/build-pregcc-$(CROSSARCH) \
223 CFLAGS_FOR_TARGET="-O2 -g" \
224 CXXFLAGS_FOR_TARGET="-O2 -g" \
225 install-gcc
226 cp $(SDKROOT)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/libgcc.a \
227 $(SDKROOT)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/libgcc_eh.a
228 touch $@
230 .PHONY: pregcc
231 pregcc: BUILD/stamp-pregcc
233 ##################################################################
234 # newlib:
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) && \
245 PATH=$(BUILDPATH) \
246 CFLAGS="-m32 -march=i486 -msse2 -mfpmath=sse" \
247 ../newlib-$(NEWLIB_VERSION)/configure \
248 --prefix=$(SDKROOT) \
249 --target=$(CROSSARCH)
250 PATH=$(BUILDPATH) \
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" \
255 PATH=$(BUILDPATH) \
256 $(MAKE) -C BUILD/build-newlib-$(CROSSARCH) \
257 install_root=$(SDKROOT)/$(CROSSARCH) install
258 rm $(SDKROOT)/$(CROSSARCH)/include/pthread.h
259 touch $@
261 .PHONY: newlib
262 newlib: BUILD/stamp-newlib
264 ##################################################################
265 # gcc:
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" \
276 LDFLAGS="-s" \
277 ../gcc-$(GCC_VERSION)/configure \
278 --prefix=$(SDKROOT) \
279 --with-newlib \
280 --enable-threads=nacl \
281 --enable-tls \
282 --disable-libmudflap \
283 --disable-libssp \
284 --disable-shared \
285 --disable-libgomp \
286 --disable-libstdcxx-pch \
287 --enable-languages="c,c++" \
288 --target=$(CROSSARCH)
289 PATH=$(BUILDPATH) \
290 $(MAKE) -C BUILD/build-gcc-$(CROSSARCH) \
291 CFLAGS_FOR_TARGET="-O2 -g" \
292 CXXFLAGS_FOR_TARGET="-O2 -g" \
294 PATH=$(BUILDPATH) \
295 $(MAKE) -C BUILD/build-gcc-$(CROSSARCH) \
296 CFLAGS_FOR_TARGET="-O2 -g" \
297 CXXFLAGS_FOR_TARGET="-O2 -g" \
298 install
299 touch $@
301 .PHONY: gcc
302 gcc: BUILD/stamp-gcc
304 ##################################################################
305 # gdb:
306 # Builds gdb.
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 \
312 *-linux*) ;; \
313 *) echo "Unsupported host" >&2 ; false ;; \
314 esac
315 rm -rf BUILD/build-gdb-$(CROSSARCH)
316 mkdir BUILD/build-gdb-$(CROSSARCH)
317 CC=gcc ; \
318 BUILD= ; \
319 case $$(BUILD/gdb-$(GDB_VERSION)/config.guess) in \
320 x86_64-*) CC="gcc -m32" ; BUILD=--build=i686-linux ;; \
321 esac ; \
322 cd BUILD/build-gdb-$(CROSSARCH) && \
323 CC="$${CC}" \
324 LDFLAGS="-s" \
325 ../gdb-$(GDB_VERSION)/configure \
326 --prefix=$(SDKROOT) \
327 $${BUILD} \
328 --target=${CROSSARCH}
329 $(MAKE) -C BUILD/build-gdb-$(CROSSARCH) all
330 $(MAKE) -C BUILD/build-gdb-$(CROSSARCH) install
331 touch $@
333 .PHONY: gdb
334 gdb: BUILD/stamp-gdb
336 ##################################################################
337 # Build the libraries and c runtime stubs.
338 ##################################################################
339 nc_threads: ALWAYS
340 cd .. && \
341 ./$(SCONS) naclsdk_mode=custom:$(SDKLOC_NATIVE)/nacl-sdk \
342 MODE=nacl_extra_sdk install_libpthread
344 nacl_libraries: ALWAYS
345 cd .. && \
346 ./$(SCONS) naclsdk_mode=custom:$(SDKLOC_NATIVE)/nacl-sdk \
347 MODE=nacl_extra_sdk extra_sdk_update
349 sdk_minimal_test: ALWAYS
350 cd .. && \
351 ./$(SCONS) naclsdk_mode=custom:$(SDKLOC_NATIVE)/nacl-sdk \
352 MODE=nacl sdk_minimal_test
355 ##################################################################
356 # Build the entire sdk
357 ##################################################################
359 build:
360 $(MAKE) -f $(THISMAKEFILE) sdkdirs
361 $(CYGWIN_DLL_COPY)
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 ;; \
370 esac
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 ##################################################################
378 PRISTINE:
379 mkdir PRISTINE
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
387 -(cd BUILD; \
388 diff -Naur ../PRISTINE/binutils-$(BINUTILS_VERSION) \
389 binutils-$(BINUTILS_VERSION) > binutils_patchfile)
391 BUILD/newlib_patchfile: | PRISTINE
392 -(cd BUILD; \
393 diff -Naur ../PRISTINE/newlib-$(NEWLIB_VERSION) \
394 newlib-$(NEWLIB_VERSION) > newlib_patchfile)
396 BUILD/gcc_patchfile: | PRISTINE
397 -(cd BUILD; \
398 diff -Naur ../PRISTINE/gcc-$(GCC_VERSION) \
399 gcc-$(GCC_VERSION) > gcc_patchfile)
401 BUILD/gdb_patchfile: | PRISTINE
402 -(cd BUILD; \
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 \
409 BUILD/gdb_patchfile
411 ##################################################################
412 # Build an SDK tarball.
413 ##################################################################
414 TARBALL_FILE=$(shell pwd)/BUILD/nacl-sdk.tar
415 tarball:
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 ##################################################################
422 clean:
423 -rm -rf BUILD PRISTINE
425 .PHONY: ALWAYS