1*9e94795aSAndroid Build Coastguard Worker<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2*9e94795aSAndroid Build Coastguard Worker "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3*9e94795aSAndroid Build Coastguard Worker 4*9e94795aSAndroid Build Coastguard Worker<html xmlns="http://www.w3.org/1999/xhtml"> 5*9e94795aSAndroid Build Coastguard Worker 6*9e94795aSAndroid Build Coastguard Worker<!-- 7*9e94795aSAndroid Build Coastguard Worker A lot of people read this document template. Please keep it clean: 8*9e94795aSAndroid Build Coastguard Worker 9*9e94795aSAndroid Build Coastguard Worker - keep the document xhtml-compliant, as many people use validating editors 10*9e94795aSAndroid Build Coastguard Worker - check your edits for typos, spelling errors, and questionable grammar 11*9e94795aSAndroid Build Coastguard Worker - prefer css styles to formatting tags like <font>, <tt>, etc. 12*9e94795aSAndroid Build Coastguard Worker - keep it human-readable and human-editable in a plain text editor: 13*9e94795aSAndroid Build Coastguard Worker - strive to keep lines wrapped at 80 columns, unless a link prevents it 14*9e94795aSAndroid Build Coastguard Worker - use plenty of whitespace 15*9e94795aSAndroid Build Coastguard Worker - try to pretty-format (wrt nesting and indenting) any hairy html 16*9e94795aSAndroid Build Coastguard Worker - check your inline javascript for errors using the javascript console 17*9e94795aSAndroid Build Coastguard Worker 18*9e94795aSAndroid Build Coastguard Worker Your readers will be very appreciative. 19*9e94795aSAndroid Build Coastguard Worker--> 20*9e94795aSAndroid Build Coastguard Worker 21*9e94795aSAndroid Build Coastguard Worker<head> 22*9e94795aSAndroid Build Coastguard Worker <title>Android Build System</title> 23*9e94795aSAndroid Build Coastguard Worker 24*9e94795aSAndroid Build Coastguard Worker <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 25*9e94795aSAndroid Build Coastguard Worker 26*9e94795aSAndroid Build Coastguard Worker <link href="../android.css" type="text/css" rel="stylesheet" /> 27*9e94795aSAndroid Build Coastguard Worker 28*9e94795aSAndroid Build Coastguard Worker<!-- commenting out so the xhtml validator doesn't whine about < and &&; 29*9e94795aSAndroid Build Coastguard Worker the browser should still find the script tag. --> 30*9e94795aSAndroid Build Coastguard Worker<script language="JavaScript1.2" type="text/javascript"> 31*9e94795aSAndroid Build Coastguard Worker<!-- 32*9e94795aSAndroid Build Coastguard Workerfunction highlight(name) { 33*9e94795aSAndroid Build Coastguard Worker if (document.getElementsByTagName) { 34*9e94795aSAndroid Build Coastguard Worker tags = [ 'span', 'div', 'tr', 'td' ]; 35*9e94795aSAndroid Build Coastguard Worker for (i in tags) { 36*9e94795aSAndroid Build Coastguard Worker elements = document.getElementsByTagName(tags[i]); 37*9e94795aSAndroid Build Coastguard Worker if (elements) { 38*9e94795aSAndroid Build Coastguard Worker for (j = 0; j < elements.length; j++) { 39*9e94795aSAndroid Build Coastguard Worker elementName = elements[j].getAttribute("class"); 40*9e94795aSAndroid Build Coastguard Worker if (elementName == name) { 41*9e94795aSAndroid Build Coastguard Worker elements[j].style.backgroundColor = "#C0F0C0"; 42*9e94795aSAndroid Build Coastguard Worker } else if (elementName && elementName.indexOf("rev") == 0) { 43*9e94795aSAndroid Build Coastguard Worker elements[j].style.backgroundColor = "#FFFFFF"; 44*9e94795aSAndroid Build Coastguard Worker } 45*9e94795aSAndroid Build Coastguard Worker } 46*9e94795aSAndroid Build Coastguard Worker } 47*9e94795aSAndroid Build Coastguard Worker } 48*9e94795aSAndroid Build Coastguard Worker } 49*9e94795aSAndroid Build Coastguard Worker} 50*9e94795aSAndroid Build Coastguard Worker//--> 51*9e94795aSAndroid Build Coastguard Worker </script> 52*9e94795aSAndroid Build Coastguard Worker <!-- this style sheet is for the style of the toc --> 53*9e94795aSAndroid Build Coastguard Worker <link href="toc.css" type="text/css" rel="stylesheet" /> 54*9e94795aSAndroid Build Coastguard Worker 55*9e94795aSAndroid Build Coastguard Worker <style type="text/css"> 56*9e94795aSAndroid Build Coastguard Worker .warning { 57*9e94795aSAndroid Build Coastguard Worker border: 1px solid red; 58*9e94795aSAndroid Build Coastguard Worker padding: 8px; 59*9e94795aSAndroid Build Coastguard Worker color: red; 60*9e94795aSAndroid Build Coastguard Worker } 61*9e94795aSAndroid Build Coastguard Worker pre.prettyprint { 62*9e94795aSAndroid Build Coastguard Worker margin-top: 0; 63*9e94795aSAndroid Build Coastguard Worker } 64*9e94795aSAndroid Build Coastguard Worker li { 65*9e94795aSAndroid Build Coastguard Worker margin-top: 8px; 66*9e94795aSAndroid Build Coastguard Worker } 67*9e94795aSAndroid Build Coastguard Worker </style> 68*9e94795aSAndroid Build Coastguard Worker</head> 69*9e94795aSAndroid Build Coastguard Worker 70*9e94795aSAndroid Build Coastguard Worker<body onload="prettyPrint()"> 71*9e94795aSAndroid Build Coastguard Worker 72*9e94795aSAndroid Build Coastguard Worker<h1><a name="My_Project_" />Android Build System</h1> 73*9e94795aSAndroid Build Coastguard Worker 74*9e94795aSAndroid Build Coastguard Worker<!-- Status is one of: Draft, Current, Needs Update, Obsolete --> 75*9e94795aSAndroid Build Coastguard Worker<p style="text-align:center"> 76*9e94795aSAndroid Build Coastguard Worker <strong>Status:</strong> <em>Draft </em> 77*9e94795aSAndroid Build Coastguard Worker <small>(as of May 18, 2006)</small> 78*9e94795aSAndroid Build Coastguard Worker</p> 79*9e94795aSAndroid Build Coastguard Worker 80*9e94795aSAndroid Build Coastguard Worker<p><b>Contents</b></p> 81*9e94795aSAndroid Build Coastguard Worker<!-- this div expands out to a list of contents based on the H2 and H3 headings. 82*9e94795aSAndroid Build Coastguard WorkerBelieve it! --> 83*9e94795aSAndroid Build Coastguard Worker <div id="nav" class="nav-2-levels"></div> 84*9e94795aSAndroid Build Coastguard Worker 85*9e94795aSAndroid Build Coastguard Worker<h2>Objective</h2> 86*9e94795aSAndroid Build Coastguard Worker<p>The primary goals of reworking the build system are (1) to make dependencies 87*9e94795aSAndroid Build Coastguard Workerwork more reliably, so that when files need to rebuilt, they are, and (2) to 88*9e94795aSAndroid Build Coastguard Workerimprove performance of the build system so that unnecessary modules are not 89*9e94795aSAndroid Build Coastguard Workerrebuilt, and so doing a top-level build when little or nothing needs to be done 90*9e94795aSAndroid Build Coastguard Workerfor a build takes as little time as possible.</p> 91*9e94795aSAndroid Build Coastguard Worker 92*9e94795aSAndroid Build Coastguard Worker<h2>Principles and Use Cases and Policy</h2> 93*9e94795aSAndroid Build Coastguard Worker<p>Given the above objective, these are the overall principles and use cases 94*9e94795aSAndroid Build Coastguard Workerthat we will support. This is not an exhaustive list.</p> 95*9e94795aSAndroid Build Coastguard Worker<h3>Multiple Targets</h3> 96*9e94795aSAndroid Build Coastguard Worker<p>It needs to be possible to build the Android platform for multiple targets. 97*9e94795aSAndroid Build Coastguard WorkerThis means:</p> 98*9e94795aSAndroid Build Coastguard Worker<ul> 99*9e94795aSAndroid Build Coastguard Worker <li>The build system will support building tools for the host platform, 100*9e94795aSAndroid Build Coastguard Worker both ones that are used in the build process itself, and developer tools 101*9e94795aSAndroid Build Coastguard Worker like the simulator.</li> 102*9e94795aSAndroid Build Coastguard Worker <li>The build system will need to be able to build tools on Linux 103*9e94795aSAndroid Build Coastguard Worker (definitely Goobuntu and maybe Grhat), MacOS, and to some degree on 104*9e94795aSAndroid Build Coastguard Worker Windows.</li> 105*9e94795aSAndroid Build Coastguard Worker <li>The build system will need to be able to build the OS on Linux, and in 106*9e94795aSAndroid Build Coastguard Worker the short-term, MacOS. Note that this is a conscious decision to stop 107*9e94795aSAndroid Build Coastguard Worker building the OS on Windows. We are going to rely on the emulator there 108*9e94795aSAndroid Build Coastguard Worker and not attempt to use the simulator. This is a requirement change now 109*9e94795aSAndroid Build Coastguard Worker that the emulator story is looking brighter.</li> 110*9e94795aSAndroid Build Coastguard Worker</ul> 111*9e94795aSAndroid Build Coastguard Worker<h3>Non-Recursive Make</h3> 112*9e94795aSAndroid Build Coastguard Worker<p>To achieve the objectives, the build system will be rewritten to use make 113*9e94795aSAndroid Build Coastguard Workernon-recursively. For more background on this, read <a href="http://aegis.sourceforge.net/auug97.pdf">Recursive Make Considered Harmful</a>. For those that don't 114*9e94795aSAndroid Build Coastguard Workerwant PDF, here is the 115*9e94795aSAndroid Build Coastguard Worker<a href="http://72.14.203.104/search?q=cache:HwuX7YF2uBIJ:aegis.sourceforge.net/auug97.pdf&hl=en&gl=us&ct=clnk&cd=2&client=firefox">Google translated version</a>. 116*9e94795aSAndroid Build Coastguard Worker<h3>Rapid Compile-Test Cycles</h3> 117*9e94795aSAndroid Build Coastguard Worker<p>When developing a component, for example a C++ shared library, it must be 118*9e94795aSAndroid Build Coastguard Workerpossible to easily rebuild just that component, and not have to wait more than a 119*9e94795aSAndroid Build Coastguard Workercouple seconds for dependency checks, and not have to wait for unneeded 120*9e94795aSAndroid Build Coastguard Workercomponents to be built.</p> 121*9e94795aSAndroid Build Coastguard Worker<h3>Both Environment and Config File Based Settings</h3> 122*9e94795aSAndroid Build Coastguard Worker<p>To set the target, and other options, some people on the team like to have a 123*9e94795aSAndroid Build Coastguard Workerconfiguration file in a directory so they do not have an environment setup 124*9e94795aSAndroid Build Coastguard Workerscript to run, and others want an environment setup script to run so they can 125*9e94795aSAndroid Build Coastguard Workerrun builds in different terminals on the same tree, or switch back and forth 126*9e94795aSAndroid Build Coastguard Workerin one terminal. We will support both.</p> 127*9e94795aSAndroid Build Coastguard Worker<h3>Object File Directory / make clean</h3> 128*9e94795aSAndroid Build Coastguard Worker<p>Object files and other intermediate files will be generated into a directory 129*9e94795aSAndroid Build Coastguard Workerthat is separate from the source tree. The goal is to have make clean be 130*9e94795aSAndroid Build Coastguard Worker"rm -rf <obj>" in the tree root directory. The primary goals of 131*9e94795aSAndroid Build Coastguard Workerthis are to simplify searching the source tree, and to make "make clean" more 132*9e94795aSAndroid Build Coastguard Workerreliable.</p> 133*9e94795aSAndroid Build Coastguard Worker 134*9e94795aSAndroid Build Coastguard Worker<h3>SDK</h3> 135*9e94795aSAndroid Build Coastguard Worker<p>The SDK will be a tarball that will allow non-OS-developers to write apps. 136*9e94795aSAndroid Build Coastguard WorkerThe apps will actually be built by first building the SDK, and then building 137*9e94795aSAndroid Build Coastguard Workerthe apps against that SDK. This will hopefully (1) make writing apps easier 138*9e94795aSAndroid Build Coastguard Workerfor us, because we won't have to rebuild the OS as much, and we can use the 139*9e94795aSAndroid Build Coastguard Workerstandard java-app development tools, and (2) allow us to dog-food the SDK, to 140*9e94795aSAndroid Build Coastguard Workerhelp ensure its quality. Cedric has suggested (and I agree) that apps built 141*9e94795aSAndroid Build Coastguard Workerfrom the SDK should be built with ant. Stay tuned for more details as we 142*9e94795aSAndroid Build Coastguard Workerfigure out exactly how this will work.</p> 143*9e94795aSAndroid Build Coastguard Worker 144*9e94795aSAndroid Build Coastguard Worker<h3>Dependecies</h3> 145*9e94795aSAndroid Build Coastguard Worker<p>Dependencies should all be automatic. Unless there is a custom tool involved 146*9e94795aSAndroid Build Coastguard Worker(e.g. the webkit has several), the dependencies for shared and static libraries, 147*9e94795aSAndroid Build Coastguard Worker.c, .cpp, .h, .java, java libraries, etc., should all work without intervention 148*9e94795aSAndroid Build Coastguard Workerin the Android.mk file.</p> 149*9e94795aSAndroid Build Coastguard Worker 150*9e94795aSAndroid Build Coastguard Worker<h3>Wildcard source files</h3> 151*9e94795aSAndroid Build Coastguard Worker<p>Wildcarding source file will be discouraged. It may be useful in some 152*9e94795aSAndroid Build Coastguard Workerscenarios. The default <code>$(wildcard *)</code> will not work due to the 153*9e94795aSAndroid Build Coastguard Workercurrent directory being set to the root of the build tree.<p> 154*9e94795aSAndroid Build Coastguard Worker 155*9e94795aSAndroid Build Coastguard Worker<h3>Multiple targets in one directory</h3> 156*9e94795aSAndroid Build Coastguard Worker<p>It will be possible to generate more than one target from a given 157*9e94795aSAndroid Build Coastguard Workersubdirectory. For example, libutils generates a shared library for the target 158*9e94795aSAndroid Build Coastguard Workerand a static library for the host.</p> 159*9e94795aSAndroid Build Coastguard Worker 160*9e94795aSAndroid Build Coastguard Worker<h3>Makefile fragments for modules</h3> 161*9e94795aSAndroid Build Coastguard Worker<p><b>Android.mk</b> is the standard name for the makefile fragments that 162*9e94795aSAndroid Build Coastguard Workercontrol the building of a given module. Only the top directory should 163*9e94795aSAndroid Build Coastguard Workerhave a file named "Makefile".</p> 164*9e94795aSAndroid Build Coastguard Worker 165*9e94795aSAndroid Build Coastguard Worker<h3>Use shared libraries</h3> 166*9e94795aSAndroid Build Coastguard Worker<p>Currently, the simulator is not built to use shared libraries. This should 167*9e94795aSAndroid Build Coastguard Workerbe fixed, and now is a good time to do it. This implies getting shared 168*9e94795aSAndroid Build Coastguard Workerlibraries to work on Mac OS.</p> 169*9e94795aSAndroid Build Coastguard Worker 170*9e94795aSAndroid Build Coastguard Worker 171*9e94795aSAndroid Build Coastguard Worker<h2>Nice to Have</h2> 172*9e94795aSAndroid Build Coastguard Worker 173*9e94795aSAndroid Build Coastguard Worker<p>These things would be nice to have, and this is a good place to record them, 174*9e94795aSAndroid Build Coastguard Workerhowever these are not promises.</p> 175*9e94795aSAndroid Build Coastguard Worker 176*9e94795aSAndroid Build Coastguard Worker<h3>Simultaneous Builds</h3> 177*9e94795aSAndroid Build Coastguard Worker<p>The hope is to be able to do two builds for different combos in the same 178*9e94795aSAndroid Build Coastguard Workertree at the same time, but this is a stretch goal, not a requirement. 179*9e94795aSAndroid Build Coastguard WorkerDoing two builds in the same tree, not at the same time must work. (update: 180*9e94795aSAndroid Build Coastguard Workerit's looking like we'll get the two builds at the same time working)</p> 181*9e94795aSAndroid Build Coastguard Worker 182*9e94795aSAndroid Build Coastguard Worker<h3>Deleting headers (or other dependecies)</h3> 183*9e94795aSAndroid Build Coastguard Worker<p>Problems can arise if you delete a header file that is referenced in 184*9e94795aSAndroid Build Coastguard Worker".d" files. The easy way to deal with this is "make clean". There 185*9e94795aSAndroid Build Coastguard Workershould be a better way to handle it. (from fadden)</p> 186*9e94795aSAndroid Build Coastguard Worker<p>One way of solving this is introducing a dependency on the directory. The 187*9e94795aSAndroid Build Coastguard Workerproblem is that this can create extra dependecies and slow down the build. 188*9e94795aSAndroid Build Coastguard WorkerIt's a tradeoff.</p> 189*9e94795aSAndroid Build Coastguard Worker 190*9e94795aSAndroid Build Coastguard Worker<h3>Multiple builds</h3> 191*9e94795aSAndroid Build Coastguard Worker<p>General way to perform builds across the set of known platforms. This 192*9e94795aSAndroid Build Coastguard Workerwould make it easy to perform multiple platform builds when testing a 193*9e94795aSAndroid Build Coastguard Workerchange, and allow a wide-scale "make clean". Right now the buildspec.mk 194*9e94795aSAndroid Build Coastguard Workeror environment variables need to be updated before each build. (from fadden)</p> 195*9e94795aSAndroid Build Coastguard Worker 196*9e94795aSAndroid Build Coastguard Worker<h3>Aftermarket Locales and Carrier</h3> 197*9e94795aSAndroid Build Coastguard Worker<p>We will eventually need to add support for creating locales and carrier 198*9e94795aSAndroid Build Coastguard Workercustomizations to the SDK, but that will not be addressed right now.</p> 199*9e94795aSAndroid Build Coastguard Worker 200*9e94795aSAndroid Build Coastguard Worker 201*9e94795aSAndroid Build Coastguard Worker<h2><a id="usage"/>Usage</h2> 202*9e94795aSAndroid Build Coastguard Worker<p>You've read (or scrolled past) all of the motivations for this build system, 203*9e94795aSAndroid Build Coastguard Workerand you want to know how to use it. This is the place.</p> 204*9e94795aSAndroid Build Coastguard Worker 205*9e94795aSAndroid Build Coastguard Worker<h3>Your first build</h3> 206*9e94795aSAndroid Build Coastguard Worker<p>The <a href="../building.html">Building</a> document describes how do do 207*9e94795aSAndroid Build Coastguard Workerbuilds.</p> 208*9e94795aSAndroid Build Coastguard Worker 209*9e94795aSAndroid Build Coastguard Worker<h3>build/envsetup.sh functions</h3> 210*9e94795aSAndroid Build Coastguard WorkerIf you source the file build/envsetup.sh into your bash environment, 211*9e94795aSAndroid Build Coastguard Worker<code>. build/envsetup.sh</code>you'll get a few helpful shell functions: 212*9e94795aSAndroid Build Coastguard Worker 213*9e94795aSAndroid Build Coastguard Worker<ul> 214*9e94795aSAndroid Build Coastguard Worker<li><b>printconfig</b> - Prints the current configuration as set by the 215*9e94795aSAndroid Build Coastguard Workerlunch and choosecombo commands.</li> 216*9e94795aSAndroid Build Coastguard Worker<li><b>m</b> - Runs <code>make</code> from the top of the tree. This is 217*9e94795aSAndroid Build Coastguard Workeruseful because you can run make from within subdirectories. If you have the 218*9e94795aSAndroid Build Coastguard Worker<code>TOP</code> environment variable set, it uses that. If you don't, it looks 219*9e94795aSAndroid Build Coastguard Workerup the tree from the current directory, trying to find the top of the tree.</li> 220*9e94795aSAndroid Build Coastguard Worker<li><b>croot</b> - <code>cd</code> to the top of the tree.</li> 221*9e94795aSAndroid Build Coastguard Worker<li><b>sgrep</b> - grep for the regex you provide in all .c, .cpp, .h, .java, 222*9e94795aSAndroid Build Coastguard Workerand .xml files below the current directory.</li> 223*9e94795aSAndroid Build Coastguard Worker</ul> 224*9e94795aSAndroid Build Coastguard Worker 225*9e94795aSAndroid Build Coastguard Worker<h3>Build flavors/types</h3> 226*9e94795aSAndroid Build Coastguard Worker<p> 227*9e94795aSAndroid Build Coastguard WorkerWhen building for a particular product, it's often useful to have minor 228*9e94795aSAndroid Build Coastguard Workervariations on what is ultimately the final release build. These are the 229*9e94795aSAndroid Build Coastguard Workercurrently-defined "flavors" or "types" (we need to settle on a real name 230*9e94795aSAndroid Build Coastguard Workerfor these). 231*9e94795aSAndroid Build Coastguard Worker</p> 232*9e94795aSAndroid Build Coastguard Worker 233*9e94795aSAndroid Build Coastguard Worker<table border=1> 234*9e94795aSAndroid Build Coastguard Worker<tr> 235*9e94795aSAndroid Build Coastguard Worker <td> 236*9e94795aSAndroid Build Coastguard Worker <code>eng<code> 237*9e94795aSAndroid Build Coastguard Worker </td> 238*9e94795aSAndroid Build Coastguard Worker <td> 239*9e94795aSAndroid Build Coastguard Worker This is the default flavor. A plain "<code>make</code>" is the 240*9e94795aSAndroid Build Coastguard Worker same as "<code>make eng</code>". <code>droid</code> is an alias 241*9e94795aSAndroid Build Coastguard Worker for <code>eng</code>. 242*9e94795aSAndroid Build Coastguard Worker <ul> 243*9e94795aSAndroid Build Coastguard Worker <li>Installs modules tagged with: <code>eng</code>, <code>debug</code>, 244*9e94795aSAndroid Build Coastguard Worker <code>user</code>, and/or <code>development</code>. 245*9e94795aSAndroid Build Coastguard Worker <li>Installs non-APK modules that have no tags specified. 246*9e94795aSAndroid Build Coastguard Worker <li>Installs APKs according to the product definition files, in 247*9e94795aSAndroid Build Coastguard Worker addition to tagged APKs. 248*9e94795aSAndroid Build Coastguard Worker <li><code>ro.secure=0</code> 249*9e94795aSAndroid Build Coastguard Worker <li><code>ro.debuggable=1</code> 250*9e94795aSAndroid Build Coastguard Worker <li><code>ro.kernel.android.checkjni=1</code> 251*9e94795aSAndroid Build Coastguard Worker <li><code>adb</code> is enabled by default. 252*9e94795aSAndroid Build Coastguard Worker </td> 253*9e94795aSAndroid Build Coastguard Worker</tr> 254*9e94795aSAndroid Build Coastguard Worker<tr> 255*9e94795aSAndroid Build Coastguard Worker <td> 256*9e94795aSAndroid Build Coastguard Worker <code>user<code> 257*9e94795aSAndroid Build Coastguard Worker </td> 258*9e94795aSAndroid Build Coastguard Worker <td> 259*9e94795aSAndroid Build Coastguard Worker "<code>make user</code>" 260*9e94795aSAndroid Build Coastguard Worker <p> 261*9e94795aSAndroid Build Coastguard Worker This is the flavor intended to be the final release bits. 262*9e94795aSAndroid Build Coastguard Worker <ul> 263*9e94795aSAndroid Build Coastguard Worker <li>Installs modules tagged with <code>user</code>. 264*9e94795aSAndroid Build Coastguard Worker <li>Installs non-APK modules that have no tags specified. 265*9e94795aSAndroid Build Coastguard Worker <li>Installs APKs according to the product definition files; tags 266*9e94795aSAndroid Build Coastguard Worker are ignored for APK modules. 267*9e94795aSAndroid Build Coastguard Worker <li><code>ro.adb.secure=1</code> 268*9e94795aSAndroid Build Coastguard Worker <li><code>ro.secure=1</code> 269*9e94795aSAndroid Build Coastguard Worker <li><code>ro.debuggable=0</code> 270*9e94795aSAndroid Build Coastguard Worker <li><code>adb</code> is disabled by default. 271*9e94795aSAndroid Build Coastguard Worker </td> 272*9e94795aSAndroid Build Coastguard Worker</tr> 273*9e94795aSAndroid Build Coastguard Worker<tr> 274*9e94795aSAndroid Build Coastguard Worker <td> 275*9e94795aSAndroid Build Coastguard Worker <code>userdebug<code> 276*9e94795aSAndroid Build Coastguard Worker </td> 277*9e94795aSAndroid Build Coastguard Worker <td> 278*9e94795aSAndroid Build Coastguard Worker "<code>make userdebug</code>" 279*9e94795aSAndroid Build Coastguard Worker <p> 280*9e94795aSAndroid Build Coastguard Worker The same as <code>user</code>, except: 281*9e94795aSAndroid Build Coastguard Worker <ul> 282*9e94795aSAndroid Build Coastguard Worker <li>Also installs modules tagged with <code>debug</code>. 283*9e94795aSAndroid Build Coastguard Worker <li><code>ro.debuggable=1</code> 284*9e94795aSAndroid Build Coastguard Worker <li><code>adb</code> is enabled by default. 285*9e94795aSAndroid Build Coastguard Worker </td> 286*9e94795aSAndroid Build Coastguard Worker</tr> 287*9e94795aSAndroid Build Coastguard Worker</table> 288*9e94795aSAndroid Build Coastguard Worker 289*9e94795aSAndroid Build Coastguard Worker<p> 290*9e94795aSAndroid Build Coastguard WorkerIf you build one flavor and then want to build another, you should run 291*9e94795aSAndroid Build Coastguard Worker"<code>make installclean</code>" between the two makes to guarantee that 292*9e94795aSAndroid Build Coastguard Workeryou don't pick up files installed by the previous flavor. "<code>make 293*9e94795aSAndroid Build Coastguard Workerclean</code>" will also suffice, but it takes a lot longer. 294*9e94795aSAndroid Build Coastguard Worker</p> 295*9e94795aSAndroid Build Coastguard Worker 296*9e94795aSAndroid Build Coastguard Worker 297*9e94795aSAndroid Build Coastguard Worker<h3>More pseudotargets</h3> 298*9e94795aSAndroid Build Coastguard Worker<p>Sometimes you want to just build one thing. The following pseudotargets are 299*9e94795aSAndroid Build Coastguard Workerthere for your convenience:</p> 300*9e94795aSAndroid Build Coastguard Worker 301*9e94795aSAndroid Build Coastguard Worker<ul> 302*9e94795aSAndroid Build Coastguard Worker<li><b>droid</b> - <code>make droid</code> is the normal build. This target 303*9e94795aSAndroid Build Coastguard Workeris here because the default target has to have a name.</li> 304*9e94795aSAndroid Build Coastguard Worker<li><b>all</b> - <code>make all</code> builds everything <code>make 305*9e94795aSAndroid Build Coastguard Workerdroid</code> does, plus everything whose <code>LOCAL_MODULE_TAGS</code> do not 306*9e94795aSAndroid Build Coastguard Workerinclude the "droid" tag. The build server runs this to make sure 307*9e94795aSAndroid Build Coastguard Workerthat everything that is in the tree and has an Android.mk builds.</li> 308*9e94795aSAndroid Build Coastguard Worker<li><b>clean-$(LOCAL_MODULE)</b> and <b>clean-$(LOCAL_PACKAGE_NAME)</b> - 309*9e94795aSAndroid Build Coastguard WorkerLet you selectively clean one target. For example, you can type 310*9e94795aSAndroid Build Coastguard Worker<code>make clean-libutils</code> and it will delete libutils.so and all of the 311*9e94795aSAndroid Build Coastguard Workerintermediate files, or you can type <code>make clean-Home</code> and it will 312*9e94795aSAndroid Build Coastguard Workerclean just the Home app.</li> 313*9e94795aSAndroid Build Coastguard Worker<li><b>clean</b> - <code>make clean</code> deletes all of the output and 314*9e94795aSAndroid Build Coastguard Workerintermediate files for this configuration. This is the same as <code>rm -rf 315*9e94795aSAndroid Build Coastguard Workerout/<configuration>/</code></li> 316*9e94795aSAndroid Build Coastguard Worker<li><b>clobber</b> - <code>make clobber</code> deletes all of the output 317*9e94795aSAndroid Build Coastguard Workerand intermediate files for all configurations. This is the same as 318*9e94795aSAndroid Build Coastguard Worker<code>rm -rf out/</code>.</li> 319*9e94795aSAndroid Build Coastguard Worker<li><b>dataclean</b> - <code>make dataclean</code> deletes contents of the data 320*9e94795aSAndroid Build Coastguard Workerdirectory inside the current combo directory. This is especially useful on the 321*9e94795aSAndroid Build Coastguard Workersimulator and emulator, where the persistent data remains present between 322*9e94795aSAndroid Build Coastguard Workerbuilds.</li> 323*9e94795aSAndroid Build Coastguard Worker<li><b>LOCAL_MODULE</b> - Anything you specify as a <code>LOCAL_MODULE</code> 324*9e94795aSAndroid Build Coastguard Workerin an Android.mk is made into a pseudotarget. For example, <code>make 325*9e94795aSAndroid Build Coastguard Workerruntime</code> might be shorthand for <code>make 326*9e94795aSAndroid Build Coastguard Workerout/linux-x86-debug/system/bin/runtime</code> (which would work), and 327*9e94795aSAndroid Build Coastguard Worker<code>make libkjs</code> might be shorthand for <code>make 328*9e94795aSAndroid Build Coastguard Workerout/linux-x86-debug/system/lib/libkjs.so</code> (which would also work).</li> 329*9e94795aSAndroid Build Coastguard Worker<li><b>targets</b> - <code>make targets</code> will print a list of all of 330*9e94795aSAndroid Build Coastguard Workerthe LOCAL_MODULE names you can make.</li> 331*9e94795aSAndroid Build Coastguard Worker</ul> 332*9e94795aSAndroid Build Coastguard Worker 333*9e94795aSAndroid Build Coastguard Worker<h3><a name="templates"/>How to add another component to the build - Android.mk templates</h3> 334*9e94795aSAndroid Build Coastguard Worker<p>You have a new library, a new app, or a new executable. For each of the 335*9e94795aSAndroid Build Coastguard Workercommon types of modules, there is a corresponding file in the templates 336*9e94795aSAndroid Build Coastguard Workerdirectory. It will usually be enough to copy one of these, and fill in your 337*9e94795aSAndroid Build Coastguard Workerown values. Some of the more esoteric values are not included in the 338*9e94795aSAndroid Build Coastguard Workertemplates, but are instead just documented here, as is the documentation 339*9e94795aSAndroid Build Coastguard Workeron using custom tools to generate files.</p> 340*9e94795aSAndroid Build Coastguard Worker<p>Mostly, you can just look for the TODO comments in the templates and do 341*9e94795aSAndroid Build Coastguard Workerwhat it says. Please remember to delete the TODO comments when you're done 342*9e94795aSAndroid Build Coastguard Workerto keep the files clean. The templates have minimal documentation in them, 343*9e94795aSAndroid Build Coastguard Workerbecause they're going to be copied, and when that gets stale, the copies just 344*9e94795aSAndroid Build Coastguard Workerwon't get updated. So read on...</p> 345*9e94795aSAndroid Build Coastguard Worker 346*9e94795aSAndroid Build Coastguard Worker<h4>Apps</h4> 347*9e94795aSAndroid Build Coastguard Worker<p>Use the <code>templates/apps</code> file.</p> 348*9e94795aSAndroid Build Coastguard Worker<p>This template is pretty self-explanitory. See the variables below for more 349*9e94795aSAndroid Build Coastguard Workerdetails.</p> 350*9e94795aSAndroid Build Coastguard Worker 351*9e94795aSAndroid Build Coastguard Worker<h4>Java Libraries</h4> 352*9e94795aSAndroid Build Coastguard Worker<p>Use the <code>templates/java_library</code> file.</p> 353*9e94795aSAndroid Build Coastguard Worker<p>The interesting thing here is the value of LOCAL_MODULE, which becomes 354*9e94795aSAndroid Build Coastguard Workerthe name of the jar file. (Actually right now, we're not making jar files yet, 355*9e94795aSAndroid Build Coastguard Workerjust directories of .class files, but the directory is named according to 356*9e94795aSAndroid Build Coastguard Workerwhat you put in LOCAL_MODULE). This name will be what goes in the 357*9e94795aSAndroid Build Coastguard WorkerLOCAL_JAVA_LIBRARIES variable in modules that depend on your java library.</p> 358*9e94795aSAndroid Build Coastguard Worker 359*9e94795aSAndroid Build Coastguard Worker<h4>C/C++ Executables</h4> 360*9e94795aSAndroid Build Coastguard Worker<p>Use the <code>templates/executable</code> file, or the 361*9e94795aSAndroid Build Coastguard Worker<code>templates/executable_host</code> file.</p> 362*9e94795aSAndroid Build Coastguard Worker<p>This template has a couple extra options that you usually don't need. 363*9e94795aSAndroid Build Coastguard WorkerPlease delete the ones you don't need, and remove the TODO comments. It makes 364*9e94795aSAndroid Build Coastguard Workerthe rest of them easier to read, and you can always refer back to the templates 365*9e94795aSAndroid Build Coastguard Workerif you need them again later.</p> 366*9e94795aSAndroid Build Coastguard Worker<p>By default, on the target these are built into /system/bin, and on the 367*9e94795aSAndroid Build Coastguard Workerhost, they're built into <combo>/host/bin. These can be overridden by setting 368*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_MODULE_PATH</code> or <code>LOCAL_MODULE_RELATIVE_PATH</code>. See 369*9e94795aSAndroid Build Coastguard Worker<a href="#moving-targets">Putting targets elsewhere</a> 370*9e94795aSAndroid Build Coastguard Workerfor more.</p> 371*9e94795aSAndroid Build Coastguard Worker 372*9e94795aSAndroid Build Coastguard Worker<h4>Shared Libraries</h4> 373*9e94795aSAndroid Build Coastguard Worker<p>Use the <code>templates/shared_library</code> file, or the 374*9e94795aSAndroid Build Coastguard Worker<code>templates/shared_library_host</code> file.</p> 375*9e94795aSAndroid Build Coastguard Worker<p>Remember that on the target, we use shared libraries, and on the host, 376*9e94795aSAndroid Build Coastguard Workerwe use static libraries, since executable size isn't as big an issue, and it 377*9e94795aSAndroid Build Coastguard Workersimplifies distribution in the SDK.</p> 378*9e94795aSAndroid Build Coastguard Worker 379*9e94795aSAndroid Build Coastguard Worker<h4>Static Libraries</h4> 380*9e94795aSAndroid Build Coastguard Worker<p>Use the <code>templates/static_library</code> file, or the 381*9e94795aSAndroid Build Coastguard Worker<code>templates/static_library_host</code> file.</p> 382*9e94795aSAndroid Build Coastguard Worker<p>Remember that on the target, we use shared libraries, and on the host, 383*9e94795aSAndroid Build Coastguard Workerwe use static libraries, since executable size isn't as big an issue, and it 384*9e94795aSAndroid Build Coastguard Workersimplifies distribution in the SDK.</p> 385*9e94795aSAndroid Build Coastguard Worker 386*9e94795aSAndroid Build Coastguard Worker<h4><a name="custom-tools"/>Using Custom Tools</h4> 387*9e94795aSAndroid Build Coastguard Worker<p>If you have a tool that generates source files for you, it's possible 388*9e94795aSAndroid Build Coastguard Workerto have the build system get the dependencies correct for it. Here are 389*9e94795aSAndroid Build Coastguard Workera couple of examples. <code>$@</code> is the make built-in variable for 390*9e94795aSAndroid Build Coastguard Worker"the current target." The <font color=red>red</font> parts are the parts you'll 391*9e94795aSAndroid Build Coastguard Workerneed to change.</p> 392*9e94795aSAndroid Build Coastguard Worker 393*9e94795aSAndroid Build Coastguard Worker<p>You need to put this after you have declared <code>LOCAL_PATH</code> and 394*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_MODULE</code>, because the <code>$(local-generated-sources-dir)</code> 395*9e94795aSAndroid Build Coastguard Workerand <code>$(local-host-generated-sources-dir)</code> macros use these variables 396*9e94795aSAndroid Build Coastguard Workerto determine where to put the files. 397*9e94795aSAndroid Build Coastguard Worker 398*9e94795aSAndroid Build Coastguard Worker<h5>Example 1</h5> 399*9e94795aSAndroid Build Coastguard Worker<p>Here, there is one generated file, called 400*9e94795aSAndroid Build Coastguard Workerchartables.c, which doesn't depend on anything. And is built by the tool 401*9e94795aSAndroid Build Coastguard Workerbuilt to $(HOST_OUT_EXECUTABLES)/dftables. Note on the second to last line 402*9e94795aSAndroid Build Coastguard Workerthat a dependency is created on the tool.</p> 403*9e94795aSAndroid Build Coastguard Worker<pre> 404*9e94795aSAndroid Build Coastguard Workerintermediates:= $(local-generated-sources-dir) 405*9e94795aSAndroid Build Coastguard WorkerGEN := $(intermediates)/<font color=red>chartables.c</font> 406*9e94795aSAndroid Build Coastguard Worker$(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>$(HOST_OUT_EXECUTABLES)/dftables $@</font> 407*9e94795aSAndroid Build Coastguard Worker$(GEN): <font color=red>$(HOST_OUT_EXECUTABLES)/dftables</font> 408*9e94795aSAndroid Build Coastguard Worker $(transform-generated-source) 409*9e94795aSAndroid Build Coastguard WorkerLOCAL_GENERATED_SOURCES += $(GEN) 410*9e94795aSAndroid Build Coastguard Worker</pre> 411*9e94795aSAndroid Build Coastguard Worker 412*9e94795aSAndroid Build Coastguard Worker<h5>Example 2</h5> 413*9e94795aSAndroid Build Coastguard Worker<p>Here as a hypothetical example, we use use cat as if it were to transform 414*9e94795aSAndroid Build Coastguard Workera file. Pretend that it does something useful. Note how we use a 415*9e94795aSAndroid Build Coastguard Workertarget-specific variable called PRIVATE_INPUT_FILE to store the name of the 416*9e94795aSAndroid Build Coastguard Workerinput file.</p> 417*9e94795aSAndroid Build Coastguard Worker<pre> 418*9e94795aSAndroid Build Coastguard Workerintermediates:= $(local-generated-sources-dir) 419*9e94795aSAndroid Build Coastguard WorkerGEN := $(intermediates)/<font color=red>file.c</font> 420*9e94795aSAndroid Build Coastguard Worker$(GEN): PRIVATE_INPUT_FILE := $(LOCAL_PATH)/<font color=red>input.file</font> 421*9e94795aSAndroid Build Coastguard Worker$(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>cat $(PRIVATE_INPUT_FILE) > $@</font> 422*9e94795aSAndroid Build Coastguard Worker$(GEN): <font color=red>$(LOCAL_PATH)/input.file</font> 423*9e94795aSAndroid Build Coastguard Worker $(transform-generated-source) 424*9e94795aSAndroid Build Coastguard WorkerLOCAL_GENERATED_SOURCES += $(GEN) 425*9e94795aSAndroid Build Coastguard Worker</pre> 426*9e94795aSAndroid Build Coastguard Worker 427*9e94795aSAndroid Build Coastguard Worker<h5>Example 3</h5> 428*9e94795aSAndroid Build Coastguard Worker<p>If you have several files that are all similar in 429*9e94795aSAndroid Build Coastguard Workername, and use the same tool, you can combine them. (here the *.lut.h files are 430*9e94795aSAndroid Build Coastguard Workerthe generated ones, and the *.cpp files are the input files)</p> 431*9e94795aSAndroid Build Coastguard Worker<pre> 432*9e94795aSAndroid Build Coastguard Workerintermediates:= $(local-generated-sources-dir) 433*9e94795aSAndroid Build Coastguard WorkerGEN := $(addprefix $(intermediates)<font color=red>/kjs/, \ 434*9e94795aSAndroid Build Coastguard Worker array_object.lut.h \ 435*9e94795aSAndroid Build Coastguard Worker bool_object.lut.h \</font> 436*9e94795aSAndroid Build Coastguard Worker ) 437*9e94795aSAndroid Build Coastguard Worker$(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>perl libs/WebKitLib/WebKit/JavaScriptCore/kjs/create_hash_table $< -i > $@</font> 438*9e94795aSAndroid Build Coastguard Worker$(GEN): $(intermediates)/<font color=red>%.lut.h</font> : $(LOCAL_PATH)/<font color=red>%.cpp</font> 439*9e94795aSAndroid Build Coastguard Worker $(transform-generated-source) 440*9e94795aSAndroid Build Coastguard WorkerLOCAL_GENERATED_SOURCES += $(GEN) 441*9e94795aSAndroid Build Coastguard Worker</pre> 442*9e94795aSAndroid Build Coastguard Worker 443*9e94795aSAndroid Build Coastguard Worker<h3><a name="unbundled-build"/>Unbundled build</h3> 444*9e94795aSAndroid Build Coastguard Worker<p>Unbundled build has several meanings by the context. 445*9e94795aSAndroid Build Coastguard WorkerLet me explain the meaning by the flags related to "unbundled build"</p> 446*9e94795aSAndroid Build Coastguard Worker<h4>TARGET_BUILD_UNBUNDLED</h4> 447*9e94795aSAndroid Build Coastguard Worker<p> 448*9e94795aSAndroid Build Coastguard Worker The source tree might not have the full platform sources. It turns on 449*9e94795aSAndroid Build Coastguard Worker <code>TARGET_BUILD_USE_PREBUILT_SDKS</code>, unless 450*9e94795aSAndroid Build Coastguard Worker <code>UNBUNDLED_BUILD_SDKS_FROM_SOURCE</code> is set. It is always set if 451*9e94795aSAndroid Build Coastguard Worker <code>TARGET_BUILD_APPS</code> or <code>TARGET_BUILD_UNBUNDLED_IMAGE</code> is set. 452*9e94795aSAndroid Build Coastguard Worker</p> 453*9e94795aSAndroid Build Coastguard Worker<h4>TARGET_BUILD_USE_PREBUILT_SDKS</h4> 454*9e94795aSAndroid Build Coastguard Worker<p>It is an internal flag. If it is set, prebuilt SDKs are used, even if a module's 455*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_SDK_VERSION</code> is <code>current</code> (including <code>system_current</code>, 456*9e94795aSAndroid Build Coastguard Worker<code>core_current</code>, and so on). If it is unset, build current SDKs, 457*9e94795aSAndroid Build Coastguard Workerand use them as usual.</p> 458*9e94795aSAndroid Build Coastguard Worker<h4>DISABLE_PREOPT</h4> 459*9e94795aSAndroid Build Coastguard Worker<p>It is an internal flag as well. If it is set, dexpreopt is disabled. 460*9e94795aSAndroid Build Coastguard WorkerIt is always set if <code>TARGET_BUILD_APPS</code> or <code>TARGET_BUILD_UNBUNDLED_IMAGE</code> is set, 461*9e94795aSAndroid Build Coastguard Workerbecause dexpreopt tightly depends on the platform.</p> 462*9e94795aSAndroid Build Coastguard Worker<h4>TARGET_BUILD_APPS</h4> 463*9e94795aSAndroid Build Coastguard Worker<p>Build the apps that can be distributed outside the platform, so it turns on 464*9e94795aSAndroid Build Coastguard Worker<code>TARGET_BUILD_UNBUNDLED</code> and <code>DISABLE_PREOPT</code>. 465*9e94795aSAndroid Build Coastguard WorkerAlso, it turns on <code>TARGET_BUILD_USE_PREBUILT_SDKS</code>, unless 466*9e94795aSAndroid Build Coastguard Worker<code>UNBUNDLED_BUILD_SDKS_FROM_SOURCE</code> is set.</p> 467*9e94795aSAndroid Build Coastguard Worker<h4>TARGET_BUILD_UNBUNDLED_IMAGE</h4> 468*9e94795aSAndroid Build Coastguard Worker<p>It is similar to <code>TARGET_BUILD_APPS</code>, but its target is an unbundled partition 469*9e94795aSAndroid Build Coastguard Worker(such as the vendor partition). Accordingly, it sets <code>TARGET_BUILD_UNBUNDLED</code> and <code>DISABLE_PREOPT</code>. 470*9e94795aSAndroid Build Coastguard WorkerWe can call the partition unbundled, because the partition can be distributed outside the platform. 471*9e94795aSAndroid Build Coastguard WorkerAnd also, it turns on <code>TARGET_BUILD_USE_PREBUILT_SDKS</code>, unless 472*9e94795aSAndroid Build Coastguard Worker<code>UNBUNDLED_BUILD_SDKS_FROM_SOURCE</code> is set.</p> 473*9e94795aSAndroid Build Coastguard Worker 474*9e94795aSAndroid Build Coastguard Worker<h3><a name="platform-specific"/>Platform specific conditionals</h3> 475*9e94795aSAndroid Build Coastguard Worker<p>Sometimes you need to set flags specifically for different platforms. Here 476*9e94795aSAndroid Build Coastguard Workeris a list of which values the different build-system defined variables will be 477*9e94795aSAndroid Build Coastguard Workerset to and some examples.</p> 478*9e94795aSAndroid Build Coastguard Worker<table cellspacing=25> 479*9e94795aSAndroid Build Coastguard Worker<tr> 480*9e94795aSAndroid Build Coastguard Worker <td valign=top align=center> 481*9e94795aSAndroid Build Coastguard Worker <b>HOST_OS</b><br/> 482*9e94795aSAndroid Build Coastguard Worker linux<br/> 483*9e94795aSAndroid Build Coastguard Worker darwin 484*9e94795aSAndroid Build Coastguard Worker </td> 485*9e94795aSAndroid Build Coastguard Worker <td valign=top align=center> 486*9e94795aSAndroid Build Coastguard Worker <b>HOST_ARCH</b><br/> 487*9e94795aSAndroid Build Coastguard Worker x86<br/> 488*9e94795aSAndroid Build Coastguard Worker x86_64 489*9e94795aSAndroid Build Coastguard Worker </td> 490*9e94795aSAndroid Build Coastguard Worker <td valign=top align=center> 491*9e94795aSAndroid Build Coastguard Worker <b>HOST_BUILD_TYPE</b><br/> 492*9e94795aSAndroid Build Coastguard Worker release<br/> 493*9e94795aSAndroid Build Coastguard Worker debug 494*9e94795aSAndroid Build Coastguard Worker </td> 495*9e94795aSAndroid Build Coastguard Worker</tr> 496*9e94795aSAndroid Build Coastguard Worker<tr> 497*9e94795aSAndroid Build Coastguard Worker <td valign=top align=center> 498*9e94795aSAndroid Build Coastguard Worker <b>TARGET_ARCH</b><br/> 499*9e94795aSAndroid Build Coastguard Worker arm<br/> 500*9e94795aSAndroid Build Coastguard Worker arm64<br/> 501*9e94795aSAndroid Build Coastguard Worker x86<br/> 502*9e94795aSAndroid Build Coastguard Worker x86_64 503*9e94795aSAndroid Build Coastguard Worker </td> 504*9e94795aSAndroid Build Coastguard Worker <td valign=top align=center> 505*9e94795aSAndroid Build Coastguard Worker <b>TARGET_BUILD_TYPE</b><br/> 506*9e94795aSAndroid Build Coastguard Worker release<br/> 507*9e94795aSAndroid Build Coastguard Worker debug 508*9e94795aSAndroid Build Coastguard Worker </td> 509*9e94795aSAndroid Build Coastguard Worker</tr> 510*9e94795aSAndroid Build Coastguard Worker</table> 511*9e94795aSAndroid Build Coastguard Worker 512*9e94795aSAndroid Build Coastguard Worker<p>There are also special variables to use instead of conditionals. Many of the 513*9e94795aSAndroid Build Coastguard Workernormal variables (LOCAL_SRC_FILES, LOCAL_CFLAGS, etc) can be conditionally added 514*9e94795aSAndroid Build Coastguard Workerto with _{arch} _{32|64}, and for the host, _{os}.</p> 515*9e94795aSAndroid Build Coastguard Worker 516*9e94795aSAndroid Build Coastguard Worker<h4>Some Examples</h4> 517*9e94795aSAndroid Build Coastguard Worker<pre>ifeq ($(TARGET_BUILD_TYPE),release) 518*9e94795aSAndroid Build Coastguard WorkerLOCAL_CFLAGS += -DNDEBUG=1 519*9e94795aSAndroid Build Coastguard Workerendif 520*9e94795aSAndroid Build Coastguard Worker 521*9e94795aSAndroid Build Coastguard WorkerLOCAL_CFLAGS_arm += -DTARGET_IS_ARM 522*9e94795aSAndroid Build Coastguard Worker 523*9e94795aSAndroid Build Coastguard WorkerLOCAL_CFLAGS_64 += -DBIG_POINTER 524*9e94795aSAndroid Build Coastguard Worker 525*9e94795aSAndroid Build Coastguard Worker# from libutils 526*9e94795aSAndroid Build Coastguard Worker# Use the futex based mutex and condition variable 527*9e94795aSAndroid Build Coastguard Worker# implementation from android-arm because it's shared mem safe 528*9e94795aSAndroid Build Coastguard WorkerLOCAL_SRC_FILES_linux += futex_synchro.c 529*9e94795aSAndroid Build Coastguard WorkerLOCAL_LDLIBS_linux += -lrt -ldl 530*9e94795aSAndroid Build Coastguard Worker 531*9e94795aSAndroid Build Coastguard Worker</pre> 532*9e94795aSAndroid Build Coastguard Worker 533*9e94795aSAndroid Build Coastguard Worker 534*9e94795aSAndroid Build Coastguard Worker<h3><a name="moving-modules"/>Putting modules elsewhere</h3> 535*9e94795aSAndroid Build Coastguard Worker<p>If you have modules that normally go somewhere, and you need to have them 536*9e94795aSAndroid Build Coastguard Workerbuild somewhere else, read this.</p> 537*9e94795aSAndroid Build Coastguard Worker<p>If you have modules that need to go in a subdirectory of their normal 538*9e94795aSAndroid Build Coastguard Workerlocation, for example HAL modules that need to go in /system/lib/hw or 539*9e94795aSAndroid Build Coastguard Worker/vendor/lib/hw, set LOCAL_MODULE_RELATIVE_PATH in your Android.mk, for 540*9e94795aSAndroid Build Coastguard Workerexample:</p> 541*9e94795aSAndroid Build Coastguard Worker<pre> 542*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_RELATIVE_PATH := hw 543*9e94795aSAndroid Build Coastguard Worker</pre> 544*9e94795aSAndroid Build Coastguard Worker<p>If you have modules that need to go in an entirely different location, for 545*9e94795aSAndroid Build Coastguard Workerexample the root filesystem instead of in /system, add these lines to your 546*9e94795aSAndroid Build Coastguard WorkerAndroid.mk:</p> 547*9e94795aSAndroid Build Coastguard Worker<pre> 548*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_PATH := $(TARGET_ROOT_OUT) 549*9e94795aSAndroid Build Coastguard WorkerLOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED) 550*9e94795aSAndroid Build Coastguard Worker</pre> 551*9e94795aSAndroid Build Coastguard Worker<p>For executables and libraries, you need to specify a 552*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_UNSTRIPPED_PATH</code> location if you specified a 553*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_MODULE_PATH</code>, because on target builds, we keep 554*9e94795aSAndroid Build Coastguard Workerthe unstripped executables so GDB can find the symbols. 555*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_UNSTRIPPED_PATH</code> is not necessary if you only specified 556*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_MODULE_RELATIVE_PATH</code>.</p> 557*9e94795aSAndroid Build Coastguard Worker<p>Look in <code>core/envsetup.mk</code> for all of the variables defining 558*9e94795aSAndroid Build Coastguard Workerplaces to build things.</p> 559*9e94795aSAndroid Build Coastguard Worker 560*9e94795aSAndroid Build Coastguard Worker 561*9e94795aSAndroid Build Coastguard Worker<h3>Android.mk variables</h3> 562*9e94795aSAndroid Build Coastguard Worker<p>These are the variables that you'll commonly see in Android.mk files, listed 563*9e94795aSAndroid Build Coastguard Workeralphabetically.</p> 564*9e94795aSAndroid Build Coastguard Worker<p>But first, a note on variable naming: 565*9e94795aSAndroid Build Coastguard Worker<ul> 566*9e94795aSAndroid Build Coastguard Worker <li><b>LOCAL_</b> - These variables are set per-module. They are cleared 567*9e94795aSAndroid Build Coastguard Worker by the <code>include $(CLEAR_VARS)</code> line, so you can rely on them 568*9e94795aSAndroid Build Coastguard Worker being empty after including that file. Most of the variables you'll use 569*9e94795aSAndroid Build Coastguard Worker in most modules are LOCAL_ variables.</li> 570*9e94795aSAndroid Build Coastguard Worker <li><b>PRIVATE_</b> - These variables are make-target-specific variables. That 571*9e94795aSAndroid Build Coastguard Worker means they're only usable within the commands for that module. It also 572*9e94795aSAndroid Build Coastguard Worker means that they're unlikely to change behind your back from modules that 573*9e94795aSAndroid Build Coastguard Worker are included after yours. This 574*9e94795aSAndroid Build Coastguard Worker <a href="http://www.gnu.org/software/make/manual/make.html#Target_002dspecific">link to the make documentation</a> 575*9e94795aSAndroid Build Coastguard Worker describes more about target-specific variables. Please note that there 576*9e94795aSAndroid Build Coastguard Worker are a couple of these laying around the tree that aren't prefixed with 577*9e94795aSAndroid Build Coastguard Worker PRIVATE_. It is safe, and they will be fixed as they are discovered. 578*9e94795aSAndroid Build Coastguard Worker Sorry for the confusion.</li> 579*9e94795aSAndroid Build Coastguard Worker <li><b>INTERNAL_</b> - These variables are critical to functioning of 580*9e94795aSAndroid Build Coastguard Worker the build system, so you shouldn't create variables named like this, and 581*9e94795aSAndroid Build Coastguard Worker you probably shouldn't be messing with these variables in your makefiles. 582*9e94795aSAndroid Build Coastguard Worker </li> 583*9e94795aSAndroid Build Coastguard Worker <li><b>HOST_</b> and <b>TARGET_</b> - These contain the directories 584*9e94795aSAndroid Build Coastguard Worker and definitions that are specific to either the host or the target builds. 585*9e94795aSAndroid Build Coastguard Worker Do not set variables that start with HOST_ or TARGET_ in your makefiles. 586*9e94795aSAndroid Build Coastguard Worker </li> 587*9e94795aSAndroid Build Coastguard Worker <li><b>HOST_CROSS_</b> - These contain the directories and definitions that 588*9e94795aSAndroid Build Coastguard Worker are specific to cross-building host binaries. The common case is building 589*9e94795aSAndroid Build Coastguard Worker windows host tools on linux. Do not set variables that start with 590*9e94795aSAndroid Build Coastguard Worker HOST_CROSS_ in your makefiles. 591*9e94795aSAndroid Build Coastguard Worker </li> 592*9e94795aSAndroid Build Coastguard Worker <li><b>BUILD_</b> and <b>CLEAR_VARS</b> - These contain the names of 593*9e94795aSAndroid Build Coastguard Worker well-defined template makefiles to include. Some examples are CLEAR_VARS 594*9e94795aSAndroid Build Coastguard Worker and BUILD_HOST_PACKAGE.</li> 595*9e94795aSAndroid Build Coastguard Worker <li>Any other name is fair-game for you to use in your Android.mk. However, 596*9e94795aSAndroid Build Coastguard Worker remember that this is a non-recursive build system, so it is possible that 597*9e94795aSAndroid Build Coastguard Worker your variable will be changed by another Android.mk included later, and be 598*9e94795aSAndroid Build Coastguard Worker different when the commands for your rule / module are executed.</li> 599*9e94795aSAndroid Build Coastguard Worker</ul> 600*9e94795aSAndroid Build Coastguard Worker</p> 601*9e94795aSAndroid Build Coastguard Worker 602*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_ANNOTATION_PROCESSORS</h4> 603*9e94795aSAndroid Build Coastguard Worker<p>Set this to a list of modules built with <code>BUILD_HOST_JAVA_LIBRARY</code> 604*9e94795aSAndroid Build Coastguard Workerto have their jars passed to javac with -processorpath for use as annotation 605*9e94795aSAndroid Build Coastguard Workerprocessors.</p> 606*9e94795aSAndroid Build Coastguard Worker 607*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_ANNOTATION_PROCESSOR_CLASSES</h4> 608*9e94795aSAndroid Build Coastguard Worker<p>Set this to a list of classes to be passed to javac as -processor arguments. 609*9e94795aSAndroid Build Coastguard WorkerThis list is would be unnecessary, as javac will autodetect annotation processor 610*9e94795aSAndroid Build Coastguard Workerclasses, except that the Grok tool that is used on the Android source code 611*9e94795aSAndroid Build Coastguard Workerdoes not autodetect them and requires listing them manually.</p> 612*9e94795aSAndroid Build Coastguard Worker 613*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_ASSET_FILES</h4> 614*9e94795aSAndroid Build Coastguard Worker<p>In Android.mk files that <code>include $(BUILD_PACKAGE)</code> set this 615*9e94795aSAndroid Build Coastguard Workerto the set of files you want built into your app. Usually:</p> 616*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_ASSET_FILES += $(call find-subdir-assets)</code></p> 617*9e94795aSAndroid Build Coastguard Worker<p>This will probably change when we switch to ant for the apps' build 618*9e94795aSAndroid Build Coastguard Workersystem.</p> 619*9e94795aSAndroid Build Coastguard Worker 620*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_CC</h4> 621*9e94795aSAndroid Build Coastguard Worker<p>If you want to use a different C compiler for this module, set LOCAL_CC 622*9e94795aSAndroid Build Coastguard Workerto the path to the compiler. If LOCAL_CC is blank, the appropriate default 623*9e94795aSAndroid Build Coastguard Workercompiler is used.</p> 624*9e94795aSAndroid Build Coastguard Worker 625*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_CXX</h4> 626*9e94795aSAndroid Build Coastguard Worker<p>If you want to use a different C++ compiler for this module, set LOCAL_CXX 627*9e94795aSAndroid Build Coastguard Workerto the path to the compiler. If LOCAL_CXX is blank, the appropriate default 628*9e94795aSAndroid Build Coastguard Workercompiler is used.</p> 629*9e94795aSAndroid Build Coastguard Worker 630*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_CFLAGS</h4> 631*9e94795aSAndroid Build Coastguard Worker<p>If you have additional flags to pass into the C or C++ compiler, add 632*9e94795aSAndroid Build Coastguard Workerthem here. For example:</p> 633*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1</code></p> 634*9e94795aSAndroid Build Coastguard Worker 635*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_CPPFLAGS</h4> 636*9e94795aSAndroid Build Coastguard Worker<p>If you have additional flags to pass into <i>only</i> the C++ compiler, add 637*9e94795aSAndroid Build Coastguard Workerthem here. For example:</p> 638*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_CPPFLAGS += -ffriend-injection</code></p> 639*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_CPPFLAGS</code> is guaranteed to be after <code>LOCAL_CFLAGS</code> 640*9e94795aSAndroid Build Coastguard Workeron the compile line, so you can use it to override flags listed in 641*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_CFLAGS</code>. 642*9e94795aSAndroid Build Coastguard Worker 643*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_CPP_EXTENSION</h4> 644*9e94795aSAndroid Build Coastguard Worker<p>If your C++ files end in something other than "<code>.cpp</code>", 645*9e94795aSAndroid Build Coastguard Workeryou can specify the custom extension here. For example:</p> 646*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_CPP_EXTENSION := .cc</code></p> 647*9e94795aSAndroid Build Coastguard WorkerNote that all C++ files for a given module must have the same 648*9e94795aSAndroid Build Coastguard Workerextension; it is not currently possible to mix different extensions. 649*9e94795aSAndroid Build Coastguard Worker 650*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_NO_DEFAULT_COMPILER_FLAGS</h4> 651*9e94795aSAndroid Build Coastguard Worker<p>Normally, the compile line for C and C++ files includes global include 652*9e94795aSAndroid Build Coastguard Workerpaths and global cflags. If <code>LOCAL_NO_DEFAULT_COMPILER_FLAGS</code> 653*9e94795aSAndroid Build Coastguard Workeris non-empty, none of the default includes or flags will be used when compiling 654*9e94795aSAndroid Build Coastguard WorkerC and C++ files in this module. 655*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_C_INCLUDES</code>, <code>LOCAL_CFLAGS</code>, and 656*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_CPPFLAGS</code> will still be used in this case, as will 657*9e94795aSAndroid Build Coastguard Workerany <code>DEBUG_CFLAGS</code> that are defined for the module. 658*9e94795aSAndroid Build Coastguard Worker 659*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_COPY_HEADERS</h4> 660*9e94795aSAndroid Build Coastguard Worker<p class=warning>This will be going away.</p> 661*9e94795aSAndroid Build Coastguard Worker<p>The set of files to copy to the install include tree. You must also 662*9e94795aSAndroid Build Coastguard Workersupply <code>LOCAL_COPY_HEADERS_TO</code>.</p> 663*9e94795aSAndroid Build Coastguard Worker<p>This is going away because copying headers messes up the error messages, and 664*9e94795aSAndroid Build Coastguard Workermay lead to people editing those headers instead of the correct ones. It also 665*9e94795aSAndroid Build Coastguard Workermakes it easier to do bad layering in the system, which we want to avoid. We 666*9e94795aSAndroid Build Coastguard Workeralso aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any 667*9e94795aSAndroid Build Coastguard Workerheaders.</p> 668*9e94795aSAndroid Build Coastguard Worker 669*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_COPY_HEADERS_TO</h4> 670*9e94795aSAndroid Build Coastguard Worker<p class=warning>This will be going away.</p> 671*9e94795aSAndroid Build Coastguard Worker<p>The directory within "include" to copy the headers listed in 672*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_COPY_HEADERS</code> to.</p> 673*9e94795aSAndroid Build Coastguard Worker<p>This is going away because copying headers messes up the error messages, and 674*9e94795aSAndroid Build Coastguard Workermay lead to people editing those headers instead of the correct ones. It also 675*9e94795aSAndroid Build Coastguard Workermakes it easier to do bad layering in the system, which we want to avoid. We 676*9e94795aSAndroid Build Coastguard Workeralso aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any 677*9e94795aSAndroid Build Coastguard Workerheaders.</p> 678*9e94795aSAndroid Build Coastguard Worker 679*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_C_INCLUDES</h4> 680*9e94795aSAndroid Build Coastguard Worker<p>Additional directories to instruct the C/C++ compilers to look for header 681*9e94795aSAndroid Build Coastguard Workerfiles in. These paths are rooted at the top of the tree. Use 682*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_PATH</code> if you have subdirectories of your own that you 683*9e94795aSAndroid Build Coastguard Workerwant in the include paths. For example:</p> 684*9e94795aSAndroid Build Coastguard Worker<p><code> 685*9e94795aSAndroid Build Coastguard WorkerLOCAL_C_INCLUDES += extlibs/zlib-1.2.3<br/> 686*9e94795aSAndroid Build Coastguard WorkerLOCAL_C_INCLUDES += $(LOCAL_PATH)/src 687*9e94795aSAndroid Build Coastguard Worker</code></p> 688*9e94795aSAndroid Build Coastguard Worker<p>You should not add subdirectories of include to 689*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_C_INCLUDES</code>, instead you should reference those files 690*9e94795aSAndroid Build Coastguard Workerin the <code>#include</code> statement with their subdirectories. For 691*9e94795aSAndroid Build Coastguard Workerexample:</p> 692*9e94795aSAndroid Build Coastguard Worker<p><code>#include <utils/KeyedVector.h></code><br/> 693*9e94795aSAndroid Build Coastguard Workernot <code><s>#include <KeyedVector.h></s></code></p> 694*9e94795aSAndroid Build Coastguard Worker<p>There are some components that are doing this wrong, and should be cleaned 695*9e94795aSAndroid Build Coastguard Workerup.</p> 696*9e94795aSAndroid Build Coastguard Worker 697*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_MODULE_TAGS</h4> 698*9e94795aSAndroid Build Coastguard Worker<p>Set <code>LOCAL_MODULE_TAGS</code> to any number of whitespace-separated 699*9e94795aSAndroid Build Coastguard Workertags. If the tag list is empty or contains <code>droid</code>, the module 700*9e94795aSAndroid Build Coastguard Workerwill get installed as part of a <code>make droid</code>. Otherwise, it will 701*9e94795aSAndroid Build Coastguard Workeronly get installed by running <code>make <your-module></code> 702*9e94795aSAndroid Build Coastguard Workeror with the <code>make all</code> pseudotarget.</p> 703*9e94795aSAndroid Build Coastguard Worker 704*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_REQUIRED_MODULES</h4> 705*9e94795aSAndroid Build Coastguard Worker<p>Set <code>LOCAL_REQUIRED_MODULES</code> to any number of whitespace-separated 706*9e94795aSAndroid Build Coastguard Workermodule names, like "libblah" or "Email". If this module is installed, all 707*9e94795aSAndroid Build Coastguard Workerof the modules that it requires will be installed as well. This can be 708*9e94795aSAndroid Build Coastguard Workerused to, e.g., ensure that necessary shared libraries or providers are 709*9e94795aSAndroid Build Coastguard Workerinstalled when a given app is installed. 710*9e94795aSAndroid Build Coastguard Worker 711*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_FORCE_STATIC_EXECUTABLE</h4> 712*9e94795aSAndroid Build Coastguard Worker<p>If your executable should be linked statically, set 713*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_FORCE_STATIC_EXECUTABLE:=true</code>. There is a very short 714*9e94795aSAndroid Build Coastguard Workerlist of libraries that we have in static form (currently only libc).</p> 715*9e94795aSAndroid Build Coastguard Worker 716*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_GENERATED_SOURCES</h4> 717*9e94795aSAndroid Build Coastguard Worker<p>Files that you add to <code>LOCAL_GENERATED_SOURCES</code> will be 718*9e94795aSAndroid Build Coastguard Workerautomatically generated and then linked in when your module is built. 719*9e94795aSAndroid Build Coastguard WorkerSee the <a href="#custom-tools">Custom Tools</a> template makefile for an 720*9e94795aSAndroid Build Coastguard Workerexample.</p> 721*9e94795aSAndroid Build Coastguard Worker 722*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_JAVACFLAGS</h4> 723*9e94795aSAndroid Build Coastguard Worker<p>If you have additional flags to pass into the javac compiler, add 724*9e94795aSAndroid Build Coastguard Workerthem here. For example:</p> 725*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_JAVACFLAGS += -Xlint:deprecation</code></p> 726*9e94795aSAndroid Build Coastguard Worker 727*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_ERROR_PRONE_FLAGS</h4> 728*9e94795aSAndroid Build Coastguard Worker<p>If you have additional flags to pass into the error prone compiler, add 729*9e94795aSAndroid Build Coastguard Workerthem here. For example:</p> 730*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_ERROR_PRONE_FLAGS += -Xep:ClassCanBeStatic:ERROR</code></p> 731*9e94795aSAndroid Build Coastguard Worker 732*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_JAVA_LIBRARIES</h4> 733*9e94795aSAndroid Build Coastguard Worker<p>When linking Java apps and libraries, <code>LOCAL_JAVA_LIBRARIES</code> 734*9e94795aSAndroid Build Coastguard Workerspecifies which sets of java classes to include. Currently there are 735*9e94795aSAndroid Build Coastguard Workertwo of these: <code>core</code> and <code>framework</code>. 736*9e94795aSAndroid Build Coastguard WorkerIn most cases, it will look like this:</p> 737*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_JAVA_LIBRARIES := core framework</code></p> 738*9e94795aSAndroid Build Coastguard Worker<p>Note that setting <code>LOCAL_JAVA_LIBRARIES</code> is not necessary 739*9e94795aSAndroid Build Coastguard Worker(and is not allowed) when building an APK with 740*9e94795aSAndroid Build Coastguard Worker"<code>include $(BUILD_PACKAGE)</code>". The appropriate libraries 741*9e94795aSAndroid Build Coastguard Workerwill be included automatically.</p> 742*9e94795aSAndroid Build Coastguard Worker 743*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_LDFLAGS</h4> 744*9e94795aSAndroid Build Coastguard Worker<p>You can pass additional flags to the linker by setting 745*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_LDFLAGS</code>. Keep in mind that the order of parameters is 746*9e94795aSAndroid Build Coastguard Workervery important to ld, so test whatever you do on all platforms.</p> 747*9e94795aSAndroid Build Coastguard Worker 748*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_LDLIBS</h4> 749*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_LDLIBS</code> allows you to specify additional libraries 750*9e94795aSAndroid Build Coastguard Workerthat are not part of the build for your executable or library. Specify 751*9e94795aSAndroid Build Coastguard Workerthe libraries you want in -lxxx format; they're passed directly to the 752*9e94795aSAndroid Build Coastguard Workerlink line. However, keep in mind that there will be no dependency generated 753*9e94795aSAndroid Build Coastguard Workerfor these libraries. It's most useful in simulator builds where you want 754*9e94795aSAndroid Build Coastguard Workerto use a library preinstalled on the host. The linker (ld) is a particularly 755*9e94795aSAndroid Build Coastguard Workerfussy beast, so it's sometimes necessary to pass other flags here if you're 756*9e94795aSAndroid Build Coastguard Workerdoing something sneaky. Some examples:</p> 757*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_LDLIBS += -lcurses -lpthread<br/> 758*9e94795aSAndroid Build Coastguard WorkerLOCAL_LDLIBS += -Wl,-z,origin 759*9e94795aSAndroid Build Coastguard Worker</code></p> 760*9e94795aSAndroid Build Coastguard Worker 761*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_NO_MANIFEST</h4> 762*9e94795aSAndroid Build Coastguard Worker<p>If your package doesn't have a manifest (AndroidManifest.xml), then 763*9e94795aSAndroid Build Coastguard Workerset <code>LOCAL_NO_MANIFEST:=true</code>. The common resources package 764*9e94795aSAndroid Build Coastguard Workerdoes this.</p> 765*9e94795aSAndroid Build Coastguard Worker 766*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_PACKAGE_NAME</h4> 767*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_PACKAGE_NAME</code> is the name of an app. For example, 768*9e94795aSAndroid Build Coastguard WorkerDialer, Contacts, etc. This will probably change or go away when we switch 769*9e94795aSAndroid Build Coastguard Workerto an ant-based build system for the apps.</p> 770*9e94795aSAndroid Build Coastguard Worker 771*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_PATCH_MODULE (experimental option)</h4> 772*9e94795aSAndroid Build Coastguard Worker<p>As of January 2018, you almost certainly don't need this option, so please 773*9e94795aSAndroid Build Coastguard Workerask and only use it if you understand what you're doing. This feature is 774*9e94795aSAndroid Build Coastguard Workerexperimental and may go away in future.</p> 775*9e94795aSAndroid Build Coastguard Worker<p> 776*9e94795aSAndroid Build Coastguard WorkerWhen compiling language level 9+ .java code in packages that are part of a 777*9e94795aSAndroid Build Coastguard Workera system module, <code>LOCAL_PATCH_MODULE</code> names the module that your 778*9e94795aSAndroid Build Coastguard Workersources and dependencies should be patched into. The Android runtime currently 779*9e94795aSAndroid Build Coastguard Worker(Jan 2018) doesn't implement the JEP 261 module system so this option is only 780*9e94795aSAndroid Build Coastguard Workersupported at compile time. It should only be needed to compile tests in packages 781*9e94795aSAndroid Build Coastguard Workerthat exist in libcore and which are inconvenient to move elsewhere. 782*9e94795aSAndroid Build Coastguard Worker</p> 783*9e94795aSAndroid Build Coastguard Worker 784*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_PATH</h4> 785*9e94795aSAndroid Build Coastguard Worker<p>The directory your Android.mk file is in. You can set it by putting the 786*9e94795aSAndroid Build Coastguard Workerfollowing as the first line in your Android.mk:</p> 787*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_PATH := $(my-dir)</code></p> 788*9e94795aSAndroid Build Coastguard Worker<p>The <code>my-dir</code> macro uses the 789*9e94795aSAndroid Build Coastguard Worker<code><a href="http://www.gnu.org/software/make/manual/make.html#MAKEFILE_005fLIST-Variable">MAKEFILE_LIST</a></code> 790*9e94795aSAndroid Build Coastguard Workervariable, so you must call it before you include any other makefiles. Also, 791*9e94795aSAndroid Build Coastguard Workerconsider that any subdirectories you inlcude might reset LOCAL_PATH, so do your 792*9e94795aSAndroid Build Coastguard Workerown stuff before you include them. This also means that if you try to write 793*9e94795aSAndroid Build Coastguard Workerseveral <code>include</code> lines that reference <code>LOCAL_PATH</code>, 794*9e94795aSAndroid Build Coastguard Workerit won't work, because those included makefiles might reset LOCAL_PATH. 795*9e94795aSAndroid Build Coastguard Worker 796*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_POST_PROCESS_COMMAND</h4> 797*9e94795aSAndroid Build Coastguard Worker<p>For host executables, you can specify a command to run on the module 798*9e94795aSAndroid Build Coastguard Workerafter it's been linked. You might have to go through some contortions 799*9e94795aSAndroid Build Coastguard Workerto get variables right because of early or late variable evaluation:</p> 800*9e94795aSAndroid Build Coastguard Worker<p><code>module := $(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)<br/> 801*9e94795aSAndroid Build Coastguard WorkerLOCAL_POST_PROCESS_COMMAND := /Developer/Tools/Rez -d __DARWIN__ -t APPL\<br/> 802*9e94795aSAndroid Build Coastguard Worker -d __WXMAC__ -o $(module) Carbon.r 803*9e94795aSAndroid Build Coastguard Worker</code></p> 804*9e94795aSAndroid Build Coastguard Worker 805*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_PREBUILT_EXECUTABLES</h4> 806*9e94795aSAndroid Build Coastguard Worker<p>When including $(BUILD_MULTI_PREBUILT) or $(BUILD_HOST_PREBUILT), set these 807*9e94795aSAndroid Build Coastguard Workerto executables that you want copied. They're located automatically into the 808*9e94795aSAndroid Build Coastguard Workerright bin directory.</p> 809*9e94795aSAndroid Build Coastguard Worker 810*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_PREBUILT_LIBS</h4> 811*9e94795aSAndroid Build Coastguard Worker<p>When including $(BUILD_MULTI_PREBUILT) or $(BUILD_HOST_PREBUILT), set these 812*9e94795aSAndroid Build Coastguard Workerto libraries that you want copied. They're located automatically into the 813*9e94795aSAndroid Build Coastguard Workerright lib directory.</p> 814*9e94795aSAndroid Build Coastguard Worker 815*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_SHARED_LIBRARIES</h4> 816*9e94795aSAndroid Build Coastguard Worker<p>These are the libraries you directly link against. You don't need to 817*9e94795aSAndroid Build Coastguard Workerpass transitively included libraries. Specify the name without the suffix:</p> 818*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_SHARED_LIBRARIES := \<br/> 819*9e94795aSAndroid Build Coastguard Worker libutils \<br/> 820*9e94795aSAndroid Build Coastguard Worker libui \<br/> 821*9e94795aSAndroid Build Coastguard Worker libaudio \<br/> 822*9e94795aSAndroid Build Coastguard Worker libexpat \<br/> 823*9e94795aSAndroid Build Coastguard Worker libsgl 824*9e94795aSAndroid Build Coastguard Worker</code></p> 825*9e94795aSAndroid Build Coastguard Worker 826*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_SRC_FILES</h4> 827*9e94795aSAndroid Build Coastguard Worker<p>The build system looks at <code>LOCAL_SRC_FILES</code> to know what source 828*9e94795aSAndroid Build Coastguard Workerfiles to compile -- .cpp .c .y .l .java. For lex and yacc files, it knows 829*9e94795aSAndroid Build Coastguard Workerhow to correctly do the intermediate .h and .c/.cpp files automatically. If 830*9e94795aSAndroid Build Coastguard Workerthe files are in a subdirectory of the one containing the Android.mk, prefix 831*9e94795aSAndroid Build Coastguard Workerthem with the directory name:</p> 832*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_SRC_FILES := \<br/> 833*9e94795aSAndroid Build Coastguard Worker file1.cpp \<br/> 834*9e94795aSAndroid Build Coastguard Worker dir/file2.cpp 835*9e94795aSAndroid Build Coastguard Worker</code></p> 836*9e94795aSAndroid Build Coastguard Worker 837*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_STATIC_LIBRARIES</h4> 838*9e94795aSAndroid Build Coastguard Worker<p>These are the static libraries that you want to include in your module. 839*9e94795aSAndroid Build Coastguard WorkerMostly, we use shared libraries, but there are a couple of places, like 840*9e94795aSAndroid Build Coastguard Workerhost executables where we use static libraries instead. 841*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_STATIC_LIBRARIES := \<br/> 842*9e94795aSAndroid Build Coastguard Worker libutils \<br/> 843*9e94795aSAndroid Build Coastguard Worker libtinyxml 844*9e94795aSAndroid Build Coastguard Worker</code></p> 845*9e94795aSAndroid Build Coastguard Worker 846*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_MODULE</h4> 847*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_MODULE</code> is the name of what's supposed to be generated 848*9e94795aSAndroid Build Coastguard Workerfrom your Android.mk. For exmample, for libkjs, the <code>LOCAL_MODULE</code> 849*9e94795aSAndroid Build Coastguard Workeris "libkjs" (the build system adds the appropriate suffix -- .so .dylib .dll). 850*9e94795aSAndroid Build Coastguard WorkerFor app modules, use <code>LOCAL_PACKAGE_NAME</code> instead of 851*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_MODULE</code>. We're planning on switching to ant for the apps, 852*9e94795aSAndroid Build Coastguard Workerso this might become moot.</p> 853*9e94795aSAndroid Build Coastguard Worker 854*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_MODULE_PATH</h4> 855*9e94795aSAndroid Build Coastguard Worker<p>Instructs the build system to put the module somewhere other than what's 856*9e94795aSAndroid Build Coastguard Workernormal for its type. If you override this, make sure you also set 857*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_UNSTRIPPED_PATH</code> if it's an executable or a shared library 858*9e94795aSAndroid Build Coastguard Workerso the unstripped binary has somewhere to go. An error will occur if you forget 859*9e94795aSAndroid Build Coastguard Workerto.</p> 860*9e94795aSAndroid Build Coastguard Worker<p>See <a href="#moving-modules">Putting modules elsewhere</a> for more.</p> 861*9e94795aSAndroid Build Coastguard Worker 862*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_MODULE_RELATIVE_PATH</h4> 863*9e94795aSAndroid Build Coastguard Worker<p>Instructs the build system to put the module in a subdirectory under the 864*9e94795aSAndroid Build Coastguard Workerdirectory that is normal for its type. If you set this you do not need to 865*9e94795aSAndroid Build Coastguard Workerset <code>LOCAL_UNSTRIPPED_PATH</code>, the unstripped binaries will also use 866*9e94795aSAndroid Build Coastguard Workerthe relative path.</p> 867*9e94795aSAndroid Build Coastguard Worker<p>See <a href="#moving-modules">Putting modules elsewhere</a> for more.</p> 868*9e94795aSAndroid Build Coastguard Worker 869*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_MODULE_HOST_OS</h4> 870*9e94795aSAndroid Build Coastguard Worker<p>This specifies which OSes are supported by this host module. It is not used 871*9e94795aSAndroid Build Coastguard Workerfor target builds. The accepted values here are combinations of 872*9e94795aSAndroid Build Coastguard Worker<code>linux</code>, <code>darwin</code>, and <code>windows</code>. By default, 873*9e94795aSAndroid Build Coastguard Workerlinux and darwin(MacOS) are considered to be supported. If a module should 874*9e94795aSAndroid Build Coastguard Workerbuild under windows, you must specify windows, and any others to be supported. 875*9e94795aSAndroid Build Coastguard WorkerSome examples:</p> 876*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_MODULE_HOST_OS := linux<br/> 877*9e94795aSAndroid Build Coastguard WorkerLOCAL_MODULE_HOST_OS := darwin linux windows</code></p> 878*9e94795aSAndroid Build Coastguard Worker 879*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_UNSTRIPPED_PATH</h4> 880*9e94795aSAndroid Build Coastguard Worker<p>Instructs the build system to put the unstripped version of the module 881*9e94795aSAndroid Build Coastguard Workersomewhere other than what's normal for its type. Usually, you override this 882*9e94795aSAndroid Build Coastguard Workerbecause you overrode <code>LOCAL_MODULE_PATH</code> for an executable or a 883*9e94795aSAndroid Build Coastguard Workershared library. If you overrode <code>LOCAL_MODULE_PATH</code>, but not 884*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_UNSTRIPPED_PATH</code>, an error will occur.</p> 885*9e94795aSAndroid Build Coastguard Worker<p>See <a href="#moving-modules">Putting modules elsewhere</a> for more.</p> 886*9e94795aSAndroid Build Coastguard Worker 887*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_WHOLE_STATIC_LIBRARIES</h4> 888*9e94795aSAndroid Build Coastguard Worker<p>These are the static libraries that you want to include in your module without allowing 889*9e94795aSAndroid Build Coastguard Workerthe linker to remove dead code from them. This is mostly useful if you want to add a static library 890*9e94795aSAndroid Build Coastguard Workerto a shared library and have the static library's content exposed from the shared library. 891*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_WHOLE_STATIC_LIBRARIES := \<br/> 892*9e94795aSAndroid Build Coastguard Worker libsqlite3_android<br/> 893*9e94795aSAndroid Build Coastguard Worker</code></p> 894*9e94795aSAndroid Build Coastguard Worker 895*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_YACCFLAGS</h4> 896*9e94795aSAndroid Build Coastguard Worker<p>Any flags to pass to invocations of yacc for your module. A known limitation 897*9e94795aSAndroid Build Coastguard Workerhere is that the flags will be the same for all invocations of YACC for your 898*9e94795aSAndroid Build Coastguard Workermodule. This can be fixed. If you ever need it to be, just ask.</p> 899*9e94795aSAndroid Build Coastguard Worker<p><code>LOCAL_YACCFLAGS := -p kjsyy</code></p> 900*9e94795aSAndroid Build Coastguard Worker 901*9e94795aSAndroid Build Coastguard Worker 902*9e94795aSAndroid Build Coastguard Worker 903*9e94795aSAndroid Build Coastguard Worker<h2>Implementation Details</h2> 904*9e94795aSAndroid Build Coastguard Worker 905*9e94795aSAndroid Build Coastguard Worker<p>You should never have to touch anything in the config directory unless 906*9e94795aSAndroid Build Coastguard Workeryou're adding a new platform, new tools, or adding new features to the 907*9e94795aSAndroid Build Coastguard Workerbuild system. In general, please consult with the build system owner(s) 908*9e94795aSAndroid Build Coastguard Worker(<a href="mailto:android-build-team">android-build-team</a>) before you go 909*9e94795aSAndroid Build Coastguard Workermucking around in here. That said, here are some notes on what's going on 910*9e94795aSAndroid Build Coastguard Workerunder the hood.</p> 911*9e94795aSAndroid Build Coastguard Worker 912*9e94795aSAndroid Build Coastguard Worker<h3>Environment Setup / buildspec.mk Versioning</h3> 913*9e94795aSAndroid Build Coastguard Worker<p>In order to make easier for people when the build system changes, when 914*9e94795aSAndroid Build Coastguard Workerit is necessary to make changes to buildspec.mk or to rerun the environment 915*9e94795aSAndroid Build Coastguard Workersetup scripts, they contain a version number in the variable 916*9e94795aSAndroid Build Coastguard WorkerBUILD_ENV_SEQUENCE_NUMBER. If this variable does not match what the build 917*9e94795aSAndroid Build Coastguard Workersystem expects, it fails printing an error message explaining what happened. 918*9e94795aSAndroid Build Coastguard WorkerIf you make a change that requires an update, you need to update two places 919*9e94795aSAndroid Build Coastguard Workerso this message will be printed. 920*9e94795aSAndroid Build Coastguard Worker<ul> 921*9e94795aSAndroid Build Coastguard Worker <li>In core/envsetup.mk, increment the 922*9e94795aSAndroid Build Coastguard Worker CORRECT_BUILD_ENV_SEQUENCE_NUMBER definition.</li> 923*9e94795aSAndroid Build Coastguard Worker <li>In buildspec.mk.default, update the BUILD_ENV_SEQUENCE_DUMBER 924*9e94795aSAndroid Build Coastguard Worker definition to match the one in core/envsetup.mk</li> 925*9e94795aSAndroid Build Coastguard Worker</ul> 926*9e94795aSAndroid Build Coastguard WorkerThe scripts automatically get the value from the build system, so they will 927*9e94795aSAndroid Build Coastguard Workertrigger the warning as well. 928*9e94795aSAndroid Build Coastguard Worker</p> 929*9e94795aSAndroid Build Coastguard Worker 930*9e94795aSAndroid Build Coastguard Worker<h3>Additional makefile variables</h3> 931*9e94795aSAndroid Build Coastguard Worker<p>You probably shouldn't use these variables. Please consult 932*9e94795aSAndroid Build Coastguard Worker<a href="mailto:android-build-team">android-build-team</a> before using them. 933*9e94795aSAndroid Build Coastguard WorkerThese are mostly there for workarounds for other issues, or things that aren't 934*9e94795aSAndroid Build Coastguard Workercompletely done right.</p> 935*9e94795aSAndroid Build Coastguard Worker 936*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_ADDITIONAL_DEPENDENCIES</h4> 937*9e94795aSAndroid Build Coastguard Worker<p>If your module needs to depend on anything else that 938*9e94795aSAndroid Build Coastguard Workerisn't actually built in to it, you can add those make targets to 939*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_ADDITIONAL_DEPENDENCIES</code>. Usually this is a workaround 940*9e94795aSAndroid Build Coastguard Workerfor some other dependency that isn't created automatically.</p> 941*9e94795aSAndroid Build Coastguard Worker 942*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_BUILT_MODULE</h4> 943*9e94795aSAndroid Build Coastguard Worker<p class=warning>This should not be used, since multiple binaries are now 944*9e94795aSAndroid Build Coastguard Workercreated from a single module defintiion.</p> 945*9e94795aSAndroid Build Coastguard Worker<p>When a module is built, the module is created in an intermediate 946*9e94795aSAndroid Build Coastguard Workerdirectory then copied to its final location. LOCAL_BUILT_MODULE is 947*9e94795aSAndroid Build Coastguard Workerthe full path to the intermediate file. See LOCAL_INSTALLED_MODULE 948*9e94795aSAndroid Build Coastguard Workerfor the path to the final installed location of the module.</p> 949*9e94795aSAndroid Build Coastguard Worker 950*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_IS_HOST_MODULE</h4> 951*9e94795aSAndroid Build Coastguard Worker<p>Set by the host_xxx.mk includes to tell base_rules.mk and the other 952*9e94795aSAndroid Build Coastguard Workerincludes that we're building for the host.</p> 953*9e94795aSAndroid Build Coastguard Worker 954*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_INSTALLED_MODULE</h4> 955*9e94795aSAndroid Build Coastguard Worker<p class=warning>This should not be used, since multiple binaries are now 956*9e94795aSAndroid Build Coastguard Workercreated from a single module defintiion.</p> 957*9e94795aSAndroid Build Coastguard Worker<p>The fully qualified path name of the final location of the module. 958*9e94795aSAndroid Build Coastguard WorkerSee LOCAL_BUILT_MODULE for the location of the intermediate file that 959*9e94795aSAndroid Build Coastguard Workerthe make rules should actually be constructing.</p> 960*9e94795aSAndroid Build Coastguard Worker 961*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_MODULE_CLASS</h4> 962*9e94795aSAndroid Build Coastguard Worker<p>Which kind of module this is. This variable is used to construct other 963*9e94795aSAndroid Build Coastguard Workervariable names used to locate the modules. See base_rules.mk and 964*9e94795aSAndroid Build Coastguard Workerenvsetup.mk.</p> 965*9e94795aSAndroid Build Coastguard Worker 966*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_MODULE_SUFFIX</h4> 967*9e94795aSAndroid Build Coastguard Worker<p>The suffix that will be appended to <code>LOCAL_MODULE</code> to form 968*9e94795aSAndroid Build Coastguard Worker<code>LOCAL_MODULE_NAME</code>. For example, .so, .a, .dylib.</p> 969*9e94795aSAndroid Build Coastguard Worker 970*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_STRIP_MODULE</h4> 971*9e94795aSAndroid Build Coastguard Worker<p>If set to true (the default), the binary will be stripped and a debug 972*9e94795aSAndroid Build Coastguard Workerlink will be set up so that GDB will still work. If set to no_debuglink, 973*9e94795aSAndroid Build Coastguard Workerthe binary will be stripped, but no debug link will be added. If set to 974*9e94795aSAndroid Build Coastguard Workerkeep_symbols, it will strip the debug information, but keep the symbol table. 975*9e94795aSAndroid Build Coastguard WorkerAny other value will prevent stripping.</p> 976*9e94795aSAndroid Build Coastguard Worker 977*9e94795aSAndroid Build Coastguard Worker<h4>LOCAL_SYSTEM_SHARED_LIBRARIES</h4> 978*9e94795aSAndroid Build Coastguard Worker<p>Used while building the base libraries: libc, libm, libdl. Usually 979*9e94795aSAndroid Build Coastguard Workerit should be set to "none," as it is in $(CLEAR_VARS). When building 980*9e94795aSAndroid Build Coastguard Workerthese libraries, it's set to the ones they link against. For example, 981*9e94795aSAndroid Build Coastguard Workerlibc, libstdc++ and libdl don't link against anything, and libm links against 982*9e94795aSAndroid Build Coastguard Workerlibc. Normally, when the value is none, these libraries are automatically 983*9e94795aSAndroid Build Coastguard Workerlinked in to executables and libraries, so you don't need to specify them 984*9e94795aSAndroid Build Coastguard Workermanually.</p> 985*9e94795aSAndroid Build Coastguard Worker 986*9e94795aSAndroid Build Coastguard Worker 987*9e94795aSAndroid Build Coastguard Worker</body> 988*9e94795aSAndroid Build Coastguard Worker</html> 989