Run the validator on dynamically loaded code
[nativeclient.git] / common / Makefile.mk
blob133d0fcabf942319e0e920b048326d7712ba6f64
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.
31 # Simple Makefile.mk for demos
33 # Supported on Linux & Mac.
34 # Limited support under Cygwin on Windows (see note below)
36 # This makefile requires GNU make to run -- it is not compatible with nmake
37 # (and unlikely to be compatible with any other version of make.)
39 # The main purpose of this makefile component is to demonstrate building
40 # both nacl and non-nacl versions of some of the demos. The non-nacl
41 # versions are regular executables that can be debugged using standard host
42 # debugging tools (gdb, KDbg, etc.) The nacl versions (.nexe) require sel_ldr
43 # to execute, but the exact same nexe can be run on any nacl supported
44 # platform.
46 # This makefile component is intended to be included by a higher level
47 # Makefile after it has defined FILES and NAME. Here are some examples
48 # of how to invoke from the higher level Makefile:
50 # make clean Remove all built files
52 # make debug Build standalone debug version using g++ compiler
53 # (default) Output executable is $(NAME)_debug
54 # This executable can be debugged with gdb, kdbg, etc.
55 # Runnable on build platform only.
57 # make release Build standalone release version using g++ compiler
58 # Output executable is $(NAME)
59 # Runnable on build platform only.
61 # make debug nacl Build debug nacl version using nacl-g++
62 # Output executable is $(NAME)_debug.nexe
63 # Runnable on any nacl platform.
65 # make release nacl Build release nacl version using nacl-g++
66 # Output executable is $(NAME).nexe
67 # Runnable on any nacl platform.
69 # make debug run Build and run debug standalone build
71 # make release nacl run Build and run release nacl version
73 # make release run ARGS="-w1024 -h1024 -m4"
74 # Build standalone release, and run it passing along
75 # command line arguments -w1024 -h1024 -m4
77 # on any build target, you can override optimization (OPT),
78 # add extra flags (CCFLAGS) add debug info (DBG) add extra
79 # libraries (LIBS) pass extra arguments onto the application
80 # when running it (ARGS) and (experimental) set optional platform
81 # (PLATFORM) (default is autodetect between Mac & Linux)
83 # These overrides can be environment variables in your shell, passed
84 # in as arguments on the command line, or defined in Makefiles that
85 # include this file.
87 # For example, to override on the command line:
89 # make debug OPT=-O2 build debug with -O2
90 # make release DBG=-g build release with debug info
91 # make release nacl OPT=-O0 build release nacl with -O0
92 # make release run ARGS="-m2" build and run release passing "-m2"
93 # make debug run ARGS="-w768 -h768" build and run debug with "-w768 -h768"
94 # make release nacl run ARGS="-w1024 -h1024"
96 # Special Note for Cygwin on Windows: this makefile can be used
97 # to compile nacl versions of the demos, but does not support
98 # building them stand-alone.
101 CCFLAGS ?=
102 LIBS ?=
103 RUN ?=
104 ARGS ?=
105 SUBSYSTEM ?= multimedia
106 PRE_BUILD ?= @echo
107 POST_BUILD ?= @echo
108 SEL_LDR_ARGS ?= -d
109 NACL_CPP ?= nacl-g++
110 STANDALONE_CPP ?= g++
111 RELEASE_NAME := $(NAME)_release
112 DEBUG_NAME := $(NAME)_debug
113 GOOGLE_CLIENT := $(subst /googleclient,/googleclient *,$(CURDIR))
114 GOOGLE_CLIENT := $(filter-out *%,$(GOOGLE_CLIENT))
115 NATIVE_CLIENT := $(GOOGLE_CLIENT)/native_client
116 NACL_BIN_PATH ?= $(GOOGLE_CLIENT)/third_party/nacl_sdk/$(PLATFORM)/sdk/nacl-sdk/bin
117 SEL_LDR ?= $(NATIVE_CLIENT)/scons-out/opt-$(PLATFORM)/staging/sel_ldr
118 NACL_INCLUDE ?=
119 INCLUDE := -I$(GOOGLE_CLIENT) $(NACL_INCLUDE)
121 args:=$(MAKECMDGOALS)
123 # platform...
124 ifeq ($(shell uname -s), Darwin)
125 PLATFORM ?= mac
126 FRAMEWORKS_DIR ?= /Library/Frameworks
127 SDL_FRAMEWORK_DIR ?= $(GOOGLE_CLIENT)/third_party/sdl/osx/v1_2_13
128 PLATFORM_SDL := -I$(SDL_FRAMEWORK_DIR)/SDL.framework/Headers
129 PLATFORM_SDL += $(NATIVE_CLIENT)/common/SDLApplication.m
130 PLATFORM_SDL += -F$(SDL_FRAMEWORK_DIR)
131 PLATFORM_SDL += -framework SDL -framework Cocoa
132 else
133 ENVIRON := $(shell uname -o)
134 ifeq (Linux,$(findstring Linux,$(ENVIRON)))
135 PLATFORM ?= linux
136 SDL_FRAMEWORK_DIR ?= $(GOOGLE_CLIENT)/third_party/sdl/linux/v1_2_13
137 PLATFORM_SDL := -I$(SDL_FRAMEWORK_DIR)/include
138 PLATFORM_SDL += -L$(SDL_FRAMEWORK_DIR)/lib
139 PLATFORM_SDL += -lSDLmain -lSDL
140 else
141 ifeq (Cygwin,$(ENVIRON))
142 PLATFORM ?= win
143 PATH+= :$(NACL_BIN_PATH)
144 SDL_FRAMEWORK_DIR ?= $(GOOGLE_CLIENT)/third_party/sdl/win/v1_2_13
145 NACL_BIN_PATH := $(GOOGLE_CLIENT)/third_party/nacl_sdk/windows/sdk/nacl-sdk/bin
146 PLATFORM_SDL := -I$(SDL_FRAMEWORK_DIR)/include
147 PLATFORM_SDL += -L$(SDL_FRAMEWORK_DIR)/lib
148 PLATFORM_SDL += -lSDLmain -lSDL
149 ifneq (nacl,$(filter nacl,$(args)))
150 $(warning Stand-alone non-nacl builds are unsupported on Windows/Cygwin)
151 $(error Please add 'nacl' target when invoking make)
152 endif
153 else
154 $(error $(ENVIRON) is an unrecognized platform -- unable to continue)
155 endif
156 endif
157 endif
159 # process release vs debug options here
160 ifeq (release,$(filter release,$(args)))
161 OPT ?= -O3 -mfpmath=sse -msse -fomit-frame-pointer
162 DBG ?=
163 OUTPUT_NAME :=$(RELEASE_NAME)
164 else
165 # if release not specified, default to debug
166 OPT ?= -O0
167 DBG ?= -g
168 OUTPUT_NAME := $(DEBUG_NAME)
169 endif
171 # xray profiler target
172 ifeq (xray,$(filter xray,$(MAKECMDGOALS)))
173 XRAY_FILES := $(NATIVE_CLIENT)/tools/xray/xray.c
174 XRAY_FILES += $(NATIVE_CLIENT)/tools/xray/stringpool.c
175 XRAY_FILES += $(NATIVE_CLIENT)/tools/xray/hashtable.c
176 XRAY_FILES += $(NATIVE_CLIENT)/tools/xray/symtable.c
177 XRAY_OPT := -O2 -finstrument-functions -falign-functions=32
178 XRAY_OPT += -DXRAY -DXRAY_ANNOTATE
179 XRAY_OPT += -I$(NATIVE_CLIENT)/tools/xray
180 XRAY_OPT += -Wl,-Map,$(NAME).map
181 XRAY_POST_BUILD := c++filt <$(NAME).map >$(NAME).map2 ;
182 XRAY_POST_BUILD += mv $(NAME).map2 $(NAME).map
183 else
184 XRAY_FILES :=
185 XRAY_OPT :=
186 XRAY_POST_BUILD :=
187 endif
189 # process nacl vs non-nacl options here
190 ifeq (nacl,$(filter nacl,$(args)))
191 CPP := $(NACL_BIN_PATH)/$(NACL_CPP)
192 EXE_NAME := $(OUTPUT_NAME).nexe
193 # args to nacl app need "--" prefix
194 ifdef ARGS
195 APP_ARGS := -- $(ARGS)
196 else
197 APP_ARGS :=
198 endif
199 MULTIMEDIA :=
200 APP_FILES := $(FILES)
201 RUN := $(SEL_LDR) $(SEL_LDR_ARGS) -f $(EXE_NAME)
202 OBJDUMP = $(NACL_BIN_PATH)/nacl-objdump
203 LIBS += -lav -lsrpc
204 else
205 CPP := $(STANDALONE_CPP)
206 CCFLAGS += -DSTANDALONE
207 EXE_NAME := $(OUTPUT_NAME)
208 ifeq ($(SUBSYSTEM),multimedia)
209 MULTIMEDIA := $(PLATFORM_SDL)
210 APP_FILES := $(FILES) $(NATIVE_CLIENT)/common/standalone.cc
211 else
212 MULTIMEDIA :=
213 APP_FILES := $(FILES)
214 endif
215 APP_ARGS := $(ARGS)
216 RUN := ./$(EXE_NAME)
217 OBJDUMP = objdump
218 endif
220 SRC_FILES := $(APP_FILES) $(XRAY_FILES)
222 # include common libs that most demos want
223 LIBS += -lpthread -lm
225 # build up all the various options
226 OPTIONS:=$(CCFLAGS) $(OPT) $(XRAY_OPT) $(DBG) $(LIBS)
228 # targets
230 debug: $(EXE_NAME)
232 release: $(EXE_NAME)
234 info:
235 @echo -----------------
236 @echo args: $(args)
237 @echo PATH: $(PATH)
238 @echo CURDIR: $(CURDIR)
239 @echo GOOGLE_CLIENT: $(GOOGLE_CLIENT)
240 @echo NATIVE_CLIENT: $(NATIVE_CLIENT)
241 @echo CCFLAGS: $(CCFLAGS)
242 @echo DBG: $(DBG)
243 @echo OPT: $(OPT)
244 @echo APP_FILES: $(APP_FILES)
245 @echo SRC_FILES: $(SRC_FILES)
246 @echo OPTIONS: $(OPTIONS)
247 @echo LIBS: $(LIBS)
248 @echo PLATFORM_SDL: $(PLATFORM_SDL)
249 @echo INCLUDE: $(INCLUDE)
250 @echo EXE_NAME: $(EXE_NAME)
251 @echo CPP: $(CPP)
252 @echo PRE_BUILD: $(PRE_BUILD)
253 @echo POST_BUILD: $(POST_BUILD)
254 @echo XRAY_OPT: $(XRAY_OPT)
255 @echo XRAY_FILES: $(XRAY_FILES)
256 @echo XRAY_POST_BUILD: $(XRAY_POST_BUILD)
257 @echo -----------------
259 nacl:
260 @echo make: Native Client target specified
262 clean:
263 rm -f *.o *.nexe $(DEBUG_NAME) $(RELEASE_NAME)
264 rm -rf $(DEBUG_NAME).dSYM
266 $(EXE_NAME): $(SRC_FILES)
267 $(PRE_BUILD)
268 $(CPP) $(SRC_FILES) $(INCLUDE) $(OPTIONS) -o $(EXE_NAME) $(MULTIMEDIA)
269 $(POST_BUILD)
270 $(XRAY_POST_BUILD)
272 run:
273 $(RUN) $(APP_ARGS)
275 xray:
276 @echo make: XRay Profiler target specified
278 .PHONY: debug release clean nacl run xray info