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

**URL:** https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278
**Category:** Usage
**Tags:** os:windows, gen:ninja
**Created:** [March 4, 2024, 2:22am UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278 "2024-03-04T02:22:55Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Bruce\_Ye](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@Bruce\_Ye](https://discourse.cmake.org/u/Bruce_Ye)
#### Post date: [March 4, 2024, 2:22am UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/1 "2024-03-04T02:22:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 10, 2024, 9:28pm UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/2 "2024-04-10T21:28:57Z")

</div>

How about this:

> [@Bruce\_Ye](#):
>
> set(CMAKE\_STRIP “gstrip”)  
> add\_custom\_command(TARGET ${target\_name}.elf POST\_BUILD  
> COMMAND ${CMAKE\_STRIP} -r=.debug\_frame “$\<TARGET\_FILE:${target\_name}.elf\>” )

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.

---

<div class="post-metadata">

### Author: ![Bruce\_Ye](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@Bruce\_Ye](https://discourse.cmake.org/u/Bruce_Ye)
#### Post date: [April 19, 2024, 2:08am UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/3 "2024-04-19T02:08:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bruce\_Ye](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@Bruce\_Ye](https://discourse.cmake.org/u/Bruce_Ye)
#### Post date: [April 19, 2024, 2:43am UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/4 "2024-04-19T02:43:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 19, 2024, 3:21pm UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/5 "2024-04-19T15:21:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Bruce\_Ye](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@Bruce\_Ye](https://discourse.cmake.org/u/Bruce_Ye)
#### Post date: [April 23, 2024, 7:31am UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/6 "2024-04-23T07:31:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 18, 2024, 12:49pm UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/7 "2024-05-18T12:49:21Z")

</div>

> [@Bruce\_Ye](#):
>
> ‘“gstrip”’ is not an internal or external command, nor is it a runnable program or batch file  
> ninja: build stopped

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

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [May 21, 2024, 11:12pm UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/8 "2024-05-21T23:12:31Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bruce\_Ye](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@Bruce\_Ye](https://discourse.cmake.org/u/Bruce_Ye)
#### Post date: [May 22, 2024, 8:05am UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/9 "2024-05-22T08:05:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bruce\_Ye](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@Bruce\_Ye](https://discourse.cmake.org/u/Bruce_Ye)
#### Post date: [May 22, 2024, 8:07am UTC](https://discourse.cmake.org/t/how-to-modify-the-makefile-post-build-gstrip-item-to-adapt-to-the-cmake-project/10278/10 "2024-05-22T08:07:52Z")

</div>

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