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