*************************************************************************************************************** ************
Easywave Time: 2015.01.23
Category: Android system source code analysis-based on Android2.3.5 system: ANDROID.MK file Parsing declaration: reprint, please keep the link
Note: If there is an error, please correct me. These are the journal articles I studied ...
*************************************************************************************************************** ************
A: Android.mk file brief Introduction
Under Linux, the editor often writes a makefile file, which can be used to interpret the makefile file as a compiled configuration file that instructs the compiler to compile the program and determine what the result of the compilation is. Of course, it is a terrible thing for Linux to manually write makefile files for large projects, so there are tools like automake,autoconf, While the Android.mk file under Android is also this similar feature, that is, the Android.mk file is for Android makefile files. You can define one or more modules in each android.mk file, and you can use the same source code file in several modules. The rest is given to Android's compilation system.
II: The overall structure of the ANDROID.MK
The structure of the android.mk, where android2.3.5/frameworks/base/core/jni/android.mk is used as an example, is as follows:
Local_path:= $ (call My-dir) include $ (clear_vars) Local_cflags + =-dhave_config_h-dkhtml_no_exceptions-dgkwq_no_ Javalocal_cflags + =-dno_support_js_binding-dqt_no_wheelevent-dkhtml_no_xbllocal_cflags +-U__APPLE__ifeq ($ ( Target_arch), arm) Local_cflags + =-dpacked= "__attribute__ ((Packed))" Elselocal_cflags + =-dpacked= "" Endififeq ($ (with _jit), true) Local_cflags + =-dwith_jitendififneq ($ (Use_custom_runtime_heap_max),) local_cflags + =-DCUSTOM_RUNTIME_ heap_max=$ (use_custom_runtime_heap_max) endiflocal_cflags + =-dgl_glext_prototypes-degl_eglext_prototypeslocal_ src_files:= ActivityManager.cpp AndroidRuntime.cpp CursorWindow.cpp Time.cpp com_google_android_gles_jni_ EGLImpl.cpp com_google_android_gles_jni_GLImpl.cpp.arm android_app_nativeactivity.cpp Android_opengl_gles10.cpp Android_opengl_gles10ext.cpp android_opengl_gles11.cpp android_opengl_gles11ext.cpp Android_opengl_GLES20.cpp Android_database_cursorwindow.cpp Android_database_sqlitecompiledsql.cpp Android_database_sqlitedebug.cpp Android_database_sqlitedatabase.cpp android_database_sqliteprogram.cpp android_database_sqlitequery.cpp android_ Database_sqlitestatement.cpp android_emoji_emojifactory.cpp android_view_display.cpp Android_view_Surface.cpp Android_view_viewroot.cpp android_view_inputchannel.cpp android_view_inputqueue.cpp Android_view_KeyEvent.cpp Android_view_motionevent.cpp android_text_androidcharacter.cpp android_text_androidbidi.cpp Android_text_ KeyCharacterMap.cpp android_os_debug.cpp android_os_fileutils.cpp android_os_memoryfile.cpp android_os_ MessageQueue.cpp android_os_parcelfiledescriptor.cpp android_os_power.cpp android_os_statfs.cpp android_os_ SystemClock.cpp android_os_systemproperties.cpp android_os_ueventobserver.cpp Android_net_localsocketimpl.cpp Android_net_netutils.cpp android_net_trafficstats.cpp android_net_wifi_wifi.cpp android_net_ethernet.cpp android_ Nio_utils.cpp android_nfc_ndefmessage.cpp android_nfc_ndefrecord.cpp android_pim_eventrecurrence.cpp android_text_ Format_time.cpp Android_security_md5messagedigest.cpp android_util_assetmanager.cpp android_util_binder.cpp Android_util_ EventLog.cpp android_util_log.cpp android_util_floatmath.cpp android_util_process.cpp android_util_stringblock.cpp Android_util_xmlblock.cpp android/graphics/autodecodecancel.cpp android/graphics/bitmap.cpp android/graphics/ BitmapFactory.cpp android/graphics/camera.cpp android/graphics/canvas.cpp android/graphics/colorfilter.cpp Android /graphics/drawfilter.cpp Android/graphics/createjavaoutputstreamadaptor.cpp android/graphics/graphics.cpp Android /graphics/interpolator.cpp android/graphics/layerrasterizer.cpp android/graphics/maskfilter.cpp android/graphics/ Matrix.cpp android/graphics/movie.cpp android/graphics/ninepatch.cpp android/graphics/ninepatchimpl.cpp Android/ Graphics/paint.cpp android/graphics/path.cpp android/graphics/pathmeasure.cpp Android/graphics/PathEffect.cpp Android_graphics_pixelformat.cpp android/graphics/picture.cpp android/graphics/porterduff.cpp Android/graphiCs/bitmapregiondecoder.cpp android/graphics/rasterizer.cpp android/graphics/region.cpp android/graphics/ Shader.cpp android/graphics/typeface.cpp android/graphics/utils.cpp android/graphics/xfermode.cpp android/graphics /yuvtojpegencoder.cpp android_media_audiorecord.cpp android_media_audiosystem.cpp Android_media_AudioTrack.cpp Android_media_jetplayer.cpp android_media_tonegenerator.cpp android_hardware_camera.cpp android_hardware_ SensorManager.cpp android_debug_jnitest.cpp android_util_fileobserver.cpp android/opengl/poly_clip.cpp.arm Android /opengl/util.cpp.arm android_bluetooth_headsetbase.cpp android_bluetooth_common.cpp Android_bluetooth_ BluetoothAudioGateway.cpp android_bluetooth_bluetoothsocket.cpp android_bluetooth_scosocket.cpp Android_server_ BluetoothService.cpp android_server_bluetootheventloop.cpp android_server_bluetootha2dpservice.cpp Android_server _watchdog.cpp android_message_digest_sha1.cpp android_ddm_ddmhandlenativeheap.cpp Com_android_internal_os_ ZygoteInit.cpp Com_aNdroid_internal_graphics_nativeutils.cpp Android_backup_backupdatainput.cpp Android_backup_backupdataoutput.cpp Android_backup_filebackuphelperbase.cpp Android_backup_backuphelperdispatcher.cpp Android_content_res_ ObbScanner.cpp Android_content_res_configuration.cpplocal_c_includes + = $ (jni_h_include) $ (local_path)/android/ Graphics $ (call Include-path-for, bluedroid) $ (call include-path-for, Libhardware)/hardware $ (Call include-path-for, Libhardware_legacy)/hardware_legacy $ (local_path)/. /.. /include/ui $ (local_path)/. /.. /include/utils External/skia/include/core external/skia/include/effects external/skia/include/images External/skia /src/ports external/skia/include/utils external/sqlite/dist external/sqlite/android external/expat/lib external/ Openssl/include external/tremor/tremor external/icu4c/i18n External/icu4c/common external/jpeg frameworks/opt/ Emojilocal_shared_libraries: = Libexpat libnativehelper libcutils libutils libbinder libnetutils libui Libgui Libsurfaceflinger_clieNT Libcamera_client libskiagl Libskia libsqlite libdvm libegl libglesv1_cm libGLESv2 libETC1 libhardware Libhardware_lega Cy Libsonivox libcrypto libssl libicuuc libicui18n libmedia libwpa_client libjpeg libnfc_ndefifeq ($ (BOARD_HAVE_ BLUETOOTH), true) Local_c_includes + = External/dbus System/bluetooth/bluez-clean-headerslocal_cflags + =-DHAVE_ Bluetoothlocal_shared_libraries + = Libbluedroid libdbusendififneq ($ (target_simulator), true) LOCAL_SHARED_LIBRARIES + = LIBDL # We need to access the private Bionic headers # <bionic_tls.h> in Com_google_android_gles_jni_glimpl.cpp Local_cflags + =-i$ (Local_path)/. /.. /.. /.. /bionic/libc/privateendiflocal_ldlibs + =-lpthread-ldlifeq ($ (target_simulator), True) ifeq ($ (target_os)-$ (TARGET_ ARCH), linux-x86) Local_ldlibs + =-lrtendifendififeq ($ (With_malloc_leak_check), true) Local_cflags + =-dmalloc_leak_ checkendiflocal_module:= Libandroid_runtimeinclude $ (build_shared_library) include $ (call all-makefiles-under,$ ( Local_path))
You must first define the Local_path variable. Then clear all the values of the LOCAL_XX variable, except the value of Local_path, and then define the source file, the header file, followed by the compile option parameter, followed by the compilation of the generated file name, and finally the resulting file type.
Three: variable definition of ANDROID.MK
3.1:local_path
A android.mk file must first define a good local_path variable. It is used to find source files in the development tree. For example:
Local_path:= $ (call MY-DIR) macro function ' My-dir ', provided by the compilation system, to return the current path (that is, the directory containing the android.mk file)
3.2:include $ (clear_vars)
Macro Clear_vars is provided by the compilation system, specifying that GNU makefile clears many local_xxx variables for you (such as Local_module, Local_src_files,local_static_libraries, and so on ...). ), except Local_path. This is necessary because all the compilation control files are in the same GNU make execution environment, and all the variables are global.
3.3:local_src_files
This time you need to compile the source file as follows:
local_src_files:= \
ActivityManager.cpp \
AndroidRuntime.cpp \
CursorWindow.cpp \
Time.cpp \
The following omit .....
3.4:local_shared_libraries
This compilation requires a linked dynamic link library file, which is a. so file
3.5:local_static_libraries
Static link library.
3.6:local_c_includes
This compilation needs to include a header file, a list of paths relative to the current directory, and when all the source files (c,c++ and compilations) are compiled, it is added to the include search path as follows:
local_c_includes: = Include/ui
or even:
Local_c_includes: = $ (Local_path)/. /ui
The specific wording is as follows:
Local_c_includes + = \
$ (jni_h_include) \
$ (local_path)/android/graphics \
$ (call include-path-for, bluedroid) \
$ (call include-path-for, libhardware)/hardware \
$ (call include-path-for, libhardware_legacy)/hardware_legacy \
$ (Local_path)/.. /.. /include/ui \
$ (Local_path)/.. /.. /include/utils \
External/skia/include/core \
External/skia/include/effects \
External/skia/include/images \
External/skia/src/ports \
External/skia/include/utils \
External/sqlite/dist \
External/sqlite/android \
External/expat/lib \
External/openssl/include \
External/tremor/tremor \
external/icu4c/i18n \
External/icu4c/common \
External/jpeg \
Frameworks/opt/emoji
The following omit .....
3.6:local_ldlibs
Link Options for this compilation, equivalent to the parameters after Gcc-l
3.7:local_cflags
The same is the compile option, which is equivalent to the parameters behind Gcc-o
3.8:local_module
The generated module name, which must be defined to indicate the name of the file that will be generated after make
IV: Include usage in android.mk files
include can appear in this form, such as: Include $ (clear_vars), include $ (build_shared_library). In fact, this include can be understood as the meaning of "implementation", then the implementation of what? Of course, look at the macro behind. Macro Clear_vars has been introduced in section 3.2, to clear some variables . macro build_shared_library means to generate a shared library, that is, to generate. So files, the same type of macro is as follows:
clear_vars Clear local_xxx variable
build_shared_library Generate lib$ (local_moudule). So file in the/system/lib/directory;
Build_static_library generate lib$ (local_moudule). a file
build_executable to generate executable files in the/system/bin/directory
build_package & nbsp compile into an apk file
V: summary
Simple introduction of the use of android.mk, but also in the process of familiarity, more or less will appear in the learning process errors.
Based on Android2.3.5 system: ANDROID.MK file parsing