Cocos2d-x的Android.mk自动生成

前端之家收集整理的这篇文章主要介绍了Cocos2d-x的Android.mk自动生成前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

编译至Android平台时,若手动修改需编译的源文件及头文件目录,那会比较麻烦。还有就是若直接在Android.mk里面写自动搜索的话,需要Linux环境(或Windows上的Cygwin)才能正确运行。所以这里写了一个Python脚本,直接放在jni文件夹下运行即可生成Android.mk。生成的Android.mk文件内容如下图:

Python脚本:

import os
from sets import Set
text = """LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp"""
includeSet = Set()
def findall(path):
    global text
    dirList = os.listdir(path) 
    for dirName in dirList:
        if os.path.isfile(path + "/" + dirName):
            if dirName[-2:]==".h":
                includeSet.add(path)
            elif dirName[-4:]==".cpp" or dirName[-2:]==".c":
                text += " \\\n" + path + "/" + dirName
        else:
            findall(path+"/"+dirName)
findall("../../Classes")
text += "\n\n"
text += "LOCAL_C_INCLUDES :="
for include in includeSet:
    text += " \\\n$(LOCAL_PATH)/" + include
text += """
LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_LDLIBS += -L$(call host-path,$(NDK_ROOT)/sources/cxx-stl/llvm-libc++/libs/$(TARGET_ARCH_ABI)) -lc++_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,./prebuilt-mk)
"""
f = open('Android.mk','w')
f.write(text)
f.close()

猜你在找的Cocos2d-x相关文章