How to modify the makefile post build: gstrip item to adapt to the Cmake project

I am trying to build my project using Cmake to replace the work of the IDE(S32DS for GHS).

How to modify IDE makefile scripts to adapt to C make syntax?

post-build:
-gstrip -r=.debug_frame S32K344_DEMO_20.elf
-@echo ’ ’

Script statements are used to address: The GHS toolchain does not generate DWARF Call Frame information that is suitable for unwinding the call stack.

I have already tried the C make statement:

set(CMAKE_STRIP “-gstrip”)
add_custom_command(TARGET ${target_name}.elf POST_BUILD
COMMAND ${CMAKE_STRIP} -r=.debug_frame ${target_name}.elf )

Does anyone have similar experience and can you give me some advice? Thank you very much.

How about this:

The - prefix is a Makefile syntax that won’t work as a straight command in CMake. Then the other change is to use $<TARGET_FILE> instead of hoping that the command is executed in the same directory as the file.

Thank you for your suggestion. But it did not solve the problem as expected. Cmake error: ‘gstrip’ is not an internal or external command, nor is it a runnable program or batch file.

In S32DS IDE,during the compilation process, the statement works like this:

Building target: S32K344_DEMO_20.elf
Invoking: GHS C Linker for ARM Standalone
ccarm --gnu_asm -g -dwarf2 -T “D:/D/workpalce/S32k344/S32K344_DEMO_20/Projectcode/Mcal/Platform_TS_T40D34M10I0R0/build_files/ghs/linker_flash_s32k344.ld” -e Reset_Handler -nostartfiles -cpu=cortexm7 -thumb -o “S32K344_DEMO_20.elf” ./src/main.o ./RTOS/Platform/Arch_Extend.o ./RTOS/Platform/Arch_Irq.o

Finished building target: S32K344_DEMO_20.elf
gstrip -r=.debug_frame S32K344_DEMO_20.elf

Once again, I’m grateful for your support.

Can you please share the command line that is failing? Digging into the generated makefiles to find the actual written command would help too.

The following are command errors:

[121/121] Linking C executable S32K344.elf
FAILED: S32K344.elf
C:\Windows\system32\cmd.exe /C "cd . && D:\D\tools\ghs\comp_202114\ccarm.exe -preprocess_assembly_files -c99 --gnu_asm -g -dwarf2 -Onone -DSTART_FROM_FLASH -DS32K3XX -DENABLE_FPU -DLTC_ISOFT_CUSTOM -DINIT_STDBY_RAM -DARMCM7_SP -D__ITCM_INIT -D__DTCM_INIT -D__ghs__ -DGEELY_SPECIFICATION_USED=1 -DDISABLE_MCAL_INTERMODULE_ASR_CHECK -DBTB_ENABLE -DUSING_OS_AUTOSAROS -DS32K344 -DGHS -cpu=cortexm7 -fsingle -thumb -MD -Odebug -g --gnu_asm -g -dwarf2 -nostartfiles -cpu=cortexm7 -thumb -T …/src/McalLib/Mcal_lib/Platform_TS_T40D34M10I0R0/build_files/ghs/linker_flash_s32k344.ld -e Reset_Handler @CMakeFiles\S32K344.elf.rsp -o S32K344.elf && C:\Windows\system32\cmd.exe /C “cd /D D:\D\workpalce\S32k344\S32K344_Cmake\02_ProjectCode\00_OS_Project\S32K344_CMake\build && 鈥済strip鈥?-r=.debug_frame 鈥淒:/D/workpalce/S32k344/S32K344_Cmake/02_ProjectCode/00_OS_Project/S32K344_CMake/build/S32K344.elf鈥?”
‘“gstrip”’ is not an internal or external command, nor is it a runnable program or batch file
ninja: build stopped

I also tried to modify CMAKE-STRIP to “strip” and “- gstrip”, but it also failed
The following is the makefile file generated by S32DS IDE:
################################################################################

Automatically-generated file. Do not edit!

################################################################################
-include …/makefile.init

RM := rm -f

All of the sources participating in the build are defined here

-include sources.mk
-include src/subdir.mk
-include RTOS/Platform/subdir.mk
-include RTOS/Kernel/subdir.mk
-include RTOS/Extend/subdir.mk
-include Projectcode/Mcal_config/src/subdir.mk
-include Projectcode/Mcal/Rte_TS_T40D34M10I0R0/src/subdir.mk
-include Projectcode/Mcal/Platform_TS_T40D34M10I0R0/startup/src/m7/ghs/subdir.mk
-include Projectcode/Mcal/Platform_TS_T40D34M10I0R0/startup/src/m7/subdir.mk
-include Projectcode/Mcal/Platform_TS_T40D34M10I0R0/startup/src/subdir.mk
-include Projectcode/Mcal/Platform_TS_T40D34M10I0R0/src/subdir.mk
-include Projectcode/Mcal/Mcu_TS_T40D34M10I0R0/src/subdir.mk
-include Projectcode/Mcal/Det_TS_T40D34M10I0R0/src/subdir.mk
-include Projectcode/Mcal/Base_TS_T40D34M10I0R0/src/subdir.mk
-include Projectcode/BSW_Config/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(THM_DEPS)),)
-include $(THM_DEPS)
endif
ifneq ($(strip $(S_DEPS)),)
-include $(S_DEPS)
endif
ifneq ($(strip $(ARM_DEPS)),)
-include $(ARM_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

-include …/makefile.defs

OPTIONAL_TOOL_DEPS :=
$(wildcard …/makefile.defs)
$(wildcard …/makefile.init)
$(wildcard …/makefile.targets) \

BUILD_ARTIFACT_NAME := S32K344_DEMO_20
BUILD_ARTIFACT_EXTENSION := elf
BUILD_ARTIFACT_PREFIX :=
BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),)

Add inputs and outputs from these tool invocations to the build variables

All Target

all:
+@$(MAKE) --no-print-directory main-build && $(MAKE) --no-print-directory post-build

Main-build Target

main-build: S32K344_DEMO_20.elf

Tool invocations

S32K344_DEMO_20.elf: $(OBJS) $(LD_SRCS) makefile objects.mk $(OPTIONAL_TOOL_DEPS)
@echo ‘Building target: $@’
@echo ‘Invoking: GHS C Linker for ARM Standalone’
ccarm --gnu_asm -g -dwarf2 -T “D:/D/workpalce/S32k344/S32K344_DEMO_20/Projectcode/Mcal/Platform_TS_T40D34M10I0R0/build_files/ghs/linker_flash_s32k344.ld” -e Reset_Handler -nostartfiles -cpu=cortexm7 -thumb -o “S32K344_DEMO_20.elf” $(OBJS) $(LD_SRCS)
@echo ‘Finished building target: $@’
@echo ’ ’

Other Targets

clean:
-$(RM) $(EXECUTABLES)$(OBJS)$(THM_DEPS)$(S_DEPS)$(ARM_DEPS)$(S_UPPER_DEPS)$(C_DEPS) S32K344_DEMO_20.elf
-@echo ’ ’

post-build:
-gstrip -r=.debug_frame S32K344_DEMO_20.elf
-@echo ’ ’

.PHONY: all clean dependents post-build

-include …/makefile.targets

There are quotes somewhere they shouldn’t be. It is looking for a file named "gstrip" in PATH.

1 Like

In make syntax a leading - is used to ignore the exit code of a command line.
So the program to use, is definitely gstrip.

The IDE adds one ore more path variables, so the program can be found when it calls its make.
You can see in your log, that it simply calls ccarm without absolute path.

So you need to search for the gstrip executable, or give it an absolute path. It’s most likely in the same path as your ccarm, but may be in a different utility directory. I would suggest to do it similarly as you specify the compiler.

1 Like

I have searched for the gstrip executable, give it an absolute path, like this:

set(CMAKE_STRIP “D:/D/tools/ghs/comp_202114/gstrip.exe”)
add_custom_command(TARGET ${target_name}.elf POST_BUILD
COMMAND ${CMAKE_STRIP} -r=.debug_frame “$<TARGET_FILE:${target_name}.elf>” )

Now, it wroks. Thank you for your help.

I did not specify the correct path for gstrip. After modification, it wroks. Thank you for your help.