diff --git a/android/androidmk.go b/android/androidmk.go index 2732c82e4..46e7fcf20 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -43,9 +43,11 @@ type AndroidMkData struct { OutputFile OptionalPath Disabled bool - Custom func(w io.Writer, name, prefix, moduleDir string) + Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) Extra []AndroidMkExtraFunc + + preamble bytes.Buffer } type AndroidMkExtraFunc func(w io.Writer, outputFile Path) @@ -166,50 +168,32 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b return nil } - if data.SubName != "" { - name += data.SubName - } + prefix := "" + if amod.ArchSpecific() { + switch amod.Os().Class { + case Host: + prefix = "HOST_" + case HostCross: + prefix = "HOST_CROSS_" + case Device: + prefix = "TARGET_" - if data.Custom != nil { - prefix := "" - if amod.ArchSpecific() { - switch amod.Os().Class { - case Host: - prefix = "HOST_" - case HostCross: - prefix = "HOST_CROSS_" - case Device: - prefix = "TARGET_" - - } - - config := ctx.Config().(Config) - if amod.Arch().ArchType != config.Targets[amod.Os().Class][0].Arch.ArchType { - prefix = "2ND_" + prefix - } } - data.Custom(w, name, prefix, filepath.Dir(ctx.BlueprintFile(mod))) - - return nil + config := ctx.Config().(Config) + if amod.Arch().ArchType != config.Targets[amod.Os().Class][0].Arch.ArchType { + prefix = "2ND_" + prefix + } } - if data.Disabled { - return nil - } - - if !data.OutputFile.Valid() { - return nil - } - - fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") - fmt.Fprintln(w, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod))) - fmt.Fprintln(w, "LOCAL_MODULE :=", name) - fmt.Fprintln(w, "LOCAL_MODULE_CLASS :=", data.Class) - fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String()) + fmt.Fprintln(&data.preamble, "\ninclude $(CLEAR_VARS)") + fmt.Fprintln(&data.preamble, "LOCAL_PATH :=", filepath.Dir(ctx.BlueprintFile(mod))) + fmt.Fprintln(&data.preamble, "LOCAL_MODULE :=", name+data.SubName) + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_CLASS :=", data.Class) + fmt.Fprintln(&data.preamble, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String()) if len(amod.commonProperties.Required) > 0 { - fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(amod.commonProperties.Required, " ")) + fmt.Fprintln(&data.preamble, "LOCAL_REQUIRED_MODULES := "+strings.Join(amod.commonProperties.Required, " ")) } archStr := amod.Arch().ArchType.String() @@ -218,48 +202,68 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b case Host: // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. if archStr != "common" { - fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_ARCH :=", archStr) } host = true case HostCross: // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. if archStr != "common" { - fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) } host = true case Device: // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. if archStr != "common" { - fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_TARGET_ARCH :=", archStr) } if len(amod.commonProperties.Logtags) > 0 { - fmt.Fprintln(w, "LOCAL_LOGTAGS_FILES := ", strings.Join(amod.commonProperties.Logtags, " ")) + fmt.Fprintln(&data.preamble, "LOCAL_LOGTAGS_FILES := ", strings.Join(amod.commonProperties.Logtags, " ")) } if len(amod.commonProperties.Init_rc) > 0 { - fmt.Fprintln(w, "LOCAL_INIT_RC := ", strings.Join(amod.commonProperties.Init_rc, " ")) + fmt.Fprintln(&data.preamble, "LOCAL_INIT_RC := ", strings.Join(amod.commonProperties.Init_rc, " ")) } if amod.commonProperties.Proprietary { - fmt.Fprintln(w, "LOCAL_PROPRIETARY_MODULE := true") + fmt.Fprintln(&data.preamble, "LOCAL_PROPRIETARY_MODULE := true") } if amod.commonProperties.Vendor { - fmt.Fprintln(w, "LOCAL_VENDOR_MODULE := true") + fmt.Fprintln(&data.preamble, "LOCAL_VENDOR_MODULE := true") } if amod.commonProperties.Owner != nil { - fmt.Fprintln(w, "LOCAL_MODULE_OWNER :=", *amod.commonProperties.Owner) + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_OWNER :=", *amod.commonProperties.Owner) } } if host { - fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", amod.Os().String()) - fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") + fmt.Fprintln(&data.preamble, "LOCAL_MODULE_HOST_OS :=", amod.Os().String()) + fmt.Fprintln(&data.preamble, "LOCAL_IS_HOST_MODULE := true") } + blueprintDir := filepath.Dir(ctx.BlueprintFile(mod)) + + if data.Custom != nil { + data.Custom(w, name, prefix, blueprintDir, data) + } else { + WriteAndroidMkData(w, data) + } + + return nil +} + +func WriteAndroidMkData(w io.Writer, data AndroidMkData) { + if data.Disabled { + return + } + + if !data.OutputFile.Valid() { + return + } + + w.Write(data.preamble.Bytes()) + for _, extra := range data.Extra { extra(w, data.OutputFile.Path()) } fmt.Fprintln(w, "include $(BUILD_PREBUILT)") - - return nil } diff --git a/cc/androidmk.go b/cc/androidmk.go index 4421b1c45..fc45b7ad7 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -136,10 +136,10 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An ret.Class = "SHARED_LIBRARIES" } else if library.header() { - ret.Custom = func(w io.Writer, name, prefix, moduleDir string) { + ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) - fmt.Fprintln(w, "LOCAL_MODULE :=", name) + fmt.Fprintln(w, "LOCAL_MODULE :=", name+data.SubName) archStr := ctx.Target().Arch.ArchType.String() var host bool @@ -194,10 +194,10 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An } func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { - ret.Custom = func(w io.Writer, name, prefix, moduleDir string) { + ret.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { out := ret.OutputFile.Path() - fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+objectExtension+":", out.String()) + fmt.Fprintln(w, "\n$("+prefix+"OUT_INTERMEDIATE_LIBRARIES)/"+name+data.SubName+objectExtension+":", out.String()) fmt.Fprintln(w, "\t$(copy-file-to-target)") } } diff --git a/phony/phony.go b/phony/phony.go index 5f0187f92..a39b5d51e 100644 --- a/phony/phony.go +++ b/phony/phony.go @@ -50,7 +50,7 @@ func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (p *phony) AndroidMk() android.AndroidMkData { return android.AndroidMkData{ - Custom: func(w io.Writer, name, prefix, moduleDir string) { + Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) fmt.Fprintln(w, "LOCAL_MODULE :=", name)