diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go index 1eefd8006..dc54b68e4 100644 --- a/newt/builder/targetbuild.go +++ b/newt/builder/targetbuild.go @@ -292,7 +292,11 @@ func (t *TargetBuilder) validateAndWriteCfg() error { srcDir := GeneratedSrcDir(t.target.FullName()) lpkgs := resolve.RpkgSliceToLpkgSlice(t.res.MasterSet.Rpkgs) - if err := syscfg.EnsureWritten(t.res.Cfg, incDir, lpkgs); err != nil { + apis := []string{} + for api := range t.res.ApiMap { + apis = append(apis, api) + } + if err := syscfg.EnsureWritten(t.res.Cfg, incDir, lpkgs, apis); err != nil { return err } diff --git a/newt/syscfg/syscfg.go b/newt/syscfg/syscfg.go index a9906685a..e7f62ff09 100644 --- a/newt/syscfg/syscfg.go +++ b/newt/syscfg/syscfg.go @@ -1599,7 +1599,19 @@ func writePackages(lpkgs []*pkg.LocalPackage, w io.Writer) { } } -func write(cfg Cfg, lpkgs []*pkg.LocalPackage, w io.Writer) { +func writeApis(apis []string, w io.Writer) { + for i, api := range apis { + apis[i] = cfgPkgIllegalChar.ReplaceAllLiteralString(api, "_") + } + sort.Strings(apis) + + fmt.Fprintf(w, "/*** Included APIs */\n") + for _, name := range apis { + fmt.Fprintf(w, "#define MYNEWT_API_%s 1\n", name) + } +} + +func write(cfg Cfg, lpkgs []*pkg.LocalPackage, apis []string, w io.Writer) { fmt.Fprintf(w, newtutil.GeneratedPreamble()) fmt.Fprintf(w, "#ifndef H_MYNEWT_SYSCFG_\n") @@ -1619,10 +1631,13 @@ func write(cfg Cfg, lpkgs []*pkg.LocalPackage, w io.Writer) { writePackages(lpkgs, w) fmt.Fprintf(w, "\n") + writeApis(apis, w) + fmt.Fprintf(w, "\n") + fmt.Fprintf(w, "#endif\n") } -func EnsureWritten(cfg Cfg, includeDir string, lpkgs []*pkg.LocalPackage) error { +func EnsureWritten(cfg Cfg, includeDir string, lpkgs []*pkg.LocalPackage, apis []string) error { // XXX: Detect these problems at error text generation time. if err := calcPriorities(cfg, CFG_SETTING_TYPE_TASK_PRIO, SYSCFG_TASK_PRIO_MAX, false); err != nil { @@ -1631,7 +1646,7 @@ func EnsureWritten(cfg Cfg, includeDir string, lpkgs []*pkg.LocalPackage) error } buf := bytes.Buffer{} - write(cfg, lpkgs, &buf) + write(cfg, lpkgs, apis, &buf) path := includeDir + "/" + HEADER_PATH