
from SCons.Script import AlwaysBuild, Default, DefaultEnvironment

from platformio.util import get_systype


env = DefaultEnvironment()

env.Replace(
    SIZEPRINTCMD="size $SOURCES",
    PROGSUFFIX=".exe"
)

if get_systype() == "darwin_x86_64":
    env.Replace(
        AR="i586-mingw32-ar",
        AS="i586-mingw32-as",
        CC="i586-mingw32-gcc",
        CXX="i586-mingw32-g++",
        OBJCOPY="i586-mingw32-objcopy",
        RANLIB="i586-mingw32-ranlib",
        SIZETOOL="i586-mingw32-size",
        SIZEPRINTCMD='"$SIZETOOL" $SOURCES'
    )

#
# Target: Build executable program
#

target_bin = env.BuildProgram()

#
# Target: Print binary size
#

target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Define targets
#

Default([target_bin])


from SCons.Script import AlwaysBuild, Default, DefaultEnvironment

from platformio.util import get_systype


env = DefaultEnvironment()

env.Replace(
    AR="$_MINGWPREFIX-ar",
    AS="$_MINGWPREFIX-as",
    CC="$_MINGWPREFIX-gcc",
    CXX="$_MINGWPREFIX-g++",
    OBJCOPY="$_MINGWPREFIX-objcopy",
    RANLIB="$_MINGWPREFIX-ranlib",
    SIZETOOL="$_MINGWPREFIX-size",

    SIZEPRINTCMD='"$SIZETOOL" $SOURCES',
    PROGSUFFIX=".exe"
)

if get_systype() == "darwin_x86_64":
    env.Replace(
        _MINGWPREFIX="i586-mingw32"
    )
elif get_systype() in ("linux_x86_64", "linux_i686"):
    env.Replace(
        _MINGWPREFIX="i686-w64-mingw32"
    )

#
# Target: Build executable program
#

target_bin = env.BuildProgram()

#
# Target: Print binary size
#

target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Define targets
#

Default([target_bin])

Add support for mingw-linux toolchains
Add support for mingw-linux toolchains

  
  from SCons.Script import AlwaysBuild, Default, DefaultEnvironment
  
  from platformio.util import get_systype
  
  
  env = DefaultEnvironment()
  
  env.Replace(
+     AR="$_MINGWPREFIX-ar",
+     AS="$_MINGWPREFIX-as",
+     CC="$_MINGWPREFIX-gcc",
+     CXX="$_MINGWPREFIX-g++",
+     OBJCOPY="$_MINGWPREFIX-objcopy",
+     RANLIB="$_MINGWPREFIX-ranlib",
+     SIZETOOL="$_MINGWPREFIX-size",
+ 
-     SIZEPRINTCMD="size $SOURCES",
+     SIZEPRINTCMD='"$SIZETOOL" $SOURCES',
      PROGSUFFIX=".exe"
  )
  
  if get_systype() == "darwin_x86_64":
      env.Replace(
-         AR="i586-mingw32-ar",
+         _MINGWPREFIX="i586-mingw32"
+     )
+ elif get_systype() in ("linux_x86_64", "linux_i686"):
+     env.Replace(
+         _MINGWPREFIX="i686-w64-mingw32"
-         AS="i586-mingw32-as",
-         CC="i586-mingw32-gcc",
-         CXX="i586-mingw32-g++",
-         OBJCOPY="i586-mingw32-objcopy",
-         RANLIB="i586-mingw32-ranlib",
-         SIZETOOL="i586-mingw32-size",
-         SIZEPRINTCMD='"$SIZETOOL" $SOURCES'
      )
  
  #
  # Target: Build executable program
  #
  
  target_bin = env.BuildProgram()
  
  #
  # Target: Print binary size
  #
  
  target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
  AlwaysBuild(target_size)
  
  #
  # Target: Define targets
  #
  
  Default([target_bin])
  
Add support for mingw-linux toolchains
## Code Before:

from SCons.Script import AlwaysBuild, Default, DefaultEnvironment

from platformio.util import get_systype


env = DefaultEnvironment()

env.Replace(
    SIZEPRINTCMD="size $SOURCES",
    PROGSUFFIX=".exe"
)

if get_systype() == "darwin_x86_64":
    env.Replace(
        AR="i586-mingw32-ar",
        AS="i586-mingw32-as",
        CC="i586-mingw32-gcc",
        CXX="i586-mingw32-g++",
        OBJCOPY="i586-mingw32-objcopy",
        RANLIB="i586-mingw32-ranlib",
        SIZETOOL="i586-mingw32-size",
        SIZEPRINTCMD='"$SIZETOOL" $SOURCES'
    )

#
# Target: Build executable program
#

target_bin = env.BuildProgram()

#
# Target: Print binary size
#

target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Define targets
#

Default([target_bin])

## Instruction:
Add support for mingw-linux toolchains
## Code After:

from SCons.Script import AlwaysBuild, Default, DefaultEnvironment

from platformio.util import get_systype


env = DefaultEnvironment()

env.Replace(
    AR="$_MINGWPREFIX-ar",
    AS="$_MINGWPREFIX-as",
    CC="$_MINGWPREFIX-gcc",
    CXX="$_MINGWPREFIX-g++",
    OBJCOPY="$_MINGWPREFIX-objcopy",
    RANLIB="$_MINGWPREFIX-ranlib",
    SIZETOOL="$_MINGWPREFIX-size",

    SIZEPRINTCMD='"$SIZETOOL" $SOURCES',
    PROGSUFFIX=".exe"
)

if get_systype() == "darwin_x86_64":
    env.Replace(
        _MINGWPREFIX="i586-mingw32"
    )
elif get_systype() in ("linux_x86_64", "linux_i686"):
    env.Replace(
        _MINGWPREFIX="i686-w64-mingw32"
    )

#
# Target: Build executable program
#

target_bin = env.BuildProgram()

#
# Target: Print binary size
#

target_size = env.Alias("size", target_bin, "$SIZEPRINTCMD")
AlwaysBuild(target_size)

#
# Target: Define targets
#

Default([target_bin])
