首先来看一个简单的Android makefile,这个是我上篇文章写的,重新摘出来:
LOCAL_PATH:=$(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := eng LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog LOCAL_SRC_FILES:= \ ppp.c LOCAL_MODULE:= PPPreboot include $(BUILD_EXECUTABLE) #include $(BUILD_SHARED_LIBRARY)下面对上面的语法进行解析:
LOCAL_PATH:=$(call my-dir) 定义了当前模块的相对路径 include $(CLEAR_VARS) 清空了当前的环境变量 LOCAL_MODULE_TAGS := eng 指定模块在eng模式下才进行编译 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog 编译需要的库 LOCAL_SRC_FILES:ppp.c 编译所需要的目标源文件,一般都是当前目录下,或者依赖于其它目录下 LOCAL_MODULE:= PPPreboot 编译生成该目标的名称,也就是最终的可执行文件 include $(BUILD_EXECUTABLE) 编译所生成的目标的文件格式其中:
my-dir在build/core/definitions.mk定义
CLEAR_VARS在build/core/config.mk定义
以下就是我之前写的源码,简单的功能。
#include <stdio.h> #include <stdlib.h> #include <android/log.h> #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "keymatch", __VA_ARGS__) int main(void) { int i ; freopen("/dev/ttyMT0", "a", stdout);setbuf(stdout, NULL); freopen("/dev/ttyMT0", "a", stderr);setbuf(stderr, NULL); LOGD("YYX---->reboot system!!!!!!--->201612.1\n"); system("reboot"); return 0 ; }makefile还有源码写完以后我们就可以进行编译了。
首先,需要source build/envsetup.sh 初始化参数和环境变量
接着lunch 对应的平台的版本
接着就拥有了mm、mmm等编译工具
然后对刚刚写的程序进行手动编译: mmm external/test/
编译成功信息如下:
PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=6.0 TARGET_PRODUCT=em_t8350_emmc TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm TARGET_ARCH_VARIANT=armv7-a-neon TARGET_CPU_VARIANT=cortex-a7 TARGET_2ND_ARCH= TARGET_2ND_ARCH_VARIANT= TARGET_2ND_CPU_VARIANT= HOST_ARCH=x86_64 HOST_OS=linux HOST_OS_EXTRA=Linux-3.13.0-32-generic-x86_64-with-Ubuntu-14.04-trusty HOST_BUILD_TYPE=release BUILD_ID=MRA58K OUT_DIR=out ============================================ PRODUCT_COPY_FILES frameworks/base/data/sounds/effects/ogg/camera_click.ogg:system/media/audio/ui/camera_click.ogg ignored. PRODUCT_COPY_FILES device/pskyed/em_t8350_emmc/init.recovery.mt8127.rc:root/init.recovery.mt8127.rc ignored. PRODUCT_COPY_FILES device/pskyed/em_t8350_emmc/handheld_core_hardware.xml:system/etc/permissions/handheld_core_hardware.xml ignored. make: Entering directory `/mnt/sdb1/yangyx/MT8127_t8350_Debug_Camera_20161121/MT8127_M0_MP8_0407_for_t8350' build/core/Makefile:614: warning: overriding commands for target `out/target/product/em_t8350_emmc/boot.img' build/core/Makefile:39: warning: ignoring old commands for target `out/target/product/em_t8350_emmc/boot.img' No private recovery resources for TARGET_DEVICE em_t8350_emmc Import includes file: out/target/product/em_t8350_emmc/obj/EXECUTABLES/PPPreboot_intermediates/import_includes target thumb C: PPPreboot <= external/test/ppp.c target Executable: PPPreboot (out/target/product/em_t8350_emmc/obj/EXECUTABLES/PPPreboot_intermediates/LINKED/PPPreboot) target Unpacked: PPPreboot (out/target/product/em_t8350_emmc/obj/EXECUTABLES/PPPreboot_intermediates/PACKED/PPPreboot) target Symbolic: PPPreboot (out/target/product/em_t8350_emmc/symbols/system/bin/PPPreboot) Export includes file: external/test/Android.mk -- out/target/product/em_t8350_emmc/obj/EXECUTABLES/PPPreboot_intermediates/export_includes target Strip: PPPreboot (out/target/product/em_t8350_emmc/obj/EXECUTABLES/PPPreboot_intermediates/PPPreboot) Install: out/target/product/em_t8350_emmc/system/bin/PPPreboot make: Leaving directory `/mnt/sdb1/yangyx/MT8127_t8350_Debug_Camera_20161121/MT8127_M0_MP8_0407_for_t8350' #### make completed successfully (2 seconds) #### 输出的文件就在out/target/product/em_t8350_emmc/system/bin/PPPreboot,用什么手段执行它都可以,就看你的需求了。