2013-09-06 21:54:27 +08:00
|
|
|
import os
|
2023-06-07 11:46:18 +08:00
|
|
|
import sys
|
2020-05-12 16:15:35 +08:00
|
|
|
import SCons.Tool.MSCommon.vc
|
2013-09-06 21:54:27 +08:00
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
# toolchains options
|
|
|
|
ARCH='sim'
|
2023-06-07 11:46:18 +08:00
|
|
|
ASAN = False
|
2013-03-02 18:39:05 +08:00
|
|
|
#CROSS_TOOL='msvc' or 'gcc' or 'mingw'
|
|
|
|
#'msvc' and 'mingw' are both for windows
|
|
|
|
# 'gcc' is for linux
|
2023-06-07 11:46:18 +08:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
CROSS_TOOL='msvc'
|
|
|
|
else:
|
|
|
|
CROSS_TOOL='gcc'
|
|
|
|
ASAN = True
|
2013-01-08 22:40:58 +08:00
|
|
|
|
2013-09-06 21:54:27 +08:00
|
|
|
if os.getenv('RTT_CC'):
|
|
|
|
CROSS_TOOL = os.getenv('RTT_CC')
|
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
# cross_tool provides the cross compiler
|
2013-01-24 17:24:31 +08:00
|
|
|
# EXEC_PATH is the compiler execute path
|
2013-09-07 15:01:28 +08:00
|
|
|
if CROSS_TOOL == 'gcc' or CROSS_TOOL == 'clang-analyze':
|
2013-01-24 17:24:31 +08:00
|
|
|
CPU = 'posix'
|
|
|
|
PLATFORM = 'gcc'
|
2023-06-07 11:46:18 +08:00
|
|
|
EXEC_PATH = '/usr/bin'
|
2013-01-08 22:40:58 +08:00
|
|
|
|
2013-02-26 16:03:08 +08:00
|
|
|
elif CROSS_TOOL == 'mingw':
|
|
|
|
CPU = 'win32'
|
|
|
|
PLATFORM = 'mingw'
|
|
|
|
EXEC_PATH = r'D:\Program Files\CodeBlocks\MinGW\bin'
|
|
|
|
|
|
|
|
elif CROSS_TOOL == 'msvc':
|
2013-01-24 17:24:31 +08:00
|
|
|
CPU = 'win32'
|
|
|
|
PLATFORM = 'cl'
|
|
|
|
EXEC_PATH = ''
|
2022-08-11 02:12:02 +08:00
|
|
|
try:
|
|
|
|
vc_version = ''
|
|
|
|
vc_versions = SCons.Tool.MSCommon.vc.get_installed_vcs()
|
|
|
|
if not vc_versions:
|
|
|
|
print("No vc version!")
|
2022-08-15 07:40:50 +08:00
|
|
|
exit(1)
|
2022-08-11 02:12:02 +08:00
|
|
|
else:
|
|
|
|
vc_version = vc_versions[0]
|
|
|
|
EXEC_PATH = SCons.Tool.MSCommon.vc.find_vc_pdir(vc_version)
|
|
|
|
if not EXEC_PATH:
|
|
|
|
print('Installed VC %s failure!' % vc_version)
|
2022-08-15 07:40:50 +08:00
|
|
|
exit(1)
|
2022-08-11 02:12:02 +08:00
|
|
|
else:
|
|
|
|
print('Successfully installed VC %s, path:%s' % (vc_version, EXEC_PATH))
|
|
|
|
except:
|
|
|
|
pass
|
2020-05-12 16:15:35 +08:00
|
|
|
|
2013-09-07 15:01:28 +08:00
|
|
|
else:
|
2021-10-29 02:23:07 +08:00
|
|
|
print("Simulator does not support this CROSS TOOL!")
|
2013-02-26 16:03:08 +08:00
|
|
|
exit(1)
|
|
|
|
|
2013-09-06 21:54:27 +08:00
|
|
|
if os.getenv('RTT_EXEC_PATH'):
|
|
|
|
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
|
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
BUILD = 'debug'
|
|
|
|
#BUILD = ''
|
|
|
|
|
|
|
|
if PLATFORM == 'gcc':
|
|
|
|
# toolchains
|
|
|
|
PREFIX = ''
|
|
|
|
CC = PREFIX + 'gcc'
|
|
|
|
AS = PREFIX + 'gcc'
|
|
|
|
AR = PREFIX + 'ar'
|
|
|
|
LINK = PREFIX + 'gcc'
|
2018-03-07 15:28:51 +08:00
|
|
|
TARGET_EXT = 'elf'
|
2013-01-08 22:40:58 +08:00
|
|
|
SIZE = PREFIX + 'size'
|
|
|
|
OBJDUMP = PREFIX + 'objdump'
|
|
|
|
OBJCPY = PREFIX + 'objcopy'
|
|
|
|
|
|
|
|
DEVICE = ' -ffunction-sections -fdata-sections'
|
2023-06-07 11:46:18 +08:00
|
|
|
# DEVICE = ' -m32 ' # open this when build 32bit target on 64bit PC
|
2018-03-03 16:34:01 +08:00
|
|
|
CFLAGS = DEVICE + ' -I/usr/include -w -D_REENTRANT -D_LINUX -DHAVE_SYS_SIGNALS'
|
2013-01-08 22:40:58 +08:00
|
|
|
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
|
2023-06-07 11:46:18 +08:00
|
|
|
# LFLAGS = DEVICE + ' -Wl,-Map=rtthread-linux.map -pthread -T gcc.ld' # open this when build 32bit target
|
|
|
|
LFLAGS = DEVICE + ' -Wl,-Map=rtthread-linux.map -pthread -T gcc_elf64.ld' # open this when build 64bit target
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
|
|
CPATH = ''
|
|
|
|
LPATH = ''
|
|
|
|
|
|
|
|
if BUILD == 'debug':
|
2013-01-22 16:57:47 +08:00
|
|
|
CFLAGS += ' -g -O0 -gdwarf-2'
|
2013-01-08 22:40:58 +08:00
|
|
|
AFLAGS += ' -gdwarf-2'
|
|
|
|
else:
|
|
|
|
CFLAGS += ' -O2'
|
|
|
|
|
2023-06-07 11:46:18 +08:00
|
|
|
if ASAN == True:
|
|
|
|
CFLAGS += ' -Wall -g -O0 -fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer -fsanitize=leak -fsanitize=undefined -fdiagnostics-color'
|
2013-01-24 13:06:12 +08:00
|
|
|
POST_ACTION = ''
|
2013-01-08 22:40:58 +08:00
|
|
|
|
2013-02-26 16:03:08 +08:00
|
|
|
elif PLATFORM == 'mingw':
|
2017-11-30 23:56:52 +08:00
|
|
|
# toolchains
|
2013-02-26 16:03:08 +08:00
|
|
|
PREFIX = ''
|
2017-10-20 13:26:47 +08:00
|
|
|
CC = PREFIX + 'gcc'
|
|
|
|
CXX = PREFIX + 'g++'
|
|
|
|
AS = PREFIX + 'gcc'
|
|
|
|
AR = PREFIX + 'ar'
|
|
|
|
LINK = PREFIX + 'g++'
|
2013-02-26 16:03:08 +08:00
|
|
|
TARGET_EXT = 'exe'
|
|
|
|
SIZE = PREFIX + 'size'
|
|
|
|
OBJDUMP = PREFIX + 'objdump'
|
|
|
|
OBJCPY = PREFIX + 'objcopy'
|
|
|
|
|
2017-10-20 13:26:47 +08:00
|
|
|
DEVICE = ''
|
|
|
|
CFLAGS = DEVICE + ' -D_Win32 -DNO_OLDNAMES -fno-pic -fno-builtin -fno-exceptions -fno-omit-frame-pointer'
|
|
|
|
|
2013-02-26 16:03:08 +08:00
|
|
|
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
|
2017-10-20 13:26:47 +08:00
|
|
|
LFLAGS = DEVICE + ' -static-libgcc -Wl,--gc-sections,-Map=rtthread-win32.map -T mingw.ld '
|
2013-02-26 16:03:08 +08:00
|
|
|
CPATH = ''
|
|
|
|
LPATH = ''
|
|
|
|
|
|
|
|
if BUILD == 'debug':
|
|
|
|
CFLAGS += ' -g -O0 -gdwarf-2'
|
|
|
|
AFLAGS += ' -gdwarf-2'
|
|
|
|
else:
|
|
|
|
CFLAGS += ' -O2'
|
|
|
|
|
2017-10-20 13:26:47 +08:00
|
|
|
CXXFLAGS = CFLAGS
|
2013-02-26 16:03:08 +08:00
|
|
|
POST_ACTION = ''
|
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
elif PLATFORM == 'cl':
|
|
|
|
# toolchains
|
|
|
|
PREFIX = ''
|
|
|
|
TARGET_EXT = 'exe'
|
|
|
|
AS = PREFIX + 'cl'
|
|
|
|
CC = PREFIX + 'cl'
|
|
|
|
AR = PREFIX + 'cl'
|
|
|
|
LINK = PREFIX + 'cl'
|
|
|
|
AFLAGS = ''
|
|
|
|
CFLAGS = ''
|
|
|
|
LFLAGS = ''
|
|
|
|
|
|
|
|
if BUILD == 'debug':
|
|
|
|
CFLAGS += ' /MTd'
|
|
|
|
LFLAGS += ' /DEBUG'
|
|
|
|
else:
|
|
|
|
CFLAGS += ' /MT'
|
|
|
|
LFLAGS += ''
|
|
|
|
|
2017-11-30 23:56:52 +08:00
|
|
|
CFLAGS += ' /Zi /Od /W 3 /WL /D_Win32'
|
2015-09-30 16:26:40 +08:00
|
|
|
LFLAGS += ' /SUBSYSTEM:CONSOLE /MACHINE:X86 /INCREMENTAL:NO'
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
|
|
CPATH = ''
|
|
|
|
LPATH = ''
|
|
|
|
|
|
|
|
POST_ACTION = ''
|