Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate armcc into scons

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to integrate armcc to scons", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to integrate armcc to scons" this article.

Integrate armcc into scons

Integrating armcc into scons is not an easy task. If you only modify a few environment variables of CC/CXX/AR/LINK, scons will be called with the parameters of Visual C++, such as-c becomes / c, causing armcc not to recognize it.

After spending half a day reading the source code of scons, I found in the SCons/Tool directory that each compiler has a plug-in-like tool. Visual inspection did not find armcc's tool. Writing a tool for armcc should solve this problem.

In the ToolsForFools article, you learned that you can define your own tool, as long as you put it in the project's site_scons/site_tools directory.

In order to support armcc, we create a tool of armcc in the site_scons/site_tools/armcc directory. It is troublesome to write a tool from scratch. Considering that armcc is similar to cc, copy the SCons/Tool/cc.py directly to site_scons/site_tools/armcc/__init__.py and modify it based on it.

After the following line of code

Add_common_cc_variables (env)

Add the following code:

Armcc = SCons.Tool.find_program_path (env, 'armcc.exe'); armar = SCons.Tool.find_program_path (env,' armar.exe'); armlink = SCons.Tool.find_program_path (env, 'armlink.exe') Env ['CC'] = armcc env [' CXX'] = armcc env ['AR'] = armar env [' LINK'] = armlink env ['CXXCOM'] =' $CC-o $TARGET-c $CFLAGS $CCFLAGS $_ CCCOMCOM $SOURCES' env ['ARFLAGS'] = SCons.Util.CLVar ('-create-r') env ['ARCOM'] =' $AR $ARFLAGS $TARGET $SOURCES' env [' OBJSUFFIX'] ='.o 'env [' LIBPREFIX'] = 'lib' env [' LIBSUFFIX'] ='.a'

Referring to the code in scons's Tool, in the SConstruct file, add the following code to enable the armcc we defined earlier:

Env = DefaultEnvironment (); SCons.Tool.Tool ('armcc') (env)

Compiling with scons works fine, but the following error occurs when armar generates .a files:

The command line is too long.

This is mainly due to the fact that there are too many .o files. Armar does not read parameters through @ match to the file as ar does, but armar can first create a .a file and then append .o files to it one by one.

From the source code of scons, it is found that the command is finally called in SCons/Platform/win32.py. But this is a system file, so it's not wise to modify it directly, so let's write a tool to solve this problem.

To avoid implementing it from scratch, copy the SCons/Platform/win32.py to site_scons/site_tools/win4armcc/__init__.py and then modify it.

First change the values of the following variables to:

Env ['OBJSUFFIX'] =' .o 'env [' LIBPREFIX'] = 'lib' env [' LIBSUFFIX'] ='.a'

Add an exists function

Def exists (env): return True

Reimplement the spawn function.

Def exe_ar (sh, cmd, args, env): armar = args [0] # args [1] is-create # args [2] is-r target = args [3] Objs = args [4:] for i in range (len (objs)): ARFLAGS='-r' if I = = 0: ARFLAGS='--create-r 'all_args= [armar, target, ARFLAGS, objs [I]] sargs =' .join (all_args) .replace ('\','/'); print (str (I) +':'+ sargs) Exec_spawn ([sh,'/ caching, sargs], env) def spawn (sh, escape, cmd, args, env): if cmd.endswith ('armar.exe'): exe_ar (sh, cmd, args, env); else: sargs =' .join (args) .replace ('\','/'); return exec_spawn ([sh,'/ cations, sargs], env)

Again, enable win4armcc in the SConstruct file.

SCons.Tool.Tool ('win4armcc') (env)

OK, now you can call armcc with scons.

The above is all the content of the article "how to integrate armcc into scons". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report