Android.mk auto generator

make file 生成

需要批量写mk文件时 使用模板自动填充

useage :

./auto_generator.py vendor lib so

#!/usr/bin/env python
import sys
import os
import re
import zipfile
import shutil

templet = """include $(CLEAR_VARS)
LOCAL_MODULE := %s
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).so
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/lib
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
include $(BUILD_PREBUILT)

"""

def main(argv):
    preinstall_dir = os.path.join(argv[1],argv[2])

    print "preinstall dir "+ preinstall_dir
    if os.path.exists(preinstall_dir):
        #Use to include modules
        isfound = 'not_found_lib'
        include_path = preinstall_dir + '/preinstall.mk'
        android_path = preinstall_dir + '/Android.mk'
        if os.path.exists(include_path):
            os.remove(include_path)
        if os.path.exists(android_path):
            os.remove(android_path)

        includefile = file(include_path, 'w')
        androidfile = file(android_path, 'w')

        androidfile.write("include $(call all-subdir-makefiles)\n\n")

        MY_LOCAL_PREBUILT_JNI_LIBS = '\\' + '\n'

        for root, dirs, files in os.walk(preinstall_dir):
            for file_name in files:
                p = re.compile(r'\S*(?=.so\b)')
                found = p.search(file_name)
                if found:
                    include_apk_path = preinstall_dir + '/' + found.group()
                    makefile_path = include_apk_path + '/Android.mk'
                    apk = preinstall_dir + '/' + found.group() + '.so'
                    apkpath = preinstall_dir + '/' + found.group() + '/'
                    if os.path.exists(include_apk_path):
                        shutil.rmtree(include_apk_path)
                    os.makedirs(include_apk_path)
                    shutil.move(apk,apkpath)
                    makefile = file(makefile_path,'w')
                    makefile.write("LOCAL_PATH := $(my-dir)\n\n")
                    makefile.write(templet % (found.group()))
                    makefile.close()

        for root, dirs,files in os.walk(preinstall_dir):
            for dir_file in dirs:
                includefile.write('PRODUCT_PACKAGES += %s\n' %dir_file)
            break
        includefile.close()

if __name__=="__main__":
  main(sys.argv)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值