当前位置:   article > 正文

Android.bp中添加条件编译控制_android.bp 条件编译

android.bp 条件编译

Android.bp

//引入go脚本
bootstrap_go_package {
    name: "soong-xxxparser",
    pkgPath: "android/soong/xxxparser",
    deps: [
    "blueprint",
    "blueprint-pathtools",
    "soong",
    "soong-android",
    "soong-cc",
    "soong-genrule",
    ],
    srcs: [
        "xxxparser.go",
    ],
    pluginFor: ["soong_build"],
}

xxxparser {
    name: "xxxparser_defaults",
}

cc_binary {
    defaults: ["xxxparser_defaults"],
    name: "AndroidBp",
    srcs: ["main.c"],


    cflags: ["-Wno-error=implicit-function-declaration"],



    shared_libs: [
        "libcutils",
        "liblog",
        "libutils",
    ],

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

main.c

#include<stdio.h>
int main()
{
    #ifdef PRINT  //宏控制
    printf("Hello world\n");
    #endif

    #ifdef XXX //宏控制
    printf("XXOOX\n");
    #endif

    printf("This is AndroidBp Test\n");
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

xxxparser.go

package  xxxparser

import (
        "android/soong/android"
        "android/soong/cc"
)

func init() {
    // resister a module "xxxparser_defaults"
    android.RegisterModuleType("xxxparser", xxxdroidDefaultsFactory)
}

func xxxdroidDefaultsFactory() (android.Module) {
    module := cc.DefaultsFactory()
    android.AddLoadHook(module, xxxdroidDefaults)
    return module
}

func xxxdroidDefaults(ctx android.LoadHookContext) {
   type props struct {
        Cflags []string
    }
    p := &props{}
    p.Cflags = globalDefaults(ctx)
    ctx.AppendProperties(p)
}

func globalDefaults(ctx android.BaseContext) ([]string) {
    var cppflags []string
    if ctx.AConfig().Getenv("TARGET_PRODUCT") == "dockdroid_arm64" {
          cppflags = append(cppflags,"-DXXX")
    }
    return cppflags
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/526394
推荐阅读
相关标签
  

闽ICP备14008679号