Fix: $(HAMMER) -> scons
[nativeclient.git] / tools / Makefile
blob6fd46d6a3fbaebadf34d4de8efdd902da7333664
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 ##################################################################
46 CROSSARCH=nacl
47 SDKLOC?=/usr/local
48 SDKNAME=nacl-sdk
49 SDKROOT=$(SDKLOC)/$(SDKNAME)
50 BUILDNCCDIR=$(SDKROOT)/$(CROSSARCH)
52 ifeq ($(shell uname -s), Darwin)
53 PLATFORM=osx
54 else
55 # No 'uname -o' on OSX
56 PLATFORM:=$(shell uname -o)
57 endif
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
65 HAMMER?=hammer.bat
66 SDKLOC_NATIVE=$(shell cygpath -m $(SDKLOC))
67 CYGWIN_DLL_COPY=cp -f ../../third_party/gnu_binutils/files/cygwin1.dll $(SDKROOT)/bin
68 else
69 BUILDPATH=$(SDKROOT)/bin:$(PATH)
70 HAMMER?=hammer
71 SDKLOC_NATIVE=$(SDKLOC)
72 CYGWIN_DLL_COPY=echo "Cygwin not used on this platform"
73 endif
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
82 # values.
83 ##################################################################
84 DEFAULT_ALIGN_BYTES=32
85 DEFAULT_ALIGN_POW2=5
87 ##################################################################
88 # The version numbers for the tools we will be building.
89 ##################################################################
90 BINUTILS_VERSION=2.18
91 NEWLIB_VERSION=1.16.0
92 GCC_VERSION=4.2.2
93 GDB_VERSION=6.8
95 ##################################################################
96 # Copying the sources, applying patches, etc.
97 ##################################################################
98 # Create the BUILD subdirectory:
99 BUILD:
100 mkdir BUILD
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 ##################################################################
124 SDKDIRS=\
125 $(SDKROOT)/bin \
126 $(SDKROOT)/lib \
127 $(SDKROOT)/include \
128 $(SDKROOT)/$(CROSSARCH)/include \
129 $(SDKROOT)/$(CROSSARCH)/lib \
131 sdkdirs:
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; \
137 fi; \
138 done
140 ##################################################################
141 # binutils:
142 # Builds the cross assembler, linker, archiver, etc.
143 ##################################################################
144 binutils: | BUILD/binutils-$(BINUTILS_VERSION)
145 binutils:
146 rm -rf BUILD/build-binutils-$(CROSSARCH)
147 mkdir BUILD/build-binutils-$(CROSSARCH)
148 (cd BUILD/build-binutils-$(CROSSARCH); \
149 CC="gcc" \
150 CFLAGS="-DNACL_ALIGN_BYTES=$(DEFAULT_ALIGN_BYTES) -DNACL_ALIGN_POW2=$(DEFAULT_ALIGN_POW2)" \
151 LDFLAGS="-s" \
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 ##################################################################
159 # pregcc:
160 # Builds the cross gcc used to build the libraries.
161 ##################################################################
162 pregcc: | BUILD/gcc-$(GCC_VERSION)
163 pregcc:
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)" \
169 LDFLAGS="-s" \
170 ../gcc-$(GCC_VERSION)/configure \
171 --prefix=$(SDKROOT) \
172 --without-headers \
173 --disable-libmudflap \
174 --enable-languages=c \
175 --disable-threads \
176 --disable-libstdcxx-pch \
177 --disable-shared \
178 --target=$(CROSSARCH))
179 PATH=$(BUILDPATH) \
180 $(MAKE) -C BUILD/build-gcc-$(CROSSARCH) \
181 CFLAGS_FOR_TARGET="-O2 -g" \
182 CXXFLAGS_FOR_TARGET="-O2 -g" \
183 all-gcc
184 PATH=$(BUILDPATH) \
185 $(MAKE) -C BUILD/build-gcc-$(CROSSARCH) \
186 CFLAGS_FOR_TARGET="-O2 -g" \
187 CXXFLAGS_FOR_TARGET="-O2 -g" \
188 install-gcc
189 cp $(SDKROOT)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/libgcc.a \
190 $(SDKROOT)/lib/gcc/$(CROSSARCH)/$(GCC_VERSION)/libgcc_eh.a
192 ##################################################################
193 # newlib:
194 # Builds the bare-bones library used by NativeClient applications.
195 ##################################################################
196 newlib: | BUILD/newlib-$(NEWLIB_VERSION)
197 newlib:
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); \
203 PATH=$(BUILDPATH) \
204 CFLAGS="-m32 -march=i486 -msse2 -mfpmath=sse" \
205 ../newlib-$(NEWLIB_VERSION)/configure \
206 --prefix=$(SDKROOT) \
207 --target=$(CROSSARCH))
208 PATH=$(BUILDPATH) \
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" \
213 PATH=$(BUILDPATH) \
214 $(MAKE) -C BUILD/build-newlib-$(CROSSARCH) \
215 install_root=$(SDKROOT)/$(CROSSARCH) install
217 ##################################################################
218 # gcc:
219 # Builds the gcc that will be used to build applications.
220 ##################################################################
221 gcc: | BUILD/gcc-$(GCC_VERSION)
222 gcc:
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" \
230 LDFLAGS="-s" \
231 ../gcc-$(GCC_VERSION)/configure \
232 --prefix=$(SDKROOT) \
233 --with-newlib \
234 --enable-threads=nacl \
235 --enable-tls \
236 --disable-libmudflap \
237 --disable-shared \
238 --disable-libgomp \
239 --disable-libstdcxx-pch \
240 --enable-languages="c,c++" \
241 --target=$(CROSSARCH))
242 PATH=$(BUILDPATH) \
243 $(MAKE) -C BUILD/build-gcc-$(CROSSARCH) \
244 CFLAGS_FOR_TARGET="-O2 -g" \
245 CXXFLAGS_FOR_TARGET="-O2 -g" \
247 PATH=$(BUILDPATH) \
248 $(MAKE) -C BUILD/build-gcc-$(CROSSARCH) \
249 CFLAGS_FOR_TARGET="-O2 -g" \
250 CXXFLAGS_FOR_TARGET="-O2 -g" \
251 install
253 ##################################################################
254 # Build the individual libraries and c runtime stubs.
255 ##################################################################
256 stubs: ALWAYS
257 (cd stubs; \
258 $(MAKE) NCCDIR=$(BUILDNCCDIR) clean; \
259 $(MAKE) NCCDIR=$(BUILDNCCDIR) all; \
260 $(MAKE) NCCDIR=$(BUILDNCCDIR) install)
262 libnacl: ALWAYS
263 (cd libnacl; \
264 $(MAKE) NCCDIR=$(BUILDNCCDIR) clean; \
265 $(MAKE) NCCDIR=$(BUILDNCCDIR) all; \
266 $(MAKE) NCCDIR=$(BUILDNCCDIR) install)
268 libsrpc: ALWAYS
269 (cd libsrpc; \
270 $(MAKE) -f Makefile.nacl NCCDIR=$(BUILDNCCDIR) clean; \
271 $(MAKE) -f Makefile.nacl NCCDIR=$(BUILDNCCDIR) all; \
272 $(MAKE) -f Makefile.nacl NCCDIR=$(BUILDNCCDIR) install)
274 nc_threads: ALWAYS
275 (cd nc_threads; \
276 $(MAKE) -f Makefile NCCDIR=$(BUILDNCCDIR) clean; \
277 $(MAKE) -f Makefile NCCDIR=$(BUILDNCCDIR) all; \
278 $(MAKE) -f Makefile NCCDIR=$(BUILDNCCDIR) install)
280 imc: ALWAYS
281 (cd ..; \
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)
287 libav: ALWAYS
288 (cd libav; \
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))
298 build:
299 $(MAKE) -f $(THISMAKEFILE) sdkdirs
300 $(CYGWIN_DLL_COPY)
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 ##################################################################
317 PRISTINE:
318 mkdir PRISTINE
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
325 -(cd BUILD; \
326 diff -Naur ../PRISTINE/binutils-$(BINUTILS_VERSION) \
327 binutils-$(BINUTILS_VERSION) > binutils_patchfile)
329 BUILD/newlib_patchfile: | PRISTINE
330 -(cd BUILD; \
331 diff -Naur ../PRISTINE/newlib-$(NEWLIB_VERSION) \
332 newlib-$(NEWLIB_VERSION) > newlib_patchfile)
334 BUILD/gcc_patchfile: | PRISTINE
335 -(cd BUILD; \
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
347 tarball:
348 (cd $(SDKLOC); tar -cvhf $(TARBALL_FILE) $(SDKNAME); gzip $(TARBALL_FILE))
350 ##################################################################
351 # Remove the BUILD directory.
352 ##################################################################
353 clean:
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)
361 .PHONY: ALWAYS