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 ##################################################################
49 SDKROOT
=$(SDKLOC
)/$(SDKNAME
)
50 BUILDNCCDIR
=$(SDKROOT
)/$(CROSSARCH
)
52 ifeq ($(shell uname
-s
), Darwin
)
55 # No 'uname -o' on OSX
56 PLATFORM
:=$(shell uname
-o
)
59 SRCDIR
=..
/..
/..
/third_party
61 ifeq ($(PLATFORM
), Cygwin
)
62 # Ugh, Cygwin and spaces in paths don't work well.
63 # I'm explicitly coding the path.
64 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
66 SDKLOC_NATIVE
=$(shell cygpath
-m
$(SDKLOC
))
67 CYGWIN_DLL_COPY
=cp
-f ..
/..
/third_party
/gnu_binutils
/files
/cygwin1.dll
$(SDKROOT
)/bin
69 BUILDPATH
=$(SDKROOT
)/bin
:$(PATH
)
71 SDKLOC_NATIVE
=$(SDKLOC
)
72 CYGWIN_DLL_COPY
=echo
"Cygwin not used on this platform"
75 ##################################################################
76 # The default alignment used by the tools.
77 # DEFAULT_ALIGN_BYTES is the alignment constraint that is enforced
78 # by the tools. No instruction may span a multiple of this value.
79 # DEFAULT_ALIGN_POW2 is the log base 2 of DEFAULT_ALIGN_BYTES.
80 # Both of these variables are used to set the default values of
81 # alignment for gcc and gas. Command-line flags may override the
83 ##################################################################
84 DEFAULT_ALIGN_BYTES
=32
87 ##################################################################
88 # The version numbers for the tools we will be building.
89 ##################################################################
95 ##################################################################
96 # Copying the sources, applying patches, etc.
97 ##################################################################
98 # Create the BUILD subdirectory:
102 # copy binutils, apply patches
103 BUILD
/binutils-
$(BINUTILS_VERSION
): | BUILD
104 @echo
"Unpacking binutils-$(BINUTILS_VERSION)"
105 (cd BUILD
; tar xf
$(SRCDIR
)/binutils
/binutils-
$(BINUTILS_VERSION
).
tar.bz2
)
106 (cd BUILD
; patch
-p0
< ..
/patches
/binutils-
$(BINUTILS_VERSION
).patch
)
108 # copy newlib, apply patches
109 BUILD
/newlib-
$(NEWLIB_VERSION
): | BUILD
110 @echo
"Unpacking newlib-$(NEWLIB_VERSION)"
111 (cd BUILD
; tar xf
$(SRCDIR
)/newlib
/newlib-
$(NEWLIB_VERSION
).
tar.gz
)
112 (cd BUILD
; patch
-p0
< ..
/patches
/newlib-
$(NEWLIB_VERSION
).patch
)
114 # copy gcc, apply patches
115 BUILD
/gcc-
$(GCC_VERSION
): | BUILD
116 @echo
"Unpacking gcc-$(GCC_VERSION)"
117 (cd BUILD
; tar xf
$(SRCDIR
)/gcc
/gcc-core-
$(GCC_VERSION
).
tar.bz2
)
118 (cd BUILD
; tar xf
$(SRCDIR
)/gcc
/gcc-g
++-$(GCC_VERSION
).
tar.bz2
)
119 (cd BUILD
; patch
-p0
< ..
/patches
/gcc-
$(GCC_VERSION
).patch
)
121 ##################################################################
122 # Create the SDK output directories.
123 ##################################################################
128 $(SDKROOT
)/$(CROSSARCH
)/include \
129 $(SDKROOT
)/$(CROSSARCH
)/lib \
132 echo
"Creating the SDK tree at $(SDKROOT)"
133 @for d in
$(SDKDIRS
); do \
134 if
[ ! -d
$$d ]; then \
135 echo
install -m
755 -d
$$d; \
136 install -m
755 -d
$$d; \
140 ##################################################################
142 # Builds the cross assembler, linker, archiver, etc.
143 ##################################################################
144 binutils
: | BUILD
/binutils-
$(BINUTILS_VERSION
)
146 rm -rf BUILD
/build-binutils-
$(CROSSARCH
)
147 mkdir BUILD
/build-binutils-
$(CROSSARCH
)
148 (cd BUILD
/build-binutils-
$(CROSSARCH
); \
150 CFLAGS
="-DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
152 ..
/binutils-
$(BINUTILS_VERSION
)/configure \
153 --prefix=$(SDKROOT
) \
154 --target
=${CROSSARCH})
155 $(MAKE
) -C BUILD
/build-binutils-
$(CROSSARCH
) all
156 $(MAKE
) -C BUILD
/build-binutils-
$(CROSSARCH
) install
158 ##################################################################
160 # Builds the cross gcc used to build the libraries.
161 ##################################################################
162 pregcc
: | BUILD
/gcc-
$(GCC_VERSION
)
164 rm -rf BUILD
/build-gcc-
$(CROSSARCH
)
165 mkdir BUILD
/build-gcc-
$(CROSSARCH
)
166 (cd BUILD
/build-gcc-
$(CROSSARCH
); \
167 PATH
=$(BUILDPATH
) CC
="gcc" \
168 CFLAGS
="-Dinhibit_libc -D__gthr_posix_h -DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
170 ..
/gcc-
$(GCC_VERSION
)/configure \
171 --prefix=$(SDKROOT
) \
173 --disable-libmudflap \
174 --enable-languages
=c \
176 --disable-libstdcxx-pch \
178 --target
=$(CROSSARCH
))
180 $(MAKE
) -C BUILD
/build-gcc-
$(CROSSARCH
) \
181 CFLAGS_FOR_TARGET
="-O2 -g" \
182 CXXFLAGS_FOR_TARGET
="-O2 -g" \
185 $(MAKE
) -C BUILD
/build-gcc-
$(CROSSARCH
) \
186 CFLAGS_FOR_TARGET
="-O2 -g" \
187 CXXFLAGS_FOR_TARGET
="-O2 -g" \
189 cp
$(SDKROOT
)/lib
/gcc
/$(CROSSARCH
)/$(GCC_VERSION
)/libgcc.a \
190 $(SDKROOT
)/lib
/gcc
/$(CROSSARCH
)/$(GCC_VERSION
)/libgcc_eh.a
192 ##################################################################
194 # Builds the bare-bones library used by NativeClient applications.
195 ##################################################################
196 newlib
: | BUILD
/newlib-
$(NEWLIB_VERSION
)
198 rm -rf BUILD
/build-newlib-
$(CROSSARCH
)
199 mkdir BUILD
/build-newlib-
$(CROSSARCH
)
200 (..
/service_runtime
/export_header.py ..
/service_runtime
/include \
201 BUILD
/newlib-
$(NEWLIB_VERSION
)/newlib
/libc
/sys
/nacl
)
202 (cd BUILD
/build-newlib-
$(CROSSARCH
); \
204 CFLAGS
="-m32 -march=i486 -msse2 -mfpmath=sse" \
205 ..
/newlib-
$(NEWLIB_VERSION
)/configure \
206 --prefix=$(SDKROOT
) \
207 --target
=$(CROSSARCH
))
209 $(MAKE
) -C BUILD
/build-newlib-
$(CROSSARCH
) \
210 CFLAGS_FOR_TARGET
="-m32 -march=i486 -msse2 -mfpmath=sse -O2" \
211 CXXFLAGS_FOR_TARGET
="-m32 -march=i486 -msse2 -mfpmath=sse -O2" \
214 $(MAKE
) -C BUILD
/build-newlib-
$(CROSSARCH
) \
215 install_root
=$(SDKROOT
)/$(CROSSARCH
) install
217 ##################################################################
219 # Builds the gcc that will be used to build applications.
220 ##################################################################
221 gcc
: | BUILD
/gcc-
$(GCC_VERSION
)
223 rm -rf BUILD
/build-gcc-
$(CROSSARCH
)
224 mkdir BUILD
/build-gcc-
$(CROSSARCH
)
225 (cd BUILD
/build-gcc-
$(CROSSARCH
); \
226 PATH
=$(BUILDPATH
) CC
="gcc" \
227 CFLAGS
="-Dinhibit_libc -DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
228 CFLAGS_FOR_TARGET
="-O2 -g" \
229 CXXFLAGS_FOR_TARGET
="-O2 -g" \
231 ..
/gcc-
$(GCC_VERSION
)/configure \
232 --prefix=$(SDKROOT
) \
234 --enable-threads
=nacl \
236 --disable-libmudflap \
239 --disable-libstdcxx-pch \
240 --enable-languages
="c,c++" \
241 --target
=$(CROSSARCH
))
243 $(MAKE
) -C BUILD
/build-gcc-
$(CROSSARCH
) \
244 CFLAGS_FOR_TARGET
="-O2 -g" \
245 CXXFLAGS_FOR_TARGET
="-O2 -g" \
248 $(MAKE
) -C BUILD
/build-gcc-
$(CROSSARCH
) \
249 CFLAGS_FOR_TARGET
="-O2 -g" \
250 CXXFLAGS_FOR_TARGET
="-O2 -g" \
253 ##################################################################
254 # Build the individual libraries and c runtime stubs.
255 ##################################################################
258 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) clean; \
259 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) all; \
260 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) install)
264 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) clean; \
265 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) all; \
266 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) install)
270 $(MAKE
) -f Makefile.nacl NCCDIR
=$(BUILDNCCDIR
) clean; \
271 $(MAKE
) -f Makefile.nacl NCCDIR
=$(BUILDNCCDIR
) all; \
272 $(MAKE
) -f Makefile.nacl NCCDIR
=$(BUILDNCCDIR
) install)
276 $(MAKE
) -f Makefile NCCDIR
=$(BUILDNCCDIR
) clean; \
277 $(MAKE
) -f Makefile NCCDIR
=$(BUILDNCCDIR
) all; \
278 $(MAKE
) -f Makefile NCCDIR
=$(BUILDNCCDIR
) install)
282 .
/scons naclsdk_mode
=custom
:$(SDKLOC_NATIVE
)/nacl-sdk \
283 MODE
=nacl google_nacl_imc google_nacl_imc_c
; \
284 cp scons-out
/nacl
/lib
/libgoogle_nacl_imc.a
$(BUILDNCCDIR
)/lib
; \
285 cp scons-out
/nacl
/lib
/libgoogle_nacl_imc_c.a
$(BUILDNCCDIR
)/lib
)
289 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) clean; \
290 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) all; \
291 $(MAKE
) NCCDIR
=$(BUILDNCCDIR
) install)
293 ##################################################################
294 # Build the entire sdk
295 ##################################################################
296 THISMAKEFILE
:= $(lastword
$(MAKEFILE_LIST
))
299 $(MAKE
) -f
$(THISMAKEFILE
) sdkdirs
301 cp
-f ..
/..
/third_party
/gcc
/COPYING
$(SDKROOT
)
302 $(MAKE
) -f
$(THISMAKEFILE
) binutils
303 $(MAKE
) -f
$(THISMAKEFILE
) pregcc
304 $(MAKE
) -f
$(THISMAKEFILE
) newlib
305 $(MAKE
) -f
$(THISMAKEFILE
) nc_threads
306 $(MAKE
) -f
$(THISMAKEFILE
) gcc
307 $(MAKE
) -f
$(THISMAKEFILE
) stubs
308 $(MAKE
) -f
$(THISMAKEFILE
) libnacl
309 $(MAKE
) -f
$(THISMAKEFILE
) imc
310 $(MAKE
) -f
$(THISMAKEFILE
) libsrpc
311 $(MAKE
) -f
$(THISMAKEFILE
) libav
313 ##################################################################
314 # Build an updated set of patches from the current build versions.
315 ##################################################################
319 (cd PRISTINE
; tar xf
$(SRCDIR
)/binutils
/binutils-
$(BINUTILS_VERSION
).
tar.bz2
)
320 (cd PRISTINE
; tar xf
$(SRCDIR
)/newlib
/newlib-
$(NEWLIB_VERSION
).
tar.gz
)
321 (cd PRISTINE
; tar xf
$(SRCDIR
)/gcc
/gcc-core-
$(GCC_VERSION
).
tar.bz2
)
322 (cd PRISTINE
; tar xf
$(SRCDIR
)/gcc
/gcc-g
++-$(GCC_VERSION
).
tar.bz2
)
324 BUILD
/binutils_patchfile
: | PRISTINE
326 diff
-Naur ..
/PRISTINE
/binutils-
$(BINUTILS_VERSION
) \
327 binutils-
$(BINUTILS_VERSION
) > binutils_patchfile
)
329 BUILD
/newlib_patchfile
: | PRISTINE
331 diff
-Naur ..
/PRISTINE
/newlib-
$(NEWLIB_VERSION
) \
332 newlib-
$(NEWLIB_VERSION
) > newlib_patchfile
)
334 BUILD
/gcc_patchfile
: | PRISTINE
336 diff
-Naur ..
/PRISTINE
/gcc-
$(GCC_VERSION
) \
337 gcc-
$(GCC_VERSION
) > gcc_patchfile
)
339 patches
: BUILD
/binutils_patchfile \
340 BUILD
/newlib_patchfile \
341 BUILD
/gcc_patchfile \
343 ##################################################################
344 # Build an SDK tarball.
345 ##################################################################
346 TARBALL_FILE
=$(shell pwd
)/BUILD
/nacl-sdk.
tar
348 (cd
$(SDKLOC
); tar -cvhf
$(TARBALL_FILE
) $(SDKNAME
); gzip
$(TARBALL_FILE
))
350 ##################################################################
351 # Remove the BUILD directory.
352 ##################################################################
354 -rm -rf BUILD PRISTINE
355 -(cd stubs
; $(MAKE
) clean)
356 -(cd libnacl
; $(MAKE
) clean)
357 -(cd libsrpc
; $(MAKE
) clean)
358 -(cd nc_threads
; $(MAKE
) clean)
359 -(cd libav
; $(MAKE
) clean)