[Perfectly solved] scons problem for help: How to set the compilation output directory After figuring it out, some compiled output obj files are in the source code directory instead of the set output directory.

[Perfectly solved] scons problem for help: How to set the compilation output directory After figuring it out, some compiled output obj files are in the source code directory instead of the set output directory.

1 front background

Recently, based on the existing rt-thread construction framework, a new software architecture and construction has been transformed and designed. Based on the RA series of BSP, the construction method of scons is used to advance in the env environment of windows.

During this period, referring to the community post on how to specify the output directory in scons , it is basically possible to import the compiled output obj file to the compiled output directory instead of the original source code directory.

However, I found a case, taking bsp\renesas\ra2l1-cpk as an example, this problem also exists in its native rt-thread env construction process.

See below to execute the compilation of scons:

CC build\kernel\src\kservice.o
CC build\kernel\src\mem.o
CC build\kernel\src\mempool.o
CC build\kernel\src\object.o
CC build\kernel\src\scheduler.o
CC build\kernel\src\thread.o
CC build\kernel\src\timer.o
CC build\ra_gen\common_data.o
CC build\ra_gen\hal_data.o
CC build\ra_gen\main.o
CC build\ra_gen\pin_data.o
CC build\ra_gen\vector_data.o
CC build\src\hal_entry.o
CC ra\fsp\src\bsp\cmsis\Device\RENESAS\Source\startup.o
CC ra\fsp\src\bsp\cmsis\Device\RENESAS\Source\system.o
CC ra\fsp\src\bsp\mcu\all\bsp_clocks.o
CC ra\fsp\src\bsp\mcu\all\bsp_common.o
CC ra\fsp\src\bsp\mcu\all\bsp_delay.o
CC ra\fsp\src\bsp\mcu\all\bsp_group_irq.o
CC ra\fsp\src\bsp\mcu\all\bsp_guard.o
CC ra\fsp\src\bsp\mcu\all\bsp_io.o
CC ra\fsp\src\bsp\mcu\all\bsp_irq.o
CC ra\fsp\src\bsp\mcu\all\bsp_register_protection.o
CC ra\fsp\src\bsp\mcu\all\bsp_rom_registers.o
CC ra\fsp\src\bsp\mcu\all\bsp_sbrk.o
CC ra\fsp\src\bsp\mcu\all\bsp_security.o
CC ra\fsp\src\r_icu\r_icu.o
CC ra\fsp\src\r_ioport\r_ioport.o
CC ra\fsp\src\r_sci_uart\r_sci_uart.o
CC D:\llc\git_repos\rt-thread-share\rt-thread-share\rtt-5.0\rt-thread\bsp\renesas\libraries\HAL_Drivers\drv_common.o
CC D:\llc\git_repos\rt-thread-share\rt-thread-share\rtt-5.0\rt-thread\bsp\renesas\libraries\HAL_Drivers\drv_gpio.o
CC D:\llc\git_repos\rt-thread-share\rt-thread-share\rtt-5.0\rt-thread\bsp\renesas\libraries\HAL_Drivers\drv_usart_v2.o
D:\llc\git_repos\rt-thread-share\rt-thread-share\rtt-5.0\rt-thread\bsp\renesas\libraries\HAL_Drivers\drv_usart_v2.c: In function 'ra_uart_transmit':
D:\llc\git_repos\rt-thread-share\rt-thread-share\rtt-5.0\rt-thread\bsp\renesas\libraries\HAL_Drivers\drv_usart_v2.c:260:21: warning: variable 'uart' set but not used [-Wunused-but-set-variable]
  260 |     struct ra_uart *uart;
      |                     ^~~~
LINK rtthread.elf
arm-none-eabi-objcopy -O ihex rtthread.elf rtthread.hex
arm-none-eabi-size rtthread.elf
   text    data     bss     dec     hex filename
  87364    1592    4728   93684   16df4 rtthread.elf
scons: done building targets.

Pay attention to several obj files in the ra directory, such as ( CC ra\fsp\src\bsp\mcu\all\bsp_clocks.o ), the output is in the source code directory, and other directories at the same level as ra, such as ra_gen They are all stored in the build directory ( the build tool of rt-thread puts the obj file in the build directory by default ).

At first, I thought there was some difference between the SConscript file in the ra directory and the SConscript file in the ra_gen directory, but I read the content, and I really didn’t want to understand why the obj file compiled and output from the source code in the ra directory is in the source code directory. The source code of the ra_gen directory will not be like this.

SConscript file content of the bsp top-level directory:

# for module compiling
import os
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = []
CPPPATH = []
list = os.listdir(cwd)
if rtconfig.PLATFORM in ['iccarm']:
    print("\nThe current project does not support IAR build\n")
    Return('group')
elif rtconfig.PLATFORM in ['gcc', 'armclang']:
    if GetOption('target') != 'mdk5':
        CPPPATH = [cwd + './src']
        src = Glob('./src/*.c')
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
for d in list:
    path = os.path.join(cwd, d)
    if os.path.isfile(os.path.join(path, 'SConscript')):
        group = group + SConscript(os.path.join(d, 'SConscript'))
Return('group')

Contents of the SConscript file in the ra directory:

Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = []
group = []
CPPPATH = []
if rtconfig.PLATFORM in ['iccarm']:
    print("\nThe current project does not support IAR build\n")
    Return('group')
elif rtconfig.PLATFORM in ['gcc', 'armclang']:
    if GetOption('target') != 'mdk5':
        src += Glob(cwd + '/fsp/src/bsp/mcu/all/*.c')
        src += [cwd + '/fsp/src/bsp/cmsis/Device/RENESAS/Source/system.c']
        src += [cwd + '/fsp/src/bsp/cmsis/Device/RENESAS/Source/startup.c']
        src += Glob(cwd + '/fsp/src/r_*/*.c')
        CPPPATH = [ cwd + '/arm/CMSIS_5/CMSIS/Core/Include',
                    cwd + '/fsp/inc',
                    cwd + '/fsp/inc/api',
                    cwd + '/fsp/inc/instances',]
group = DefineGroup('ra', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
ra_gen目录下的SConscript文件内容:

Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = []
group = []
CPPPATH = []
if rtconfig.PLATFORM in ['iccarm']:
    print("\nThe current project does not support IAR build\n")
    Return('group')
elif rtconfig.PLATFORM in ['gcc', 'armclang']:
    if GetOption('target') != 'mdk5':
        src = Glob('*.c')
        CPPPATH = [cwd, ]
group = DefineGroup('ra_gen', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

The compiled output of the ra directory is stored in the source directory:
insert image description here

The compiled output of the ra_gen directory is stored in the build directory:
insert image description here

The directory structure of bsp looks roughly like this:
insert image description here

2 my question

I have a few questions about this:

  • Why is there such a difference between the ra directory and the ra_gen directory? And I found that these Renesas BSPs have similar problems
  • Is it the top-level SConscript file that determines the above phenomenon or is it caused by the SConscript file in the ra directory?
  • If you want to store the generated files in the ra directory in the build directory like the compilation in the ra_gen directory, how do you modify them?

If anyone knows the above questions, please give guidance, thank you very much.

3 Dial with one hand

As soon as the post was posted, I got advice from the boss:
insert image description here
insert image description here
At the same time, it also attracted heated discussions from the boss, including me participating in it. From the reply from the boss, I suddenly thought that it might be the problem of "absolute path and relative path".
insert image description here
insert image description here

insert image description here

4 problem solving

I'm very happy. After the advice of the big guys above, I basically confirmed that the SConscript file in the ra directory defined src using an absolute path instead of a relative path , which caused the problem.

Thanks again to the bosses for your advice, it really awakened the dreamer with one word. The power of the community is strong, and there are always gains with little intention!

At present, the problem has been solved, refer to the following records.

The modified place is the SConscript file in the ra directory :

screenshot_image.png

Modified compilation output:

screenshot_image.png

Verification of obj file generation:

screenshot_image.png

Perfectly handcrafted.

@recan

Guess you like

Origin blog.csdn.net/szullc/article/details/130957073