背景
有时候我们想创建一个程序,放在系统中,供其他APP执行。我们知道,在生成system.img的时候,编译系统会将out/target/product/[product]/system/bin目录打包进去。所以,我们想办法让编译系统在编译的过程中,把我们的程序编译了,并把编译生成的二进制文件自动放到out/target/product/[product]/system/bin。
做法
假如我们要创建一个mytest的程序
1.在external目录下创建名为mytest的文件夹,这个文件夹用于存放我们的程序代码和makefile文件以及这个程序的依赖库。
2.创建我们的程序代码和makefile文件,这里主要看看makefile文件怎么写,例子如下:
LOCAL_PATH := $(call my-dir)
common_cflags := -std=c99 -Os -Wall -Wextra -Wno-char-subscripts -Wno-sign-compare -Wno-string-plus-int -Wno-uninitialized -Wno-unused-parameter -funsigned-char -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables
# static executable for use in limited environments
include $(CLEAR_VARS)
LOCAL_SRC_FILES := mytest.c
LOCAL_CFLAGS := $(common_cflags)
LOCAL_CXX_STL := none
LOCAL_CLANG := true
# LOCAL_MODULE_PATH and LOCAL_UNSTRIPPED_PATH do not equal
LOCAL_UNSTRIPPED_PAT