Beispiel #1
0
def BuildProgram(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(
            AS="$CC",
            ASCOM="$ASPPCOM"
        )

    env.ProcessFlags([
        env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"),
        env.get("BUILD_FLAGS")
    ])

    if env.get("FRAMEWORK"):
        env.BuildFrameworks([
            f.lower().strip() for f in env.get("FRAMEWORK", "").split(",")])

    # build dependent libs
    deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env and
            not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(
            LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"']
        )

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs) and env.GetCompilerType() == "gcc":
        env.Prepend(
            _LIBFLAGS="-Wl,--start-group "
        )
        env.Append(
            _LIBFLAGS=" -Wl,--end-group"
        )

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags([env.get("SRC_BUILD_FLAGS", None)])

    env.Append(
        CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
            *pioversion_to_intstr())],
        LIBS=deplibs,
        LIBPATH=["$BUILD_DIR"]
    )

    sources = env.LookupSources(
        "$BUILDSRC_DIR", "$PROJECTSRC_DIR", duplicate=False,
        src_filter=env.get("SRC_FILTER"))

    if not sources and not COMMAND_LINE_TARGETS:
        env.Exit(
            "Error: Nothing to build. Please put your source code files "
            "to '%s' folder" % env.subst("$PROJECTSRC_DIR"))

    return env.Program(
        join("$BUILD_DIR", env.subst("$PROGNAME")),
        sources
    )
Beispiel #2
0
def BuildFirmware(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(
            AS="$CC",
            ASCOM="$ASPPCOM"
        )

    env.ProcessFlags()
    env.BuildFramework()

    firmenv = env.Clone()
    vdirs = firmenv.VariantDirRecursive(
        join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR", duplicate=False)

    # build dependent libs
    deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if "LDSCRIPT_PATH" in firmenv:
        firmenv.Append(
            LINKFLAGS=["-T", "$LDSCRIPT_PATH"]
        )

    # enable "cyclic reference" for linker
    firmenv.Prepend(
        _LIBFLAGS="-Wl,--start-group "
    )
    firmenv.Append(
        _LIBFLAGS=" -Wl,--end-group"
    )

    # Handle SRCBUILD_FLAGS
    if getenv("PLATFORMIO_SRCBUILD_FLAGS", None):
        firmenv.MergeFlags(getenv("PLATFORMIO_SRCBUILD_FLAGS"))
    if "SRCBUILD_FLAGS" in env:
        firmenv.MergeFlags(env['SRCBUILD_FLAGS'])

    firmenv.Append(
        CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
            *pioversion_to_intstr())]
    )

    if "envdump" in COMMAND_LINE_TARGETS:
        print env.Dump()
        Exit()

    if "idedata" in COMMAND_LINE_TARGETS:
        print json.dumps(env.DumpIDEData())
        Exit()

    return firmenv.Program(
        join("$BUILD_DIR", "firmware"),
        [firmenv.GlobCXXFiles(vdir) for vdir in vdirs],
        LIBS=env.get("LIBS", []) + deplibs,
        LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"],
        PROGSUFFIX=".elf"
    )
Beispiel #3
0
def BuildProgram(env):
    def _append_pio_macros():
        if any(["PLATFORMIO=" in str(d) for d in env.get("CPPDEFINES", [])]):
            return
        env.Append(CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())])

    _append_pio_macros()

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    # process extra flags from board
    env.ProcessFlags([env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags")])
    # remove base flags
    env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))
    # apply user flags
    env.ProcessFlags([env.get("BUILD_FLAGS")])

    if env.get("FRAMEWORK"):
        env.BuildFrameworks([f.lower().strip() for f in env.get("FRAMEWORK", "").split(",")])

    # restore PIO macros if it was deleted by framework
    _append_pio_macros()

    # build dependent libs
    deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if "LDSCRIPT_PATH" in env and not any(["-Wl,-T" in f for f in env["LINKFLAGS"]]):
        env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"'])

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs) and env.GetCompilerType() == "gcc":
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags([env.get("SRC_BUILD_FLAGS", None)])

    env.Append(CPPPATH=["$PROJECTSRC_DIR"], LIBS=deplibs, LIBPATH=["$BUILD_DIR"])

    sources = env.LookupSources("$BUILDSRC_DIR", "$PROJECTSRC_DIR", duplicate=False, src_filter=env.get("SRC_FILTER"))

    if not sources and not COMMAND_LINE_TARGETS:
        env.Exit(
            "Error: Nothing to build. Please put your source code files "
            "to '%s' folder" % env.subst("$PROJECTSRC_DIR")
        )

    program = env.Program(join("$BUILD_DIR", env.subst("$PROGNAME")), sources)

    if set(["upload", "uploadlazy", "program"]) & set(COMMAND_LINE_TARGETS):
        env.AddPostAction(program, env.CheckUploadSize)

    return program
Beispiel #4
0
def BuildFirmware(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes('.s', '.S'):
        env.Replace(
            AS="$CC",
            ASCOM="$ASPPCOM"
        )

    if "extra_flags" in env.get("BOARD_OPTIONS", {}).get("build", {}):
        env.MergeFlags(env.subst("${BOARD_OPTIONS['build']['extra_flags']}"))

    if "BUILD_FLAGS" in env:
        env.MergeFlags(env['BUILD_FLAGS'])

    env.BuildFramework()

    firmenv = env.Clone()
    vdirs = firmenv.VariantDirRecursive(
        join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR")

    # build dependent libs
    deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if "LDSCRIPT_PATH" in firmenv:
        firmenv.Append(
            LINKFLAGS=["-T", "$LDSCRIPT_PATH"]
        )

    # enable "cyclic reference" for linker
    firmenv.Prepend(
        _LIBFLAGS="-Wl,--start-group "
    )
    firmenv.Append(
        _LIBFLAGS=" -Wl,--end-group"
    )

    _srcbuild_flags = getenv("PLATFORMIO_SRCBUILD_FLAGS",
                             env.subst("$SRCBUILD_FLAGS"))
    if _srcbuild_flags:
        firmenv.MergeFlags(_srcbuild_flags)

    firmenv.Append(
        CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
            *pioversion_to_intstr())]
    )

    return firmenv.Program(
        join("$BUILD_DIR", "firmware"),
        [firmenv.GlobCXXFiles(vdir) for vdir in vdirs],
        LIBS=env.get("LIBS", []) + deplibs,
        LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"],
        PROGSUFFIX=".elf"
    )
Beispiel #5
0
def BuildProgram(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(
            AS="$CC",
            ASCOM="$ASPPCOM"
        )

    env.ProcessFlags([
        env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"),
        env.get("BUILD_FLAGS"),
        getenv("PLATFORMIO_BUILD_FLAGS"),
    ])
    env.BuildFramework()

    # build dependent libs
    deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env and
            not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(
            LINKFLAGS=["-Wl,-T", "$LDSCRIPT_PATH"]
        )

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs) and env.GetCompilerType() == "gcc":
        env.Prepend(
            _LIBFLAGS="-Wl,--start-group "
        )
        env.Append(
            _LIBFLAGS=" -Wl,--end-group"
        )

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags([
        env.get("SRC_BUILD_FLAGS", None),
        getenv("PLATFORMIO_SRC_BUILD_FLAGS"),
    ])

    env.Append(
        CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
            *pioversion_to_intstr())]
    )

    return env.Program(
        join("$BUILD_DIR", env.subst("$PROGNAME")),
        env.LookupSources(
            "$BUILDSRC_DIR", "$PROJECTSRC_DIR", duplicate=False,
            src_filter=getenv("PLATFORMIO_SRC_FILTER",
                              env.get("SRC_FILTER"))),
        LIBS=env.get("LIBS", []) + deplibs,
        LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"]
    )
Beispiel #6
0
def BuildFirmware(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(
            AS="$CC",
            ASCOM="$ASPPCOM"
        )

    env.ProcessFlags()
    env.BuildFramework()

    # build dependent libs
    deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env and
            not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(
            LINKFLAGS=["-Wl,-T", "$LDSCRIPT_PATH"]
        )

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs):
        env.Prepend(
            _LIBFLAGS="-Wl,--start-group "
        )
        env.Append(
            _LIBFLAGS=" -Wl,--end-group"
        )

    # Handle SRC_BUILD_FLAGS
    if getenv("PLATFORMIO_SRC_BUILD_FLAGS", None):
        env.MergeFlags(getenv("PLATFORMIO_SRC_BUILD_FLAGS"))
    if "SRC_BUILD_FLAGS" in env:
        env.MergeFlags(env['SRC_BUILD_FLAGS'])

    env.Append(
        CPPDEFINES=["PLATFORMIO={0:02d}{1:02d}{2:02d}".format(
            *pioversion_to_intstr())]
    )

    return env.Program(
        join("$BUILD_DIR", "firmware"),
        env.LookupSources(
            "$BUILDSRC_DIR", "$PROJECTSRC_DIR", duplicate=False,
            src_filter=getenv("PLATFORMIO_SRC_FILTER",
                              env.get("SRC_FILTER", None))),
        LIBS=env.get("LIBS", []) + deplibs,
        LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"],
        PROGSUFFIX=".elf"
    )
Beispiel #7
0
def BuildProgram(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    env.ProcessFlags([
        env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"),
        env.get("BUILD_FLAGS"),
        getenv("PLATFORMIO_BUILD_FLAGS"),
    ])

    if env.get("FRAMEWORK"):
        env.BuildFrameworks(
            [f.lower().strip() for f in env.get("FRAMEWORK", "").split(",")])

    # build dependent libs
    deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env
            and not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"'])

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs) and env.GetCompilerType() == "gcc":
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags([
        env.get("SRC_BUILD_FLAGS", None),
        getenv("PLATFORMIO_SRC_BUILD_FLAGS"),
    ])

    env.Append(CPPDEFINES=[
        "PLATFORMIO={0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())
    ],
               LIBS=deplibs,
               LIBPATH=["$BUILD_DIR"])

    sources = env.LookupSources("$BUILDSRC_DIR",
                                "$PROJECTSRC_DIR",
                                duplicate=False,
                                src_filter=getenv("PLATFORMIO_SRC_FILTER",
                                                  env.get("SRC_FILTER")))

    if not sources and not COMMAND_LINE_TARGETS:
        env.Exit("Error: Nothing to build. Please put your source code files "
                 "to '%s' folder" % env.subst("$PROJECTSRC_DIR"))

    return env.Program(join("$BUILD_DIR", env.subst("$PROGNAME")), sources)
Beispiel #8
0
def BuildFirmware(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    env.ProcessFlags()
    env.BuildFramework()

    firmenv = env.Clone()
    vdirs = firmenv.VariantDirRecursive(join("$BUILD_DIR", "src"),
                                        "$PROJECTSRC_DIR",
                                        duplicate=False)

    # build dependent libs
    deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if "LDSCRIPT_PATH" in firmenv:
        firmenv.Append(LINKFLAGS=["-T", "$LDSCRIPT_PATH"])

    # enable "cyclic reference" for linker
    firmenv.Prepend(_LIBFLAGS="-Wl,--start-group ")
    firmenv.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRCBUILD_FLAGS
    if getenv("PLATFORMIO_SRCBUILD_FLAGS", None):
        firmenv.MergeFlags(getenv("PLATFORMIO_SRCBUILD_FLAGS"))
    if "SRCBUILD_FLAGS" in env:
        firmenv.MergeFlags(env['SRCBUILD_FLAGS'])

    firmenv.Append(CPPDEFINES=[
        "PLATFORMIO={0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())
    ])

    if "envdump" in COMMAND_LINE_TARGETS:
        print env.Dump()
        Exit()

    if "idedata" in COMMAND_LINE_TARGETS:
        print json.dumps(env.DumpIDEData())
        Exit()

    return firmenv.Program(join("$BUILD_DIR", "firmware"),
                           [firmenv.GlobCXXFiles(vdir) for vdir in vdirs],
                           LIBS=env.get("LIBS", []) + deplibs,
                           LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"],
                           PROGSUFFIX=".elf")
Beispiel #9
0
def BuildFirmware(env):

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    env.ProcessFlags()
    env.BuildFramework()

    # build dependent libs
    deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env
            and not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(LINKFLAGS=["-Wl,-T", "$LDSCRIPT_PATH"])

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs):
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRC_BUILD_FLAGS
    if getenv("PLATFORMIO_SRC_BUILD_FLAGS", None):
        env.MergeFlags(getenv("PLATFORMIO_SRC_BUILD_FLAGS"))
    if "SRC_BUILD_FLAGS" in env:
        env.MergeFlags(env['SRC_BUILD_FLAGS'])

    env.Append(CPPDEFINES=[
        "PLATFORMIO={0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())
    ])

    return env.Program(join("$BUILD_DIR", "firmware"),
                       env.LookupSources("$BUILDSRC_DIR",
                                         "$PROJECTSRC_DIR",
                                         duplicate=False,
                                         src_filter=getenv(
                                             "PLATFORMIO_SRC_FILTER",
                                             env.get("SRC_FILTER", None))),
                       LIBS=env.get("LIBS", []) + deplibs,
                       LIBPATH=env.get("LIBPATH", []) + ["$BUILD_DIR"],
                       PROGSUFFIX=".elf")
def BuildProgram(env):
    def _append_pio_macros():
        env.AppendUnique(CPPDEFINES=[("PLATFORMIO",
                                      int("{0:02d}{1:02d}{2:02d}".format(
                                          *pioversion_to_intstr())))])

    _append_pio_macros()

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    if "__debug" in COMMAND_LINE_TARGETS:
        env.ProcessDebug()

    # process extra flags from board
    if "BOARD" in env and "build.extra_flags" in env.BoardConfig():
        env.ProcessFlags(env.BoardConfig().get("build.extra_flags"))
    # remove base flags
    env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))
    # apply user flags
    env.ProcessFlags(env.get("BUILD_FLAGS"))

    # process framework scripts
    env.BuildFrameworks(env.get("PIOFRAMEWORK"))

    # restore PIO macros if it was deleted by framework
    _append_pio_macros()

    # build dependent libs
    env.Append(LIBS=env.BuildProjectLibraries())

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env
            and not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"'])

    # enable "cyclic reference" for linker
    if env.get("LIBS") and env.GetCompilerType() == "gcc":
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))

    env.Append(LIBPATH=["$BUILD_DIR"],
               PIOBUILDFILES=env.CollectBuildFiles(
                   "$BUILDSRC_DIR",
                   "$PROJECTSRC_DIR",
                   src_filter=env.get("SRC_FILTER"),
                   duplicate=False))

    if "__test" in COMMAND_LINE_TARGETS:
        env.Append(PIOBUILDFILES=env.ProcessTest())

    if not env['PIOBUILDFILES'] and not COMMAND_LINE_TARGETS:
        sys.stderr.write(
            "Error: Nothing to build. Please put your source code files "
            "to '%s' folder\n" % env.subst("$PROJECTSRC_DIR"))
        env.Exit(1)

    program = env.Program(join("$BUILD_DIR", env.subst("$PROGNAME")),
                          env['PIOBUILDFILES'])

    checksize_action = Action(env.CheckUploadSize, "Checking program size")
    AlwaysBuild(env.Alias("checkprogsize", program, checksize_action))
    if set(["upload", "program"]) & set(COMMAND_LINE_TARGETS):
        env.AddPostAction(program, checksize_action)

    return program
Beispiel #11
0
def BuildProgram(env):
    def _append_pio_macros():
        env.AppendUnique(CPPDEFINES=[
            "PLATFORMIO={0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())
        ])

    _append_pio_macros()

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    # process extra flags from board
    env.ProcessFlags(
        env.get("BOARD_OPTIONS", {}).get("build", {}).get("extra_flags"))
    # remove base flags
    env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))
    # apply user flags
    env.ProcessFlags(env.get("BUILD_FLAGS"))

    if env.get("FRAMEWORK"):
        env.BuildFrameworks(
            [f.lower().strip() for f in env.get("FRAMEWORK", "").split(",")])

    # restore PIO macros if it was deleted by framework
    _append_pio_macros()

    # build dependent libs
    deplibs = env.BuildDependentLibraries("$PROJECTSRC_DIR")

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env
            and not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"'])

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs) and env.GetCompilerType() == "gcc":
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))

    env.Append(CPPPATH=["$PROJECTSRC_DIR"],
               LIBS=deplibs,
               LIBPATH=["$BUILD_DIR"])

    sources = env.LookupSources("$BUILDSRC_DIR",
                                "$PROJECTSRC_DIR",
                                duplicate=False,
                                src_filter=env.get("SRC_FILTER"))

    if not sources and not COMMAND_LINE_TARGETS:
        env.Exit("Error: Nothing to build. Please put your source code files "
                 "to '%s' folder" % env.subst("$PROJECTSRC_DIR"))

    program = env.Program(join("$BUILD_DIR", env.subst("$PROGNAME")), sources)

    if set(["upload", "uploadlazy", "program"]) & set(COMMAND_LINE_TARGETS):
        env.AddPostAction(program, env.CheckUploadSize)

    return program
Beispiel #12
0
def BuildProgram(env):

    def _append_pio_macros():
        env.AppendUnique(CPPDEFINES=[
            ("PLATFORMIO",
             int("{0:02d}{1:02d}{2:02d}".format(*pioversion_to_intstr())))
        ])

    _append_pio_macros()

    # fix ASM handling under non-casitive OS
    if not case_sensitive_suffixes(".s", ".S"):
        env.Replace(AS="$CC", ASCOM="$ASPPCOM")

    if "__debug" in COMMAND_LINE_TARGETS:
        env.ProcessDebug()

    # process extra flags from board
    if "BOARD" in env and "build.extra_flags" in env.BoardConfig():
        env.ProcessFlags(env.BoardConfig().get("build.extra_flags"))
    # remove base flags
    env.ProcessUnFlags(env.get("BUILD_UNFLAGS"))
    # apply user flags
    env.ProcessFlags(env.get("BUILD_FLAGS"))

    env.BuildFrameworks(env.get("PIOFRAMEWORK"))

    # restore PIO macros if it was deleted by framework
    _append_pio_macros()

    # build dependent libs
    deplibs = env.BuildProjectLibraries()

    # append specified LD_SCRIPT
    if ("LDSCRIPT_PATH" in env
            and not any(["-Wl,-T" in f for f in env['LINKFLAGS']])):
        env.Append(LINKFLAGS=['-Wl,-T"$LDSCRIPT_PATH"'])

    # enable "cyclic reference" for linker
    if env.get("LIBS", deplibs) and env.GetCompilerType() == "gcc":
        env.Prepend(_LIBFLAGS="-Wl,--start-group ")
        env.Append(_LIBFLAGS=" -Wl,--end-group")

    # Handle SRC_BUILD_FLAGS
    env.ProcessFlags(env.get("SRC_BUILD_FLAGS"))

    env.Append(
        LIBS=deplibs,
        LIBPATH=["$BUILD_DIR"],
        PIOBUILDFILES=env.CollectBuildFiles(
            "$BUILDSRC_DIR",
            "$PROJECTSRC_DIR",
            src_filter=env.get("SRC_FILTER"),
            duplicate=False))

    if "__test" in COMMAND_LINE_TARGETS:
        env.Append(PIOBUILDFILES=env.ProcessTest())

    if not env['PIOBUILDFILES'] and not COMMAND_LINE_TARGETS:
        sys.stderr.write(
            "Error: Nothing to build. Please put your source code files "
            "to '%s' folder\n" % env.subst("$PROJECTSRC_DIR"))
        env.Exit(1)

    program = env.Program(
        join("$BUILD_DIR", env.subst("$PROGNAME")), env['PIOBUILDFILES'])

    checksize_action = Action(env.CheckUploadSize, "Checking program size")
    AlwaysBuild(env.Alias("checkprogsize", program, checksize_action))
    if set(["upload", "program"]) & set(COMMAND_LINE_TARGETS):
        env.AddPostAction(program, checksize_action)

    return program