sel_ldr: Remove support for rodata segment at start of executable
[nativeclient.git] / common / Makefile.mk
blobdf866bd3f54b1dc75cefb3d0247cd90b64b51407
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 # Use the 'dbgldr' target to invoke the debug sel_ldr instead of
88 # the default optimized sel_ldr.
90 # For example, to override on the command line:
92 # make debug OPT=-O2 build debug with -O2
93 # make release DBG=-g build release with debug info
94 # make release nacl OPT=-O0 build release nacl with -O0
95 # make release run ARGS="-m2" build and run release passing "-m2"
96 # make debug run ARGS="-w768 -h768" build and run debug with "-w768 -h768"
97 # make release nacl run ARGS="-w1024 -h1024"
99 # Special Note for Cygwin on Windows: this makefile can be used
100 # to compile nacl versions of the demos, but does not support
101 # building them stand-alone.
104 CCFLAGS ?=
105 LIBS ?=
106 RUN ?=
107 ARGS ?=
108 SUBSYSTEM ?= multimedia
109 PRE_BUILD ?= @echo
110 POST_BUILD ?= @echo
111 SEL_LDR_ARGS ?= -d
112 NACL_CPP ?= nacl-g++
113 STANDALONE_CPP ?= g++
114 RELEASE_NAME := $(NAME)_release
115 DEBUG_NAME := $(NAME)_debug
116 GOOGLE_CLIENT := $(subst /googleclient,/googleclient *,$(CURDIR))
117 GOOGLE_CLIENT := $(filter-out *%,$(GOOGLE_CLIENT))
118 NATIVE_CLIENT := $(GOOGLE_CLIENT)/native_client
119 NACL_BIN_PATH ?= $(GOOGLE_CLIENT)/third_party/nacl_sdk/$(PLATFORM)/sdk/nacl-sdk/bin
120 SEL_LDR ?= $(NATIVE_CLIENT)/scons-out/opt-$(PLATFORM)/staging/sel_ldr
121 NACL_INCLUDE ?=
122 INCLUDE := -I$(GOOGLE_CLIENT) $(NACL_INCLUDE)
124 args:=$(MAKECMDGOALS)
126 # use debug sel_ldr...
127 ifeq (dbgldr,$(filter dbgldr,$(args)))
128 SEL_LDR = $(NATIVE_CLIENT)/scons-out/dbg-$(PLATFORM)/staging/sel_ldr
129 endif
131 # platform...
132 ifeq ($(shell uname -s), Darwin)
133 PLATFORM ?= mac
134 FRAMEWORKS_DIR ?= /Library/Frameworks
135 SDL_FRAMEWORK_DIR ?= $(GOOGLE_CLIENT)/third_party/sdl/osx/v1_2_13
136 PLATFORM_SDL := -I$(SDL_FRAMEWORK_DIR)/SDL.framework/Headers
137 PLATFORM_SDL += $(NATIVE_CLIENT)/common/SDLApplication.m
138 PLATFORM_SDL += -F$(SDL_FRAMEWORK_DIR)
139 PLATFORM_SDL += -framework SDL -framework Cocoa
140 else
141 ENVIRON := $(shell uname -o)
142 ifeq (Linux,$(findstring Linux,$(ENVIRON)))
143 PLATFORM ?= linux
144 SDL_FRAMEWORK_DIR ?= $(GOOGLE_CLIENT)/third_party/sdl/linux/v1_2_13
145 PLATFORM_SDL := -I$(SDL_FRAMEWORK_DIR)/include
146 PLATFORM_SDL += -L$(SDL_FRAMEWORK_DIR)/lib
147 PLATFORM_SDL += -lSDLmain -lSDL
148 else
149 ifeq (Cygwin,$(ENVIRON))
150 PLATFORM ?= win
151 PATH+= :$(NACL_BIN_PATH)
152 SDL_FRAMEWORK_DIR ?= $(GOOGLE_CLIENT)/third_party/sdl/win/v1_2_13
153 NACL_BIN_PATH := $(GOOGLE_CLIENT)/third_party/nacl_sdk/windows/sdk/nacl-sdk/bin
154 PLATFORM_SDL := -I$(SDL_FRAMEWORK_DIR)/include
155 PLATFORM_SDL += -L$(SDL_FRAMEWORK_DIR)/lib
156 PLATFORM_SDL += -lSDLmain -lSDL
157 ifneq (nacl,$(filter nacl,$(args)))
158 $(warning Stand-alone non-nacl builds are unsupported on Windows/Cygwin)
159 $(error Please add 'nacl' target when invoking make)
160 endif
161 else
162 $(error $(ENVIRON) is an unrecognized platform -- unable to continue)
163 endif
164 endif
165 endif
167 # process release vs debug options here
168 ifeq (release,$(filter release,$(args)))
169 OPT ?= -O3 -mfpmath=sse -msse -fomit-frame-pointer
170 DBG ?=
171 OUTPUT_NAME :=$(RELEASE_NAME)
172 else
173 # if release not specified, default to debug
174 OPT ?= -O0
175 DBG ?= -g
176 OUTPUT_NAME := $(DEBUG_NAME)
177 endif
179 # xray profiler target
180 ifeq (xray,$(filter xray,$(MAKECMDGOALS)))
181 XRAY_FILES := $(NATIVE_CLIENT)/tools/xray/xray.c
182 XRAY_FILES += $(NATIVE_CLIENT)/tools/xray/stringpool.c
183 XRAY_FILES += $(NATIVE_CLIENT)/tools/xray/hashtable.c
184 XRAY_FILES += $(NATIVE_CLIENT)/tools/xray/symtable.c
185 XRAY_OPT := -O2 -finstrument-functions -falign-functions=32
186 XRAY_OPT += -DXRAY -DXRAY_ANNOTATE
187 XRAY_OPT += -I$(NATIVE_CLIENT)/tools/xray
188 XRAY_OPT += -Wl,-Map,$(NAME).map
189 XRAY_POST_BUILD := c++filt <$(NAME).map >$(NAME).map2 ;
190 XRAY_POST_BUILD += mv $(NAME).map2 $(NAME).map
191 else
192 XRAY_FILES :=
193 XRAY_OPT :=
194 XRAY_POST_BUILD :=
195 endif
197 # process nacl vs non-nacl options here
198 ifeq (nacl,$(filter nacl,$(args)))
199 CPP := $(NACL_BIN_PATH)/$(NACL_CPP)
200 EXE_NAME := $(OUTPUT_NAME).nexe
201 # args to nacl app need "--" prefix
202 ifdef ARGS
203 APP_ARGS := -- $(ARGS)
204 else
205 APP_ARGS :=
206 endif
207 MULTIMEDIA :=
208 APP_FILES := $(FILES)
209 RUN := $(SEL_LDR) $(SEL_LDR_ARGS) -f $(EXE_NAME)
210 OBJDUMP = $(NACL_BIN_PATH)/nacl-objdump
211 LIBS += -lav -lsrpc
212 else
213 CPP := $(STANDALONE_CPP)
214 CCFLAGS += -DSTANDALONE
215 EXE_NAME := $(OUTPUT_NAME)
216 ifeq ($(SUBSYSTEM),multimedia)
217 MULTIMEDIA := $(PLATFORM_SDL)
218 APP_FILES := $(FILES) $(NATIVE_CLIENT)/common/standalone.cc
219 else
220 MULTIMEDIA :=
221 APP_FILES := $(FILES)
222 endif
223 APP_ARGS := $(ARGS)
224 RUN := ./$(EXE_NAME)
225 OBJDUMP = objdump
226 endif
228 SRC_FILES := $(APP_FILES) $(XRAY_FILES)
230 # include common libs that most demos want
231 LIBS += -lpthread -lm
233 # build up all the various options
234 OPTIONS:=$(CCFLAGS) $(OPT) $(XRAY_OPT) $(DBG) $(LIBS)
236 # targets
238 debug: $(EXE_NAME)
240 release: $(EXE_NAME)
242 info:
243 @echo -----------------
244 @echo args: $(args)
245 @echo PATH: $(PATH)
246 @echo CURDIR: $(CURDIR)
247 @echo GOOGLE_CLIENT: $(GOOGLE_CLIENT)
248 @echo NATIVE_CLIENT: $(NATIVE_CLIENT)
249 @echo CCFLAGS: $(CCFLAGS)
250 @echo DBG: $(DBG)
251 @echo OPT: $(OPT)
252 @echo APP_FILES: $(APP_FILES)
253 @echo SRC_FILES: $(SRC_FILES)
254 @echo OPTIONS: $(OPTIONS)
255 @echo LIBS: $(LIBS)
256 @echo PLATFORM_SDL: $(PLATFORM_SDL)
257 @echo INCLUDE: $(INCLUDE)
258 @echo EXE_NAME: $(EXE_NAME)
259 @echo SEL_LDR: $(SEL_LDR)
260 @echo CPP: $(CPP)
261 @echo PRE_BUILD: $(PRE_BUILD)
262 @echo POST_BUILD: $(POST_BUILD)
263 @echo XRAY_OPT: $(XRAY_OPT)
264 @echo XRAY_FILES: $(XRAY_FILES)
265 @echo XRAY_POST_BUILD: $(XRAY_POST_BUILD)
266 @echo -----------------
268 nacl:
269 @echo make: Native Client target specified
271 clean:
272 rm -f *.o *.nexe $(DEBUG_NAME) $(RELEASE_NAME)
273 rm -rf $(DEBUG_NAME).dSYM
275 $(EXE_NAME): $(SRC_FILES)
276 $(PRE_BUILD)
277 $(CPP) $(SRC_FILES) $(INCLUDE) $(OPTIONS) -o $(EXE_NAME) $(MULTIMEDIA)
278 $(POST_BUILD)
279 $(XRAY_POST_BUILD)
281 dbgldr:
282 @echo make: Using debug build of sel_ldr
284 run:
285 $(RUN) $(APP_ARGS)
287 xray:
288 @echo make: XRay Profiler target specified
290 .PHONY: debug release clean nacl run xray info dbgldr